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_DRIVER_SMC91111
54 #include "../drivers/net/smc91111.h"
56 #ifdef CONFIG_DRIVER_LAN91C96
57 #include "../drivers/net/lan91c96.h"
60 DECLARE_GLOBAL_DATA_PTR;
62 ulong monitor_flash_len;
64 #ifdef CONFIG_HAS_DATAFLASH
65 extern int AT91F_DataflashInit(void);
66 extern void dataflash_print_info(void);
69 #ifndef CONFIG_IDENT_STRING
70 #define CONFIG_IDENT_STRING ""
73 const char version_string[] =
74 U_BOOT_VERSION" (" U_BOOT_DATE " - " U_BOOT_TIME ")"CONFIG_IDENT_STRING;
76 #ifdef CONFIG_DRIVER_CS8900
77 extern void cs8900_get_enetaddr(void);
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 * Begin and End of memory area for malloc(), and current "brk"
92 static void *mem_malloc_start;
93 static void *mem_malloc_end;
94 static void *mem_malloc_brk;
97 void mem_malloc_init(void *dest_addr)
99 mem_malloc_start = dest_addr;
100 mem_malloc_end = dest_addr + CONFIG_SYS_MALLOC_LEN;
101 mem_malloc_brk = mem_malloc_start;
103 memset(mem_malloc_start, 0,
104 mem_malloc_end - mem_malloc_start);
107 void *sbrk(ptrdiff_t increment)
109 void *old = mem_malloc_brk;
110 void *new = old + increment;
112 if ((new < mem_malloc_start) || (new > mem_malloc_end)) {
115 mem_malloc_brk = new;
121 /************************************************************************
122 * Coloured LED functionality
123 ************************************************************************
124 * May be supplied by boards if desired
126 void __coloured_LED_init(void) {}
127 void coloured_LED_init(void) __attribute__((weak, alias("__coloured_LED_init")));
128 void __red_LED_on(void) {}
129 void red_LED_on(void) __attribute__((weak, alias("__red_LED_on")));
130 void __red_LED_off(void) {}
131 void red_LED_off(void) __attribute__((weak, alias("__red_LED_off")));
132 void __green_LED_on(void) {}
133 void green_LED_on(void) __attribute__((weak, alias("__green_LED_on")));
134 void __green_LED_off(void) {}
135 void green_LED_off(void)__attribute__((weak, alias("__green_LED_off")));
136 void __yellow_LED_on(void) {}
137 void yellow_LED_on(void)__attribute__((weak, alias("__yellow_LED_on")));
138 void __yellow_LED_off(void) {}
139 void yellow_LED_off(void)__attribute__((weak, alias("__yellow_LED_off")));
140 void __blue_LED_on(void) {}
141 void blue_LED_on(void)__attribute__((weak, alias("__blue_LED_on")));
142 void __blue_LED_off(void) {}
143 void blue_LED_off(void)__attribute__((weak, alias("__blue_LED_off")));
145 /************************************************************************
147 ************************************************************************
148 * Some of this code should be moved into the core functions,
149 * or dropped completely,
150 * but let's get it working (again) first...
153 #if defined(CONFIG_ARM_DCC) && !defined(CONFIG_BAUDRATE)
154 #define CONFIG_BAUDRATE 115200
156 static int init_baudrate(void)
158 char tmp[64]; /* long enough for environment variables */
159 int i = getenv_r("baudrate", tmp, sizeof(tmp));
161 gd->bd->bi_baudrate = gd->baudrate = (i > 0) ?
162 (int)simple_strtoul(tmp, NULL, 10) :
168 static int display_banner(void)
170 printf("\n\n%s\n\n", version_string);
171 debug("U-Boot code: %08lX -> %08lX BSS: -> %08lX\n",
172 _armboot_start, _bss_start, _bss_end);
173 #ifdef CONFIG_MODEM_SUPPORT
174 debug("Modem Support enabled\n");
176 #ifdef CONFIG_USE_IRQ
177 debug("IRQ Stack: %08lx\n", IRQ_STACK_START);
178 debug("FIQ Stack: %08lx\n", FIQ_STACK_START);
185 * WARNING: this code looks "cleaner" than the PowerPC version, but
186 * has the disadvantage that you either get nothing, or everything.
187 * On PowerPC, you might see "DRAM: " before the system hangs - which
188 * gives a simple yet clear indication which part of the
189 * initialization if failing.
191 static int display_dram_config(void)
196 puts("RAM Configuration:\n");
198 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
199 printf("Bank #%d: %08lx ", i, gd->bd->bi_dram[i].start);
200 print_size(gd->bd->bi_dram[i].size, "\n");
205 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
206 size += gd->bd->bi_dram[i].size;
209 print_size(size, "\n");
215 #ifndef CONFIG_SYS_NO_FLASH
216 static void display_flash_config(ulong size)
219 print_size(size, "\n");
221 #endif /* CONFIG_SYS_NO_FLASH */
223 #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
224 static int init_func_i2c(void)
227 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
233 #if defined(CONFIG_CMD_PCI) || defined(CONFIG_PCI)
235 static int arm_pci_init(void)
240 #endif /* CONFIG_CMD_PCI || CONFIG_PCI */
243 * Breathe some life into the board...
245 * Initialize a serial port as console, and carry out some hardware
248 * The first part of initialization is running from Flash memory;
249 * its main purpose is to initialize the RAM so that we
250 * can relocate the monitor code to RAM.
254 * All attempts to come up with a "common" initialization sequence
255 * that works for all boards and architectures failed: some of the
256 * requirements are just _too_ different. To get rid of the resulting
257 * mess of board dependent #ifdef'ed code we now make the whole
258 * initialization sequence configurable to the user.
260 * The requirements for any new initalization function is simple: it
261 * receives a pointer to the "global data" structure as it's only
262 * argument, and returns an integer return code, where 0 means
263 * "continue" and != 0 means "fatal error, hang the system".
265 typedef int (init_fnc_t)(void);
267 int print_cpuinfo(void);
269 init_fnc_t *init_sequence[] = {
270 #if defined(CONFIG_ARCH_CPU_INIT)
271 arch_cpu_init, /* basic arch cpu dependent setup */
273 board_init, /* basic board dependent setup */
274 #if defined(CONFIG_USE_IRQ)
275 interrupt_init, /* set up exceptions */
277 timer_init, /* initialize timer */
278 env_init, /* initialize environment */
279 init_baudrate, /* initialze baudrate settings */
280 serial_init, /* serial communications setup */
281 console_init_f, /* stage 1 init of console */
282 display_banner, /* say that we are here */
283 #if defined(CONFIG_DISPLAY_CPUINFO)
284 print_cpuinfo, /* display cpu info (and speed) */
286 #if defined(CONFIG_DISPLAY_BOARDINFO)
287 checkboard, /* display board info */
289 #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
292 dram_init, /* configure available RAM banks */
293 #if defined(CONFIG_CMD_PCI) || defined(CONFIG_PCI)
300 void start_armboot(void)
302 init_fnc_t **init_fnc_ptr;
304 #if defined(CONFIG_VFD) || defined(CONFIG_LCD)
308 /* Pointer is writable since we allocated a register for it */
309 gd = (gd_t*)(_armboot_start - CONFIG_SYS_MALLOC_LEN - sizeof(gd_t));
310 /* compiler optimization barrier needed for GCC >= 3.4 */
311 __asm__ __volatile__("": : :"memory");
313 memset((void *)gd, 0, sizeof(gd_t));
314 gd->bd = (bd_t*)((char*)gd - sizeof(bd_t));
315 memset(gd->bd, 0, sizeof(bd_t));
317 gd->flags |= GD_FLG_RELOC;
319 monitor_flash_len = _bss_start - _armboot_start;
321 for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
322 if ((*init_fnc_ptr)() != 0) {
327 /* armboot_start is defined in the board-specific linker script */
328 mem_malloc_init((void *)(_armboot_start - CONFIG_SYS_MALLOC_LEN));
330 #ifndef CONFIG_SYS_NO_FLASH
331 /* configure available FLASH banks */
332 display_flash_config(flash_init());
333 #endif /* CONFIG_SYS_NO_FLASH */
337 # define PAGE_SIZE 4096
340 * reserve memory for VFD display (always full pages)
342 /* bss_end is defined in the board-specific linker script */
343 addr = (_bss_end + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
346 #endif /* CONFIG_VFD */
349 /* board init may have inited fb_base */
352 # define PAGE_SIZE 4096
355 * reserve memory for LCD display (always full pages)
357 /* bss_end is defined in the board-specific linker script */
358 addr = (_bss_end + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
362 #endif /* CONFIG_LCD */
364 #if defined(CONFIG_CMD_NAND)
366 nand_init(); /* go init the NAND */
369 #if defined(CONFIG_CMD_ONENAND)
373 #ifdef CONFIG_HAS_DATAFLASH
374 AT91F_DataflashInit();
375 dataflash_print_info();
378 #ifdef CONFIG_GENERIC_MMC
380 mmc_initialize(gd->bd);
383 /* initialize environment */
387 /* must do this after the framebuffer is allocated */
389 #endif /* CONFIG_VFD */
391 #ifdef CONFIG_SERIAL_MULTI
396 gd->bd->bi_ip_addr = getenv_IPaddr("ipaddr");
398 stdio_init(); /* get the devices list going. */
402 #if defined(CONFIG_API)
407 console_init_r(); /* fully init console as a device */
409 #if defined(CONFIG_ARCH_MISC_INIT)
410 /* miscellaneous arch dependent initialisations */
413 #if defined(CONFIG_MISC_INIT_R)
414 /* miscellaneous platform dependent initialisations */
418 /* enable exceptions */
421 /* Perform network card initialisation if necessary */
422 #ifdef CONFIG_DRIVER_TI_EMAC
423 /* XXX: this needs to be moved to board init */
424 extern void davinci_eth_set_mac_addr(const u_int8_t *addr);
425 if (getenv("ethaddr")) {
427 eth_getenv_enetaddr("ethaddr", enetaddr);
428 davinci_eth_set_mac_addr(enetaddr);
432 #ifdef CONFIG_DRIVER_CS8900
433 /* XXX: this needs to be moved to board init */
434 cs8900_get_enetaddr();
437 #if defined(CONFIG_DRIVER_SMC91111) || defined(CONFIG_DRIVER_LAN91C96)
438 /* XXX: this needs to be moved to board init */
439 if (getenv("ethaddr")) {
441 eth_getenv_enetaddr("ethaddr", enetaddr);
442 smc_set_mac_addr(enetaddr);
444 #endif /* CONFIG_DRIVER_SMC91111 || CONFIG_DRIVER_LAN91C96 */
446 #if defined(CONFIG_ENC28J60_ETH) && !defined(CONFIG_ETHADDR)
447 extern void enc_set_mac_addr(void);
449 #endif /* CONFIG_ENC28J60_ETH && !CONFIG_ETHADDR*/
451 /* Initialize from environment */
452 if ((s = getenv("loadaddr")) != NULL) {
453 load_addr = simple_strtoul(s, NULL, 16);
455 #if defined(CONFIG_CMD_NET)
456 if ((s = getenv("bootfile")) != NULL) {
457 copy_filename(BootFile, s, sizeof(BootFile));
461 #ifdef BOARD_LATE_INIT
465 #if defined(CONFIG_CMD_NET)
466 #if defined(CONFIG_NET_MULTI)
469 eth_initialize(gd->bd);
470 #if defined(CONFIG_RESET_PHY_R)
471 debug("Reset Ethernet PHY\n");
475 /* main_loop() can return to retry autoboot, if so just run it again. */
480 /* NOTREACHED - no way out of command loop except booting */
485 puts("### ERROR ### Please RESET the board ###\n");