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