2 * Copyright (c) 2011 The Chromium OS Authors.
3 * (C) Copyright 2002-2006
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
7 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
8 * Marius Groeger <mgroeger@sysgo.de>
10 * See file CREDITS for list of people who contributed to this
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License as
15 * published by the Free Software Foundation; either version 2 of
16 * the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
30 /* TODO: can we just include all these headers whether needed or not? */
31 #if defined(CONFIG_CMD_BEDBUG)
32 #include <bedbug/type.h>
34 #ifdef CONFIG_HAS_DATAFLASH
35 #include <dataflash.h>
37 #include <environment.h>
39 #if defined(CONFIG_CMD_IDE)
46 #if defined(CONFIG_CMD_KGDB)
51 #ifdef CONFIG_BITBANGMII
56 #include <onenand_uboot.h>
60 #include <stdio_dev.h>
62 #ifdef CONFIG_ADDR_MAP
65 #include <asm/sections.h>
67 #include <asm/init_helpers.h>
69 #include <linux/compiler.h>
71 DECLARE_GLOBAL_DATA_PTR;
73 ulong monitor_flash_len;
75 int __board_flash_wp_on(void)
78 * Most flashes can't be detected when write protection is enabled,
79 * so provide a way to let U-Boot gracefully ignore write protected
85 int board_flash_wp_on(void)
86 __attribute__ ((weak, alias("__board_flash_wp_on")));
88 void __cpu_secondary_init_r(void)
92 void cpu_secondary_init_r(void)
93 __attribute__ ((weak, alias("__cpu_secondary_init_r")));
95 static int initr_secondary_cpu(void)
98 * after non-volatile devices & environment is setup and cpu code have
99 * another round to deal with any initialization that might require
100 * full access to the environment or loading of some image (firmware)
101 * from a non-volatile device
103 /* TODO: maybe define this for all archs? */
104 cpu_secondary_init_r();
109 static int initr_reloc(void)
111 gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
112 bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_R, "board_init_r");
119 * Some of these functions are needed purely because the functions they
120 * call return void. If we change them to return 0, these stubs can go away.
122 static int initr_caches(void)
130 __weak int fixup_cpu(void)
135 static int initr_reloc_global_data(void)
137 #ifdef CONFIG_SYS_SYM_OFFSETS
138 monitor_flash_len = _end_ofs;
139 #elif !defined(CONFIG_SANDBOX)
140 monitor_flash_len = (ulong)&__init_end - gd->relocaddr;
142 #if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx)
144 * The gd->cpu pointer is set to an address in flash before relocation.
145 * We need to update it to point to the same CPU entry in RAM.
146 * TODO: why not just add gd->reloc_ofs?
148 gd->arch.cpu += gd->relocaddr - CONFIG_SYS_MONITOR_BASE;
151 * If we didn't know the cpu mask & # cores, we can save them of
152 * now rather than 'computing' them constantly
156 #ifdef CONFIG_SYS_EXTRA_ENV_RELOC
158 * Some systems need to relocate the env_addr pointer early because the
159 * location it points to will get invalidated before env_relocate is
160 * called. One example is on systems that might use a L2 or L3 cache
161 * in SRAM mode and initialize that cache from SRAM mode back to being
162 * a cache in cpu_init_r.
164 gd->env_addr += gd->relocaddr - CONFIG_SYS_MONITOR_BASE;
169 static int initr_serial(void)
176 static int initr_trap(void)
179 * Setup trap handlers
181 trap_init(gd->relocaddr);
187 #ifdef CONFIG_ADDR_MAP
188 static int initr_addr_map(void)
196 #ifdef CONFIG_LOGBUFFER
197 unsigned long logbuffer_base(void)
199 return gd->ram_top - LOGBUFF_LEN;
202 static int initr_logbuffer(void)
210 static int initr_post_backlog(void)
212 post_output_backlog();
217 #ifdef CONFIG_SYS_DELAYED_ICACHE
218 static int initr_icache_enable(void)
224 #if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500)
225 static int initr_unlock_ram_in_cache(void)
227 unlock_ram_in_cache(); /* it's time to unlock D-cache in e500 */
233 static int initr_pci(void)
241 #ifdef CONFIG_WINBOND_83C553
242 static int initr_w83c553f(void)
245 * Initialise the ISA bridge
247 initialise_w83c553f();
252 static int initr_barrier(void)
255 /* TODO: Can we not use dmb() macros for this? */
261 static int initr_malloc(void)
265 /* The malloc area is immediately below the monitor copy in DRAM */
266 malloc_start = gd->relocaddr - TOTAL_MALLOC_LEN;
267 mem_malloc_init((ulong)map_sysmem(malloc_start, TOTAL_MALLOC_LEN),
272 __weak int power_init_board(void)
277 static int initr_announce(void)
279 debug("Now running in RAM - U-Boot at: %08lx\n", gd->relocaddr);
283 #if !defined(CONFIG_SYS_NO_FLASH)
284 static int initr_flash(void)
286 ulong flash_size = 0;
292 if (board_flash_wp_on()) {
293 printf("Uninitialized - Write Protect On\n");
294 /* Since WP is on, we can't find real size. Set to 0 */
297 flash_size = flash_init();
301 puts("*** failed ***\n");
303 /* Why does PPC do this? */
308 print_size(flash_size, "");
309 #ifdef CONFIG_SYS_FLASH_CHECKSUM
311 * Compute and print flash CRC if flashchecksum is set to 'y'
313 * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
315 if (getenv_yesno("flashchecksum") == 1) {
316 printf(" CRC: %08X", crc32(0,
317 (const unsigned char *) CONFIG_SYS_FLASH_BASE,
320 #endif /* CONFIG_SYS_FLASH_CHECKSUM */
323 /* update start of FLASH memory */
324 #ifdef CONFIG_SYS_FLASH_BASE
325 bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
327 /* size of FLASH memory (final value) */
328 bd->bi_flashsize = flash_size;
330 #if defined(CONFIG_SYS_UPDATE_FLASH_SIZE)
331 /* Make a update of the Memctrl. */
332 update_flash_size(flash_size);
336 #if defined(CONFIG_OXC) || defined(CONFIG_RMU)
337 /* flash mapped at end of memory map */
338 bd->bi_flashoffset = CONFIG_SYS_TEXT_BASE + flash_size;
339 #elif CONFIG_SYS_MONITOR_BASE == CONFIG_SYS_FLASH_BASE
340 bd->bi_flashoffset = monitor_flash_len; /* reserved area for monitor */
347 static int initr_spi(void)
349 /* PPC does this here */
351 #if !defined(CONFIG_ENV_IS_IN_EEPROM)
360 #ifdef CONFIG_CMD_NAND
361 /* go init the NAND */
370 #if defined(CONFIG_CMD_ONENAND)
371 /* go init the NAND */
372 int initr_onenand(void)
380 #ifdef CONFIG_GENERIC_MMC
384 mmc_initialize(gd->bd);
389 #ifdef CONFIG_HAS_DATAFLASH
390 int initr_dataflash(void)
392 AT91F_DataflashInit();
393 dataflash_print_info();
399 * Tell if it's OK to load the environment early in boot.
401 * If CONFIG_OF_CONFIG is defined, we'll check with the FDT to see
402 * if this is OK (defaulting to saying it's OK).
404 * NOTE: Loading the environment early can be a bad idea if security is
405 * important, since no verification is done on the environment.
407 * @return 0 if environment should not be loaded, !=0 if it is ok to load
409 static int should_load_env(void)
411 #ifdef CONFIG_OF_CONTROL
412 return fdtdec_get_config_int(gd->fdt_blob, "load-environment", 1);
413 #elif defined CONFIG_DELAY_ENVIRONMENT
420 static int initr_env(void)
422 /* initialize environment */
423 if (should_load_env())
426 set_default_env(NULL);
428 /* Initialize from environment */
429 load_addr = getenv_ulong("loadaddr", 16, load_addr);
430 #if defined(CONFIG_SYS_EXTBDINFO)
431 #if defined(CONFIG_405GP) || defined(CONFIG_405EP)
432 #if defined(CONFIG_I2CFAST)
434 * set bi_iic_fast for linux taking environment variable
435 * "i2cfast" into account
438 char *s = getenv("i2cfast");
440 if (s && ((*s == 'y') || (*s == 'Y'))) {
441 gd->bd->bi_iic_fast[0] = 1;
442 gd->bd->bi_iic_fast[1] = 1;
445 #endif /* CONFIG_I2CFAST */
446 #endif /* CONFIG_405GP, CONFIG_405EP */
447 #endif /* CONFIG_SYS_EXTBDINFO */
452 static int initr_hermes(void)
454 if ((gd->board_type >> 16) == 2)
455 gd->bd->bi_ethspeed = gd->board_type & 0xFFFF;
457 gd->bd->bi_ethspeed = 0xFFFF;
461 static int initr_hermes_start(void)
463 if (gd->bd->bi_ethspeed != 0xFFFF)
464 hermes_start_lxt980((int) gd->bd->bi_ethspeed);
470 /* TODO: with new initcalls, move this into the driver */
471 extern void sc3_read_eeprom(void);
473 static int initr_sc3_read_eeprom(void)
480 static int initr_jumptable(void)
486 #if defined(CONFIG_API)
487 static int initr_api(void)
495 #ifdef CONFIG_DISPLAY_BOARDINFO_LATE
496 static int show_model_r(void)
498 /* Put this here so it appears on the LCD, now it is ready */
499 # ifdef CONFIG_OF_CONTROL
502 model = (char *)fdt_getprop(gd->fdt_blob, 0, "model", NULL);
503 printf("Model: %s\n", model ? model : "<unknown>");
510 /* enable exceptions */
512 static int initr_enable_interrupts(void)
519 #ifdef CONFIG_CMD_NET
520 static int initr_ethaddr(void)
524 /* kept around for legacy kernels only ... ignore the next section */
525 eth_getenv_enetaddr("ethaddr", bd->bi_enetaddr);
526 #ifdef CONFIG_HAS_ETH1
527 eth_getenv_enetaddr("eth1addr", bd->bi_enet1addr);
529 #ifdef CONFIG_HAS_ETH2
530 eth_getenv_enetaddr("eth2addr", bd->bi_enet2addr);
532 #ifdef CONFIG_HAS_ETH3
533 eth_getenv_enetaddr("eth3addr", bd->bi_enet3addr);
535 #ifdef CONFIG_HAS_ETH4
536 eth_getenv_enetaddr("eth4addr", bd->bi_enet4addr);
538 #ifdef CONFIG_HAS_ETH5
539 eth_getenv_enetaddr("eth5addr", bd->bi_enet5addr);
543 #endif /* CONFIG_CMD_NET */
545 #ifdef CONFIG_CMD_KGDB
546 static int initr_kgdb(void)
554 #if defined(CONFIG_STATUS_LED) && defined(STATUS_LED_BOOT)
555 static int initr_status_led(void)
557 status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING);
563 #if defined(CONFIG_CMD_SCSI)
564 static int initr_scsi(void)
566 /* Not supported properly on ARM yet */
574 #endif /* CONFIG_CMD_NET */
576 #if defined(CONFIG_CMD_DOC)
577 static int initr_doc(void)
584 #ifdef CONFIG_BITBANGMII
585 static int initr_bbmii(void)
592 #ifdef CONFIG_CMD_NET
593 static int initr_net(void)
596 eth_initialize(gd->bd);
597 #if defined(CONFIG_RESET_PHY_R)
598 debug("Reset Ethernet PHY\n");
606 static int initr_post(void)
608 post_run(NULL, POST_RAM | post_bootmode_get(0));
613 #if defined(CONFIG_CMD_PCMCIA) && !defined(CONFIG_CMD_IDE)
614 static int initr_pcmcia(void)
622 #if defined(CONFIG_CMD_IDE)
623 static int initr_ide(void)
625 #ifdef CONFIG_IDE_8xx_PCCARD
630 #if defined(CONFIG_START_IDE)
631 if (board_start_ide())
640 #if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
642 * Export available size of memory for Linux, taking into account the
643 * protected RAM at top of memory
651 pram = getenv_ulong("pram", 10, CONFIG_PRAM);
653 # if defined(CONFIG_LOGBUFFER) && !defined(CONFIG_ALT_LB_ADDR)
654 /* Also take the logbuffer into account (pram is in kB) */
655 pram += (LOGBUFF_LEN + LOGBUFF_OVERHEAD) / 1024;
657 sprintf(memsz, "%ldk", (gd->ram_size / 1024) - pram);
658 setenv("mem", memsz);
664 #ifdef CONFIG_CMD_BEDBUG
665 static int initr_bedbug(void)
674 static int initr_kbd(void)
682 #ifdef CONFIG_MODEM_SUPPORT
683 static int initr_modem(void)
685 /* TODO: with new initcalls, move this into the driver */
686 extern int do_mdm_init;
688 do_mdm_init = gd->do_mdm_init;
693 static int run_main_loop(void)
695 #ifdef CONFIG_SANDBOX
696 sandbox_main_loop_init();
698 /* main_loop() can return to retry autoboot, if so just run it again */
705 * Over time we hope to remove these functions with code fragments and
706 * stub funtcions, and instead call the relevant function directly.
708 * We also hope to remove most of the driver-related init and do it if/when
709 * the driver is later used.
711 * TODO: perhaps reset the watchdog in the initcall function after each call?
713 init_fnc_t init_sequence_r[] = {
715 /* TODO: could x86/PPC have this also perhaps? */
718 board_init, /* Setup chipselects */
721 * TODO: printing of the clock inforamtion of the board is now
722 * implemented as part of bdinfo command. Currently only support for
723 * davinci SOC's is added. Remove this check once all the board
727 set_cpu_clk_info, /* Setup clock information */
729 initr_reloc_global_data,
732 INIT_FUNC_WATCHDOG_RESET
736 #ifdef CONFIG_ADDR_MAP
739 #if defined(CONFIG_BOARD_EARLY_INIT_R)
742 INIT_FUNC_WATCHDOG_RESET
743 #ifdef CONFIG_LOGBUFFER
749 INIT_FUNC_WATCHDOG_RESET
750 #ifdef CONFIG_SYS_DELAYED_ICACHE
753 #if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500)
754 initr_unlock_ram_in_cache,
756 #if defined(CONFIG_PCI) && defined(CONFIG_SYS_EARLY_PCI_INIT)
758 * Do early PCI configuration _before_ the flash gets initialised,
759 * because PCU ressources are crucial for flash access on some boards.
763 #ifdef CONFIG_WINBOND_83C553
769 #ifdef CONFIG_ARCH_EARLY_INIT_R
773 #ifndef CONFIG_SYS_NO_FLASH
776 INIT_FUNC_WATCHDOG_RESET
777 #if defined(CONFIG_PPC) || defined(CONFIG_X86)
778 /* initialize higher level parts of CPU like time base and timers */
784 #if defined(CONFIG_X86) && defined(CONFIG_SPI)
787 #ifdef CONFIG_CMD_NAND
790 #ifdef CONFIG_CMD_ONENAND
793 #ifdef CONFIG_GENERIC_MMC
796 #ifdef CONFIG_HAS_DATAFLASH
800 INIT_FUNC_WATCHDOG_RESET
803 initr_sc3_read_eeprom,
808 #if defined(CONFIG_ID_EEPROM) || defined(CONFIG_SYS_I2C_MAC_OFFSET)
809 mac_read_from_eeprom,
811 INIT_FUNC_WATCHDOG_RESET
812 #if defined(CONFIG_PCI) && !defined(CONFIG_SYS_EARLY_PCI_INIT)
814 * Do pci configuration
823 console_init_r, /* fully init console as a device */
824 #ifdef CONFIG_DISPLAY_BOARDINFO_LATE
827 #ifdef CONFIG_ARCH_MISC_INIT
828 arch_misc_init, /* miscellaneous arch-dependent init */
830 #ifdef CONFIG_MISC_INIT_R
831 misc_init_r, /* miscellaneous platform-dependent init */
836 INIT_FUNC_WATCHDOG_RESET
837 #ifdef CONFIG_CMD_KGDB
844 #if defined(CONFIG_ARM) || defined(CONFIG_x86)
845 initr_enable_interrupts,
848 timer_init, /* initialize timer */
850 #if defined(CONFIG_STATUS_LED) && defined(STATUS_LED_BOOT)
853 /* PPC has a udelay(20) here dating from 2002. Why? */
854 #ifdef CONFIG_CMD_NET
857 #ifdef CONFIG_BOARD_LATE_INIT
860 #ifdef CONFIG_CMD_SCSI
861 INIT_FUNC_WATCHDOG_RESET
864 #ifdef CONFIG_CMD_DOC
865 INIT_FUNC_WATCHDOG_RESET
868 #ifdef CONFIG_BITBANGMII
871 #ifdef CONFIG_CMD_NET
872 INIT_FUNC_WATCHDOG_RESET
878 #if defined(CONFIG_CMD_PCMCIA) && !defined(CONFIG_CMD_IDE)
881 #if defined(CONFIG_CMD_IDE)
884 #ifdef CONFIG_LAST_STAGE_INIT
885 INIT_FUNC_WATCHDOG_RESET
887 * Some parts can be only initialized if all others (like
888 * Interrupts) are up and running (i.e. the PC-style ISA
893 #ifdef CONFIG_CMD_BEDBUG
894 INIT_FUNC_WATCHDOG_RESET
897 #if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
903 #ifdef CONFIG_MODEM_SUPPORT
909 void board_init_r(gd_t *new_gd, ulong dest_addr)
914 if (initcall_run_list(init_sequence_r))
917 /* NOTREACHED - run_main_loop() does not return */