blob: 7e586fea5c076a9a6104e3ce0ebab95873b2a6c3 [file] [log] [blame]
wdenkabf7a7c2003-12-08 01:34:36 +00001/*
wdenke65527f2004-02-12 00:47:09 +00002 * (C) Copyright 2003
3 * Josef Baumgartner <josef.baumgartner@telex.de>
4 *
5 * (C) Copyright 2000-2002
wdenkabf7a7c2003-12-08 01:34:36 +00006 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
7 *
8 * See file CREDITS for list of people who contributed to this
9 * project.
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24 * MA 02111-1307 USA
25 */
26
27#include <common.h>
28#include <watchdog.h>
29#include <command.h>
30#include <malloc.h>
31#include <devices.h>
wdenke65527f2004-02-12 00:47:09 +000032
33#ifdef CONFIG_M5272
34#include <asm/immap_5272.h>
35#endif
36
wdenkabf7a7c2003-12-08 01:34:36 +000037#if (CONFIG_COMMANDS & CFG_CMD_IDE)
38#include <ide.h>
39#endif
40#if (CONFIG_COMMANDS & CFG_CMD_SCSI)
41#include <scsi.h>
42#endif
43#if (CONFIG_COMMANDS & CFG_CMD_KGDB)
44#include <kgdb.h>
45#endif
46#ifdef CONFIG_STATUS_LED
47#include <status_led.h>
48#endif
49#include <net.h>
50#if (CONFIG_COMMANDS & CFG_CMD_BEDBUG)
51#include <cmd_bedbug.h>
52#endif
53#ifdef CFG_ALLOC_DPRAM
54#include <commproc.h>
55#endif
56#include <version.h>
57
58static char *failed = "*** failed ***\n";
59
60#ifdef CONFIG_PCU_E
61extern flash_info_t flash_info[];
62#endif
63
wdenke65527f2004-02-12 00:47:09 +000064#include <environment.h>
65
wdenkabf7a7c2003-12-08 01:34:36 +000066#if ( ((CFG_ENV_ADDR+CFG_ENV_SIZE) < CFG_MONITOR_BASE) || \
67 (CFG_ENV_ADDR >= (CFG_MONITOR_BASE + CFG_MONITOR_LEN)) ) || \
68 defined(CFG_ENV_IS_IN_NVRAM)
69#define TOTAL_MALLOC_LEN (CFG_MALLOC_LEN + CFG_ENV_SIZE)
70#else
71#define TOTAL_MALLOC_LEN CFG_MALLOC_LEN
72#endif
73
wdenke65527f2004-02-12 00:47:09 +000074extern ulong __init_end;
75extern ulong _end;
76
77extern void timer_init(void);
78
79#if defined(CONFIG_WATCHDOG)
80# define INIT_FUNC_WATCHDOG_INIT watchdog_init,
81# define WATCHDOG_DISABLE watchdog_disable
82
83extern int watchdog_init(void);
84extern int watchdog_disable(void);
85#else
86# define INIT_FUNC_WATCHDOG_INIT /* undef */
87# define WATCHDOG_DISABLE /* undef */
88#endif /* CONFIG_WATCHDOG */
89
90ulong monitor_flash_len;
91
wdenkabf7a7c2003-12-08 01:34:36 +000092/*
93 * Begin and End of memory area for malloc(), and current "brk"
94 */
wdenke65527f2004-02-12 00:47:09 +000095static ulong mem_malloc_start = 0;
96static ulong mem_malloc_end = 0;
97static ulong mem_malloc_brk = 0;
wdenkabf7a7c2003-12-08 01:34:36 +000098
99/************************************************************************
100 * Utilities *
101 ************************************************************************
102 */
103
104/*
105 * The Malloc area is immediately below the monitor copy in DRAM
106 */
wdenke65527f2004-02-12 00:47:09 +0000107static void mem_malloc_init (void)
wdenkabf7a7c2003-12-08 01:34:36 +0000108{
wdenke65527f2004-02-12 00:47:09 +0000109 DECLARE_GLOBAL_DATA_PTR;
110
111 ulong dest_addr = CFG_MONITOR_BASE + gd->reloc_off;
112
wdenkabf7a7c2003-12-08 01:34:36 +0000113 mem_malloc_end = dest_addr;
114 mem_malloc_start = dest_addr - TOTAL_MALLOC_LEN;
115 mem_malloc_brk = mem_malloc_start;
116
wdenke65527f2004-02-12 00:47:09 +0000117 memset ((void *) mem_malloc_start,
118 0,
wdenkabf7a7c2003-12-08 01:34:36 +0000119 mem_malloc_end - mem_malloc_start);
120}
121
122void *sbrk (ptrdiff_t increment)
123{
124 ulong old = mem_malloc_brk;
125 ulong new = old + increment;
126
wdenke65527f2004-02-12 00:47:09 +0000127 if ((new < mem_malloc_start) ||
128 (new > mem_malloc_end) ) {
wdenkabf7a7c2003-12-08 01:34:36 +0000129 return (NULL);
130 }
131 mem_malloc_brk = new;
wdenke65527f2004-02-12 00:47:09 +0000132 return ((void *)old);
wdenkabf7a7c2003-12-08 01:34:36 +0000133}
134
wdenke65527f2004-02-12 00:47:09 +0000135char *strmhz(char *buf, long hz)
wdenkabf7a7c2003-12-08 01:34:36 +0000136{
wdenke65527f2004-02-12 00:47:09 +0000137 long l, n;
138 long m;
wdenkabf7a7c2003-12-08 01:34:36 +0000139
wdenke65527f2004-02-12 00:47:09 +0000140 n = hz / 1000000L;
wdenkabf7a7c2003-12-08 01:34:36 +0000141
wdenke65527f2004-02-12 00:47:09 +0000142 l = sprintf (buf, "%ld", n);
wdenkabf7a7c2003-12-08 01:34:36 +0000143
wdenke65527f2004-02-12 00:47:09 +0000144 m = (hz % 1000000L) / 1000L;
wdenkabf7a7c2003-12-08 01:34:36 +0000145
wdenke65527f2004-02-12 00:47:09 +0000146 if (m != 0)
147 sprintf (buf+l, ".%03ld", m);
wdenkabf7a7c2003-12-08 01:34:36 +0000148
wdenke65527f2004-02-12 00:47:09 +0000149 return (buf);
wdenkabf7a7c2003-12-08 01:34:36 +0000150}
151
wdenke65527f2004-02-12 00:47:09 +0000152/*
153 * All attempts to come up with a "common" initialization sequence
154 * that works for all boards and architectures failed: some of the
155 * requirements are just _too_ different. To get rid of the resulting
156 * mess of board dependend #ifdef'ed code we now make the whole
157 * initialization sequence configurable to the user.
158 *
159 * The requirements for any new initalization function is simple: it
160 * receives a pointer to the "global data" structure as it's only
161 * argument, and returns an integer return code, where 0 means
162 * "continue" and != 0 means "fatal error, hang the system".
163 */
164typedef int (init_fnc_t) (void);
165
166/************************************************************************
167 * Init Utilities *
168 ************************************************************************
169 * Some of this code should be moved into the core functions,
170 * but let's get it working (again) first...
171 */
172
173static int init_baudrate (void)
wdenkabf7a7c2003-12-08 01:34:36 +0000174{
wdenke65527f2004-02-12 00:47:09 +0000175 DECLARE_GLOBAL_DATA_PTR;
176
177 uchar tmp[64]; /* long enough for environment variables */
178 int i = getenv_r ("baudrate", tmp, sizeof (tmp));
179
180 gd->baudrate = (i > 0)
181 ? (int) simple_strtoul (tmp, NULL, 10)
182 : CONFIG_BAUDRATE;
183 return (0);
184}
wdenkabf7a7c2003-12-08 01:34:36 +0000185
wdenke65527f2004-02-12 00:47:09 +0000186/***********************************************************************/
wdenkabf7a7c2003-12-08 01:34:36 +0000187
wdenke65527f2004-02-12 00:47:09 +0000188static int init_func_ram (void)
189{
190 DECLARE_GLOBAL_DATA_PTR;
wdenkabf7a7c2003-12-08 01:34:36 +0000191
wdenke65527f2004-02-12 00:47:09 +0000192 int board_type = 0; /* use dummy arg */
193 puts ("DRAM: ");
wdenkabf7a7c2003-12-08 01:34:36 +0000194
wdenke65527f2004-02-12 00:47:09 +0000195 if ((gd->ram_size = initdram (board_type)) > 0) {
196 print_size (gd->ram_size, "\n");
197 return (0);
198 }
199 puts (failed);
200 return (1);
wdenkabf7a7c2003-12-08 01:34:36 +0000201}
202
wdenke65527f2004-02-12 00:47:09 +0000203/***********************************************************************/
204
205/************************************************************************
206 * Initialization sequence *
207 ************************************************************************
208 */
209
210init_fnc_t *init_sequence[] = {
211 env_init,
212 init_baudrate,
213 serial_init,
214 console_init_f,
215 display_options,
216 checkcpu,
217 checkboard,
218 init_func_ram,
219#if defined(CFG_DRAM_TEST)
220 testdram,
221#endif /* CFG_DRAM_TEST */
222 INIT_FUNC_WATCHDOG_INIT
223 NULL, /* Terminate this list */
224};
225
226
wdenkabf7a7c2003-12-08 01:34:36 +0000227/************************************************************************
228 *
229 * This is the first part of the initialization sequence that is
230 * implemented in C, but still running from ROM.
231 *
232 * The main purpose is to provide a (serial) console interface as
233 * soon as possible (so we can see any error messages), and to
234 * initialize the RAM so that we can relocate the monitor code to
235 * RAM.
236 *
237 * Be aware of the restrictions: global data is read-only, BSS is not
238 * initialized, and stack space is limited to a few kB.
239 *
240 ************************************************************************
241 */
242
wdenke65527f2004-02-12 00:47:09 +0000243void
244board_init_f (ulong bootflag)
wdenkabf7a7c2003-12-08 01:34:36 +0000245{
wdenke65527f2004-02-12 00:47:09 +0000246 DECLARE_GLOBAL_DATA_PTR;
wdenkabf7a7c2003-12-08 01:34:36 +0000247
248 bd_t *bd;
wdenke65527f2004-02-12 00:47:09 +0000249 ulong len, addr, addr_sp;
250 gd_t *id;
251 init_fnc_t **init_fnc_ptr;
252#ifdef CONFIG_PRAM
253 int i;
254 ulong reg;
wdenkabf7a7c2003-12-08 01:34:36 +0000255 uchar tmp[64]; /* long enough for environment variables */
wdenke65527f2004-02-12 00:47:09 +0000256#endif
wdenkabf7a7c2003-12-08 01:34:36 +0000257
wdenke65527f2004-02-12 00:47:09 +0000258 /* Pointer is writable since we allocated a register for it */
259 gd = (gd_t *) (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET);
wdenk3337af42004-07-01 20:28:03 +0000260 /* compiler optimization barrier needed for GCC >= 3.4 */
261 __asm__ __volatile__("": : :"memory");
wdenkabf7a7c2003-12-08 01:34:36 +0000262
wdenke65527f2004-02-12 00:47:09 +0000263 /* Clear initial global data */
264 memset ((void *) gd, 0, sizeof (gd_t));
wdenkabf7a7c2003-12-08 01:34:36 +0000265
wdenke65527f2004-02-12 00:47:09 +0000266 for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
267 if ((*init_fnc_ptr)() != 0) {
268 hang ();
269 }
wdenkabf7a7c2003-12-08 01:34:36 +0000270 }
wdenkabf7a7c2003-12-08 01:34:36 +0000271
272 /*
273 * Now that we have DRAM mapped and working, we can
274 * relocate the code and continue running from DRAM.
275 *
276 * Reserve memory at end of RAM for (top down in that order):
wdenke65527f2004-02-12 00:47:09 +0000277 * - protected RAM
278 * - LCD framebuffer
279 * - monitor code
280 * - board info struct
wdenkabf7a7c2003-12-08 01:34:36 +0000281 */
wdenke65527f2004-02-12 00:47:09 +0000282 len = (ulong)&_end - CFG_MONITOR_BASE;
wdenkabf7a7c2003-12-08 01:34:36 +0000283
wdenke65527f2004-02-12 00:47:09 +0000284 addr = CFG_SDRAM_BASE + gd->ram_size;
wdenkabf7a7c2003-12-08 01:34:36 +0000285
wdenke65527f2004-02-12 00:47:09 +0000286#ifdef CONFIG_LOGBUFFER
287 /* reserve kernel log buffer */
288 addr -= (LOGBUFF_RESERVE);
289 debug ("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN, addr);
290#endif
291
292#ifdef CONFIG_PRAM
293 /*
294 * reserve protected RAM
295 */
296 i = getenv_r ("pram", tmp, sizeof (tmp));
297 reg = (i > 0) ? simple_strtoul (tmp, NULL, 10) : CONFIG_PRAM;
298 addr -= (reg << 10); /* size is in kB */
299 debug ("Reserving %ldk for protected RAM at %08lx\n", reg, addr);
300#endif /* CONFIG_PRAM */
wdenkabf7a7c2003-12-08 01:34:36 +0000301
wdenke65527f2004-02-12 00:47:09 +0000302 /*
303 * reserve memory for U-Boot code, data & bss
304 * round down to next 4 kB limit
305 */
wdenkabf7a7c2003-12-08 01:34:36 +0000306 addr -= len;
wdenke65527f2004-02-12 00:47:09 +0000307 addr &= ~(4096 - 1);
308
309 debug ("Reserving %ldk for U-Boot at: %08lx\n", len >> 10, addr);
wdenkabf7a7c2003-12-08 01:34:36 +0000310
311 /*
wdenke65527f2004-02-12 00:47:09 +0000312 * reserve memory for malloc() arena
wdenkabf7a7c2003-12-08 01:34:36 +0000313 */
wdenke65527f2004-02-12 00:47:09 +0000314 addr_sp = addr - TOTAL_MALLOC_LEN;
315 debug ("Reserving %dk for malloc() at: %08lx\n",
316 TOTAL_MALLOC_LEN >> 10, addr_sp);
wdenkabf7a7c2003-12-08 01:34:36 +0000317
wdenke65527f2004-02-12 00:47:09 +0000318 /*
319 * (permanently) allocate a Board Info struct
320 * and a permanent copy of the "global" data
321 */
322 addr_sp -= sizeof (bd_t);
323 bd = (bd_t *) addr_sp;
324 gd->bd = bd;
325 debug ("Reserving %d Bytes for Board Info at: %08lx\n",
326 sizeof (bd_t), addr_sp);
327 addr_sp -= sizeof (gd_t);
328 id = (gd_t *) addr_sp;
329 debug ("Reserving %d Bytes for Global Data at: %08lx\n",
330 sizeof (gd_t), addr_sp);
wdenkabf7a7c2003-12-08 01:34:36 +0000331
wdenke65527f2004-02-12 00:47:09 +0000332 /* Reserve memory for boot params. */
333 addr_sp -= CFG_BOOTPARAMS_LEN;
334 bd->bi_boot_params = addr_sp;
335 debug ("Reserving %dk for boot parameters at: %08lx\n",
336 CFG_BOOTPARAMS_LEN >> 10, addr_sp);
337
338 /*
339 * Finally, we set up a new (bigger) stack.
340 *
341 * Leave some safety gap for SP, force alignment on 16 byte boundary
342 * Clear initial stack frame
343 */
344 addr_sp -= 16;
345 addr_sp &= ~0xF;
346 *((ulong *) addr_sp)-- = 0;
347 *((ulong *) addr_sp)-- = 0;
348 debug ("Stack Pointer at: %08lx\n", addr_sp);
349
350 /*
351 * Save local variables to board info struct
352 */
353 bd->bi_memstart = CFG_SDRAM_BASE; /* start of DRAM memory */
354 bd->bi_memsize = gd->ram_size; /* size of DRAM memory in bytes */
355 bd->bi_mbar_base = CFG_MBAR; /* base of internal registers */
356
357 bd->bi_bootflags = bootflag; /* boot / reboot flag (for LynxOS) */
wdenkabf7a7c2003-12-08 01:34:36 +0000358
wdenke65527f2004-02-12 00:47:09 +0000359 WATCHDOG_RESET ();
360 bd->bi_intfreq = gd->cpu_clk; /* Internal Freq, in Hz */
361 bd->bi_busfreq = gd->bus_clk; /* Bus Freq, in Hz */
362 bd->bi_baudrate = gd->baudrate; /* Console Baudrate */
wdenkabf7a7c2003-12-08 01:34:36 +0000363
364#ifdef CFG_EXTBDINFO
365 strncpy (bd->bi_s_version, "1.2", sizeof (bd->bi_s_version));
wdenke65527f2004-02-12 00:47:09 +0000366 strncpy (bd->bi_r_version, U_BOOT_VERSION, sizeof (bd->bi_r_version));
367#endif
368
369 WATCHDOG_RESET ();
wdenkabf7a7c2003-12-08 01:34:36 +0000370
wdenke65527f2004-02-12 00:47:09 +0000371#ifdef CONFIG_POST
372 post_bootmode_init();
373 post_run (NULL, POST_ROM | post_bootmode_get(0));
wdenkabf7a7c2003-12-08 01:34:36 +0000374#endif
375
wdenke65527f2004-02-12 00:47:09 +0000376 WATCHDOG_RESET();
wdenkabf7a7c2003-12-08 01:34:36 +0000377
wdenke65527f2004-02-12 00:47:09 +0000378 memcpy (id, (void *)gd, sizeof (gd_t));
wdenkabf7a7c2003-12-08 01:34:36 +0000379
wdenke65527f2004-02-12 00:47:09 +0000380 debug ("Start relocate of code from %08x to %08lx\n", CFG_MONITOR_BASE, addr);
381 relocate_code (addr_sp, id, addr);
382
383 /* NOTREACHED - jump_to_ram() does not return */
384}
wdenkabf7a7c2003-12-08 01:34:36 +0000385
386/************************************************************************
387 *
388 * This is the next part if the initialization sequence: we are now
389 * running from RAM and have a "normal" C environment, i. e. global
390 * data can be written, BSS has been cleared, the stack size in not
391 * that critical any more, etc.
392 *
393 ************************************************************************
394 */
wdenke65527f2004-02-12 00:47:09 +0000395void board_init_r (gd_t *id, ulong dest_addr)
wdenkabf7a7c2003-12-08 01:34:36 +0000396{
397 DECLARE_GLOBAL_DATA_PTR;
wdenkabf7a7c2003-12-08 01:34:36 +0000398 cmd_tbl_t *cmdtp;
wdenke65527f2004-02-12 00:47:09 +0000399 char *s, *e;
wdenkabf7a7c2003-12-08 01:34:36 +0000400 bd_t *bd;
wdenke65527f2004-02-12 00:47:09 +0000401 int i;
402 extern void malloc_bin_reloc (void);
wdenkabf7a7c2003-12-08 01:34:36 +0000403
wdenke65527f2004-02-12 00:47:09 +0000404#ifndef CFG_ENV_IS_NOWHERE
405 extern char * env_name_spec;
406#endif
407#ifndef CFG_NO_FLASH
408 ulong flash_size;
409#endif
410 gd = id; /* initialize RAM version of global data */
wdenkabf7a7c2003-12-08 01:34:36 +0000411 bd = gd->bd;
wdenke65527f2004-02-12 00:47:09 +0000412
413 gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
414
415 debug ("Now running in RAM - U-Boot at: %08lx\n", dest_addr);
416
417 WATCHDOG_RESET ();
418
419 gd->reloc_off = dest_addr - CFG_MONITOR_BASE;
420
421 monitor_flash_len = (ulong)&__init_end - dest_addr;
wdenkabf7a7c2003-12-08 01:34:36 +0000422
423 /*
wdenke65527f2004-02-12 00:47:09 +0000424 * We have to relocate the command table manually
425 */
426 for (cmdtp = &__u_boot_cmd_start; cmdtp != &__u_boot_cmd_end; cmdtp++) {
427 ulong addr;
428 addr = (ulong) (cmdtp->cmd) + gd->reloc_off;
429#if 0
430 printf ("Command \"%s\": 0x%08lx => 0x%08lx\n",
431 cmdtp->name, (ulong) (cmdtp->cmd), addr);
432#endif
433 cmdtp->cmd =
434 (int (*)(struct cmd_tbl_s *, int, int, char *[]))addr;
435
436 addr = (ulong)(cmdtp->name) + gd->reloc_off;
437 cmdtp->name = (char *)addr;
438
439 if (cmdtp->usage) {
440 addr = (ulong)(cmdtp->usage) + gd->reloc_off;
441 cmdtp->usage = (char *)addr;
442 }
443#ifdef CFG_LONGHELP
444 if (cmdtp->help) {
445 addr = (ulong)(cmdtp->help) + gd->reloc_off;
446 cmdtp->help = (char *)addr;
447 }
448#endif
449 }
450 /* there are some other pointer constants we must deal with */
451#ifndef CFG_ENV_IS_NOWHERE
452 env_name_spec += gd->reloc_off;
453#endif
454
455 WATCHDOG_RESET ();
456
457#ifdef CONFIG_LOGBUFFER
458 logbuff_init_ptrs ();
459#endif
460#ifdef CONFIG_POST
461 post_output_backlog ();
462 post_reloc ();
463#endif
464 WATCHDOG_RESET();
465
466#if 0
467 /* instruction cache enabled in cpu_init_f() for faster relocation */
468 icache_enable (); /* it's time to enable the instruction cache */
469#endif
470
471 /*
wdenkabf7a7c2003-12-08 01:34:36 +0000472 * Setup trap handlers
473 */
wdenke65527f2004-02-12 00:47:09 +0000474 trap_init (0);
wdenkabf7a7c2003-12-08 01:34:36 +0000475
wdenke65527f2004-02-12 00:47:09 +0000476#if !defined(CFG_NO_FLASH)
wdenkabf7a7c2003-12-08 01:34:36 +0000477 puts ("FLASH: ");
478
479 if ((flash_size = flash_init ()) > 0) {
wdenke65527f2004-02-12 00:47:09 +0000480# ifdef CFG_FLASH_CHECKSUM
481 print_size (flash_size, "");
wdenkabf7a7c2003-12-08 01:34:36 +0000482 /*
483 * Compute and print flash CRC if flashchecksum is set to 'y'
484 *
wdenke65527f2004-02-12 00:47:09 +0000485 * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
wdenkabf7a7c2003-12-08 01:34:36 +0000486 */
487 s = getenv ("flashchecksum");
488 if (s && (*s == 'y')) {
489 printf (" CRC: %08lX",
wdenke65527f2004-02-12 00:47:09 +0000490 crc32 (0,
491 (const unsigned char *) CFG_FLASH_BASE,
492 flash_size)
493 );
wdenkabf7a7c2003-12-08 01:34:36 +0000494 }
495 putc ('\n');
wdenke65527f2004-02-12 00:47:09 +0000496# else /* !CFG_FLASH_CHECKSUM */
497 print_size (flash_size, "\n");
498# endif /* CFG_FLASH_CHECKSUM */
wdenkabf7a7c2003-12-08 01:34:36 +0000499 } else {
500 puts (failed);
501 hang ();
502 }
503
wdenke65527f2004-02-12 00:47:09 +0000504 bd->bi_flashstart = CFG_FLASH_BASE; /* update start of FLASH memory */
505 bd->bi_flashsize = flash_size; /* size of FLASH memory (final value) */
506 bd->bi_flashoffset = 0;
507#else /* CFG_NO_FLASH */
508 bd->bi_flashsize = 0;
509 bd->bi_flashstart = 0;
510 bd->bi_flashoffset = 0;
511#endif /* !CFG_NO_FLASH */
wdenkabf7a7c2003-12-08 01:34:36 +0000512
513 WATCHDOG_RESET ();
514
515 /* initialize higher level parts of CPU like time base and timers */
516 cpu_init_r ();
517
518 WATCHDOG_RESET ();
519
520 /* initialize malloc() area */
wdenke65527f2004-02-12 00:47:09 +0000521 mem_malloc_init ();
522 malloc_bin_reloc ();
wdenkabf7a7c2003-12-08 01:34:36 +0000523
524#ifdef CONFIG_SPI
525# if !defined(CFG_ENV_IS_IN_EEPROM)
526 spi_init_f ();
527# endif
528 spi_init_r ();
529#endif
530
531 /* relocate environment function pointers etc. */
532 env_relocate ();
533
wdenke65527f2004-02-12 00:47:09 +0000534 /*
535 * Fill in missing fields of bd_info.
536 * We do this here, where we have "normal" access to the
537 * environment; we used to do this still running from ROM,
538 * where had to use getenv_r(), which can be pretty slow when
539 * the environment is in EEPROM.
540 */
541 s = getenv ("ethaddr");
542 for (i = 0; i < 6; ++i) {
543 bd->bi_enetaddr[i] = s ? simple_strtoul (s, &e, 16) : 0;
544 if (s)
545 s = (*e) ? e + 1 : e;
546 }
547
wdenkabf7a7c2003-12-08 01:34:36 +0000548 /* IP Address */
549 bd->bi_ip_addr = getenv_IPaddr ("ipaddr");
550
551 WATCHDOG_RESET ();
552
wdenkabf7a7c2003-12-08 01:34:36 +0000553
wdenke65527f2004-02-12 00:47:09 +0000554 /** leave this here (after malloc(), environment and PCI are working) **/
555 /* Initialize devices */
556 devices_init ();
wdenkabf7a7c2003-12-08 01:34:36 +0000557
wdenke65527f2004-02-12 00:47:09 +0000558 /* Initialize the jump table for applications */
559 jumptable_init ();
wdenkabf7a7c2003-12-08 01:34:36 +0000560
wdenke65527f2004-02-12 00:47:09 +0000561 /* Initialize the console (after the relocation and devices init) */
562 console_init_r ();
wdenkabf7a7c2003-12-08 01:34:36 +0000563
564#if (CONFIG_COMMANDS & CFG_CMD_KGDB)
565 WATCHDOG_RESET ();
566 puts ("KGDB: ");
567 kgdb_init ();
568#endif
569
wdenke65527f2004-02-12 00:47:09 +0000570 debug ("U-Boot relocated to %08lx\n", dest_addr);
571
wdenkabf7a7c2003-12-08 01:34:36 +0000572 /*
573 * Enable Interrupts
574 */
575 interrupt_init ();
wdenke65527f2004-02-12 00:47:09 +0000576
577 /* Must happen after interrupts are initialized since
578 * an irq handler gets installed
579 */
580 timer_init();
581
wdenkc35ba4e2004-03-14 22:25:36 +0000582#ifdef CONFIG_SERIAL_SOFTWARE_FIFO
wdenke65527f2004-02-12 00:47:09 +0000583 serial_buffered_init();
584#endif
585
586#ifdef CONFIG_STATUS_LED
587 status_led_set (STATUS_LED_BOOT, STATUS_LED_BLINKING);
588#endif
589
wdenkabf7a7c2003-12-08 01:34:36 +0000590 udelay (20);
wdenke65527f2004-02-12 00:47:09 +0000591
wdenkabf7a7c2003-12-08 01:34:36 +0000592 set_timer (0);
593
594 /* Insert function pointers now that we have relocated the code */
595
596 /* Initialize from environment */
597 if ((s = getenv ("loadaddr")) != NULL) {
598 load_addr = simple_strtoul (s, NULL, 16);
599 }
600#if (CONFIG_COMMANDS & CFG_CMD_NET)
601 if ((s = getenv ("bootfile")) != NULL) {
602 copy_filename (BootFile, s, sizeof (BootFile));
603 }
604#endif /* CFG_CMD_NET */
605
wdenke65527f2004-02-12 00:47:09 +0000606 WATCHDOG_RESET ();
607
608#if (CONFIG_COMMANDS & CFG_CMD_DOC)
wdenkabf7a7c2003-12-08 01:34:36 +0000609 WATCHDOG_RESET ();
wdenke65527f2004-02-12 00:47:09 +0000610 puts ("DOC: ");
611 doc_init ();
612#endif
wdenkabf7a7c2003-12-08 01:34:36 +0000613
wdenke65527f2004-02-12 00:47:09 +0000614#if (CONFIG_COMMANDS & CFG_CMD_NAND)
wdenkabf7a7c2003-12-08 01:34:36 +0000615 WATCHDOG_RESET ();
wdenke65527f2004-02-12 00:47:09 +0000616 puts ("NAND:");
617 nand_init(); /* go init the NAND */
618#endif
619
620#if (CONFIG_COMMANDS & CFG_CMD_NET) && defined(FEC_ENET)
621 WATCHDOG_RESET();
622 eth_init(bd);
623#endif
624
625#ifdef CONFIG_POST
626 post_run (NULL, POST_RAM | post_bootmode_get(0));
wdenkabf7a7c2003-12-08 01:34:36 +0000627#endif
628
629#ifdef CONFIG_LAST_STAGE_INIT
630 WATCHDOG_RESET ();
631 /*
632 * Some parts can be only initialized if all others (like
633 * Interrupts) are up and running (i.e. the PC-style ISA
634 * keyboard).
635 */
636 last_stage_init ();
637#endif
638
639#if (CONFIG_COMMANDS & CFG_CMD_BEDBUG)
640 WATCHDOG_RESET ();
641 bedbug_init ();
642#endif
643
wdenke65527f2004-02-12 00:47:09 +0000644#if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
wdenkabf7a7c2003-12-08 01:34:36 +0000645 /*
646 * Export available size of memory for Linux,
647 * taking into account the protected RAM at top of memory
648 */
649 {
650 ulong pram;
wdenkabf7a7c2003-12-08 01:34:36 +0000651 uchar memsz[32];
wdenke65527f2004-02-12 00:47:09 +0000652#ifdef CONFIG_PRAM
653 char *s;
wdenkabf7a7c2003-12-08 01:34:36 +0000654
655 if ((s = getenv ("pram")) != NULL) {
656 pram = simple_strtoul (s, NULL, 10);
657 } else {
658 pram = CONFIG_PRAM;
659 }
wdenke65527f2004-02-12 00:47:09 +0000660#else
661 pram=0;
662#endif
663#ifdef CONFIG_LOGBUFFER
664 /* Also take the logbuffer into account (pram is in kB) */
665 pram += (LOGBUFF_LEN+LOGBUFF_OVERHEAD)/1024;
666#endif
wdenkabf7a7c2003-12-08 01:34:36 +0000667 sprintf (memsz, "%ldk", (bd->bi_memsize / 1024) - pram);
668 setenv ("mem", memsz);
669 }
670#endif
671
wdenke65527f2004-02-12 00:47:09 +0000672#ifdef CONFIG_MODEM_SUPPORT
673 {
674 extern int do_mdm_init;
675 do_mdm_init = gd->do_mdm_init;
676 }
677#endif
678
679#ifdef CONFIG_WATCHDOG
680 /* disable watchdog if environment is set */
681 if ((s = getenv ("watchdog")) != NULL) {
682 if (strncmp (s, "off", 3) == 0) {
683 WATCHDOG_DISABLE ();
684 }
685 }
686#endif /* CONFIG_WATCHDOG*/
687
688
wdenkabf7a7c2003-12-08 01:34:36 +0000689 /* Initialization complete - start the monitor */
690
691 /* main_loop() can return to retry autoboot, if so just run it again. */
692 for (;;) {
693 WATCHDOG_RESET ();
694 main_loop ();
695 }
696
697 /* NOTREACHED - no way out of command loop except booting */
698}
699
wdenke65527f2004-02-12 00:47:09 +0000700
701void hang(void)
wdenkabf7a7c2003-12-08 01:34:36 +0000702{
703 puts ("### ERROR ### Please RESET the board ###\n");
704 for (;;);
705}