]> git.karo-electronics.de Git - karo-tx-uboot.git/blob - arch/powerpc/lib/board.c
karo: fdt: fix panel-dpi support
[karo-tx-uboot.git] / arch / powerpc / lib / board.c
1 /*
2  * (C) Copyright 2000-2011
3  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4  *
5  * SPDX-License-Identifier:     GPL-2.0+
6  */
7
8 #include <common.h>
9 #include <watchdog.h>
10 #include <command.h>
11 #include <malloc.h>
12 #include <stdio_dev.h>
13 #ifdef CONFIG_8xx
14 #include <mpc8xx.h>
15 #endif
16 #ifdef CONFIG_5xx
17 #include <mpc5xx.h>
18 #endif
19 #ifdef CONFIG_MPC5xxx
20 #include <mpc5xxx.h>
21 #endif
22 #if defined(CONFIG_CMD_IDE)
23 #include <ide.h>
24 #endif
25 #if defined(CONFIG_CMD_SCSI)
26 #include <scsi.h>
27 #endif
28 #if defined(CONFIG_CMD_KGDB)
29 #include <kgdb.h>
30 #endif
31 #ifdef CONFIG_STATUS_LED
32 #include <status_led.h>
33 #endif
34 #include <net.h>
35 #ifdef CONFIG_GENERIC_MMC
36 #include <mmc.h>
37 #endif
38 #include <serial.h>
39 #ifdef CONFIG_SYS_ALLOC_DPRAM
40 #if !defined(CONFIG_CPM2)
41 #include <commproc.h>
42 #endif
43 #endif
44 #include <version.h>
45 #if defined(CONFIG_BAB7xx)
46 #include <w83c553f.h>
47 #endif
48 #include <dtt.h>
49 #if defined(CONFIG_POST)
50 #include <post.h>
51 #endif
52 #if defined(CONFIG_LOGBUFFER)
53 #include <logbuff.h>
54 #endif
55 #if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500)
56 #include <asm/cache.h>
57 #endif
58 #ifdef CONFIG_PS2KBD
59 #include <keyboard.h>
60 #endif
61
62 #ifdef CONFIG_ADDR_MAP
63 #include <asm/mmu.h>
64 #endif
65
66 #ifdef CONFIG_MP
67 #include <asm/mp.h>
68 #endif
69
70 #ifdef CONFIG_BITBANGMII
71 #include <miiphy.h>
72 #endif
73
74 #ifdef CONFIG_SYS_UPDATE_FLASH_SIZE
75 extern int update_flash_size(int flash_size);
76 #endif
77
78 #if defined(CONFIG_CMD_DOC)
79 void doc_init(void);
80 #endif
81 #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
82 #include <i2c.h>
83 #endif
84 #include <spi.h>
85 #include <nand.h>
86
87 static char *failed = "*** failed ***\n";
88
89 #if defined(CONFIG_OXC) || defined(CONFIG_RMU)
90 extern flash_info_t flash_info[];
91 #endif
92
93 #if defined(CONFIG_START_IDE)
94 extern int board_start_ide(void);
95 #endif
96 #include <environment.h>
97
98 DECLARE_GLOBAL_DATA_PTR;
99
100 #if !defined(CONFIG_SYS_MEM_TOP_HIDE)
101 #define CONFIG_SYS_MEM_TOP_HIDE 0
102 #endif
103
104 extern ulong __init_end;
105 extern ulong __bss_end;
106 ulong monitor_flash_len;
107
108 #if defined(CONFIG_CMD_BEDBUG)
109 #include <bedbug/type.h>
110 #endif
111
112 /*
113  * Utilities
114  */
115
116 /*
117  * All attempts to come up with a "common" initialization sequence
118  * that works for all boards and architectures failed: some of the
119  * requirements are just _too_ different. To get rid of the resulting
120  * mess of board dependend #ifdef'ed code we now make the whole
121  * initialization sequence configurable to the user.
122  *
123  * The requirements for any new initalization function is simple: it
124  * receives a pointer to the "global data" structure as it's only
125  * argument, and returns an integer return code, where 0 means
126  * "continue" and != 0 means "fatal error, hang the system".
127  */
128 typedef int (init_fnc_t)(void);
129
130 /*
131  * Init Utilities
132  *
133  * Some of this code should be moved into the core functions,
134  * but let's get it working (again) first...
135  */
136
137 static int init_baudrate(void)
138 {
139         gd->baudrate = getenv_ulong("baudrate", 10, CONFIG_BAUDRATE);
140         return 0;
141 }
142
143 /***********************************************************************/
144
145 static void __board_add_ram_info(int use_default)
146 {
147         /* please define platform specific board_add_ram_info() */
148 }
149
150 void board_add_ram_info(int)
151         __attribute__ ((weak, alias("__board_add_ram_info")));
152
153 static int __board_flash_wp_on(void)
154 {
155         /*
156          * Most flashes can't be detected when write protection is enabled,
157          * so provide a way to let U-Boot gracefully ignore write protected
158          * devices.
159          */
160         return 0;
161 }
162
163 int board_flash_wp_on(void)
164         __attribute__ ((weak, alias("__board_flash_wp_on")));
165
166 static void __cpu_secondary_init_r(void)
167 {
168 }
169
170 void cpu_secondary_init_r(void)
171         __attribute__ ((weak, alias("__cpu_secondary_init_r")));
172
173 static int init_func_ram(void)
174 {
175 #ifdef  CONFIG_BOARD_TYPES
176         int board_type = gd->board_type;
177 #else
178         int board_type = 0;     /* use dummy arg */
179 #endif
180         puts("DRAM:  ");
181
182         gd->ram_size = initdram(board_type);
183
184         if (gd->ram_size > 0) {
185                 print_size(gd->ram_size, "");
186                 board_add_ram_info(0);
187                 putc('\n');
188                 return 0;
189         }
190         puts(failed);
191         return 1;
192 }
193
194 /***********************************************************************/
195
196 #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
197 static int init_func_i2c(void)
198 {
199         puts("I2C:   ");
200 #ifdef CONFIG_SYS_I2C
201         i2c_init_all();
202 #else
203         i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
204 #endif
205         puts("ready\n");
206         return 0;
207 }
208 #endif
209
210 #if defined(CONFIG_HARD_SPI)
211 static int init_func_spi(void)
212 {
213         puts("SPI:   ");
214         spi_init();
215         puts("ready\n");
216         return 0;
217 }
218 #endif
219
220 /***********************************************************************/
221
222 #if defined(CONFIG_WATCHDOG)
223 int init_func_watchdog_init(void)
224 {
225 #if defined(CONFIG_MPC85xx)
226         init_85xx_watchdog();
227 #endif
228         puts("       Watchdog enabled\n");
229         WATCHDOG_RESET();
230         return 0;
231 }
232
233 int init_func_watchdog_reset(void)
234 {
235         WATCHDOG_RESET();
236         return 0;
237 }
238 #endif /* CONFIG_WATCHDOG */
239
240 /*
241  * Initialization sequence
242  */
243
244 static init_fnc_t *init_sequence[] = {
245 #if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx)
246         probecpu,
247 #endif
248 #if defined(CONFIG_BOARD_EARLY_INIT_F)
249         board_early_init_f,
250 #endif
251 #if !defined(CONFIG_8xx_CPUCLK_DEFAULT)
252         get_clocks,             /* get CPU and bus clocks (etc.) */
253 #if defined(CONFIG_TQM8xxL) && !defined(CONFIG_TQM866M) \
254     && !defined(CONFIG_TQM885D)
255         adjust_sdram_tbs_8xx,
256 #endif
257         init_timebase,
258 #endif
259 #ifdef CONFIG_SYS_ALLOC_DPRAM
260 #if !defined(CONFIG_CPM2)
261         dpram_init,
262 #endif
263 #endif
264 #if defined(CONFIG_BOARD_POSTCLK_INIT)
265         board_postclk_init,
266 #endif
267         env_init,
268 #if defined(CONFIG_8xx_CPUCLK_DEFAULT)
269         /* get CPU and bus clocks according to the environment variable */
270         get_clocks_866,
271         /* adjust sdram refresh rate according to the new clock */
272         sdram_adjust_866,
273         init_timebase,
274 #endif
275         init_baudrate,
276         serial_init,
277         console_init_f,
278         display_options,
279 #if defined(CONFIG_MPC8260)
280         prt_8260_rsr,
281         prt_8260_clks,
282 #endif /* CONFIG_MPC8260 */
283 #if defined(CONFIG_MPC83xx)
284         prt_83xx_rsr,
285 #endif
286         checkcpu,
287 #if defined(CONFIG_MPC5xxx)
288         prt_mpc5xxx_clks,
289 #endif /* CONFIG_MPC5xxx */
290         checkboard,
291         INIT_FUNC_WATCHDOG_INIT
292 #if defined(CONFIG_MISC_INIT_F)
293         misc_init_f,
294 #endif
295         INIT_FUNC_WATCHDOG_RESET
296 #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
297         init_func_i2c,
298 #endif
299 #if defined(CONFIG_HARD_SPI)
300         init_func_spi,
301 #endif
302 #ifdef CONFIG_POST
303         post_init_f,
304 #endif
305         INIT_FUNC_WATCHDOG_RESET
306         init_func_ram,
307 #if defined(CONFIG_SYS_DRAM_TEST)
308         testdram,
309 #endif /* CONFIG_SYS_DRAM_TEST */
310         INIT_FUNC_WATCHDOG_RESET
311         NULL,   /* Terminate this list */
312 };
313
314 static int __fixup_cpu(void)
315 {
316         return 0;
317 }
318
319 int fixup_cpu(void) __attribute__((weak, alias("__fixup_cpu")));
320
321 /*
322  * This is the first part of the initialization sequence that is
323  * implemented in C, but still running from ROM.
324  *
325  * The main purpose is to provide a (serial) console interface as
326  * soon as possible (so we can see any error messages), and to
327  * initialize the RAM so that we can relocate the monitor code to
328  * RAM.
329  *
330  * Be aware of the restrictions: global data is read-only, BSS is not
331  * initialized, and stack space is limited to a few kB.
332  */
333
334 void board_init_f(ulong bootflag)
335 {
336         bd_t *bd;
337         ulong len, addr, addr_sp;
338         ulong *s;
339         gd_t *id;
340         init_fnc_t **init_fnc_ptr;
341
342 #ifdef CONFIG_PRAM
343         ulong reg;
344 #endif
345
346         /* Pointer is writable since we allocated a register for it */
347         gd = (gd_t *) (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET);
348         /* compiler optimization barrier needed for GCC >= 3.4 */
349         __asm__ __volatile__("":::"memory");
350
351 #if !defined(CONFIG_CPM2) && !defined(CONFIG_MPC512X) && \
352     !defined(CONFIG_MPC83xx) && !defined(CONFIG_MPC85xx) && \
353     !defined(CONFIG_MPC86xx)
354         /* Clear initial global data */
355         memset((void *) gd, 0, sizeof(gd_t));
356 #endif
357
358         gd->flags = bootflag;
359
360         for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr)
361                 if ((*init_fnc_ptr) () != 0)
362                         hang();
363
364 #ifdef CONFIG_POST
365         post_bootmode_init();
366         post_run(NULL, POST_ROM | post_bootmode_get(NULL));
367 #endif
368
369         WATCHDOG_RESET();
370
371         /*
372          * Now that we have DRAM mapped and working, we can
373          * relocate the code and continue running from DRAM.
374          *
375          * Reserve memory at end of RAM for (top down in that order):
376          *  - area that won't get touched by U-Boot and Linux (optional)
377          *  - kernel log buffer
378          *  - protected RAM
379          *  - LCD framebuffer
380          *  - monitor code
381          *  - board info struct
382          */
383         len = (ulong)&__bss_end - CONFIG_SYS_MONITOR_BASE;
384
385         /*
386          * Subtract specified amount of memory to hide so that it won't
387          * get "touched" at all by U-Boot. By fixing up gd->ram_size
388          * the Linux kernel should now get passed the now "corrected"
389          * memory size and won't touch it either. This should work
390          * for arch/ppc and arch/powerpc. Only Linux board ports in
391          * arch/powerpc with bootwrapper support, that recalculate the
392          * memory size from the SDRAM controller setup will have to
393          * get fixed.
394          */
395         gd->ram_size -= CONFIG_SYS_MEM_TOP_HIDE;
396
397         addr = CONFIG_SYS_SDRAM_BASE + get_effective_memsize();
398
399 #if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500))
400         /*
401          * We need to make sure the location we intend to put secondary core
402          * boot code is reserved and not used by any part of u-boot
403          */
404         if (addr > determine_mp_bootpg(NULL)) {
405                 addr = determine_mp_bootpg(NULL);
406                 debug("Reserving MP boot page to %08lx\n", addr);
407         }
408 #endif
409
410 #ifdef CONFIG_LOGBUFFER
411 #ifndef CONFIG_ALT_LB_ADDR
412         /* reserve kernel log buffer */
413         addr -= (LOGBUFF_RESERVE);
414         debug("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN,
415               addr);
416 #endif
417 #endif
418
419 #ifdef CONFIG_PRAM
420         /*
421          * reserve protected RAM
422          */
423         reg = getenv_ulong("pram", 10, CONFIG_PRAM);
424         addr -= (reg << 10);    /* size is in kB */
425         debug("Reserving %ldk for protected RAM at %08lx\n", reg, addr);
426 #endif /* CONFIG_PRAM */
427
428         /* round down to next 4 kB limit */
429         addr &= ~(4096 - 1);
430         debug("Top of RAM usable for U-Boot at: %08lx\n", addr);
431
432 #ifdef CONFIG_LCD
433 #ifdef CONFIG_FB_ADDR
434         gd->fb_base = CONFIG_FB_ADDR;
435 #else
436         /* reserve memory for LCD display (always full pages) */
437         addr = lcd_setmem(addr);
438         gd->fb_base = addr;
439 #endif /* CONFIG_FB_ADDR */
440 #endif /* CONFIG_LCD */
441
442 #if defined(CONFIG_VIDEO) && defined(CONFIG_8xx)
443         /* reserve memory for video display (always full pages) */
444         addr = video_setmem(addr);
445         gd->fb_base = addr;
446 #endif /* CONFIG_VIDEO  */
447
448         /*
449          * reserve memory for U-Boot code, data & bss
450          * round down to next 4 kB limit
451          */
452         addr -= len;
453         addr &= ~(4096 - 1);
454 #ifdef CONFIG_E500
455         /* round down to next 64 kB limit so that IVPR stays aligned */
456         addr &= ~(65536 - 1);
457 #endif
458
459         debug("Reserving %ldk for U-Boot at: %08lx\n", len >> 10, addr);
460
461         /*
462          * reserve memory for malloc() arena
463          */
464         addr_sp = addr - TOTAL_MALLOC_LEN;
465         debug("Reserving %dk for malloc() at: %08lx\n",
466               TOTAL_MALLOC_LEN >> 10, addr_sp);
467
468         /*
469          * (permanently) allocate a Board Info struct
470          * and a permanent copy of the "global" data
471          */
472         addr_sp -= sizeof(bd_t);
473         bd = (bd_t *) addr_sp;
474         memset(bd, 0, sizeof(bd_t));
475         gd->bd = bd;
476         debug("Reserving %zu Bytes for Board Info at: %08lx\n",
477               sizeof(bd_t), addr_sp);
478         addr_sp -= sizeof(gd_t);
479         id = (gd_t *) addr_sp;
480         debug("Reserving %zu Bytes for Global Data at: %08lx\n",
481               sizeof(gd_t), addr_sp);
482
483         /*
484          * Finally, we set up a new (bigger) stack.
485          *
486          * Leave some safety gap for SP, force alignment on 16 byte boundary
487          * Clear initial stack frame
488          */
489         addr_sp -= 16;
490         addr_sp &= ~0xF;
491         s = (ulong *) addr_sp;
492         *s = 0; /* Terminate back chain */
493         *++s = 0; /* NULL return address */
494         debug("Stack Pointer at: %08lx\n", addr_sp);
495
496         /*
497          * Save local variables to board info struct
498          */
499
500         bd->bi_memstart = CONFIG_SYS_SDRAM_BASE;        /* start of memory */
501         bd->bi_memsize = gd->ram_size;                  /* size in bytes */
502
503 #ifdef CONFIG_SYS_SRAM_BASE
504         bd->bi_sramstart = CONFIG_SYS_SRAM_BASE;        /* start of SRAM */
505         bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE;         /* size  of SRAM */
506 #endif
507
508 #if defined(CONFIG_8xx) || defined(CONFIG_MPC8260) || defined(CONFIG_5xx) || \
509     defined(CONFIG_E500) || defined(CONFIG_MPC86xx)
510         bd->bi_immr_base = CONFIG_SYS_IMMR;     /* base  of IMMR register     */
511 #endif
512 #if defined(CONFIG_MPC5xxx)
513         bd->bi_mbar_base = CONFIG_SYS_MBAR;     /* base of internal registers */
514 #endif
515 #if defined(CONFIG_MPC83xx)
516         bd->bi_immrbar = CONFIG_SYS_IMMR;
517 #endif
518
519         WATCHDOG_RESET();
520         bd->bi_intfreq = gd->cpu_clk;   /* Internal Freq, in Hz */
521         bd->bi_busfreq = gd->bus_clk;   /* Bus Freq,      in Hz */
522 #if defined(CONFIG_CPM2)
523         bd->bi_cpmfreq = gd->arch.cpm_clk;
524         bd->bi_brgfreq = gd->arch.brg_clk;
525         bd->bi_sccfreq = gd->arch.scc_clk;
526         bd->bi_vco = gd->arch.vco_out;
527 #endif /* CONFIG_CPM2 */
528 #if defined(CONFIG_MPC512X)
529         bd->bi_ipsfreq = gd->arch.ips_clk;
530 #endif /* CONFIG_MPC512X */
531 #if defined(CONFIG_MPC5xxx)
532         bd->bi_ipbfreq = gd->arch.ipb_clk;
533         bd->bi_pcifreq = gd->pci_clk;
534 #endif /* CONFIG_MPC5xxx */
535
536 #ifdef CONFIG_SYS_EXTBDINFO
537         strncpy((char *) bd->bi_s_version, "1.2", sizeof(bd->bi_s_version));
538         strncpy((char *) bd->bi_r_version, U_BOOT_VERSION,
539                 sizeof(bd->bi_r_version));
540
541         bd->bi_procfreq = gd->cpu_clk;  /* Processor Speed, In Hz */
542         bd->bi_plb_busfreq = gd->bus_clk;
543 #if defined(CONFIG_405GP) || defined(CONFIG_405EP) || \
544     defined(CONFIG_440EP) || defined(CONFIG_440GR) || \
545     defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
546         bd->bi_pci_busfreq = get_PCI_freq();
547         bd->bi_opbfreq = get_OPB_freq();
548 #elif defined(CONFIG_XILINX_405)
549         bd->bi_pci_busfreq = get_PCI_freq();
550 #endif
551 #endif
552
553         debug("New Stack Pointer is: %08lx\n", addr_sp);
554
555         WATCHDOG_RESET();
556
557         gd->relocaddr = addr;   /* Store relocation addr, useful for debug */
558
559         memcpy(id, (void *) gd, sizeof(gd_t));
560
561         relocate_code(addr_sp, id, addr);
562
563         /* NOTREACHED - relocate_code() does not return */
564 }
565
566 /*
567  * This is the next part if the initialization sequence: we are now
568  * running from RAM and have a "normal" C environment, i. e. global
569  * data can be written, BSS has been cleared, the stack size in not
570  * that critical any more, etc.
571  */
572 void board_init_r(gd_t *id, ulong dest_addr)
573 {
574         bd_t *bd;
575         ulong malloc_start;
576
577 #ifndef CONFIG_SYS_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         /* The Malloc area is immediately below the monitor copy in DRAM */
587         malloc_start = dest_addr - TOTAL_MALLOC_LEN;
588
589 #if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx)
590         /*
591          * The gd->arch.cpu pointer is set to an address in flash before
592          * relocation.  We need to update it to point to the same CPU entry
593          * in RAM.
594          */
595         gd->arch.cpu += dest_addr - CONFIG_SYS_MONITOR_BASE;
596
597         /*
598          * If we didn't know the cpu mask & # cores, we can save them of
599          * now rather than 'computing' them constantly
600          */
601         fixup_cpu();
602 #endif
603
604 #ifdef CONFIG_SYS_EXTRA_ENV_RELOC
605         /*
606          * Some systems need to relocate the env_addr pointer early because the
607          * location it points to will get invalidated before env_relocate is
608          * called.  One example is on systems that might use a L2 or L3 cache
609          * in SRAM mode and initialize that cache from SRAM mode back to being
610          * a cache in cpu_init_r.
611          */
612         gd->env_addr += dest_addr - CONFIG_SYS_MONITOR_BASE;
613 #endif
614
615         serial_initialize();
616
617         debug("Now running in RAM - U-Boot at: %08lx\n", dest_addr);
618
619         WATCHDOG_RESET();
620
621         /*
622          * Setup trap handlers
623          */
624         trap_init(dest_addr);
625
626 #ifdef CONFIG_ADDR_MAP
627         init_addr_map();
628 #endif
629
630 #if defined(CONFIG_BOARD_EARLY_INIT_R)
631         board_early_init_r();
632 #endif
633
634         monitor_flash_len = (ulong)&__init_end - dest_addr;
635
636         WATCHDOG_RESET();
637
638 #ifdef CONFIG_LOGBUFFER
639         logbuff_init_ptrs();
640 #endif
641 #ifdef CONFIG_POST
642         post_output_backlog();
643 #endif
644
645         WATCHDOG_RESET();
646
647 #if defined(CONFIG_SYS_DELAYED_ICACHE)
648         icache_enable();        /* it's time to enable the instruction cache */
649 #endif
650
651 #if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500)
652         unlock_ram_in_cache();  /* it's time to unlock D-cache in e500 */
653 #endif
654
655 #if defined(CONFIG_PCI) && defined(CONFIG_SYS_EARLY_PCI_INIT)
656         /*
657          * Do early PCI configuration _before_ the flash gets initialised,
658          * because PCU ressources are crucial for flash access on some boards.
659          */
660         pci_init();
661 #endif
662 #if defined(CONFIG_WINBOND_83C553)
663         /*
664          * Initialise the ISA bridge
665          */
666         initialise_w83c553f();
667 #endif
668
669         asm("sync ; isync");
670
671         mem_malloc_init(malloc_start, TOTAL_MALLOC_LEN);
672
673 #if !defined(CONFIG_SYS_NO_FLASH)
674         puts("Flash: ");
675
676         if (board_flash_wp_on()) {
677                 printf("Uninitialized - Write Protect On\n");
678                 /* Since WP is on, we can't find real size.  Set to 0 */
679                 flash_size = 0;
680         } else if ((flash_size = flash_init()) > 0) {
681 #ifdef CONFIG_SYS_FLASH_CHECKSUM
682                 print_size(flash_size, "");
683                 /*
684                  * Compute and print flash CRC if flashchecksum is set to 'y'
685                  *
686                  * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
687                  */
688                 if (getenv_yesno("flashchecksum") == 1) {
689                         printf("  CRC: %08X",
690                                crc32(0,
691                                      (const unsigned char *)
692                                      CONFIG_SYS_FLASH_BASE, flash_size)
693                                 );
694                 }
695                 putc('\n');
696 #else  /* !CONFIG_SYS_FLASH_CHECKSUM */
697                 print_size(flash_size, "\n");
698 #endif /* CONFIG_SYS_FLASH_CHECKSUM */
699         } else {
700                 puts(failed);
701                 hang();
702         }
703
704         /* update start of FLASH memory    */
705         bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
706         /* size of FLASH memory (final value) */
707         bd->bi_flashsize = flash_size;
708
709 #if defined(CONFIG_SYS_UPDATE_FLASH_SIZE)
710         /* Make a update of the Memctrl. */
711         update_flash_size(flash_size);
712 #endif
713
714
715 #if defined(CONFIG_OXC) || defined(CONFIG_RMU)
716         /* flash mapped at end of memory map */
717         bd->bi_flashoffset = CONFIG_SYS_TEXT_BASE + flash_size;
718 #elif CONFIG_SYS_MONITOR_BASE == CONFIG_SYS_FLASH_BASE
719         bd->bi_flashoffset = monitor_flash_len; /* reserved area for monitor */
720 #endif
721 #endif /* !CONFIG_SYS_NO_FLASH */
722
723         WATCHDOG_RESET();
724
725         /* initialize higher level parts of CPU like time base and timers */
726         cpu_init_r();
727
728         WATCHDOG_RESET();
729
730 #ifdef CONFIG_SPI
731 #if !defined(CONFIG_ENV_IS_IN_EEPROM)
732         spi_init_f();
733 #endif
734         spi_init_r();
735 #endif
736
737 #if defined(CONFIG_CMD_NAND)
738         WATCHDOG_RESET();
739         puts("NAND:  ");
740         nand_init();            /* go init the NAND */
741 #endif
742
743 #ifdef CONFIG_GENERIC_MMC
744 /*
745  * MMC initialization is called before relocating env.
746  * Thus It is required that operations like pin multiplexer
747  * be put in board_init.
748  */
749         WATCHDOG_RESET();
750         puts("MMC:  ");
751         mmc_initialize(bd);
752 #endif
753
754         /* relocate environment function pointers etc. */
755         env_relocate();
756
757         /*
758          * after non-volatile devices & environment is setup and cpu code have
759          * another round to deal with any initialization that might require
760          * full access to the environment or loading of some image (firmware)
761          * from a non-volatile device
762          */
763         cpu_secondary_init_r();
764
765         /*
766          * Fill in missing fields of bd_info.
767          * We do this here, where we have "normal" access to the
768          * environment; we used to do this still running from ROM,
769          * where had to use getenv_f(), which can be pretty slow when
770          * the environment is in EEPROM.
771          */
772
773 #if defined(CONFIG_SYS_EXTBDINFO)
774 #if defined(CONFIG_405GP) || defined(CONFIG_405EP)
775 #if defined(CONFIG_I2CFAST)
776         /*
777          * set bi_iic_fast for linux taking environment variable
778          * "i2cfast" into account
779          */
780         {
781                 if (getenv_yesno("i2cfast") == 1) {
782                         bd->bi_iic_fast[0] = 1;
783                         bd->bi_iic_fast[1] = 1;
784                 }
785         }
786 #endif /* CONFIG_I2CFAST */
787 #endif /* CONFIG_405GP, CONFIG_405EP */
788 #endif /* CONFIG_SYS_EXTBDINFO */
789
790 #if defined(CONFIG_ID_EEPROM) || defined(CONFIG_SYS_I2C_MAC_OFFSET)
791         mac_read_from_eeprom();
792 #endif
793
794 #ifdef CONFIG_CMD_NET
795         /* kept around for legacy kernels only ... ignore the next section */
796         eth_getenv_enetaddr("ethaddr", bd->bi_enetaddr);
797 #ifdef CONFIG_HAS_ETH1
798         eth_getenv_enetaddr("eth1addr", bd->bi_enet1addr);
799 #endif
800 #ifdef CONFIG_HAS_ETH2
801         eth_getenv_enetaddr("eth2addr", bd->bi_enet2addr);
802 #endif
803 #ifdef CONFIG_HAS_ETH3
804         eth_getenv_enetaddr("eth3addr", bd->bi_enet3addr);
805 #endif
806 #ifdef CONFIG_HAS_ETH4
807         eth_getenv_enetaddr("eth4addr", bd->bi_enet4addr);
808 #endif
809 #ifdef CONFIG_HAS_ETH5
810         eth_getenv_enetaddr("eth5addr", bd->bi_enet5addr);
811 #endif
812 #endif /* CONFIG_CMD_NET */
813
814         WATCHDOG_RESET();
815
816 #if defined(CONFIG_PCI) && !defined(CONFIG_SYS_EARLY_PCI_INIT)
817         /*
818          * Do pci configuration
819          */
820         pci_init();
821 #endif
822
823 /** leave this here (after malloc(), environment and PCI are working) **/
824         /* Initialize stdio devices */
825         stdio_init();
826
827         /* Initialize the jump table for applications */
828         jumptable_init();
829
830 #if defined(CONFIG_API)
831         /* Initialize API */
832         api_init();
833 #endif
834
835         /* Initialize the console (after the relocation and devices init) */
836         console_init_r();
837
838 #if defined(CONFIG_MISC_INIT_R)
839         /* miscellaneous platform dependent initialisations */
840         misc_init_r();
841 #endif
842
843 #if defined(CONFIG_CMD_KGDB)
844         WATCHDOG_RESET();
845         puts("KGDB:  ");
846         kgdb_init();
847 #endif
848
849         debug("U-Boot relocated to %08lx\n", dest_addr);
850
851         /*
852          * Enable Interrupts
853          */
854         interrupt_init();
855
856 #if defined(CONFIG_STATUS_LED) && defined(STATUS_LED_BOOT)
857         status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING);
858 #endif
859
860         udelay(20);
861
862         /* Initialize from environment */
863         load_addr = getenv_ulong("loadaddr", 16, load_addr);
864
865         WATCHDOG_RESET();
866
867 #if defined(CONFIG_CMD_SCSI)
868         WATCHDOG_RESET();
869         puts("SCSI:  ");
870         scsi_init();
871 #endif
872
873 #if defined(CONFIG_CMD_DOC)
874         WATCHDOG_RESET();
875         puts("DOC:   ");
876         doc_init();
877 #endif
878
879 #ifdef CONFIG_BITBANGMII
880         bb_miiphy_init();
881 #endif
882 #if defined(CONFIG_CMD_NET)
883         WATCHDOG_RESET();
884         puts("Net:   ");
885         eth_initialize();
886 #endif
887
888 #if defined(CONFIG_CMD_NET) && defined(CONFIG_RESET_PHY_R)
889         WATCHDOG_RESET();
890         debug("Reset Ethernet PHY\n");
891         reset_phy();
892 #endif
893
894 #ifdef CONFIG_POST
895         post_run(NULL, POST_RAM | post_bootmode_get(0));
896 #endif
897
898 #if defined(CONFIG_CMD_PCMCIA) \
899     && !defined(CONFIG_CMD_IDE)
900         WATCHDOG_RESET();
901         puts("PCMCIA:");
902         pcmcia_init();
903 #endif
904
905 #if defined(CONFIG_CMD_IDE)
906         WATCHDOG_RESET();
907 #ifdef  CONFIG_IDE_8xx_PCCARD
908         puts("PCMCIA:");
909 #else
910         puts("IDE:   ");
911 #endif
912 #if defined(CONFIG_START_IDE)
913         if (board_start_ide())
914                 ide_init();
915 #else
916         ide_init();
917 #endif
918 #endif
919
920 #ifdef CONFIG_LAST_STAGE_INIT
921         WATCHDOG_RESET();
922         /*
923          * Some parts can be only initialized if all others (like
924          * Interrupts) are up and running (i.e. the PC-style ISA
925          * keyboard).
926          */
927         last_stage_init();
928 #endif
929
930 #if defined(CONFIG_CMD_BEDBUG)
931         WATCHDOG_RESET();
932         bedbug_init();
933 #endif
934
935 #if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
936         /*
937          * Export available size of memory for Linux,
938          * taking into account the protected RAM at top of memory
939          */
940         {
941                 ulong pram = 0;
942                 char memsz[32];
943
944 #ifdef CONFIG_PRAM
945                 pram = getenv_ulong("pram", 10, CONFIG_PRAM);
946 #endif
947 #ifdef CONFIG_LOGBUFFER
948 #ifndef CONFIG_ALT_LB_ADDR
949                 /* Also take the logbuffer into account (pram is in kB) */
950                 pram += (LOGBUFF_LEN + LOGBUFF_OVERHEAD) / 1024;
951 #endif
952 #endif
953                 sprintf(memsz, "%ldk", (ulong) (bd->bi_memsize / 1024) - pram);
954                 setenv("mem", memsz);
955         }
956 #endif
957
958 #ifdef CONFIG_PS2KBD
959         puts("PS/2:  ");
960         kbd_init();
961 #endif
962
963         /* Initialization complete - start the monitor */
964
965         /* main_loop() can return to retry autoboot, if so just run it again. */
966         for (;;) {
967                 WATCHDOG_RESET();
968                 main_loop();
969         }
970
971         /* NOTREACHED - no way out of command loop except booting */
972 }
973
974 #if 0   /* We could use plain global data, but the resulting code is bigger */
975 /*
976  * Pointer to initial global data area
977  *
978  * Here we initialize it.
979  */
980 #undef  XTRN_DECLARE_GLOBAL_DATA_PTR
981 #define XTRN_DECLARE_GLOBAL_DATA_PTR    /* empty = allocate here */
982 DECLARE_GLOBAL_DATA_PTR =
983         (gd_t *) (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET);
984 #endif /* 0 */
985
986 /************************************************************************/