blob: 01b71d448134663878f533ccd004d3e39bb7cf8d [file] [log] [blame]
Wolfgang Denk6cb142f2006-03-12 02:12:27 +01001/*
2 * U-boot - board.c First C file to be called contains init routines
3 *
Mike Frysingerd5bffeb2008-02-19 00:54:20 -05004 * Copyright (c) 2005-2008 Analog Devices Inc.
Wolfgang Denk6cb142f2006-03-12 02:12:27 +01005 *
6 * (C) Copyright 2000-2004
7 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
8 *
Mike Frysingerd5bffeb2008-02-19 00:54:20 -05009 * Licensed under the GPL-2 or later.
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010010 */
11
12#include <common.h>
13#include <command.h>
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010014#include <devices.h>
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010015#include <environment.h>
Mike Frysingerd5bffeb2008-02-19 00:54:20 -050016#include <malloc.h>
17#include <net.h>
Peter Tyser561858e2008-11-03 09:30:59 -060018#include <timestamp.h>
Mike Frysinger01815c22008-10-06 03:52:24 -040019#include <status_led.h>
Mike Frysingerd5bffeb2008-02-19 00:54:20 -050020#include <version.h>
21
Aubrey.Li3f0606a2007-03-09 13:38:44 +080022#include <asm/cplb.h>
Mike Frysingerd5bffeb2008-02-19 00:54:20 -050023#include <asm/mach-common/bits/mpu.h>
24
25#ifdef CONFIG_CMD_NAND
26#include <nand.h> /* cannot even include nand.h if it isnt configured */
27#endif
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010028
Mike Frysinger9171fc82008-03-30 15:46:13 -040029#if defined(CONFIG_POST)
Aubrey.Li3f0606a2007-03-09 13:38:44 +080030#include <post.h>
31int post_flag;
32#endif
Wolfgang Denkd87080b2006-03-31 18:32:53 +020033
Wolfgang Denk1218abf2007-09-15 20:48:41 +020034DECLARE_GLOBAL_DATA_PTR;
35
Peter Tyser561858e2008-11-03 09:30:59 -060036const char version_string[] = U_BOOT_VERSION " ("U_BOOT_DATE" - "U_BOOT_TIME")";
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010037
Mike Frysingerd5bffeb2008-02-19 00:54:20 -050038__attribute__((always_inline))
39static inline void serial_early_puts(const char *s)
40{
41#ifdef CONFIG_DEBUG_EARLY_SERIAL
42 serial_puts("Early: ");
43 serial_puts(s);
44#endif
45}
46
47/* Get the input voltage */
48static u_long get_vco(void)
Aubrey.Li3f0606a2007-03-09 13:38:44 +080049{
50 u_long msel;
51 u_long vco;
52
53 msel = (*pPLL_CTL >> 9) & 0x3F;
54 if (0 == msel)
55 msel = 64;
56
57 vco = CONFIG_CLKIN_HZ;
58 vco >>= (1 & *pPLL_CTL); /* DF bit */
59 vco = msel * vco;
60 return vco;
61}
62
Mike Frysingerd5bffeb2008-02-19 00:54:20 -050063/* Get the Core clock */
Aubrey.Li3f0606a2007-03-09 13:38:44 +080064u_long get_cclk(void)
65{
66 u_long csel, ssel;
67 if (*pPLL_STAT & 0x1)
68 return CONFIG_CLKIN_HZ;
69
70 ssel = *pPLL_DIV;
71 csel = ((ssel >> 4) & 0x03);
72 ssel &= 0xf;
73 if (ssel && ssel < (1 << csel)) /* SCLK > CCLK */
74 return get_vco() / ssel;
75 return get_vco() >> csel;
76}
77
78/* Get the System clock */
79u_long get_sclk(void)
80{
81 u_long ssel;
82
83 if (*pPLL_STAT & 0x1)
84 return CONFIG_CLKIN_HZ;
85
86 ssel = (*pPLL_DIV & 0xf);
87
88 return get_vco() / ssel;
89}
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010090
Mike Frysingerd5bffeb2008-02-19 00:54:20 -050091static void *mem_malloc_start, *mem_malloc_end, *mem_malloc_brk;
92
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010093static void mem_malloc_init(void)
94{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020095 mem_malloc_start = (void *)CONFIG_SYS_MALLOC_BASE;
96 mem_malloc_end = (void *)(CONFIG_SYS_MALLOC_BASE + CONFIG_SYS_MALLOC_LEN);
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010097 mem_malloc_brk = mem_malloc_start;
Mike Frysingerd5bffeb2008-02-19 00:54:20 -050098 memset(mem_malloc_start, 0, mem_malloc_end - mem_malloc_start);
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010099}
100
101void *sbrk(ptrdiff_t increment)
102{
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500103 void *old = mem_malloc_brk;
104 void *new = old + increment;
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100105
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500106 if (new < mem_malloc_start || new > mem_malloc_end)
107 return NULL;
108
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100109 mem_malloc_brk = new;
110
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500111 return old;
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100112}
113
114static int display_banner(void)
115{
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500116 printf("\n\n%s\n\n", version_string);
Mike Frysingerf7ce12c2008-02-18 05:26:48 -0500117 printf("CPU: ADSP " MK_STR(CONFIG_BFIN_CPU) " (Detected Rev: 0.%d)\n", bfin_revid());
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500118 return 0;
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100119}
120
121static int init_baudrate(void)
122{
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500123 char baudrate[15];
124 int i = getenv_r("baudrate", baudrate, sizeof(baudrate));
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100125 gd->bd->bi_baudrate = gd->baudrate = (i > 0)
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500126 ? simple_strtoul(baudrate, NULL, 10)
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800127 : CONFIG_BAUDRATE;
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500128 return 0;
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100129}
130
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100131static void display_global_data(void)
132{
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500133#ifdef CONFIG_DEBUG_EARLY_SERIAL
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100134 bd_t *bd;
135 bd = gd->bd;
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500136 printf(" gd: %x\n", gd);
137 printf(" |-flags: %x\n", gd->flags);
138 printf(" |-board_type: %x\n", gd->board_type);
139 printf(" |-baudrate: %i\n", gd->baudrate);
140 printf(" |-have_console: %x\n", gd->have_console);
141 printf(" |-ram_size: %x\n", gd->ram_size);
142 printf(" |-reloc_off: %x\n", gd->reloc_off);
143 printf(" |-env_addr: %x\n", gd->env_addr);
144 printf(" |-env_valid: %x\n", gd->env_valid);
145 printf(" |-jt(%x): %x\n", gd->jt, *(gd->jt));
146 printf(" \\-bd: %x\n", gd->bd);
147 printf(" |-bi_baudrate: %x\n", bd->bi_baudrate);
148 printf(" |-bi_ip_addr: %x\n", bd->bi_ip_addr);
149 printf(" |-bi_enetaddr: %x %x %x %x %x %x\n",
150 bd->bi_enetaddr[0], bd->bi_enetaddr[1],
151 bd->bi_enetaddr[2], bd->bi_enetaddr[3],
152 bd->bi_enetaddr[4], bd->bi_enetaddr[5]);
153 printf(" |-bi_boot_params: %x\n", bd->bi_boot_params);
154 printf(" |-bi_memstart: %x\n", bd->bi_memstart);
155 printf(" |-bi_memsize: %x\n", bd->bi_memsize);
156 printf(" |-bi_flashstart: %x\n", bd->bi_flashstart);
157 printf(" |-bi_flashsize: %x\n", bd->bi_flashsize);
158 printf(" \\-bi_flashoffset: %x\n", bd->bi_flashoffset);
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100159#endif
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500160}
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100161
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500162#define CPLB_PAGE_SIZE (4 * 1024 * 1024)
163#define CPLB_PAGE_MASK (~(CPLB_PAGE_SIZE - 1))
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800164void init_cplbtables(void)
165{
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500166 volatile uint32_t *ICPLB_ADDR, *ICPLB_DATA;
167 volatile uint32_t *DCPLB_ADDR, *DCPLB_DATA;
168 uint32_t extern_memory;
169 size_t i;
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800170
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500171 void icplb_add(uint32_t addr, uint32_t data)
172 {
173 *(ICPLB_ADDR + i) = addr;
174 *(ICPLB_DATA + i) = data;
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800175 }
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500176 void dcplb_add(uint32_t addr, uint32_t data)
177 {
178 *(DCPLB_ADDR + i) = addr;
179 *(DCPLB_DATA + i) = data;
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800180 }
181
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500182 /* populate a few common entries ... we'll let
183 * the memory map and cplb exception handler do
184 * the rest of the work.
185 */
186 i = 0;
187 ICPLB_ADDR = (uint32_t *)ICPLB_ADDR0;
188 ICPLB_DATA = (uint32_t *)ICPLB_DATA0;
189 DCPLB_ADDR = (uint32_t *)DCPLB_ADDR0;
190 DCPLB_DATA = (uint32_t *)DCPLB_DATA0;
191
192 icplb_add(0xFFA00000, L1_IMEMORY);
193 dcplb_add(0xFF800000, L1_DMEMORY);
194 ++i;
195
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200196 icplb_add(CONFIG_SYS_MONITOR_BASE & CPLB_PAGE_MASK, SDRAM_IKERNEL);
197 dcplb_add(CONFIG_SYS_MONITOR_BASE & CPLB_PAGE_MASK, SDRAM_DKERNEL);
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500198 ++i;
199
200 /* If the monitor crosses a 4 meg boundary, we'll need
201 * to lock two entries for it.
202 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200203 if ((CONFIG_SYS_MONITOR_BASE & CPLB_PAGE_MASK) != ((CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN) & CPLB_PAGE_MASK)) {
204 icplb_add((CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN) & CPLB_PAGE_MASK, SDRAM_IKERNEL);
205 dcplb_add((CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN) & CPLB_PAGE_MASK, SDRAM_DKERNEL);
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500206 ++i;
207 }
208
209 icplb_add(0x20000000, SDRAM_INON_CHBL);
210 dcplb_add(0x20000000, SDRAM_EBIU);
211 ++i;
212
213 /* Add entries for the rest of external RAM up to the bootrom */
214 extern_memory = 0;
215
216#ifdef CONFIG_DEBUG_NULL_PTR
217 icplb_add(extern_memory, (SDRAM_IKERNEL & ~PAGE_SIZE_MASK) | PAGE_SIZE_1KB);
218 dcplb_add(extern_memory, (SDRAM_DKERNEL & ~PAGE_SIZE_MASK) | PAGE_SIZE_1KB);
219 ++i;
220 icplb_add(extern_memory, SDRAM_IKERNEL);
221 dcplb_add(extern_memory, SDRAM_DKERNEL);
222 extern_memory += CPLB_PAGE_SIZE;
223 ++i;
224#endif
225
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200226 while (i < 16 && extern_memory < (CONFIG_SYS_MONITOR_BASE & CPLB_PAGE_MASK)) {
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500227 icplb_add(extern_memory, SDRAM_IGENERIC);
228 dcplb_add(extern_memory, SDRAM_DGENERIC);
229 extern_memory += CPLB_PAGE_SIZE;
230 ++i;
231 }
232 while (i < 16) {
233 icplb_add(0, 0);
234 dcplb_add(0, 0);
235 ++i;
236 }
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800237}
238
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100239/*
240 * All attempts to come up with a "common" initialization sequence
241 * that works for all boards and architectures failed: some of the
242 * requirements are just _too_ different. To get rid of the resulting
243 * mess of board dependend #ifdef'ed code we now make the whole
244 * initialization sequence configurable to the user.
245 *
246 * The requirements for any new initalization function is simple: it
247 * receives a pointer to the "global data" structure as it's only
248 * argument, and returns an integer return code, where 0 means
249 * "continue" and != 0 means "fatal error, hang the system".
250 */
251
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500252extern int exception_init(void);
253extern int irq_init(void);
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500254extern int timer_init(void);
255
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100256void board_init_f(ulong bootflag)
257{
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100258 ulong addr;
259 bd_t *bd;
Mike Frysinger6dadc912008-10-20 16:15:04 -0400260 char buf[32];
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800261
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500262#ifdef CONFIG_BOARD_EARLY_INIT_F
263 serial_early_puts("Board early init flash\n");
264 board_early_init_f();
265#endif
266
267 serial_early_puts("Init CPLB tables\n");
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800268 init_cplbtables();
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100269
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500270 serial_early_puts("Exceptions setup\n");
271 exception_init();
272
273#ifndef CONFIG_ICACHE_OFF
274 serial_early_puts("Turn on ICACHE\n");
275 icache_enable();
276#endif
277#ifndef CONFIG_DCACHE_OFF
278 serial_early_puts("Turn on DCACHE\n");
279 dcache_enable();
280#endif
281
Mike Frysinger78a0ba72008-10-06 03:57:39 -0400282#ifdef DEBUG
283 if (CONFIG_SYS_GBL_DATA_SIZE < sizeof(*gd))
284 hang();
285#endif
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500286 serial_early_puts("Init global data\n");
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200287 gd = (gd_t *) (CONFIG_SYS_GBL_DATA_ADDR);
Mike Frysinger78a0ba72008-10-06 03:57:39 -0400288 memset((void *)gd, 0, CONFIG_SYS_GBL_DATA_SIZE);
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100289
290 /* Board data initialization */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200291 addr = (CONFIG_SYS_GBL_DATA_ADDR + sizeof(gd_t));
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100292
293 /* Align to 4 byte boundary */
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100294 addr &= ~(4 - 1);
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800295 bd = (bd_t *) addr;
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100296 gd->bd = bd;
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800297 memset((void *)bd, 0, sizeof(bd_t));
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100298
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500299 bd->bi_r_version = version_string;
300 bd->bi_cpu = MK_STR(CONFIG_BFIN_CPU);
301 bd->bi_board_name = BFIN_BOARD_NAME;
302 bd->bi_vco = get_vco();
303 bd->bi_cclk = get_cclk();
304 bd->bi_sclk = get_sclk();
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800305
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500306 /* Initialize */
307 serial_early_puts("IRQ init\n");
308 irq_init();
309 serial_early_puts("Environment init\n");
310 env_init();
311 serial_early_puts("Baudrate init\n");
312 init_baudrate();
313 serial_early_puts("Serial init\n");
314 serial_init();
315 serial_early_puts("Console init flash\n");
316 console_init_f();
317 serial_early_puts("End of early debugging\n");
318 display_banner();
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800319
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100320 checkboard();
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100321 timer_init();
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500322
Mike Frysinger6dadc912008-10-20 16:15:04 -0400323 printf("Clock: VCO: %s MHz, ", strmhz(buf, get_vco()));
324 printf("Core: %s MHz, ", strmhz(buf, get_cclk()));
325 printf("System: %s MHz\n", strmhz(buf, get_sclk()));
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500326
327 printf("RAM: ");
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100328 print_size(initdram(0), "\n");
Mike Frysinger9171fc82008-03-30 15:46:13 -0400329#if defined(CONFIG_POST)
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800330 post_init_f();
331 post_bootmode_init();
332 post_run(NULL, POST_ROM | post_bootmode_get(0));
333#endif
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500334
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100335 board_init_r((gd_t *) gd, 0x20000010);
336}
337
338void board_init_r(gd_t * id, ulong dest_addr)
339{
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100340 extern void malloc_bin_reloc(void);
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500341 char *s;
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100342 bd_t *bd;
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100343 gd = id;
344 gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
345 bd = gd->bd;
346
Mike Frysinger9171fc82008-03-30 15:46:13 -0400347#if defined(CONFIG_POST)
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800348 post_output_backlog();
349 post_reloc();
350#endif
351
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200352#if !defined(CONFIG_SYS_NO_FLASH)
Mike Frysingerb6edc712008-10-06 04:00:07 -0400353 /* Initialize the flash and protect u-boot by default */
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500354 extern flash_info_t flash_info[];
355 ulong size = flash_init();
356 puts("Flash: ");
357 print_size(size, "\n");
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200358 flash_protect(FLAG_PROTECT_SET, CONFIG_SYS_FLASH_BASE,
Mike Frysingerb6edc712008-10-06 04:00:07 -0400359 CONFIG_SYS_FLASH_BASE + CONFIG_SYS_MONITOR_LEN - 1,
360 &flash_info[0]);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200361 bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100362 bd->bi_flashsize = size;
363 bd->bi_flashoffset = 0;
364#else
365 bd->bi_flashstart = 0;
366 bd->bi_flashsize = 0;
367 bd->bi_flashoffset = 0;
368#endif
369 /* initialize malloc() area */
370 mem_malloc_init();
371 malloc_bin_reloc();
372
Mike Frysinger39782722008-10-06 03:55:25 -0400373#ifdef CONFIG_CMD_NAND
374 puts("NAND: ");
375 nand_init(); /* go init the NAND */
376#endif
377
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100378 /* relocate environment function pointers etc. */
379 env_relocate();
380
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500381#ifdef CONFIG_CMD_NET
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100382 /* board MAC address */
383 s = getenv("ethaddr");
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500384 if (s == NULL) {
385# ifndef CONFIG_ETHADDR
386# if 0
387 if (!board_get_enetaddr(bd->bi_enetaddr)) {
388 char nid[20];
389 sprintf(nid, "%02X:%02X:%02X:%02X:%02X:%02X",
390 bd->bi_enetaddr[0], bd->bi_enetaddr[1],
391 bd->bi_enetaddr[2], bd->bi_enetaddr[3],
392 bd->bi_enetaddr[4], bd->bi_enetaddr[5]);
393 setenv("ethaddr", nid);
394 }
395# endif
396# endif
397 } else {
398 int i;
399 char *e;
400 for (i = 0; i < 6; ++i) {
401 bd->bi_enetaddr[i] = simple_strtoul(s, &e, 16);
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100402 s = (*e) ? e + 1 : e;
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500403 }
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100404 }
405
406 /* IP Address */
407 bd->bi_ip_addr = getenv_IPaddr("ipaddr");
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500408#endif
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100409
410 /* Initialize devices */
411 devices_init();
412 jumptable_init();
413
414 /* Initialize the console (after the relocation and devices init) */
415 console_init_r();
416
Mike Frysinger01815c22008-10-06 03:52:24 -0400417#ifdef CONFIG_STATUS_LED
418 status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING);
419 status_led_set(STATUS_LED_CRASH, STATUS_LED_OFF);
420#endif
421
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100422 /* Initialize from environment */
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500423 if ((s = getenv("loadaddr")) != NULL)
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100424 load_addr = simple_strtoul(s, NULL, 16);
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500425#ifdef CONFIG_CMD_NET
426 if ((s = getenv("bootfile")) != NULL)
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100427 copy_filename(BootFile, s, sizeof(BootFile));
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100428#endif
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800429
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100430#if defined(CONFIG_MISC_INIT_R)
431 /* miscellaneous platform dependent initialisations */
432 misc_init_r();
433#endif
434
Mike Frysingerf7ce12c2008-02-18 05:26:48 -0500435#ifdef CONFIG_CMD_NET
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500436 printf("Net: ");
437 eth_initialize(gd->bd);
438 if (getenv("ethaddr"))
439 printf("MAC: %02X:%02X:%02X:%02X:%02X:%02X\n",
440 bd->bi_enetaddr[0], bd->bi_enetaddr[1], bd->bi_enetaddr[2],
441 bd->bi_enetaddr[3], bd->bi_enetaddr[4], bd->bi_enetaddr[5]);
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800442#endif
443
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800444 display_global_data();
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800445
Mike Frysinger9171fc82008-03-30 15:46:13 -0400446#if defined(CONFIG_POST)
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800447 if (post_flag)
448 post_run(NULL, POST_RAM | post_bootmode_get(0));
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100449#endif
450
451 /* main_loop() can return to retry autoboot, if so just run it again. */
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500452 for (;;)
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100453 main_loop();
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100454}
455
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100456void hang(void)
457{
Mike Frysinger01815c22008-10-06 03:52:24 -0400458#ifdef CONFIG_STATUS_LED
459 status_led_set(STATUS_LED_BOOT, STATUS_LED_OFF);
460 status_led_set(STATUS_LED_CRASH, STATUS_LED_BLINKING);
461#endif
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100462 puts("### ERROR ### Please RESET the board ###\n");
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500463 while (1)
464 /* If a JTAG emulator is hooked up, we'll automatically trigger
465 * a breakpoint in it. If one isn't, this is just a NOP.
466 */
467 asm("emuexcpt;");
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100468}