]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - lib_ppc/board.c
* Add support for log buffer which can be passed to Linux kernel's
[karo-tx-uboot.git] / lib_ppc / board.c
1 /*
2  * (C) Copyright 2000-2002
3  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4  *
5  * See file CREDITS for list of people who contributed to this
6  * project.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of
11  * the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21  * MA 02111-1307 USA
22  */
23
24 #include <common.h>
25 #include <watchdog.h>
26 #include <command.h>
27 #include <malloc.h>
28 #include <devices.h>
29 #include <syscall.h>
30 #ifdef CONFIG_8xx
31 #include <mpc8xx.h>
32 #endif
33 #if (CONFIG_COMMANDS & CFG_CMD_IDE)
34 #include <ide.h>
35 #endif
36 #if (CONFIG_COMMANDS & CFG_CMD_SCSI)
37 #include <scsi.h>
38 #endif
39 #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
40 #include <kgdb.h>
41 #endif
42 #ifdef CONFIG_STATUS_LED
43 #include <status_led.h>
44 #endif
45 #include <net.h>
46 #if (CONFIG_COMMANDS & CFG_CMD_BEDBUG)
47 #include <cmd_bedbug.h>
48 #endif
49 #ifdef CFG_ALLOC_DPRAM
50 #include <commproc.h>
51 #endif
52 #include <version.h>
53 #if defined(CONFIG_BAB7xx)
54 #include <w83c553f.h>
55 #endif
56 #include <dtt.h>
57 #if defined(CONFIG_POST)
58 #include <post.h>
59 #endif
60 #if defined(CONFIG_LOGBUFFER)
61 #include <logbuff.h>
62 #endif
63
64 #if (CONFIG_COMMANDS & CFG_CMD_DOC)
65 void doc_init (void);
66 #endif
67 #if defined(CONFIG_HARD_I2C) || \
68     defined(CONFIG_SOFT_I2C)
69 #include <i2c.h>
70 #endif
71
72 static char *failed = "*** failed ***\n";
73
74 #if defined(CONFIG_PCU_E) || defined(CONFIG_OXC)
75 extern flash_info_t flash_info[];
76 #endif
77
78 #include <environment.h>
79
80 #if ( ((CFG_ENV_ADDR+CFG_ENV_SIZE) < CFG_MONITOR_BASE) || \
81       (CFG_ENV_ADDR >= (CFG_MONITOR_BASE + CFG_MONITOR_LEN)) ) || \
82     defined(CFG_ENV_IS_IN_NVRAM)
83 #define TOTAL_MALLOC_LEN        (CFG_MALLOC_LEN + CFG_ENV_SIZE)
84 #else
85 #define TOTAL_MALLOC_LEN        CFG_MALLOC_LEN
86 #endif
87
88 /*
89  * Begin and End of memory area for malloc(), and current "brk"
90  */
91 static  ulong   mem_malloc_start = 0;
92 static  ulong   mem_malloc_end   = 0;
93 static  ulong   mem_malloc_brk   = 0;
94
95 /************************************************************************
96  * Utilities                                                            *
97  ************************************************************************
98  */
99
100 /*
101  * The Malloc area is immediately below the monitor copy in DRAM
102  */
103 static void mem_malloc_init (void)
104 {
105         DECLARE_GLOBAL_DATA_PTR;
106
107         ulong dest_addr = CFG_MONITOR_BASE + gd->reloc_off;
108
109         mem_malloc_end = dest_addr;
110         mem_malloc_start = dest_addr - TOTAL_MALLOC_LEN;
111         mem_malloc_brk = mem_malloc_start;
112
113         memset ((void *) mem_malloc_start,
114                 0,
115                 mem_malloc_end - mem_malloc_start);
116 }
117
118 void *sbrk (ptrdiff_t increment)
119 {
120         ulong old = mem_malloc_brk;
121         ulong new = old + increment;
122
123         if ((new < mem_malloc_start) || (new > mem_malloc_end)) {
124                 return (NULL);
125         }
126         mem_malloc_brk = new;
127         return ((void *) old);
128 }
129
130 char *strmhz (char *buf, long hz)
131 {
132         long l, n;
133         long m;
134
135         n = hz / 1000000L;
136         l = sprintf (buf, "%ld", n);
137         m = (hz % 1000000L) / 1000L;
138         if (m != 0)
139                 sprintf (buf + l, ".%03ld", m);
140         return (buf);
141 }
142
143 static void syscalls_init (void)
144 {
145         ulong *addr;
146
147         syscall_tbl[SYSCALL_MALLOC] = (void *) malloc;
148         syscall_tbl[SYSCALL_FREE] = (void *) free;
149
150         syscall_tbl[SYSCALL_INSTALL_HDLR] = (void *) irq_install_handler;
151         syscall_tbl[SYSCALL_FREE_HDLR] = (void *) irq_free_handler;
152
153         addr = (ulong *) 0xc00;         /* syscall ISR addr */
154
155         /* patch ISR code */
156         *addr++ |= (ulong) syscall_tbl >> 16;
157         *addr++ |= (ulong) syscall_tbl & 0xFFFF;
158         *addr++ |= NR_SYSCALLS >> 16;
159         *addr++ |= NR_SYSCALLS & 0xFFFF;
160
161         flush_cache (0x0C00, 0x10);
162 }
163
164 /*
165  * All attempts to come up with a "common" initialization sequence
166  * that works for all boards and architectures failed: some of the
167  * requirements are just _too_ different. To get rid of the resulting
168  * mess of board dependend #ifdef'ed code we now make the whole
169  * initialization sequence configurable to the user.
170  *
171  * The requirements for any new initalization function is simple: it
172  * receives a pointer to the "global data" structure as it's only
173  * argument, and returns an integer return code, where 0 means
174  * "continue" and != 0 means "fatal error, hang the system".
175  */
176 typedef int (init_fnc_t) (void);
177
178 /************************************************************************
179  * Init Utilities                                                       *
180  ************************************************************************
181  * Some of this code should be moved into the core functions,
182  * but let's get it working (again) first...
183  */
184
185 static int init_baudrate (void)
186 {
187         DECLARE_GLOBAL_DATA_PTR;
188
189         uchar tmp[64];  /* long enough for environment variables */
190         int i = getenv_r ("baudrate", tmp, sizeof (tmp));
191
192         gd->baudrate = (i > 0)
193                         ? (int) simple_strtoul (tmp, NULL, 10)
194                         : CONFIG_BAUDRATE;
195
196         return (0);
197 }
198
199 /***********************************************************************/
200
201 static int init_func_ram (void)
202 {
203         DECLARE_GLOBAL_DATA_PTR;
204
205 #ifdef  CONFIG_BOARD_TYPES
206         int board_type = gd->board_type;
207 #else
208         int board_type = 0;     /* use dummy arg */
209 #endif
210         puts ("DRAM:  ");
211
212         if ((gd->ram_size = initdram (board_type)) > 0) {
213                 print_size (gd->ram_size, "\n");
214                 return (0);
215         }
216         puts (failed);
217         return (1);
218 }
219
220 /***********************************************************************/
221
222 #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
223 static int init_func_i2c (void)
224 {
225         puts ("I2C:   ");
226         i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE);
227         puts ("ready\n");
228         return (0);
229 }
230 #endif
231
232 /***********************************************************************/
233
234 #if defined(CONFIG_WATCHDOG)
235 static int init_func_watchdog_init (void)
236 {
237         puts ("       Watchdog enabled\n");
238         WATCHDOG_RESET ();
239         return (0);
240 }
241 # define INIT_FUNC_WATCHDOG_INIT        init_func_watchdog_init,
242
243 static int init_func_watchdog_reset (void)
244 {
245         WATCHDOG_RESET ();
246         return (0);
247 }
248 # define INIT_FUNC_WATCHDOG_RESET       init_func_watchdog_reset,
249 #else
250 # define INIT_FUNC_WATCHDOG_INIT        /* undef */
251 # define INIT_FUNC_WATCHDOG_RESET       /* undef */
252 #endif /* CONFIG_WATCHDOG */
253
254 /************************************************************************
255  * Initialization sequence                                              *
256  ************************************************************************
257  */
258
259 init_fnc_t *init_sequence[] = {
260
261 #if defined(CONFIG_BOARD_PRE_INIT)
262         board_pre_init,         /* very early board init code (fpga boot, etc.) */
263 #endif
264
265         get_clocks,             /* get CPU and bus clocks (etc.) */
266         init_timebase,
267 #ifdef CFG_ALLOC_DPRAM
268         dpram_init,
269 #endif
270 #if defined(CONFIG_BOARD_POSTCLK_INIT)
271         board_postclk_init,
272 #endif
273         env_init,
274         init_baudrate,
275         serial_init,
276         console_init_f,
277         display_options,
278 #if defined(CONFIG_8260)
279         prt_8260_rsr,
280         prt_8260_clks,
281 #endif /* CONFIG_8260 */
282         checkcpu,
283         checkboard,
284         INIT_FUNC_WATCHDOG_INIT
285 #if defined(CONFIG_BMW)         || \
286     defined(CONFIG_COGENT)      || \
287     defined(CONFIG_HYMOD)       || \
288     defined(CONFIG_RSD_PROTO)   || \
289     defined(CONFIG_W7O)
290         misc_init_f,
291 #endif
292         INIT_FUNC_WATCHDOG_RESET
293 #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
294         init_func_i2c,
295 #endif
296 #if defined(CONFIG_DTT)         /* Digital Thermometers and Thermostats */
297         dtt_init,
298 #endif
299         INIT_FUNC_WATCHDOG_RESET
300         init_func_ram,
301 #if defined(CFG_DRAM_TEST)
302         testdram,
303 #endif /* CFG_DRAM_TEST */
304         INIT_FUNC_WATCHDOG_RESET
305
306         NULL,                   /* Terminate this list */
307 };
308
309 /************************************************************************
310  *
311  * This is the first part of the initialization sequence that is
312  * implemented in C, but still running from ROM.
313  *
314  * The main purpose is to provide a (serial) console interface as
315  * soon as possible (so we can see any error messages), and to
316  * initialize the RAM so that we can relocate the monitor code to
317  * RAM.
318  *
319  * Be aware of the restrictions: global data is read-only, BSS is not
320  * initialized, and stack space is limited to a few kB.
321  *
322  ************************************************************************
323  */
324
325 void board_init_f (ulong bootflag)
326 {
327         DECLARE_GLOBAL_DATA_PTR;
328
329         bd_t *bd;
330         ulong len, addr, addr_sp;
331         gd_t *id;
332         init_fnc_t **init_fnc_ptr;
333 #ifdef CONFIG_PRAM
334         int i;
335         ulong reg;
336         uchar tmp[64];          /* long enough for environment variables */
337 #endif
338
339         /* Pointer is writable since we allocated a register for it */
340         gd = (gd_t *) (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET);
341
342 #ifndef CONFIG_8260
343         /* Clear initial global data */
344         memset ((void *) gd, 0, sizeof (gd_t));
345 #endif
346
347         for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
348                 if ((*init_fnc_ptr) () != 0) {
349                         hang ();
350                 }
351         }
352
353         /*
354          * Now that we have DRAM mapped and working, we can
355          * relocate the code and continue running from DRAM.
356          *
357          * Reserve memory at end of RAM for (top down in that order):
358          *  - protected RAM
359          *  - LCD framebuffer
360          *  - monitor code
361          *  - board info struct
362          */
363         len = get_endaddr () - CFG_MONITOR_BASE;
364
365         if (len > CFG_MONITOR_LEN) {
366                 printf ("*** U-Boot size %ld > reserved memory (%d)\n",
367                                 len, CFG_MONITOR_LEN);
368                 hang ();
369         }
370
371         if (CFG_MONITOR_LEN > len)
372                 len = CFG_MONITOR_LEN;
373
374 #ifndef CONFIG_VERY_BIG_RAM
375         addr = CFG_SDRAM_BASE + gd->ram_size;
376 #else
377         /* only allow stack below 256M */
378         addr = CFG_SDRAM_BASE +
379                (gd->ram_size > 256 << 20) ? 256 << 20 : gd->ram_size;
380 #endif
381
382 #ifdef CONFIG_PRAM
383         /*
384          * reserve protected RAM
385          */
386         i = getenv_r ("pram", tmp, sizeof (tmp));
387         reg = (i > 0) ? simple_strtoul (tmp, NULL, 10) : CONFIG_PRAM;
388         addr -= (reg << 10);            /* size is in kB */
389 # ifdef DEBUG
390         printf ("Reserving %ldk for protected RAM at %08lx\n", reg, addr);
391 # endif
392 #endif /* CONFIG_PRAM */
393
394         /* round down to next 4 kB limit */
395         addr &= ~(4096 - 1);
396 #ifdef DEBUG
397         printf ("Top of RAM usable for U-Boot at: %08lx\n", addr);
398 #endif
399
400 #ifdef CONFIG_LCD
401         /* reserve memory for LCD display (always full pages) */
402         addr = lcd_setmem (addr);
403         gd->fb_base = addr;
404 #endif /* CONFIG_LCD */
405
406 #if defined(CONFIG_VIDEO) && defined(CONFIG_8xx)
407         /* reserve memory for video display (always full pages) */
408         addr = video_setmem (addr);
409         gd->fb_base = addr;
410 #endif /* CONFIG_VIDEO  */
411
412         /*
413          * reserve memory for U-Boot code, data & bss
414          * round down to next 4 kB limit
415          */
416         addr -= len;
417         addr &= ~(4096 - 1);
418
419 #ifdef DEBUG
420         printf ("Reserving %ldk for U-Boot at: %08lx\n", len >> 10, addr);
421 #endif
422
423         /*
424          * reserve memory for malloc() arena
425          */
426         addr_sp = addr - TOTAL_MALLOC_LEN;
427 #ifdef DEBUG
428         printf ("Reserving %dk for malloc() at: %08lx\n",
429                         TOTAL_MALLOC_LEN >> 10, addr_sp);
430 #endif
431
432         /*
433          * (permanently) allocate a Board Info struct
434          * and a permanent copy of the "global" data
435          */
436         addr_sp -= sizeof (bd_t);
437         bd = (bd_t *) addr_sp;
438         gd->bd = bd;
439 #ifdef DEBUG
440         printf ("Reserving %d Bytes for Board Info at: %08lx\n",
441                         sizeof (bd_t), addr_sp);
442 #endif
443         addr_sp -= sizeof (gd_t);
444         id = (gd_t *) addr_sp;
445 #ifdef DEBUG
446         printf ("Reserving %d Bytes for Global Data at: %08lx\n",
447                         sizeof (gd_t), addr_sp);
448 #endif
449
450         /*
451          * Finally, we set up a new (bigger) stack.
452          *
453          * Leave some safety gap for SP, force alignment on 16 byte boundary
454          * Clear initial stack frame
455          */
456         addr_sp -= 16;
457         addr_sp &= ~0xF;
458         *((ulong *) addr_sp)-- = 0;
459         *((ulong *) addr_sp)-- = 0;
460 #ifdef DEBUG
461         printf ("Stack Pointer at: %08lx\n", addr_sp);
462 #endif
463
464         /*
465          * Save local variables to board info struct
466          */
467
468         bd->bi_memstart  = CFG_SDRAM_BASE;      /* start of  DRAM memory      */
469         bd->bi_memsize   = gd->ram_size;        /* size  of  DRAM memory in bytes */
470
471 #ifdef CONFIG_IP860
472         bd->bi_sramstart = SRAM_BASE;   /* start of  SRAM memory      */
473         bd->bi_sramsize  = SRAM_SIZE;   /* size  of  SRAM memory      */
474 #else
475         bd->bi_sramstart = 0;           /* FIXME */ /* start of  SRAM memory      */
476         bd->bi_sramsize  = 0;           /* FIXME */ /* size  of  SRAM memory      */
477 #endif
478
479 #if defined(CONFIG_8xx) || defined(CONFIG_8260)
480         bd->bi_immr_base = CFG_IMMR;    /* base  of IMMR register     */
481 #endif
482
483         bd->bi_bootflags = bootflag;    /* boot / reboot flag (for LynxOS)    */
484
485         WATCHDOG_RESET ();
486         bd->bi_intfreq = gd->cpu_clk;   /* Internal Freq, in Hz */
487         bd->bi_busfreq = gd->bus_clk;   /* Bus Freq,      in Hz */
488 #if defined(CONFIG_8260)
489         bd->bi_cpmfreq = gd->cpm_clk;
490         bd->bi_brgfreq = gd->brg_clk;
491         bd->bi_sccfreq = gd->scc_clk;
492         bd->bi_vco     = gd->vco_out;
493 #endif /* CONFIG_8260 */
494
495         bd->bi_baudrate = gd->baudrate; /* Console Baudrate     */
496
497 #ifdef CFG_EXTBDINFO
498         strncpy (bd->bi_s_version, "1.2", sizeof (bd->bi_s_version));
499         strncpy (bd->bi_r_version, U_BOOT_VERSION, sizeof (bd->bi_r_version));
500
501         bd->bi_procfreq = gd->cpu_clk;  /* Processor Speed, In Hz */
502         bd->bi_plb_busfreq = gd->bus_clk;
503 #ifdef CONFIG_405GP
504         bd->bi_pci_busfreq = get_PCI_freq ();
505 #endif
506 #endif
507
508 #ifdef DEBUG
509         printf ("New Stack Pointer is: %08lx\n", addr_sp);
510 #endif
511
512         WATCHDOG_RESET ();
513
514 #ifdef CONFIG_POST
515         post_bootmode_init();
516         post_run (NULL, POST_ROM | post_bootmode_get(0));
517 #endif
518
519         WATCHDOG_RESET();
520
521         memcpy (id, gd, sizeof (gd_t));
522
523         relocate_code (addr_sp, id, addr);
524
525         /* NOTREACHED - relocate_code() does not return */
526 }
527
528
529 /************************************************************************
530  *
531  * This is the next part if the initialization sequence: we are now
532  * running from RAM and have a "normal" C environment, i. e. global
533  * data can be written, BSS has been cleared, the stack size in not
534  * that critical any more, etc.
535  *
536  ************************************************************************
537  */
538
539 void board_init_r (gd_t *id, ulong dest_addr)
540 {
541         DECLARE_GLOBAL_DATA_PTR;
542
543         cmd_tbl_t *cmdtp;
544         char *s, *e;
545         bd_t *bd;
546         int i;
547         extern void malloc_bin_reloc (void);
548 #ifndef CFG_ENV_IS_NOWHERE
549         extern char * env_name_spec;
550 #endif
551
552 #ifndef CFG_NO_FLASH
553         ulong flash_size;
554 #endif
555
556         gd = id;                /* initialize RAM version of global data */
557         bd = gd->bd;
558
559         gd->flags |= GD_FLG_RELOC;      /* tell others: relocation done */
560
561 #ifdef DEBUG
562         printf ("Now running in RAM - U-Boot at: %08lx\n", dest_addr);
563 #endif
564
565         WATCHDOG_RESET ();
566
567         gd->reloc_off = dest_addr - CFG_MONITOR_BASE;
568
569         /*
570          * We have to relocate the command table manually
571          */
572         for (cmdtp = &cmd_tbl[0]; cmdtp->name; cmdtp++) {
573                 ulong addr;
574
575                 addr = (ulong) (cmdtp->cmd) + gd->reloc_off;
576 #if 0
577                 printf ("Command \"%s\": 0x%08lx => 0x%08lx\n",
578                                 cmdtp->name, (ulong) (cmdtp->cmd), addr);
579 #endif
580                 cmdtp->cmd =
581                         (int (*)(struct cmd_tbl_s *, int, int, char *[]))addr;
582
583                 addr = (ulong)(cmdtp->name) + gd->reloc_off;
584                 cmdtp->name = (char *)addr;
585
586                 if (cmdtp->usage) {
587                         addr = (ulong)(cmdtp->usage) + gd->reloc_off;
588                         cmdtp->usage = (char *)addr;
589                 }
590 #ifdef  CFG_LONGHELP
591                 if (cmdtp->help) {
592                         addr = (ulong)(cmdtp->help) + gd->reloc_off;
593                         cmdtp->help = (char *)addr;
594                 }
595 #endif
596         }
597         /* there are some other pointer constants we must deal with */
598 #ifndef CFG_ENV_IS_NOWHERE
599         env_name_spec += gd->reloc_off;
600 #endif
601
602         WATCHDOG_RESET ();
603
604 #ifdef CONFIG_LOGBUFFER
605         logbuff_reset ();
606 #endif
607 #ifdef CONFIG_POST
608         post_reloc ();
609 #endif
610
611         WATCHDOG_RESET();
612
613 #if defined(CONFIG_IP860) || defined(CONFIG_PCU_E) || defined (CONFIG_FLAGADM)
614         icache_enable ();       /* it's time to enable the instruction cache */
615 #endif
616
617 #if defined(CONFIG_BAB7xx)
618         /*
619          * Do pci configuration on BAB 7xx _before_ the flash
620          * is initialised, because we need the ISA bridge there.
621          */
622         pci_init ();
623         /*
624          * Initialise the ISA bridge
625          */
626         initialise_w83c553f ();
627 #endif
628
629         asm ("sync ; isync");
630
631         /*
632          * Setup trap handlers
633          */
634         trap_init (dest_addr);
635
636 #if !defined(CFG_NO_FLASH)
637         puts ("FLASH: ");
638
639         if ((flash_size = flash_init ()) > 0) {
640 #ifdef CFG_FLASH_CHECKSUM
641                 print_size (flash_size, "");
642                 /*
643                  * Compute and print flash CRC if flashchecksum is set to 'y'
644                  *
645                  * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
646                  */
647                 s = getenv ("flashchecksum");
648                 if (s && (*s == 'y')) {
649                         printf ("  CRC: %08lX",
650                                         crc32 (0,
651                                                    (const unsigned char *) CFG_FLASH_BASE,
652                                                    flash_size)
653                                         );
654                 }
655                 putc ('\n');
656 #else
657                 print_size (flash_size, "\n");
658 #endif /* CFG_FLASH_CHECKSUM */
659         } else {
660                 puts (failed);
661                 hang ();
662         }
663
664         bd->bi_flashstart = CFG_FLASH_BASE;     /* update start of FLASH memory    */
665         bd->bi_flashsize = flash_size;  /* size of FLASH memory (final value) */
666 #if defined(CONFIG_PCU_E) || defined(CONFIG_OXC)
667         bd->bi_flashoffset = 0;
668 #elif CFG_MONITOR_BASE == CFG_FLASH_BASE
669         bd->bi_flashoffset = CFG_MONITOR_LEN;   /* reserved area for startup monitor  */
670 #else
671         bd->bi_flashoffset = 0;
672 #endif
673 #else
674
675         bd->bi_flashsize = 0;
676         bd->bi_flashstart = 0;
677         bd->bi_flashoffset = 0;
678 #endif /* !CFG_NO_FLASH */
679
680         WATCHDOG_RESET ();
681
682         /* initialize higher level parts of CPU like time base and timers */
683         cpu_init_r ();
684
685         WATCHDOG_RESET ();
686
687         /* initialize malloc() area */
688         mem_malloc_init ();
689         malloc_bin_reloc ();
690
691 #ifdef CONFIG_SPI
692 # if !defined(CFG_ENV_IS_IN_EEPROM)
693         spi_init_f ();
694 # endif
695         spi_init_r ();
696 #endif
697
698         /* relocate environment function pointers etc. */
699         env_relocate ();
700
701         /*
702          * Fill in missing fields of bd_info.
703          * We do this here, where we have "normal" access to the
704          * environment; we used to do this still running from ROM,
705          * where had to use getenv_r(), which can be pretty slow when
706          * the environment is in EEPROM.
707          */
708         s = getenv ("ethaddr");
709 #if defined (CONFIG_MBX) || defined (CONFIG_RPXCLASSIC) || defined(CONFIG_IAD210)
710         if (s == NULL)
711                 board_get_enetaddr (bd->bi_enetaddr);
712         else
713 #endif
714                 for (i = 0; i < 6; ++i) {
715                         bd->bi_enetaddr[i] = s ? simple_strtoul (s, &e, 16) : 0;
716                         if (s)
717                                 s = (*e) ? e + 1 : e;
718                 }
719 #ifdef  CONFIG_HERMES
720         if ((gd->board_type >> 16) == 2)
721                 bd->bi_ethspeed = gd->board_type & 0xFFFF;
722         else
723                 bd->bi_ethspeed = 0xFFFF;
724 #endif
725
726 #ifdef CONFIG_NX823
727         load_sernum_ethaddr ();
728 #endif
729
730 #if defined(CFG_GT_6426x) || defined(CONFIG_PN62)
731         /* handle the 2nd ethernet address */
732
733         s = getenv ("eth1addr");
734
735         for (i = 0; i < 6; ++i) {
736                 bd->bi_enet1addr[i] = s ? simple_strtoul (s, &e, 16) : 0;
737                 if (s)
738                         s = (*e) ? e + 1 : e;
739         }
740 #endif
741 #if defined(CFG_GT_6426x)
742         /* handle the 3rd ethernet address */
743
744         s = getenv ("eth2addr");
745
746         for (i = 0; i < 6; ++i) {
747                 bd->bi_enet2addr[i] = s ? simple_strtoul (s, &e, 16) : 0;
748                 if (s)
749                         s = (*e) ? e + 1 : e;
750         }
751 #endif
752
753
754 #if defined(CONFIG_TQM8xxL) || defined(CONFIG_TQM8260) || \
755     defined(CONFIG_CCM)
756         load_sernum_ethaddr ();
757 #endif
758         /* IP Address */
759         bd->bi_ip_addr = getenv_IPaddr ("ipaddr");
760
761         WATCHDOG_RESET ();
762
763 #if defined(CONFIG_PCI) && !defined(CONFIG_BAB7xx)
764         /*
765          * Do pci configuration
766          */
767         pci_init ();
768 #endif
769
770 /** leave this here (after malloc(), environment and PCI are working) **/
771         /* Initialize devices */
772         devices_init ();
773
774         /* allocate syscalls table (console_init_r will fill it in */
775         syscall_tbl = (void **) malloc (NR_SYSCALLS * sizeof (void *));
776
777         /* Initialize the console (after the relocation and devices init) */
778         console_init_r ();
779 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/
780         syscalls_init ();
781
782 #if defined(CONFIG_CCM)         || \
783     defined(CONFIG_COGENT)      || \
784     defined(CONFIG_CPCI405)     || \
785     defined(CONFIG_EVB64260)    || \
786     defined(CONFIG_HYMOD)       || \
787     defined(CONFIG_KUP4K)       || \
788     defined(CONFIG_LWMON)       || \
789     defined(CONFIG_PCU_E)       || \
790     defined(CONFIG_W7O)         || \
791     defined(CONFIG_MISC_INIT_R)
792         /* miscellaneous platform dependent initialisations */
793         misc_init_r ();
794 #endif
795
796 #ifdef  CONFIG_HERMES
797         if (bd->bi_ethspeed != 0xFFFF)
798                 hermes_start_lxt980 ((int) bd->bi_ethspeed);
799 #endif
800
801 #if (CONFIG_COMMANDS & CFG_CMD_NET) && ( \
802     defined(CONFIG_CCM)         || \
803     defined(CONFIG_EP8260)      || \
804     defined(CONFIG_IP860)       || \
805     defined(CONFIG_IVML24)      || \
806     defined(CONFIG_IVMS8)       || \
807     defined(CONFIG_LWMON)       || \
808     defined(CONFIG_MPC8260ADS)  || \
809     defined(CONFIG_PCU_E)       || \
810     defined(CONFIG_RPXSUPER)    || \
811     defined(CONFIG_SPD823TS)    )
812
813         WATCHDOG_RESET ();
814 # ifdef DEBUG
815         puts ("Reset Ethernet PHY\n");
816 # endif
817         reset_phy ();
818 #endif
819
820 #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
821         WATCHDOG_RESET ();
822         puts ("KGDB:  ");
823         kgdb_init ();
824 #endif
825
826 #ifdef DEBUG
827         printf ("U-Boot relocated to %08lx\n", dest_addr);
828 #endif
829
830         /*
831          * Enable Interrupts
832          */
833         interrupt_init ();
834
835         /* Must happen after interrupts are initialized since
836          * an irq handler gets installed
837          */
838 #ifdef CONFIG_SERIAL_SOFTWARE_FIFO
839         serial_buffered_init();
840 #endif
841
842 #ifdef CONFIG_STATUS_LED
843         status_led_set (STATUS_LED_BOOT, STATUS_LED_BLINKING);
844 #endif
845
846         udelay (20);
847
848         set_timer (0);
849
850         /* Insert function pointers now that we have relocated the code */
851
852         /* Initialize from environment */
853         if ((s = getenv ("loadaddr")) != NULL) {
854                 load_addr = simple_strtoul (s, NULL, 16);
855         }
856 #if (CONFIG_COMMANDS & CFG_CMD_NET)
857         if ((s = getenv ("bootfile")) != NULL) {
858                 copy_filename (BootFile, s, sizeof (BootFile));
859         }
860 #endif /* CFG_CMD_NET */
861
862         WATCHDOG_RESET ();
863
864 #if (CONFIG_COMMANDS & CFG_CMD_SCSI)
865         WATCHDOG_RESET ();
866         puts ("SCSI:  ");
867         scsi_init ();
868 #endif
869
870 #if (CONFIG_COMMANDS & CFG_CMD_DOC)
871         WATCHDOG_RESET ();
872         puts ("DOC:   ");
873         doc_init ();
874 #endif
875
876 #if (CONFIG_COMMANDS & CFG_CMD_NET) && defined(CONFIG_NET_MULTI)
877         WATCHDOG_RESET ();
878         puts ("Net:   ");
879         eth_initialize (bd);
880 #endif
881
882 #ifdef CONFIG_POST
883         post_run (NULL, POST_RAM | post_bootmode_get(0));
884         if (post_bootmode_get(0) & POST_POWERFAIL) {
885                 post_bootmode_clear();
886                 board_poweroff();
887         }
888 #endif
889
890 #if (CONFIG_COMMANDS & CFG_CMD_PCMCIA) && !(CONFIG_COMMANDS & CFG_CMD_IDE)
891         WATCHDOG_RESET ();
892         puts ("PCMCIA:");
893         pcmcia_init ();
894 #endif
895
896 #if (CONFIG_COMMANDS & CFG_CMD_IDE)
897         WATCHDOG_RESET ();
898 # ifdef CONFIG_IDE_8xx_PCCARD
899         puts ("PCMCIA:");
900 # else
901         puts ("IDE:   ");
902 #endif
903         ide_init ();
904 #endif /* CFG_CMD_IDE */
905
906 #ifdef CONFIG_LAST_STAGE_INIT
907         WATCHDOG_RESET ();
908         /*
909          * Some parts can be only initialized if all others (like
910          * Interrupts) are up and running (i.e. the PC-style ISA
911          * keyboard).
912          */
913         last_stage_init ();
914 #endif
915
916 #if (CONFIG_COMMANDS & CFG_CMD_BEDBUG)
917         WATCHDOG_RESET ();
918         bedbug_init ();
919 #endif
920
921 #ifdef CONFIG_PRAM
922         /*
923          * Export available size of memory for Linux,
924          * taking into account the protected RAM at top of memory
925          */
926         {
927                 ulong pram;
928                 char *s;
929                 uchar memsz[32];
930
931                 if ((s = getenv ("pram")) != NULL) {
932                         pram = simple_strtoul (s, NULL, 10);
933                 } else {
934                         pram = CONFIG_PRAM;
935                 }
936                 sprintf (memsz, "%ldk", (bd->bi_memsize / 1024) - pram);
937                 setenv ("mem", memsz);
938         }
939 #endif
940
941         /* Initialization complete - start the monitor */
942
943         /* main_loop() can return to retry autoboot, if so just run it again. */
944         for (;;) {
945                 WATCHDOG_RESET ();
946                 main_loop ();
947         }
948
949         /* NOTREACHED - no way out of command loop except booting */
950 }
951
952 void hang (void)
953 {
954         puts ("### ERROR ### Please RESET the board ###\n");
955         for (;;);
956 }
957
958 #if 0 /* We could use plain global data, but the resulting code is bigger */
959 /*
960  * Pointer to initial global data area
961  *
962  * Here we initialize it.
963  */
964 #undef  XTRN_DECLARE_GLOBAL_DATA_PTR
965 #define XTRN_DECLARE_GLOBAL_DATA_PTR    /* empty = allocate here */
966 DECLARE_GLOBAL_DATA_PTR = (gd_t *) (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET);
967 #endif  /* 0 */
968
969 /************************************************************************/