blob: 5e8d9b2cf62f27199f477d4d84984a908b8583be [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001/*
2 * (C) Copyright 2002-2006
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * (C) Copyright 2002
6 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
7 * Marius Groeger <mgroeger@sysgo.de>
8 *
9 * SPDX-License-Identifier: GPL-2.0+
10 */
11
12/*
13 * To match the U-Boot user interface on ARM platforms to the U-Boot
14 * standard (as on PPC platforms), some messages with debug character
15 * are removed from the default U-Boot build.
16 *
17 * Define DEBUG here if you want additional info as shown below
18 * printed upon startup:
19 *
20 * U-Boot code: 00F00000 -> 00F3C774 BSS: -> 00FC3274
21 * IRQ Stack: 00ebff7c
22 * FIQ Stack: 00ebef7c
23 */
24
25#include <common.h>
26#include <command.h>
27#include <environment.h>
28#include <malloc.h>
29#include <stdio_dev.h>
30#include <version.h>
31#include <net.h>
32#include <serial.h>
33#include <nand.h>
34#include <spi_flash_chip.h>
35#include <onenand_uboot.h>
36#include <mmc.h>
37#include <libfdt.h>
38#include <fdtdec.h>
39#include <post.h>
40#include <logbuff.h>
41#include <asm/sections.h>
42
43#ifdef CONFIG_BITBANGMII
44#include <miiphy.h>
45#endif
46
47DECLARE_GLOBAL_DATA_PTR;
48
49ulong monitor_flash_len;
50
51#ifdef CONFIG_HAS_DATAFLASH
52extern int AT91F_DataflashInit(void);
53extern void dataflash_print_info(void);
54#endif
55
56#if defined(CONFIG_HARD_I2C) || \
57 defined(CONFIG_SYS_I2C)
58#include <i2c.h>
59#endif
60
61/************************************************************************
62 * Coloured LED functionality
63 ************************************************************************
64 * May be supplied by boards if desired
65 */
66inline void __coloured_LED_init(void) {}
67void coloured_LED_init(void)
68 __attribute__((weak, alias("__coloured_LED_init")));
69inline void __red_led_on(void) {}
70void red_led_on(void) __attribute__((weak, alias("__red_led_on")));
71inline void __red_led_off(void) {}
72void red_led_off(void) __attribute__((weak, alias("__red_led_off")));
73inline void __green_led_on(void) {}
74void green_led_on(void) __attribute__((weak, alias("__green_led_on")));
75inline void __green_led_off(void) {}
76void green_led_off(void) __attribute__((weak, alias("__green_led_off")));
77inline void __yellow_led_on(void) {}
78void yellow_led_on(void) __attribute__((weak, alias("__yellow_led_on")));
79inline void __yellow_led_off(void) {}
80void yellow_led_off(void) __attribute__((weak, alias("__yellow_led_off")));
81inline void __blue_led_on(void) {}
82void blue_led_on(void) __attribute__((weak, alias("__blue_led_on")));
83inline void __blue_led_off(void) {}
84void blue_led_off(void) __attribute__((weak, alias("__blue_led_off")));
85
86/*
87 ************************************************************************
88 * Init Utilities *
89 ************************************************************************
90 * Some of this code should be moved into the core functions,
91 * or dropped completely,
92 * but let's get it working (again) first...
93 */
94
95#if defined(CONFIG_ARM_DCC) && !defined(CONFIG_BAUDRATE)
96#define CONFIG_BAUDRATE 115200
97#endif
98
99static int init_baudrate(void)
100{
101 gd->baudrate = getenv_ulong("baudrate", 10, CONFIG_BAUDRATE);
102 return 0;
103}
104
105static int display_banner(void)
106{
107 printf("\n\n%s\n\n", version_string);
108 debug("U-Boot code: %08lX -> %08lX BSS: -> %08lX\n",
109 _TEXT_BASE,
110 _bss_start_ofs + _TEXT_BASE, _bss_end_ofs + _TEXT_BASE);
111#ifdef CONFIG_MODEM_SUPPORT
112 debug("Modem Support enabled\n");
113#endif
114#ifdef CONFIG_USE_IRQ
115 debug("IRQ Stack: %08lx\n", IRQ_STACK_START);
116 debug("FIQ Stack: %08lx\n", FIQ_STACK_START);
117#endif
118
119 return (0);
120}
121
122/*
123 * WARNING: this code looks "cleaner" than the PowerPC version, but
124 * has the disadvantage that you either get nothing, or everything.
125 * On PowerPC, you might see "DRAM: " before the system hangs - which
126 * gives a simple yet clear indication which part of the
127 * initialization if failing.
128 */
129static int display_dram_config(void)
130{
131 int i;
132
133#ifdef DEBUG
134 puts("RAM Configuration:\n");
135
136 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
137 printf("Bank #%d: %08lx ", i, gd->bd->bi_dram[i].start);
138 print_size(gd->bd->bi_dram[i].size, "\n");
139 }
140#else
141 ulong size = 0;
142
143 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
144 size += gd->bd->bi_dram[i].size;
145
146 puts("DRAM: ");
147 print_size(size, "\n");
148#endif
149
150 return (0);
151}
152
153#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
154static int init_func_i2c(void)
155{
156 puts("I2C: ");
157#ifdef CONFIG_SYS_I2C
158 i2c_init_all();
159#else
160 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
161#endif
162 puts("ready\n");
163 return (0);
164}
165#endif
166
167#if defined(CONFIG_CMD_PCI) || defined (CONFIG_PCI)
168#include <pci.h>
169static int arm_pci_init(void)
170{
171 pci_init();
172 return 0;
173}
174#endif /* CONFIG_CMD_PCI || CONFIG_PCI */
175
176/*
177 * Breathe some life into the board...
178 *
179 * Initialize a serial port as console, and carry out some hardware
180 * tests.
181 *
182 * The first part of initialization is running from Flash memory;
183 * its main purpose is to initialize the RAM so that we
184 * can relocate the monitor code to RAM.
185 */
186
187/*
188 * All attempts to come up with a "common" initialization sequence
189 * that works for all boards and architectures failed: some of the
190 * requirements are just _too_ different. To get rid of the resulting
191 * mess of board dependent #ifdef'ed code we now make the whole
192 * initialization sequence configurable to the user.
193 *
194 * The requirements for any new initalization function is simple: it
195 * receives a pointer to the "global data" structure as it's only
196 * argument, and returns an integer return code, where 0 means
197 * "continue" and != 0 means "fatal error, hang the system".
198 */
199typedef int (init_fnc_t) (void);
200
201int print_cpuinfo(void);
202
203void __dram_init_banksize(void)
204{
205 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
206 gd->bd->bi_dram[0].size = gd->ram_size;
207}
208void dram_init_banksize(void)
209 __attribute__((weak, alias("__dram_init_banksize")));
210
211int __arch_cpu_init(void)
212{
213 return 0;
214}
215int arch_cpu_init(void)
216 __attribute__((weak, alias("__arch_cpu_init")));
217
218int __d2forsysen(void)
219{
220 return 0;
221}
222int d2forsysen(void)
223 __attribute__((weak, alias("__d2forsysen")));
224
225int __boot_adc_dsp(void)
226{
227 return 0;
228}
229int boot_adc_dsp(void)
230 __attribute__((weak, alias("__boot_adc_dsp")));
231
232int __hold_cp_inreset(void)
233{
234 return 0;
235}
236int hold_cp_inreset(void)
237 __attribute__((weak, alias("__hold_cp_inreset")));
238
239int __power_init_board(void)
240{
241 return 0;
242}
243int power_init_board(void)
244 __attribute__((weak, alias("__power_init_board")));
245
246int __power_init_charge(void)
247{
248 return 0;
249}
250int power_init_charge(void)
251 __attribute__((weak, alias("__power_init_charge")));
252
253int __pmic_32khz_early_init(void)
254{
255 return 0;
256}
257int pmic_32khz_early_init(void)
258 __attribute__((weak, alias("__pmic_32khz_early_init")));
259
260 /* Record the board_init_f() bootstage (after arch_cpu_init()) */
261static int mark_bootstage(void)
262{
263 bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_F, "board_init_f");
264
265 return 0;
266}
267
268init_fnc_t *init_sequence[] = {
269 pmic_32khz_early_init,
270 d2forsysen, /* let com enter into D2 to keep sysen signal low for a short period*/
271 boot_adc_dsp, /* boot dsp to read adc */
272 arch_cpu_init, /* basic arch cpu dependent setup */
273 mark_bootstage,
274#ifdef CONFIG_OF_CONTROL
275 fdtdec_check_fdt,
276#endif
277#if defined(CONFIG_BOARD_EARLY_INIT_F)
278 board_early_init_f,
279#endif
280 timer_init, /* initialize timer */
281#ifdef CONFIG_BOARD_POSTCLK_INIT
282 board_postclk_init,
283#endif
284#ifdef CONFIG_FSL_ESDHC
285 get_clocks,
286#endif
287 env_init, /* initialize environment */
288 init_baudrate, /* initialze baudrate settings */
289 serial_init, /* serial communications setup */
290 console_init_f, /* stage 1 init of console */
291 display_banner, /* say that we are here */
292#if defined(CONFIG_DISPLAY_CPUINFO)
293 print_cpuinfo, /* display cpu info (and speed) */
294#endif
295#if defined(CONFIG_DISPLAY_BOARDINFO)
296 checkboard, /* display board info */
297#endif
298#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
299 init_func_i2c,
300#endif
301 dram_init, /* configure available RAM banks */
302 hold_cp_inreset, /* reset cp after d2forsysen since CP-in-reset is the assumption for HW-DVC and next CP release*/
303 NULL,
304};
305
306__weak int get_ramdump_flag_f(void) {return 0;}
307
308void board_init_f(ulong bootflag)
309{
310 bd_t *bd;
311 init_fnc_t **init_fnc_ptr;
312 gd_t *id;
313 ulong addr, addr_sp;
314#ifdef CONFIG_PRAM
315 ulong reg;
316#endif
317 ulong malloc_len;
318 void *new_fdt = NULL;
319 size_t fdt_size = 0;
320 int ramdump_boot;
321
322 memset((void *)gd, 0, sizeof(gd_t));
323
324 ramdump_boot = get_ramdump_flag_f();
325
326 gd->mon_len = _bss_end_ofs;
327#ifdef CONFIG_OF_EMBED
328 /* Get a pointer to the FDT */
329 gd->fdt_blob = _binary_dt_dtb_start;
330#elif defined CONFIG_OF_SEPARATE
331 /* FDT is at end of image */
332 gd->fdt_blob = (void *)(_end_ofs + _TEXT_BASE);
333#endif
334 /* Allow the early environment to override the fdt address */
335 gd->fdt_blob = (void *)getenv_ulong("fdtcontroladdr", 16,
336 (uintptr_t)gd->fdt_blob);
337
338 for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
339 if ((*init_fnc_ptr)() != 0) {
340 hang ();
341 }
342 }
343
344#ifdef CONFIG_OF_CONTROL
345 /* For now, put this check after the console is ready */
346 if (fdtdec_prepare_fdt()) {
347 panic("** CONFIG_OF_CONTROL defined but no FDT - please see "
348 "doc/README.fdt-control");
349 }
350#endif
351
352 debug("monitor len: %08lX\n", gd->mon_len);
353 /*
354 * Ram is setup, size stored in gd !!
355 */
356 debug("ramsize: %08lX\n", gd->ram_size);
357#if defined(CONFIG_SYS_MEM_TOP_HIDE)
358 /*
359 * Subtract specified amount of memory to hide so that it won't
360 * get "touched" at all by U-Boot. By fixing up gd->ram_size
361 * the Linux kernel should now get passed the now "corrected"
362 * memory size and won't touch it either. This should work
363 * for arch/ppc and arch/powerpc. Only Linux board ports in
364 * arch/powerpc with bootwrapper support, that recalculate the
365 * memory size from the SDRAM controller setup will have to
366 * get fixed.
367 */
368 gd->ram_size -= CONFIG_SYS_MEM_TOP_HIDE;
369#endif
370
371 addr = CONFIG_SYS_SDRAM_BASE + gd->ram_size;
372
373#ifdef CONFIG_LOGBUFFER
374#ifndef CONFIG_ALT_LB_ADDR
375 /* reserve kernel log buffer */
376 addr -= (LOGBUFF_RESERVE);
377 debug("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN,
378 addr);
379#endif
380#endif
381
382#ifdef CONFIG_PRAM
383 /*
384 * reserve protected RAM
385 */
386 reg = getenv_ulong("pram", 10, CONFIG_PRAM);
387 addr -= (reg << 10); /* size is in kB */
388 debug("Reserving %ldk for protected RAM at %08lx\n", reg, addr);
389#endif /* CONFIG_PRAM */
390
391#if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF))
392 /* reserve TLB table */
393 gd->arch.tlb_size = PGTABLE_SIZE;
394 addr -= gd->arch.tlb_size;
395
396 /* round down to next 64 kB limit */
397 addr &= ~(0x10000 - 1);
398
399 gd->arch.tlb_addr = addr;
400 debug("TLB table from %08lx to %08lx\n", addr, addr + gd->arch.tlb_size);
401#endif
402
403 /* round down to next 4 kB limit */
404 addr &= ~(4096 - 1);
405 debug("Top of RAM usable for U-Boot at: %08lx\n", addr);
406
407#ifdef CONFIG_LCD
408#ifdef CONFIG_FB_ADDR
409 gd->fb_base = CONFIG_FB_ADDR;
410#else
411 /* reserve memory for LCD display (always full pages) */
412 addr = lcd_setmem(addr);
413 gd->fb_base = addr;
414#endif /* CONFIG_FB_ADDR */
415#endif /* CONFIG_LCD */
416
417 /*
418 * reserve memory for U-Boot code, data & bss
419 * round down to next 4 kB limit
420 */
421 addr -= gd->mon_len;
422 addr &= ~(4096 - 1);
423
424 debug("Reserving %ldk for U-Boot at: %08lx\n", gd->mon_len >> 10, addr);
425
426#ifndef CONFIG_SPL_BUILD
427 /*
428 * reserve memory for malloc() arena
429 */
430 if (ramdump_boot) {
431 malloc_len = TOTAL_MALLOC_LEN;
432 } else {
433 malloc_len = CONFIG_SYS_LONG_MALLOC_LEN;
434 }
435 addr_sp = addr - malloc_len;
436 debug("Reserving %dk for malloc() at: %08lx ramdump_boot=%lu\n",
437 malloc_len >> 10, addr_sp, ramdump_boot);
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 debug("Reserving %zu Bytes for Board Info at: %08lx\n",
446 sizeof (bd_t), addr_sp);
447
448#ifdef CONFIG_MACH_TYPE
449 gd->bd->bi_arch_number = CONFIG_MACH_TYPE; /* board id for Linux */
450#endif
451
452 addr_sp -= sizeof (gd_t);
453 id = (gd_t *) addr_sp;
454 debug("Reserving %zu Bytes for Global Data at: %08lx\n",
455 sizeof (gd_t), addr_sp);
456
457#if defined(CONFIG_OF_SEPARATE) && defined(CONFIG_OF_CONTROL)
458 /*
459 * If the device tree is sitting immediate above our image then we
460 * must relocate it. If it is embedded in the data section, then it
461 * will be relocated with other data.
462 */
463 if (gd->fdt_blob) {
464 fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob) + 0x1000, 32);
465
466 addr_sp -= fdt_size;
467 new_fdt = (void *)addr_sp;
468 debug("Reserving %zu Bytes for FDT at: %08lx\n",
469 fdt_size, addr_sp);
470 }
471#endif
472
473#ifndef CONFIG_ARM64
474 /* setup stackpointer for exeptions */
475 gd->irq_sp = addr_sp;
476#ifdef CONFIG_USE_IRQ
477 addr_sp -= (CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ);
478 debug("Reserving %zu Bytes for IRQ stack at: %08lx\n",
479 CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ, addr_sp);
480#endif
481 /* leave 3 words for abort-stack */
482 addr_sp -= 12;
483
484 /* 8-byte alignment for ABI compliance */
485 addr_sp &= ~0x07;
486#else /* CONFIG_ARM64 */
487 /* 16-byte alignment for ABI compliance */
488 addr_sp &= ~0x0f;
489#endif /* CONFIG_ARM64 */
490#else
491 addr_sp += 128; /* leave 32 words for abort-stack */
492 gd->irq_sp = addr_sp;
493#endif
494
495 debug("New Stack Pointer is: %08lx\n", addr_sp);
496
497#ifdef CONFIG_POST
498 post_bootmode_init();
499 post_run(NULL, POST_ROM | post_bootmode_get(0));
500#endif
501
502 gd->bd->bi_baudrate = gd->baudrate;
503 /* Ram ist board specific, so move it to board code ... */
504 dram_init_banksize();
505 display_dram_config(); /* and display it */
506
507 gd->relocaddr = addr;
508 gd->start_addr_sp = addr_sp;
509 gd->reloc_off = addr - _TEXT_BASE;
510 /* Start= _TEXT_BASE = _start() */
511 printf("Start=%08lx, relocation Offset is: %08lx\n", _TEXT_BASE, gd->reloc_off);
512 if (new_fdt) {
513 memcpy(new_fdt, gd->fdt_blob, fdt_size);
514 gd->fdt_blob = new_fdt;
515 }
516 memcpy(id, (void *)gd, sizeof(gd_t));
517
518#ifdef CONFIG_SYS_SYM_OFFSETS
519 if (gd->start_addr_sp < (_TEXT_BASE + _bss_start_ofs))
520 printf("!!!!!!!! err: stack overlap with code/data area\n");
521#else
522 if (gd->start_addr_sp < __data_end)
523 printf("!!!!!!!! err: stack overlap with code/data area\n");
524#endif
525
526 get_quiet_from_obm();
527}
528
529#if !defined(CONFIG_SYS_NO_FLASH)
530static char *failed = "*** failed ***\n";
531#endif
532
533/*
534 * Tell if it's OK to load the environment early in boot.
535 *
536 * If CONFIG_OF_CONFIG is defined, we'll check with the FDT to see
537 * if this is OK (defaulting to saying it's not OK).
538 *
539 * NOTE: Loading the environment early can be a bad idea if security is
540 * important, since no verification is done on the environment.
541 *
542 * @return 0 if environment should not be loaded, !=0 if it is ok to load
543 */
544static int should_load_env(void)
545{
546#ifdef CONFIG_OF_CONTROL
547 return fdtdec_get_config_int(gd->fdt_blob, "load-environment", 1);
548#elif defined CONFIG_DELAY_ENVIRONMENT
549 return 0;
550#else
551 return 1;
552#endif
553}
554
555#if defined(CONFIG_DISPLAY_BOARDINFO_LATE) && defined(CONFIG_OF_CONTROL)
556static void display_fdt_model(const void *blob)
557{
558 const char *model;
559
560 model = (char *)fdt_getprop(blob, 0, "model", NULL);
561 printf("Model: %s\n", model ? model : "<unknown>");
562}
563#endif
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 ************************************************************************
573 */
574
575void board_init_r(gd_t *id, ulong dest_addr)
576{
577 ulong malloc_start;
578 ulong malloc_len;
579#if !defined(CONFIG_SYS_NO_FLASH)
580 ulong flash_size;
581#endif
582 int ramdump_boot = get_ramdump_flag_f();
583
584 gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
585 bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_R, "board_init_r");
586
587 monitor_flash_len = _end_ofs;
588
589 /* Enable caches */
590 enable_caches();
591
592 debug("monitor flash len: %08lX\n", monitor_flash_len);
593 board_init(); /* Setup chipselects */
594 /*
595 * TODO: printing of the clock inforamtion of the board is now
596 * implemented as part of bdinfo command. Currently only support for
597 * davinci SOC's is added. Remove this check once all the board
598 * implement this.
599 */
600#ifdef CONFIG_CLOCKS
601 set_cpu_clk_info(); /* Setup clock information */
602#endif
603 serial_initialize();
604
605 debug("Now running in RAM - U-Boot at: %08lx\n", dest_addr);
606
607#ifdef CONFIG_LOGBUFFER
608 logbuff_init_ptrs();
609#endif
610#ifdef CONFIG_POST
611 post_output_backlog();
612#endif
613
614 /* The Malloc area is immediately below the monitor copy in DRAM */
615 if (ramdump_boot)
616 malloc_len = TOTAL_MALLOC_LEN;
617 else
618 malloc_len = CONFIG_SYS_LONG_MALLOC_LEN;
619 malloc_start = dest_addr - malloc_len;
620
621 printf("malloc buf: [%08lx: %08lx]\n", malloc_start, malloc_len);
622 mem_malloc_init (malloc_start, malloc_len);
623#ifdef CONFIG_ARCH_EARLY_INIT_R
624 arch_early_init_r();
625#endif
626
627#if (!defined(CONFIG_FG_PM803)) && (!defined(CONFIG_PM803_GPADC))
628 power_init_board();
629#endif
630
631#if !defined(CONFIG_SYS_NO_FLASH)
632 puts("Flash: ");
633
634 flash_size = flash_init();
635 if (flash_size > 0) {
636# ifdef CONFIG_SYS_FLASH_CHECKSUM
637 print_size(flash_size, "");
638 /*
639 * Compute and print flash CRC if flashchecksum is set to 'y'
640 *
641 * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
642 */
643 if (getenv_yesno("flashchecksum") == 1) {
644 printf(" CRC: %08X", crc32(0,
645 (const unsigned char *) CONFIG_SYS_FLASH_BASE,
646 flash_size));
647 }
648 putc('\n');
649# else /* !CONFIG_SYS_FLASH_CHECKSUM */
650 print_size(flash_size, "\n");
651# endif /* CONFIG_SYS_FLASH_CHECKSUM */
652 } else {
653 puts(failed);
654 hang();
655 }
656#endif
657
658#if defined(CONFIG_CMD_NAND)
659 puts("NAND: ");
660 nand_init(); /* go init the NAND */
661#endif
662
663#if defined(CONFIG_CMD_SPIFLASH)
664 puts("SPI-FLASH: ");
665 spi_flash_chip_init();
666#endif
667
668#if defined(CONFIG_CMD_ONENAND)
669 onenand_init();
670#endif
671
672#if defined(CONFIG_FG_PM803) || defined(CONFIG_PM803_GPADC)
673 power_init_board();
674#endif
675
676#ifdef CONFIG_GENERIC_MMC
677 puts("MMC: ");
678 mmc_initialize(gd->bd);
679#endif
680
681#ifdef CONFIG_HAS_DATAFLASH
682 AT91F_DataflashInit();
683 dataflash_print_info();
684#endif
685
686 /* initialize environment */
687 if (should_load_env())
688 env_relocate();
689 else
690 set_default_env(NULL);
691#ifdef CONFIG_FG_PM803
692 power_init_charge();
693#endif
694#if defined(CONFIG_CMD_PCI) || defined(CONFIG_PCI)
695 arm_pci_init();
696#endif
697
698 stdio_init(); /* get the devices list going. */
699
700 jumptable_init();
701
702#if defined(CONFIG_API)
703 /* Initialize API */
704 api_init();
705#endif
706
707 console_init_r(); /* fully init console as a device */
708
709#ifdef CONFIG_DISPLAY_BOARDINFO_LATE
710# ifdef CONFIG_OF_CONTROL
711 /* Put this here so it appears on the LCD, now it is ready */
712 display_fdt_model(gd->fdt_blob);
713# else
714 checkboard();
715# endif
716#endif
717
718#if defined(CONFIG_ARCH_MISC_INIT)
719 /* miscellaneous arch dependent initialisations */
720 arch_misc_init();
721#endif
722#if defined(CONFIG_MISC_INIT_R)
723 /* miscellaneous platform dependent initialisations */
724 misc_init_r();
725#endif
726
727 /* set up exceptions */
728 interrupt_init();
729 /* enable exceptions */
730 enable_interrupts();
731
732 /* Initialize from environment */
733 load_addr = getenv_ulong("loadaddr", 16, load_addr);
734
735#ifdef CONFIG_BOARD_LATE_INIT
736 board_late_init();
737#endif
738
739#ifdef CONFIG_BITBANGMII
740 bb_miiphy_init();
741#endif
742#if defined(CONFIG_CMD_NET)
743 puts("Net: ");
744 eth_initialize(gd->bd);
745#if defined(CONFIG_RESET_PHY_R)
746 debug("Reset Ethernet PHY\n");
747 reset_phy();
748#endif
749#endif
750
751#ifdef CONFIG_POST
752 post_run(NULL, POST_RAM | post_bootmode_get(0));
753#endif
754
755#if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
756 /*
757 * Export available size of memory for Linux,
758 * taking into account the protected RAM at top of memory
759 */
760 {
761 ulong pram = 0;
762 uchar memsz[32];
763
764#ifdef CONFIG_PRAM
765 pram = getenv_ulong("pram", 10, CONFIG_PRAM);
766#endif
767#ifdef CONFIG_LOGBUFFER
768#ifndef CONFIG_ALT_LB_ADDR
769 /* Also take the logbuffer into account (pram is in kB) */
770 pram += (LOGBUFF_LEN + LOGBUFF_OVERHEAD) / 1024;
771#endif
772#endif
773 sprintf((char *)memsz, "%ldk", (gd->ram_size / 1024) - pram);
774 setenv("mem", (char *)memsz);
775 }
776#endif
777
778 /* main_loop() can return to retry autoboot, if so just run it again. */
779 for (;;) {
780 main_loop();
781 }
782
783 /* NOTREACHED - no way out of command loop except booting */
784}