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