2 * (C) Copyright 2002-2006
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
6 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
7 * Marius Groeger <mgroeger@sysgo.de>
9 * See file CREDITS for list of people who contributed to this
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of
15 * the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 * To match the U-Boot user interface on ARM platforms to the U-Boot
30 * standard (as on PPC platforms), some messages with debug character
31 * are removed from the default U-Boot build.
33 * Define DEBUG here if you want additional info as shown below
34 * printed upon startup:
36 * U-Boot code: 00F00000 -> 00F3C774 BSS: -> 00FC3274
44 #include <stdio_dev.h>
45 #include <timestamp.h>
50 #include <onenand_uboot.h>
53 #ifdef CONFIG_BITBANGMII
57 #ifdef CONFIG_DRIVER_SMC91111
58 #include "../drivers/net/smc91111.h"
60 #ifdef CONFIG_DRIVER_LAN91C96
61 #include "../drivers/net/lan91c96.h"
64 DECLARE_GLOBAL_DATA_PTR;
66 ulong monitor_flash_len;
68 #ifdef CONFIG_HAS_DATAFLASH
69 extern int AT91F_DataflashInit(void);
70 extern void dataflash_print_info(void);
73 #ifndef CONFIG_IDENT_STRING
74 #define CONFIG_IDENT_STRING ""
77 const char version_string[] =
78 U_BOOT_VERSION" (" U_BOOT_DATE " - " U_BOOT_TIME ")"CONFIG_IDENT_STRING;
80 #ifdef CONFIG_DRIVER_RTL8019
81 extern void rtl8019_get_enetaddr (uchar * addr);
84 #if defined(CONFIG_HARD_I2C) || \
85 defined(CONFIG_SOFT_I2C)
90 /************************************************************************
91 * Coloured LED functionality
92 ************************************************************************
93 * May be supplied by boards if desired
95 void inline __coloured_LED_init (void) {}
96 void coloured_LED_init (void) __attribute__((weak, alias("__coloured_LED_init")));
97 void inline __red_LED_on (void) {}
98 void red_LED_on (void) __attribute__((weak, alias("__red_LED_on")));
99 void inline __red_LED_off(void) {}
100 void red_LED_off(void) __attribute__((weak, alias("__red_LED_off")));
101 void inline __green_LED_on(void) {}
102 void green_LED_on(void) __attribute__((weak, alias("__green_LED_on")));
103 void inline __green_LED_off(void) {}
104 void green_LED_off(void) __attribute__((weak, alias("__green_LED_off")));
105 void inline __yellow_LED_on(void) {}
106 void yellow_LED_on(void) __attribute__((weak, alias("__yellow_LED_on")));
107 void inline __yellow_LED_off(void) {}
108 void yellow_LED_off(void) __attribute__((weak, alias("__yellow_LED_off")));
109 void inline __blue_LED_on(void) {}
110 void blue_LED_on(void) __attribute__((weak, alias("__blue_LED_on")));
111 void inline __blue_LED_off(void) {}
112 void blue_LED_off(void) __attribute__((weak, alias("__blue_LED_off")));
114 extern int boot_pwr_check(void);
115 /************************************************************************
117 ************************************************************************
118 * Some of this code should be moved into the core functions,
119 * or dropped completely,
120 * but let's get it working (again) first...
123 #if defined(CONFIG_ARM_DCC) && !defined(CONFIG_BAUDRATE)
124 #define CONFIG_BAUDRATE 115200
126 static int init_baudrate (void)
128 char tmp[64]; /* long enough for environment variables */
129 int i = getenv_f("baudrate", tmp, sizeof (tmp));
131 gd->baudrate = (i > 0)
132 ? (int) simple_strtoul (tmp, NULL, 10)
138 static int display_banner (void)
140 printf ("\n\n%s\n\n", version_string);
141 debug ("U-Boot code: %08lX -> %08lX BSS: -> %08lX\n",
143 _bss_start_ofs+_TEXT_BASE, _bss_end_ofs+_TEXT_BASE);
144 #ifdef CONFIG_MODEM_SUPPORT
145 debug ("Modem Support enabled\n");
147 #ifdef CONFIG_USE_IRQ
148 debug ("IRQ Stack: %08lx\n", IRQ_STACK_START);
149 debug ("FIQ Stack: %08lx\n", FIQ_STACK_START);
156 * WARNING: this code looks "cleaner" than the PowerPC version, but
157 * has the disadvantage that you either get nothing, or everything.
158 * On PowerPC, you might see "DRAM: " before the system hangs - which
159 * gives a simple yet clear indication which part of the
160 * initialization if failing.
162 static int display_dram_config (void)
167 puts ("RAM Configuration:\n");
169 for(i=0; i<CONFIG_NR_DRAM_BANKS; i++) {
170 printf ("Bank #%d: %08lx ", i, gd->bd->bi_dram[i].start);
171 print_size (gd->bd->bi_dram[i].size, "\n");
176 for (i=0; i<CONFIG_NR_DRAM_BANKS; i++) {
177 size += gd->bd->bi_dram[i].size;
180 print_size(size, "\n");
186 #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
187 static int init_func_i2c (void)
190 i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
196 #if defined(CONFIG_CMD_PCI) || defined (CONFIG_PCI)
198 static int arm_pci_init(void)
203 #endif /* CONFIG_CMD_PCI || CONFIG_PCI */
206 * Breathe some life into the board...
208 * Initialize a serial port as console, and carry out some hardware
211 * The first part of initialization is running from Flash memory;
212 * its main purpose is to initialize the RAM so that we
213 * can relocate the monitor code to RAM.
217 * All attempts to come up with a "common" initialization sequence
218 * that works for all boards and architectures failed: some of the
219 * requirements are just _too_ different. To get rid of the resulting
220 * mess of board dependent #ifdef'ed code we now make the whole
221 * initialization sequence configurable to the user.
223 * The requirements for any new initalization function is simple: it
224 * receives a pointer to the "global data" structure as it's only
225 * argument, and returns an integer return code, where 0 means
226 * "continue" and != 0 means "fatal error, hang the system".
228 typedef int (init_fnc_t) (void);
230 int print_cpuinfo (void);
232 void __dram_init_banksize(void)
234 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
235 gd->bd->bi_dram[0].size = gd->ram_size;
237 void dram_init_banksize(void)
238 __attribute__((weak, alias("__dram_init_banksize")));
240 init_fnc_t *init_sequence[] = {
241 #if defined(CONFIG_ARCH_CPU_INIT)
242 arch_cpu_init, /* basic arch cpu dependent setup */
244 #if defined(CONFIG_BOARD_EARLY_INIT_F)
247 timer_init, /* initialize timer */
248 #ifdef CONFIG_FSL_ESDHC
251 env_init, /* initialize environment */
252 init_baudrate, /* initialze baudrate settings */
253 serial_init, /* serial communications setup */
254 console_init_f, /* stage 1 init of console */
255 display_banner, /* say that we are here */
256 #if defined(CONFIG_DISPLAY_CPUINFO)
257 print_cpuinfo, /* display cpu info (and speed) */
259 #if defined(CONFIG_DISPLAY_BOARDINFO)
260 checkboard, /* display board info */
262 #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
265 dram_init, /* configure available RAM banks */
266 #if defined(CONFIG_CMD_PCI) || defined (CONFIG_PCI)
272 void board_init_f (ulong bootflag)
275 init_fnc_t **init_fnc_ptr;
280 * Fix me, when DDR size is less than or equal to 256M, uboot may destroy SPRD_SYSDUMP_MAGIC.
281 * Pointer is writable since we allocated a register for it.
283 gd = (gd_t *) ((CONFIG_SYS_INIT_SP_ADDR) & ~0x07);
285 /* compiler optimization barrier needed for GCC >= 3.4 */
286 __asm__ __volatile__("": : :"memory");
288 memset ((void*)gd, 0, sizeof (gd_t));
290 gd->mon_len = _bss_end_ofs;
292 for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
293 if ((*init_fnc_ptr)() != 0) {
298 debug ("monitor len: %08lX\n", gd->mon_len);
300 * Ram is setup, size stored in gd !!
302 debug ("ramsize: %08lX\n", gd->ram_size);
303 #if defined(CONFIG_SYS_MEM_TOP_HIDE)
305 * Subtract specified amount of memory to hide so that it won't
306 * get "touched" at all by U-Boot. By fixing up gd->ram_size
307 * the Linux kernel should now get passed the now "corrected"
308 * memory size and won't touch it either. This should work
309 * for arch/ppc and arch/powerpc. Only Linux board ports in
310 * arch/powerpc with bootwrapper support, that recalculate the
311 * memory size from the SDRAM controller setup will have to
314 gd->ram_size -= CONFIG_SYS_MEM_TOP_HIDE;
317 addr = CONFIG_SYS_SDRAM_BASE + PHYS_SDRAM_1_SIZE;
319 #ifdef CONFIG_LOGBUFFER
320 #ifndef CONFIG_ALT_LB_ADDR
321 /* reserve kernel log buffer */
322 addr -= (LOGBUFF_RESERVE);
323 debug ("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN, addr);
329 * reserve protected RAM
331 i = getenv_r ("pram", (char *)tmp, sizeof (tmp));
332 reg = (i > 0) ? simple_strtoul ((const char *)tmp, NULL, 10) : CONFIG_PRAM;
333 addr -= (reg << 10); /* size is in kB */
334 debug ("Reserving %ldk for protected RAM at %08lx\n", reg, addr);
335 #endif /* CONFIG_PRAM */
337 #if !(defined(CONFIG_SYS_NO_ICACHE) && defined(CONFIG_SYS_NO_DCACHE))
338 /* reserve TLB table */
341 /* round down to next 64 kB limit */
342 addr &= ~(0x10000 - 1);
345 debug ("TLB table at: %08lx\n", addr);
348 /* round down to next 4 kB limit */
350 debug ("Top of RAM usable for U-Boot at: %08lx\n", addr);
354 # define PAGE_SIZE 4096
357 * reserve memory for VFD display (always full pages)
359 addr -= vfd_setmem (addr);
361 #endif /* CONFIG_VFD */
364 /* reserve memory for LCD display (always full pages) */
365 addr = lcd_setmem (addr);
367 #endif /* CONFIG_LCD */
370 * reserve memory for U-Boot code, data & bss
371 * round down to next 4 kB limit
376 debug ("Reserving %ldk for U-Boot at: %08lx\n", gd->mon_len >> 10, addr);
378 #ifndef CONFIG_PRELOADER
380 * reserve memory for malloc() arena
382 addr_sp = addr - TOTAL_MALLOC_LEN;
383 debug ("Reserving %dk for malloc() at: %08lx\n",
384 TOTAL_MALLOC_LEN >> 10, addr_sp);
386 * (permanently) allocate a Board Info struct
387 * and a permanent copy of the "global" data
389 addr_sp -= sizeof (bd_t);
390 bd = (bd_t *) addr_sp;
392 debug ("Reserving %zu Bytes for Board Info at: %08lx\n",
393 sizeof (bd_t), addr_sp);
394 addr_sp -= sizeof (gd_t);
395 id = (gd_t *) addr_sp;
396 debug ("Reserving %zu Bytes for Global Data at: %08lx\n",
397 sizeof (gd_t), addr_sp);
399 /* setup stackpointer for exeptions */
400 gd->irq_sp = addr_sp;
401 #ifdef CONFIG_USE_IRQ
402 addr_sp -= (CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ);
403 debug ("Reserving %zu Bytes for IRQ stack at: %08lx\n",
404 CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ, addr_sp);
406 /* leave 3 words for abort-stack */
409 /* 8-byte alignment for ABI compliance */
412 addr_sp += 128; /* leave 32 words for abort-stack */
413 gd->irq_sp = addr_sp;
416 debug ("New Stack Pointer is: %08lx\n", addr_sp);
419 post_bootmode_init();
420 post_run (NULL, POST_ROM | post_bootmode_get(0));
423 gd->bd->bi_baudrate = gd->baudrate;
424 /* Ram ist board specific, so move it to board code ... */
425 dram_init_banksize();
426 display_dram_config(); /* and display it */
428 gd->relocaddr = addr;
429 gd->start_addr_sp = addr_sp;
430 gd->reloc_off = addr - _TEXT_BASE;
431 debug ("relocation Offset is: %08lx\n", gd->reloc_off);
432 memcpy (id, (void *)gd, sizeof (gd_t));
434 relocate_code (addr_sp, id, addr);
436 /* NOTREACHED - relocate_code() does not return */
439 #if !defined(CONFIG_SYS_NO_FLASH)
440 static char *failed = "*** failed ***\n";
443 /************************************************************************
445 * This is the next part if the initialization sequence: we are now
446 * running from RAM and have a "normal" C environment, i. e. global
447 * data can be written, BSS has been cleared, the stack size in not
448 * that critical any more, etc.
450 ************************************************************************
453 void board_init_r (gd_t *id, ulong dest_addr)
458 #if !defined(CONFIG_SYS_NO_FLASH)
465 gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
467 monitor_flash_len = _bss_start_ofs;
468 performance_debug("1:");
469 debug ("monitor flash len: %08lX\n", monitor_flash_len);
470 board_init(); /* Setup chipselects */
474 #ifdef CONFIG_SERIAL_MULTI
478 debug ("Now running in RAM - U-Boot at: %08lx\n", dest_addr);
480 #ifdef CONFIG_LOGBUFFER
481 logbuff_init_ptrs ();
484 post_output_backlog ();
487 /* The Malloc area is immediately below the monitor copy in DRAM */
488 malloc_start = dest_addr - TOTAL_MALLOC_LEN;
489 #ifdef SPRD_EVM_TAG_ON
492 mem_malloc_init (malloc_start, TOTAL_MALLOC_LEN);
493 performance_debug("2:");
494 #ifdef SPRD_EVM_TAG_ON
499 #if !defined(CONFIG_SYS_NO_FLASH)
502 if ((flash_size = flash_init ()) > 0) {
503 # ifdef CONFIG_SYS_FLASH_CHECKSUM
504 print_size (flash_size, "");
506 * Compute and print flash CRC if flashchecksum is set to 'y'
508 * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
510 s = getenv ("flashchecksum");
511 if (s && (*s == 'y')) {
512 printf (" CRC: %08X",
513 crc32 (0, (const unsigned char *) CONFIG_SYS_FLASH_BASE, flash_size)
517 # else /* !CONFIG_SYS_FLASH_CHECKSUM */
518 print_size (flash_size, "\n");
519 # endif /* CONFIG_SYS_FLASH_CHECKSUM */
527 #if !defined(CONFIG_EMMC_BOOT)
528 #if defined(CONFIG_CMD_NAND)
530 nand_init(); /* go init the NAND */
535 #ifdef SPRD_EVM_TAG_ON
539 #if defined(CONFIG_CMD_ONENAND)
540 #if !(defined CONFIG_TIGER && defined CONFIG_EMMC_BOOT)
545 #ifdef CONFIG_GENERIC_MMC
548 performance_debug("3:");
551 #ifdef CONFIG_HAS_DATAFLASH
552 AT91F_DataflashInit();
553 dataflash_print_info();
556 #ifdef CONFIG_EMMC_BOOT
559 /* initialize environment */
564 /* must do this after the framebuffer is allocated */
566 #endif /* CONFIG_VFD */
568 /*tempaily use for tiger to avoid died as refreshing LCD*/
571 gd->bd->bi_ip_addr = getenv_IPaddr ("ipaddr");
573 stdio_init (); /* get the devices list going. */
574 performance_debug("4:");
580 #if defined(CONFIG_API)
585 setenv("splashimage", fake);
587 console_init_r (); /* fully init console as a device */
590 #if defined(CONFIG_ARCH_MISC_INIT)
591 /* miscellaneous arch dependent initialisations */
594 #if defined(CONFIG_MISC_INIT_R)
595 /* miscellaneous platform dependent initialisations */
599 /* set up exceptions */
601 /* enable exceptions */
602 enable_interrupts ();
605 /* Perform network card initialisation if necessary */
606 #if defined(CONFIG_DRIVER_SMC91111) || defined (CONFIG_DRIVER_LAN91C96)
607 /* XXX: this needs to be moved to board init */
608 if (getenv ("ethaddr")) {
610 eth_getenv_enetaddr("ethaddr", enetaddr);
611 smc_set_mac_addr(enetaddr);
613 #endif /* CONFIG_DRIVER_SMC91111 || CONFIG_DRIVER_LAN91C96 */
615 /* Initialize from environment */
616 if ((s = getenv ("loadaddr")) != NULL) {
617 load_addr = simple_strtoul (s, NULL, 16);
619 #if defined(CONFIG_CMD_NET)
620 if ((s = getenv ("bootfile")) != NULL) {
621 copy_filename (BootFile, s, sizeof (BootFile));
625 //usb_eth_initialize(NULL);
626 #ifdef BOARD_LATE_INIT
630 #ifdef CONFIG_BITBANGMII
633 #if defined(CONFIG_CMD_NET)
634 #if defined(CONFIG_NET_MULTI)
637 //eth_initialize(gd->bd);
639 #if defined(CONFIG_RESET_PHY_R)
640 debug ("Reset Ethernet PHY\n");
646 post_run (NULL, POST_RAM | post_bootmode_get(0));
650 #if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
652 * Export available size of memory for Linux,
653 * taking into account the protected RAM at top of memory
661 if ((s = getenv ("pram")) != NULL) {
662 pram = simple_strtoul (s, NULL, 10);
669 #ifdef CONFIG_LOGBUFFER
670 #ifndef CONFIG_ALT_LB_ADDR
671 /* Also take the logbuffer into account (pram is in kB) */
672 pram += (LOGBUFF_LEN+LOGBUFF_OVERHEAD)/1024;
675 sprintf ((char *)memsz, "%ldk", (bd->bi_memsize / 1024) - pram);
676 setenv ("mem", (char *)memsz);
680 #ifdef SPRD_EVM_TAG_ON
683 MMU_Init(CONFIG_MMU_TABLE_ADDR);
685 #if !defined(CONFIG_FPGA)
686 #ifndef CONFIG_EMMC_BOOT
687 extern int nand_ubi_dev_init(void);
689 performance_debug("5:");
692 extern uint32_t sprdbat_get_vbatauxadc_caltype(void);
693 extern void sprdbat_init (void);
696 #if defined(CONFIG_SC8830) || defined(CONFIG_SC9630)
697 if (sprdbat_get_vbatauxadc_caltype() != 0)
700 performance_debug("6:");
709 extern int do_cboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]);
710 do_cboot(NULL, 0, 1, NULL);
711 /* main_loop() can return to retry autoboot, if so just run it again. */
716 /* NOTREACHED - no way out of command loop except booting */
721 puts ("### ERROR ### Please RESET the board ###\n");