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