blob: 30ffba1c0f25b28c1683f290ab8d68c83fb986d8 [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 Frysingerd5bffeb2008-02-19 00:54:20 -050019#include <version.h>
20
Aubrey.Li3f0606a2007-03-09 13:38:44 +080021#include <asm/cplb.h>
Mike Frysingerd5bffeb2008-02-19 00:54:20 -050022#include <asm/mach-common/bits/mpu.h>
23
24#ifdef CONFIG_CMD_NAND
25#include <nand.h> /* cannot even include nand.h if it isnt configured */
26#endif
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010027
Mike Frysinger9171fc82008-03-30 15:46:13 -040028#if defined(CONFIG_POST)
Aubrey.Li3f0606a2007-03-09 13:38:44 +080029#include <post.h>
30int post_flag;
31#endif
Wolfgang Denkd87080b2006-03-31 18:32:53 +020032
Wolfgang Denk1218abf2007-09-15 20:48:41 +020033DECLARE_GLOBAL_DATA_PTR;
34
Peter Tyser561858e2008-11-03 09:30:59 -060035const char version_string[] = U_BOOT_VERSION " ("U_BOOT_DATE" - "U_BOOT_TIME")";
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010036
Mike Frysingerd5bffeb2008-02-19 00:54:20 -050037__attribute__((always_inline))
38static inline void serial_early_puts(const char *s)
39{
40#ifdef CONFIG_DEBUG_EARLY_SERIAL
41 serial_puts("Early: ");
42 serial_puts(s);
43#endif
44}
45
46/* Get the input voltage */
47static u_long get_vco(void)
Aubrey.Li3f0606a2007-03-09 13:38:44 +080048{
49 u_long msel;
50 u_long vco;
51
52 msel = (*pPLL_CTL >> 9) & 0x3F;
53 if (0 == msel)
54 msel = 64;
55
56 vco = CONFIG_CLKIN_HZ;
57 vco >>= (1 & *pPLL_CTL); /* DF bit */
58 vco = msel * vco;
59 return vco;
60}
61
Mike Frysingerd5bffeb2008-02-19 00:54:20 -050062/* Get the Core clock */
Aubrey.Li3f0606a2007-03-09 13:38:44 +080063u_long get_cclk(void)
64{
65 u_long csel, ssel;
66 if (*pPLL_STAT & 0x1)
67 return CONFIG_CLKIN_HZ;
68
69 ssel = *pPLL_DIV;
70 csel = ((ssel >> 4) & 0x03);
71 ssel &= 0xf;
72 if (ssel && ssel < (1 << csel)) /* SCLK > CCLK */
73 return get_vco() / ssel;
74 return get_vco() >> csel;
75}
76
77/* Get the System clock */
78u_long get_sclk(void)
79{
80 u_long ssel;
81
82 if (*pPLL_STAT & 0x1)
83 return CONFIG_CLKIN_HZ;
84
85 ssel = (*pPLL_DIV & 0xf);
86
87 return get_vco() / ssel;
88}
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010089
Mike Frysingerd5bffeb2008-02-19 00:54:20 -050090static void *mem_malloc_start, *mem_malloc_end, *mem_malloc_brk;
91
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010092static void mem_malloc_init(void)
93{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020094 mem_malloc_start = (void *)CONFIG_SYS_MALLOC_BASE;
95 mem_malloc_end = (void *)(CONFIG_SYS_MALLOC_BASE + CONFIG_SYS_MALLOC_LEN);
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010096 mem_malloc_brk = mem_malloc_start;
Mike Frysingerd5bffeb2008-02-19 00:54:20 -050097 memset(mem_malloc_start, 0, mem_malloc_end - mem_malloc_start);
Wolfgang Denk6cb142f2006-03-12 02:12:27 +010098}
99
100void *sbrk(ptrdiff_t increment)
101{
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500102 void *old = mem_malloc_brk;
103 void *new = old + increment;
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100104
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500105 if (new < mem_malloc_start || new > mem_malloc_end)
106 return NULL;
107
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100108 mem_malloc_brk = new;
109
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500110 return old;
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100111}
112
113static int display_banner(void)
114{
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500115 printf("\n\n%s\n\n", version_string);
Mike Frysingerf7ce12c2008-02-18 05:26:48 -0500116 printf("CPU: ADSP " MK_STR(CONFIG_BFIN_CPU) " (Detected Rev: 0.%d)\n", bfin_revid());
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500117 return 0;
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100118}
119
120static int init_baudrate(void)
121{
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500122 char baudrate[15];
123 int i = getenv_r("baudrate", baudrate, sizeof(baudrate));
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100124 gd->bd->bi_baudrate = gd->baudrate = (i > 0)
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500125 ? simple_strtoul(baudrate, NULL, 10)
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800126 : CONFIG_BAUDRATE;
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500127 return 0;
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100128}
129
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100130static void display_global_data(void)
131{
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500132#ifdef CONFIG_DEBUG_EARLY_SERIAL
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100133 bd_t *bd;
134 bd = gd->bd;
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500135 printf(" gd: %x\n", gd);
136 printf(" |-flags: %x\n", gd->flags);
137 printf(" |-board_type: %x\n", gd->board_type);
138 printf(" |-baudrate: %i\n", gd->baudrate);
139 printf(" |-have_console: %x\n", gd->have_console);
140 printf(" |-ram_size: %x\n", gd->ram_size);
141 printf(" |-reloc_off: %x\n", gd->reloc_off);
142 printf(" |-env_addr: %x\n", gd->env_addr);
143 printf(" |-env_valid: %x\n", gd->env_valid);
144 printf(" |-jt(%x): %x\n", gd->jt, *(gd->jt));
145 printf(" \\-bd: %x\n", gd->bd);
146 printf(" |-bi_baudrate: %x\n", bd->bi_baudrate);
147 printf(" |-bi_ip_addr: %x\n", bd->bi_ip_addr);
148 printf(" |-bi_enetaddr: %x %x %x %x %x %x\n",
149 bd->bi_enetaddr[0], bd->bi_enetaddr[1],
150 bd->bi_enetaddr[2], bd->bi_enetaddr[3],
151 bd->bi_enetaddr[4], bd->bi_enetaddr[5]);
152 printf(" |-bi_boot_params: %x\n", bd->bi_boot_params);
153 printf(" |-bi_memstart: %x\n", bd->bi_memstart);
154 printf(" |-bi_memsize: %x\n", bd->bi_memsize);
155 printf(" |-bi_flashstart: %x\n", bd->bi_flashstart);
156 printf(" |-bi_flashsize: %x\n", bd->bi_flashsize);
157 printf(" \\-bi_flashoffset: %x\n", bd->bi_flashoffset);
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100158#endif
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500159}
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100160
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500161#define CPLB_PAGE_SIZE (4 * 1024 * 1024)
162#define CPLB_PAGE_MASK (~(CPLB_PAGE_SIZE - 1))
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800163void init_cplbtables(void)
164{
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500165 volatile uint32_t *ICPLB_ADDR, *ICPLB_DATA;
166 volatile uint32_t *DCPLB_ADDR, *DCPLB_DATA;
167 uint32_t extern_memory;
168 size_t i;
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800169
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500170 void icplb_add(uint32_t addr, uint32_t data)
171 {
172 *(ICPLB_ADDR + i) = addr;
173 *(ICPLB_DATA + i) = data;
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800174 }
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500175 void dcplb_add(uint32_t addr, uint32_t data)
176 {
177 *(DCPLB_ADDR + i) = addr;
178 *(DCPLB_DATA + i) = data;
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800179 }
180
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500181 /* populate a few common entries ... we'll let
182 * the memory map and cplb exception handler do
183 * the rest of the work.
184 */
185 i = 0;
186 ICPLB_ADDR = (uint32_t *)ICPLB_ADDR0;
187 ICPLB_DATA = (uint32_t *)ICPLB_DATA0;
188 DCPLB_ADDR = (uint32_t *)DCPLB_ADDR0;
189 DCPLB_DATA = (uint32_t *)DCPLB_DATA0;
190
191 icplb_add(0xFFA00000, L1_IMEMORY);
192 dcplb_add(0xFF800000, L1_DMEMORY);
193 ++i;
194
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200195 icplb_add(CONFIG_SYS_MONITOR_BASE & CPLB_PAGE_MASK, SDRAM_IKERNEL);
196 dcplb_add(CONFIG_SYS_MONITOR_BASE & CPLB_PAGE_MASK, SDRAM_DKERNEL);
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500197 ++i;
198
199 /* If the monitor crosses a 4 meg boundary, we'll need
200 * to lock two entries for it.
201 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200202 if ((CONFIG_SYS_MONITOR_BASE & CPLB_PAGE_MASK) != ((CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN) & CPLB_PAGE_MASK)) {
203 icplb_add((CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN) & CPLB_PAGE_MASK, SDRAM_IKERNEL);
204 dcplb_add((CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN) & CPLB_PAGE_MASK, SDRAM_DKERNEL);
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500205 ++i;
206 }
207
208 icplb_add(0x20000000, SDRAM_INON_CHBL);
209 dcplb_add(0x20000000, SDRAM_EBIU);
210 ++i;
211
212 /* Add entries for the rest of external RAM up to the bootrom */
213 extern_memory = 0;
214
215#ifdef CONFIG_DEBUG_NULL_PTR
216 icplb_add(extern_memory, (SDRAM_IKERNEL & ~PAGE_SIZE_MASK) | PAGE_SIZE_1KB);
217 dcplb_add(extern_memory, (SDRAM_DKERNEL & ~PAGE_SIZE_MASK) | PAGE_SIZE_1KB);
218 ++i;
219 icplb_add(extern_memory, SDRAM_IKERNEL);
220 dcplb_add(extern_memory, SDRAM_DKERNEL);
221 extern_memory += CPLB_PAGE_SIZE;
222 ++i;
223#endif
224
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200225 while (i < 16 && extern_memory < (CONFIG_SYS_MONITOR_BASE & CPLB_PAGE_MASK)) {
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500226 icplb_add(extern_memory, SDRAM_IGENERIC);
227 dcplb_add(extern_memory, SDRAM_DGENERIC);
228 extern_memory += CPLB_PAGE_SIZE;
229 ++i;
230 }
231 while (i < 16) {
232 icplb_add(0, 0);
233 dcplb_add(0, 0);
234 ++i;
235 }
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800236}
237
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100238/*
239 * All attempts to come up with a "common" initialization sequence
240 * that works for all boards and architectures failed: some of the
241 * requirements are just _too_ different. To get rid of the resulting
242 * mess of board dependend #ifdef'ed code we now make the whole
243 * initialization sequence configurable to the user.
244 *
245 * The requirements for any new initalization function is simple: it
246 * receives a pointer to the "global data" structure as it's only
247 * argument, and returns an integer return code, where 0 means
248 * "continue" and != 0 means "fatal error, hang the system".
249 */
250
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500251extern int exception_init(void);
252extern int irq_init(void);
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500253extern int timer_init(void);
254
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100255void board_init_f(ulong bootflag)
256{
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100257 ulong addr;
258 bd_t *bd;
Mike Frysinger6dadc912008-10-20 16:15:04 -0400259 char buf[32];
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800260
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500261#ifdef CONFIG_BOARD_EARLY_INIT_F
262 serial_early_puts("Board early init flash\n");
263 board_early_init_f();
264#endif
265
266 serial_early_puts("Init CPLB tables\n");
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800267 init_cplbtables();
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100268
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500269 serial_early_puts("Exceptions setup\n");
270 exception_init();
271
272#ifndef CONFIG_ICACHE_OFF
273 serial_early_puts("Turn on ICACHE\n");
274 icache_enable();
275#endif
276#ifndef CONFIG_DCACHE_OFF
277 serial_early_puts("Turn on DCACHE\n");
278 dcache_enable();
279#endif
280
281 serial_early_puts("Init global data\n");
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200282 gd = (gd_t *) (CONFIG_SYS_GBL_DATA_ADDR);
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800283 memset((void *)gd, 0, sizeof(gd_t));
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100284
285 /* Board data initialization */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200286 addr = (CONFIG_SYS_GBL_DATA_ADDR + sizeof(gd_t));
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100287
288 /* Align to 4 byte boundary */
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100289 addr &= ~(4 - 1);
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800290 bd = (bd_t *) addr;
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100291 gd->bd = bd;
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800292 memset((void *)bd, 0, sizeof(bd_t));
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100293
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500294 bd->bi_r_version = version_string;
295 bd->bi_cpu = MK_STR(CONFIG_BFIN_CPU);
296 bd->bi_board_name = BFIN_BOARD_NAME;
297 bd->bi_vco = get_vco();
298 bd->bi_cclk = get_cclk();
299 bd->bi_sclk = get_sclk();
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800300
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500301 /* Initialize */
302 serial_early_puts("IRQ init\n");
303 irq_init();
304 serial_early_puts("Environment init\n");
305 env_init();
306 serial_early_puts("Baudrate init\n");
307 init_baudrate();
308 serial_early_puts("Serial init\n");
309 serial_init();
310 serial_early_puts("Console init flash\n");
311 console_init_f();
312 serial_early_puts("End of early debugging\n");
313 display_banner();
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800314
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100315 checkboard();
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100316 timer_init();
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500317
Mike Frysinger6dadc912008-10-20 16:15:04 -0400318 printf("Clock: VCO: %s MHz, ", strmhz(buf, get_vco()));
319 printf("Core: %s MHz, ", strmhz(buf, get_cclk()));
320 printf("System: %s MHz\n", strmhz(buf, get_sclk()));
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500321
322 printf("RAM: ");
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100323 print_size(initdram(0), "\n");
Mike Frysinger9171fc82008-03-30 15:46:13 -0400324#if defined(CONFIG_POST)
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800325 post_init_f();
326 post_bootmode_init();
327 post_run(NULL, POST_ROM | post_bootmode_get(0));
328#endif
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500329
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100330 board_init_r((gd_t *) gd, 0x20000010);
331}
332
333void board_init_r(gd_t * id, ulong dest_addr)
334{
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100335 extern void malloc_bin_reloc(void);
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500336 char *s;
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100337 bd_t *bd;
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100338 gd = id;
339 gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
340 bd = gd->bd;
341
Mike Frysinger9171fc82008-03-30 15:46:13 -0400342#if defined(CONFIG_POST)
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800343 post_output_backlog();
344 post_reloc();
345#endif
346
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200347#if !defined(CONFIG_SYS_NO_FLASH)
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100348 /* There are some other pointer constants we must deal with */
349 /* configure available FLASH banks */
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500350 extern flash_info_t flash_info[];
351 ulong size = flash_init();
352 puts("Flash: ");
353 print_size(size, "\n");
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200354 flash_protect(FLAG_PROTECT_SET, CONFIG_SYS_FLASH_BASE,
355 CONFIG_SYS_FLASH_BASE + 0x1ffff, &flash_info[0]);
356 bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100357 bd->bi_flashsize = size;
358 bd->bi_flashoffset = 0;
359#else
360 bd->bi_flashstart = 0;
361 bd->bi_flashsize = 0;
362 bd->bi_flashoffset = 0;
363#endif
364 /* initialize malloc() area */
365 mem_malloc_init();
366 malloc_bin_reloc();
367
Mike Frysinger39782722008-10-06 03:55:25 -0400368#ifdef CONFIG_CMD_NAND
369 puts("NAND: ");
370 nand_init(); /* go init the NAND */
371#endif
372
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100373 /* relocate environment function pointers etc. */
374 env_relocate();
375
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500376#ifdef CONFIG_CMD_NET
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100377 /* board MAC address */
378 s = getenv("ethaddr");
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500379 if (s == NULL) {
380# ifndef CONFIG_ETHADDR
381# if 0
382 if (!board_get_enetaddr(bd->bi_enetaddr)) {
383 char nid[20];
384 sprintf(nid, "%02X:%02X:%02X:%02X:%02X:%02X",
385 bd->bi_enetaddr[0], bd->bi_enetaddr[1],
386 bd->bi_enetaddr[2], bd->bi_enetaddr[3],
387 bd->bi_enetaddr[4], bd->bi_enetaddr[5]);
388 setenv("ethaddr", nid);
389 }
390# endif
391# endif
392 } else {
393 int i;
394 char *e;
395 for (i = 0; i < 6; ++i) {
396 bd->bi_enetaddr[i] = simple_strtoul(s, &e, 16);
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100397 s = (*e) ? e + 1 : e;
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500398 }
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100399 }
400
401 /* IP Address */
402 bd->bi_ip_addr = getenv_IPaddr("ipaddr");
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500403#endif
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100404
405 /* Initialize devices */
406 devices_init();
407 jumptable_init();
408
409 /* Initialize the console (after the relocation and devices init) */
410 console_init_r();
411
412 /* Initialize from environment */
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500413 if ((s = getenv("loadaddr")) != NULL)
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100414 load_addr = simple_strtoul(s, NULL, 16);
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500415#ifdef CONFIG_CMD_NET
416 if ((s = getenv("bootfile")) != NULL)
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100417 copy_filename(BootFile, s, sizeof(BootFile));
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100418#endif
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800419
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100420#if defined(CONFIG_MISC_INIT_R)
421 /* miscellaneous platform dependent initialisations */
422 misc_init_r();
423#endif
424
Mike Frysingerf7ce12c2008-02-18 05:26:48 -0500425#ifdef CONFIG_CMD_NET
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500426 printf("Net: ");
427 eth_initialize(gd->bd);
428 if (getenv("ethaddr"))
429 printf("MAC: %02X:%02X:%02X:%02X:%02X:%02X\n",
430 bd->bi_enetaddr[0], bd->bi_enetaddr[1], bd->bi_enetaddr[2],
431 bd->bi_enetaddr[3], bd->bi_enetaddr[4], bd->bi_enetaddr[5]);
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800432#endif
433
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800434 display_global_data();
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800435
Mike Frysinger9171fc82008-03-30 15:46:13 -0400436#if defined(CONFIG_POST)
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800437 if (post_flag)
438 post_run(NULL, POST_RAM | post_bootmode_get(0));
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100439#endif
440
441 /* main_loop() can return to retry autoboot, if so just run it again. */
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500442 for (;;)
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100443 main_loop();
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100444}
445
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100446void hang(void)
447{
448 puts("### ERROR ### Please RESET the board ###\n");
Mike Frysingerd5bffeb2008-02-19 00:54:20 -0500449 while (1)
450 /* If a JTAG emulator is hooked up, we'll automatically trigger
451 * a breakpoint in it. If one isn't, this is just a NOP.
452 */
453 asm("emuexcpt;");
Wolfgang Denk6cb142f2006-03-12 02:12:27 +0100454}