xref: /openbmc/u-boot/common/board_r.c (revision 66877b0f)
1 /*
2  * Copyright (c) 2011 The Chromium OS Authors.
3  * (C) Copyright 2002-2006
4  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5  *
6  * (C) Copyright 2002
7  * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
8  * Marius Groeger <mgroeger@sysgo.de>
9  *
10  * SPDX-License-Identifier:	GPL-2.0+
11  */
12 
13 #include <common.h>
14 /* TODO: can we just include all these headers whether needed or not? */
15 #if defined(CONFIG_CMD_BEDBUG)
16 #include <bedbug/type.h>
17 #endif
18 #ifdef CONFIG_HAS_DATAFLASH
19 #include <dataflash.h>
20 #endif
21 #include <dm.h>
22 #include <environment.h>
23 #include <fdtdec.h>
24 #if defined(CONFIG_CMD_IDE)
25 #include <ide.h>
26 #endif
27 #include <initcall.h>
28 #ifdef CONFIG_PS2KBD
29 #include <keyboard.h>
30 #endif
31 #if defined(CONFIG_CMD_KGDB)
32 #include <kgdb.h>
33 #endif
34 #include <logbuff.h>
35 #include <malloc.h>
36 #include <mapmem.h>
37 #ifdef CONFIG_BITBANGMII
38 #include <miiphy.h>
39 #endif
40 #include <mmc.h>
41 #include <nand.h>
42 #include <onenand_uboot.h>
43 #include <scsi.h>
44 #include <serial.h>
45 #include <spi.h>
46 #include <stdio_dev.h>
47 #include <trace.h>
48 #include <watchdog.h>
49 #ifdef CONFIG_CMD_AMBAPP
50 #include <ambapp.h>
51 #endif
52 #ifdef CONFIG_ADDR_MAP
53 #include <asm/mmu.h>
54 #endif
55 #include <asm/sections.h>
56 #ifdef CONFIG_X86
57 #include <asm/init_helpers.h>
58 #endif
59 #include <dm/root.h>
60 #include <linux/compiler.h>
61 #include <linux/err.h>
62 #ifdef CONFIG_AVR32
63 #include <asm/arch/mmu.h>
64 #endif
65 
66 DECLARE_GLOBAL_DATA_PTR;
67 
68 ulong monitor_flash_len;
69 
70 __weak int board_flash_wp_on(void)
71 {
72 	/*
73 	 * Most flashes can't be detected when write protection is enabled,
74 	 * so provide a way to let U-Boot gracefully ignore write protected
75 	 * devices.
76 	 */
77 	return 0;
78 }
79 
80 __weak void cpu_secondary_init_r(void)
81 {
82 }
83 
84 static int initr_secondary_cpu(void)
85 {
86 	/*
87 	 * after non-volatile devices & environment is setup and cpu code have
88 	 * another round to deal with any initialization that might require
89 	 * full access to the environment or loading of some image (firmware)
90 	 * from a non-volatile device
91 	 */
92 	/* TODO: maybe define this for all archs? */
93 	cpu_secondary_init_r();
94 
95 	return 0;
96 }
97 
98 static int initr_trace(void)
99 {
100 #ifdef CONFIG_TRACE
101 	trace_init(gd->trace_buff, CONFIG_TRACE_BUFFER_SIZE);
102 #endif
103 
104 	return 0;
105 }
106 
107 static int initr_reloc(void)
108 {
109 	/* tell others: relocation done */
110 	gd->flags |= GD_FLG_RELOC | GD_FLG_FULL_MALLOC_INIT;
111 	bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_R, "board_init_r");
112 
113 	return 0;
114 }
115 
116 #ifdef CONFIG_ARM
117 /*
118  * Some of these functions are needed purely because the functions they
119  * call return void. If we change them to return 0, these stubs can go away.
120  */
121 static int initr_caches(void)
122 {
123 	/* Enable caches */
124 	enable_caches();
125 	return 0;
126 }
127 #endif
128 
129 __weak int fixup_cpu(void)
130 {
131 	return 0;
132 }
133 
134 static int initr_reloc_global_data(void)
135 {
136 #ifdef __ARM__
137 	monitor_flash_len = _end - __image_copy_start;
138 #elif defined(CONFIG_NDS32)
139 	monitor_flash_len = (ulong)&_end - (ulong)&_start;
140 #elif !defined(CONFIG_SANDBOX) && !defined(CONFIG_NIOS2)
141 	monitor_flash_len = (ulong)&__init_end - gd->relocaddr;
142 #endif
143 #if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx)
144 	/*
145 	 * The gd->cpu pointer is set to an address in flash before relocation.
146 	 * We need to update it to point to the same CPU entry in RAM.
147 	 * TODO: why not just add gd->reloc_ofs?
148 	 */
149 	gd->arch.cpu += gd->relocaddr - CONFIG_SYS_MONITOR_BASE;
150 
151 	/*
152 	 * If we didn't know the cpu mask & # cores, we can save them of
153 	 * now rather than 'computing' them constantly
154 	 */
155 	fixup_cpu();
156 #endif
157 #ifdef CONFIG_SYS_EXTRA_ENV_RELOC
158 	/*
159 	 * Some systems need to relocate the env_addr pointer early because the
160 	 * location it points to will get invalidated before env_relocate is
161 	 * called.  One example is on systems that might use a L2 or L3 cache
162 	 * in SRAM mode and initialize that cache from SRAM mode back to being
163 	 * a cache in cpu_init_r.
164 	 */
165 	gd->env_addr += gd->relocaddr - CONFIG_SYS_MONITOR_BASE;
166 #endif
167 	return 0;
168 }
169 
170 static int initr_serial(void)
171 {
172 	serial_initialize();
173 	return 0;
174 }
175 
176 #if defined(CONFIG_PPC) || defined(CONFIG_M68K)
177 static int initr_trap(void)
178 {
179 	/*
180 	 * Setup trap handlers
181 	 */
182 #if defined(CONFIG_PPC)
183 	trap_init(gd->relocaddr);
184 #else
185 	trap_init(CONFIG_SYS_SDRAM_BASE);
186 #endif
187 	return 0;
188 }
189 #endif
190 
191 #ifdef CONFIG_ADDR_MAP
192 static int initr_addr_map(void)
193 {
194 	init_addr_map();
195 
196 	return 0;
197 }
198 #endif
199 
200 #ifdef CONFIG_LOGBUFFER
201 unsigned long logbuffer_base(void)
202 {
203 	return gd->ram_top - LOGBUFF_LEN;
204 }
205 
206 static int initr_logbuffer(void)
207 {
208 	logbuff_init_ptrs();
209 	return 0;
210 }
211 #endif
212 
213 #ifdef CONFIG_POST
214 static int initr_post_backlog(void)
215 {
216 	post_output_backlog();
217 	return 0;
218 }
219 #endif
220 
221 #ifdef CONFIG_SYS_DELAYED_ICACHE
222 static int initr_icache_enable(void)
223 {
224 	return 0;
225 }
226 #endif
227 
228 #if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500)
229 static int initr_unlock_ram_in_cache(void)
230 {
231 	unlock_ram_in_cache();	/* it's time to unlock D-cache in e500 */
232 	return 0;
233 }
234 #endif
235 
236 #ifdef CONFIG_PCI
237 static int initr_pci(void)
238 {
239 #ifndef CONFIG_DM_PCI
240 	pci_init();
241 #endif
242 
243 	return 0;
244 }
245 #endif
246 
247 #ifdef CONFIG_WINBOND_83C553
248 static int initr_w83c553f(void)
249 {
250 	/*
251 	 * Initialise the ISA bridge
252 	 */
253 	initialise_w83c553f();
254 	return 0;
255 }
256 #endif
257 
258 static int initr_barrier(void)
259 {
260 #ifdef CONFIG_PPC
261 	/* TODO: Can we not use dmb() macros for this? */
262 	asm("sync ; isync");
263 #endif
264 	return 0;
265 }
266 
267 static int initr_malloc(void)
268 {
269 	ulong malloc_start;
270 
271 #ifdef CONFIG_SYS_MALLOC_F_LEN
272 	debug("Pre-reloc malloc() used %#lx bytes (%ld KB)\n", gd->malloc_ptr,
273 	      gd->malloc_ptr / 1024);
274 #endif
275 	/* The malloc area is immediately below the monitor copy in DRAM */
276 	malloc_start = gd->relocaddr - TOTAL_MALLOC_LEN;
277 	mem_malloc_init((ulong)map_sysmem(malloc_start, TOTAL_MALLOC_LEN),
278 			TOTAL_MALLOC_LEN);
279 	return 0;
280 }
281 
282 #ifdef CONFIG_SYS_NONCACHED_MEMORY
283 static int initr_noncached(void)
284 {
285 	noncached_init();
286 	return 0;
287 }
288 #endif
289 
290 #ifdef CONFIG_DM
291 static int initr_dm(void)
292 {
293 	/* Save the pre-reloc driver model and start a new one */
294 	gd->dm_root_f = gd->dm_root;
295 	gd->dm_root = NULL;
296 #ifdef CONFIG_TIMER
297 	gd->timer = NULL;
298 #endif
299 	return dm_init_and_scan(false);
300 }
301 #endif
302 
303 __weak int power_init_board(void)
304 {
305 	return 0;
306 }
307 
308 static int initr_announce(void)
309 {
310 	debug("Now running in RAM - U-Boot at: %08lx\n", gd->relocaddr);
311 	return 0;
312 }
313 
314 #ifdef CONFIG_NEEDS_MANUAL_RELOC
315 static int initr_manual_reloc_cmdtable(void)
316 {
317 	fixup_cmdtable(ll_entry_start(cmd_tbl_t, cmd),
318 		       ll_entry_count(cmd_tbl_t, cmd));
319 	return 0;
320 }
321 #endif
322 
323 #if !defined(CONFIG_SYS_NO_FLASH)
324 static int initr_flash(void)
325 {
326 	ulong flash_size = 0;
327 	bd_t *bd = gd->bd;
328 
329 	puts("Flash: ");
330 
331 	if (board_flash_wp_on())
332 		printf("Uninitialized - Write Protect On\n");
333 	else
334 		flash_size = flash_init();
335 
336 	print_size(flash_size, "");
337 #ifdef CONFIG_SYS_FLASH_CHECKSUM
338 	/*
339 	* Compute and print flash CRC if flashchecksum is set to 'y'
340 	*
341 	* NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
342 	*/
343 	if (getenv_yesno("flashchecksum") == 1) {
344 		printf("  CRC: %08X", crc32(0,
345 			(const unsigned char *) CONFIG_SYS_FLASH_BASE,
346 			flash_size));
347 	}
348 #endif /* CONFIG_SYS_FLASH_CHECKSUM */
349 	putc('\n');
350 
351 	/* update start of FLASH memory    */
352 #ifdef CONFIG_SYS_FLASH_BASE
353 	bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
354 #endif
355 	/* size of FLASH memory (final value) */
356 	bd->bi_flashsize = flash_size;
357 
358 #if defined(CONFIG_SYS_UPDATE_FLASH_SIZE)
359 	/* Make a update of the Memctrl. */
360 	update_flash_size(flash_size);
361 #endif
362 
363 
364 #if defined(CONFIG_OXC) || defined(CONFIG_RMU)
365 	/* flash mapped at end of memory map */
366 	bd->bi_flashoffset = CONFIG_SYS_TEXT_BASE + flash_size;
367 #elif CONFIG_SYS_MONITOR_BASE == CONFIG_SYS_FLASH_BASE
368 	bd->bi_flashoffset = monitor_flash_len;	/* reserved area for monitor */
369 #endif
370 	return 0;
371 }
372 #endif
373 
374 #if defined(CONFIG_PPC) && !defined(CONFIG_DM_SPI)
375 static int initr_spi(void)
376 {
377 	/* PPC does this here */
378 #ifdef CONFIG_SPI
379 #if !defined(CONFIG_ENV_IS_IN_EEPROM)
380 	spi_init_f();
381 #endif
382 	spi_init_r();
383 #endif
384 	return 0;
385 }
386 #endif
387 
388 #ifdef CONFIG_CMD_NAND
389 /* go init the NAND */
390 static int initr_nand(void)
391 {
392 	puts("NAND:  ");
393 	nand_init();
394 	return 0;
395 }
396 #endif
397 
398 #if defined(CONFIG_CMD_ONENAND)
399 /* go init the NAND */
400 static int initr_onenand(void)
401 {
402 	puts("NAND:  ");
403 	onenand_init();
404 	return 0;
405 }
406 #endif
407 
408 #ifdef CONFIG_GENERIC_MMC
409 static int initr_mmc(void)
410 {
411 	puts("MMC:   ");
412 	mmc_initialize(gd->bd);
413 	return 0;
414 }
415 #endif
416 
417 #ifdef CONFIG_HAS_DATAFLASH
418 static int initr_dataflash(void)
419 {
420 	AT91F_DataflashInit();
421 	dataflash_print_info();
422 	return 0;
423 }
424 #endif
425 
426 /*
427  * Tell if it's OK to load the environment early in boot.
428  *
429  * If CONFIG_OF_CONFIG is defined, we'll check with the FDT to see
430  * if this is OK (defaulting to saying it's OK).
431  *
432  * NOTE: Loading the environment early can be a bad idea if security is
433  *       important, since no verification is done on the environment.
434  *
435  * @return 0 if environment should not be loaded, !=0 if it is ok to load
436  */
437 static int should_load_env(void)
438 {
439 #ifdef CONFIG_OF_CONTROL
440 	return fdtdec_get_config_int(gd->fdt_blob, "load-environment", 1);
441 #elif defined CONFIG_DELAY_ENVIRONMENT
442 	return 0;
443 #else
444 	return 1;
445 #endif
446 }
447 
448 static int initr_env(void)
449 {
450 	/* initialize environment */
451 	if (should_load_env())
452 		env_relocate();
453 	else
454 		set_default_env(NULL);
455 #ifdef CONFIG_OF_CONTROL
456 	setenv_addr("fdtcontroladdr", gd->fdt_blob);
457 #endif
458 
459 	/* Initialize from environment */
460 	load_addr = getenv_ulong("loadaddr", 16, load_addr);
461 #if defined(CONFIG_SYS_EXTBDINFO)
462 #if defined(CONFIG_405GP) || defined(CONFIG_405EP)
463 #if defined(CONFIG_I2CFAST)
464 	/*
465 	 * set bi_iic_fast for linux taking environment variable
466 	 * "i2cfast" into account
467 	 */
468 	{
469 		char *s = getenv("i2cfast");
470 
471 		if (s && ((*s == 'y') || (*s == 'Y'))) {
472 			gd->bd->bi_iic_fast[0] = 1;
473 			gd->bd->bi_iic_fast[1] = 1;
474 		}
475 	}
476 #endif /* CONFIG_I2CFAST */
477 #endif /* CONFIG_405GP, CONFIG_405EP */
478 #endif /* CONFIG_SYS_EXTBDINFO */
479 	return 0;
480 }
481 
482 #ifdef CONFIG_SYS_BOOTPARAMS_LEN
483 static int initr_malloc_bootparams(void)
484 {
485 	gd->bd->bi_boot_params = (ulong)malloc(CONFIG_SYS_BOOTPARAMS_LEN);
486 	if (!gd->bd->bi_boot_params) {
487 		puts("WARNING: Cannot allocate space for boot parameters\n");
488 		return -ENOMEM;
489 	}
490 	return 0;
491 }
492 #endif
493 
494 static int initr_jumptable(void)
495 {
496 	jumptable_init();
497 	return 0;
498 }
499 
500 #if defined(CONFIG_API)
501 static int initr_api(void)
502 {
503 	/* Initialize API */
504 	api_init();
505 	return 0;
506 }
507 #endif
508 
509 /* enable exceptions */
510 #if defined(CONFIG_ARM) || defined(CONFIG_AVR32)
511 static int initr_enable_interrupts(void)
512 {
513 	enable_interrupts();
514 	return 0;
515 }
516 #endif
517 
518 #ifdef CONFIG_CMD_NET
519 static int initr_ethaddr(void)
520 {
521 	bd_t *bd = gd->bd;
522 
523 	/* kept around for legacy kernels only ... ignore the next section */
524 	eth_getenv_enetaddr("ethaddr", bd->bi_enetaddr);
525 #ifdef CONFIG_HAS_ETH1
526 	eth_getenv_enetaddr("eth1addr", bd->bi_enet1addr);
527 #endif
528 #ifdef CONFIG_HAS_ETH2
529 	eth_getenv_enetaddr("eth2addr", bd->bi_enet2addr);
530 #endif
531 #ifdef CONFIG_HAS_ETH3
532 	eth_getenv_enetaddr("eth3addr", bd->bi_enet3addr);
533 #endif
534 #ifdef CONFIG_HAS_ETH4
535 	eth_getenv_enetaddr("eth4addr", bd->bi_enet4addr);
536 #endif
537 #ifdef CONFIG_HAS_ETH5
538 	eth_getenv_enetaddr("eth5addr", bd->bi_enet5addr);
539 #endif
540 	return 0;
541 }
542 #endif /* CONFIG_CMD_NET */
543 
544 #ifdef CONFIG_CMD_KGDB
545 static int initr_kgdb(void)
546 {
547 	puts("KGDB:  ");
548 	kgdb_init();
549 	return 0;
550 }
551 #endif
552 
553 #if defined(CONFIG_STATUS_LED)
554 static int initr_status_led(void)
555 {
556 #if defined(STATUS_LED_BOOT)
557 	status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING);
558 #else
559 	status_led_init();
560 #endif
561 	return 0;
562 }
563 #endif
564 
565 #if defined(CONFIG_CMD_AMBAPP) && defined(CONFIG_SYS_AMBAPP_PRINT_ON_STARTUP)
566 extern int do_ambapp_print(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
567 
568 static int initr_ambapp_print(void)
569 {
570 	puts("AMBA:\n");
571 	do_ambapp_print(NULL, 0, 0, NULL);
572 
573 	return 0;
574 }
575 #endif
576 
577 #if defined(CONFIG_CMD_SCSI)
578 static int initr_scsi(void)
579 {
580 	puts("SCSI:  ");
581 	scsi_init();
582 
583 	return 0;
584 }
585 #endif
586 
587 #if defined(CONFIG_CMD_DOC)
588 static int initr_doc(void)
589 {
590 	puts("DOC:   ");
591 	doc_init();
592 	return 0;
593 }
594 #endif
595 
596 #ifdef CONFIG_BITBANGMII
597 static int initr_bbmii(void)
598 {
599 	bb_miiphy_init();
600 	return 0;
601 }
602 #endif
603 
604 #ifdef CONFIG_CMD_NET
605 static int initr_net(void)
606 {
607 	puts("Net:   ");
608 	eth_initialize();
609 #if defined(CONFIG_RESET_PHY_R)
610 	debug("Reset Ethernet PHY\n");
611 	reset_phy();
612 #endif
613 	return 0;
614 }
615 #endif
616 
617 #ifdef CONFIG_POST
618 static int initr_post(void)
619 {
620 	post_run(NULL, POST_RAM | post_bootmode_get(0));
621 	return 0;
622 }
623 #endif
624 
625 #if defined(CONFIG_CMD_PCMCIA) && !defined(CONFIG_CMD_IDE)
626 static int initr_pcmcia(void)
627 {
628 	puts("PCMCIA:");
629 	pcmcia_init();
630 	return 0;
631 }
632 #endif
633 
634 #if defined(CONFIG_CMD_IDE)
635 static int initr_ide(void)
636 {
637 #ifdef	CONFIG_IDE_8xx_PCCARD
638 	puts("PCMCIA:");
639 #else
640 	puts("IDE:   ");
641 #endif
642 #if defined(CONFIG_START_IDE)
643 	if (board_start_ide())
644 		ide_init();
645 #else
646 	ide_init();
647 #endif
648 	return 0;
649 }
650 #endif
651 
652 #if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
653 /*
654  * Export available size of memory for Linux, taking into account the
655  * protected RAM at top of memory
656  */
657 int initr_mem(void)
658 {
659 	ulong pram = 0;
660 	char memsz[32];
661 
662 # ifdef CONFIG_PRAM
663 	pram = getenv_ulong("pram", 10, CONFIG_PRAM);
664 # endif
665 # if defined(CONFIG_LOGBUFFER) && !defined(CONFIG_ALT_LB_ADDR)
666 	/* Also take the logbuffer into account (pram is in kB) */
667 	pram += (LOGBUFF_LEN + LOGBUFF_OVERHEAD) / 1024;
668 # endif
669 	sprintf(memsz, "%ldk", (long int) ((gd->ram_size / 1024) - pram));
670 	setenv("mem", memsz);
671 
672 	return 0;
673 }
674 #endif
675 
676 #ifdef CONFIG_CMD_BEDBUG
677 static int initr_bedbug(void)
678 {
679 	bedbug_init();
680 
681 	return 0;
682 }
683 #endif
684 
685 #ifdef CONFIG_PS2KBD
686 static int initr_kbd(void)
687 {
688 	puts("PS/2:  ");
689 	kbd_init();
690 	return 0;
691 }
692 #endif
693 
694 static int run_main_loop(void)
695 {
696 #ifdef CONFIG_SANDBOX
697 	sandbox_main_loop_init();
698 #endif
699 	/* main_loop() can return to retry autoboot, if so just run it again */
700 	for (;;)
701 		main_loop();
702 	return 0;
703 }
704 
705 /*
706  * Over time we hope to remove these functions with code fragments and
707  * stub funtcions, and instead call the relevant function directly.
708  *
709  * We also hope to remove most of the driver-related init and do it if/when
710  * the driver is later used.
711  *
712  * TODO: perhaps reset the watchdog in the initcall function after each call?
713  */
714 init_fnc_t init_sequence_r[] = {
715 	initr_trace,
716 	initr_reloc,
717 	/* TODO: could x86/PPC have this also perhaps? */
718 #ifdef CONFIG_ARM
719 	initr_caches,
720 	/* Note: For Freescale LS2 SoCs, new MMU table is created in DDR.
721 	 *	 A temporary mapping of IFC high region is since removed,
722 	 *	 so environmental variables in NOR flash is not availble
723 	 *	 until board_init() is called below to remap IFC to high
724 	 *	 region.
725 	 */
726 #endif
727 	initr_reloc_global_data,
728 #if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500)
729 	initr_unlock_ram_in_cache,
730 #endif
731 	initr_barrier,
732 	initr_malloc,
733 #ifdef CONFIG_SYS_NONCACHED_MEMORY
734 	initr_noncached,
735 #endif
736 	bootstage_relocate,
737 #ifdef CONFIG_DM
738 	initr_dm,
739 #endif
740 #if defined(CONFIG_ARM) || defined(CONFIG_NDS32)
741 	board_init,	/* Setup chipselects */
742 #endif
743 	/*
744 	 * TODO: printing of the clock inforamtion of the board is now
745 	 * implemented as part of bdinfo command. Currently only support for
746 	 * davinci SOC's is added. Remove this check once all the board
747 	 * implement this.
748 	 */
749 #ifdef CONFIG_CLOCKS
750 	set_cpu_clk_info, /* Setup clock information */
751 #endif
752 	stdio_init_tables,
753 	initr_serial,
754 	initr_announce,
755 	INIT_FUNC_WATCHDOG_RESET
756 #ifdef CONFIG_NEEDS_MANUAL_RELOC
757 	initr_manual_reloc_cmdtable,
758 #endif
759 #if defined(CONFIG_PPC) || defined(CONFIG_M68K)
760 	initr_trap,
761 #endif
762 #ifdef CONFIG_ADDR_MAP
763 	initr_addr_map,
764 #endif
765 #if defined(CONFIG_BOARD_EARLY_INIT_R)
766 	board_early_init_r,
767 #endif
768 	INIT_FUNC_WATCHDOG_RESET
769 #ifdef CONFIG_LOGBUFFER
770 	initr_logbuffer,
771 #endif
772 #ifdef CONFIG_POST
773 	initr_post_backlog,
774 #endif
775 	INIT_FUNC_WATCHDOG_RESET
776 #ifdef CONFIG_SYS_DELAYED_ICACHE
777 	initr_icache_enable,
778 #endif
779 #if defined(CONFIG_PCI) && defined(CONFIG_SYS_EARLY_PCI_INIT)
780 	/*
781 	 * Do early PCI configuration _before_ the flash gets initialised,
782 	 * because PCU ressources are crucial for flash access on some boards.
783 	 */
784 	initr_pci,
785 #endif
786 #ifdef CONFIG_WINBOND_83C553
787 	initr_w83c553f,
788 #endif
789 #ifdef CONFIG_ARCH_EARLY_INIT_R
790 	arch_early_init_r,
791 #endif
792 	power_init_board,
793 #ifndef CONFIG_SYS_NO_FLASH
794 	initr_flash,
795 #endif
796 	INIT_FUNC_WATCHDOG_RESET
797 #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_X86)
798 	/* initialize higher level parts of CPU like time base and timers */
799 	cpu_init_r,
800 #endif
801 #ifdef CONFIG_PPC
802 	initr_spi,
803 #endif
804 #ifdef CONFIG_CMD_NAND
805 	initr_nand,
806 #endif
807 #ifdef CONFIG_CMD_ONENAND
808 	initr_onenand,
809 #endif
810 #ifdef CONFIG_GENERIC_MMC
811 	initr_mmc,
812 #endif
813 #ifdef CONFIG_HAS_DATAFLASH
814 	initr_dataflash,
815 #endif
816 	initr_env,
817 #ifdef CONFIG_SYS_BOOTPARAMS_LEN
818 	initr_malloc_bootparams,
819 #endif
820 	INIT_FUNC_WATCHDOG_RESET
821 	initr_secondary_cpu,
822 #if defined(CONFIG_ID_EEPROM) || defined(CONFIG_SYS_I2C_MAC_OFFSET)
823 	mac_read_from_eeprom,
824 #endif
825 	INIT_FUNC_WATCHDOG_RESET
826 #if defined(CONFIG_PCI) && !defined(CONFIG_SYS_EARLY_PCI_INIT)
827 	/*
828 	 * Do pci configuration
829 	 */
830 	initr_pci,
831 #endif
832 	stdio_add_devices,
833 	initr_jumptable,
834 #ifdef CONFIG_API
835 	initr_api,
836 #endif
837 	console_init_r,		/* fully init console as a device */
838 #ifdef CONFIG_DISPLAY_BOARDINFO_LATE
839 	show_board_info,
840 #endif
841 #ifdef CONFIG_ARCH_MISC_INIT
842 	arch_misc_init,		/* miscellaneous arch-dependent init */
843 #endif
844 #ifdef CONFIG_MISC_INIT_R
845 	misc_init_r,		/* miscellaneous platform-dependent init */
846 #endif
847 	INIT_FUNC_WATCHDOG_RESET
848 #ifdef CONFIG_CMD_KGDB
849 	initr_kgdb,
850 #endif
851 	interrupt_init,
852 #if defined(CONFIG_ARM) || defined(CONFIG_AVR32)
853 	initr_enable_interrupts,
854 #endif
855 #if defined(CONFIG_MICROBLAZE) || defined(CONFIG_AVR32) || defined(CONFIG_M68K)
856 	timer_init,		/* initialize timer */
857 #endif
858 #if defined(CONFIG_STATUS_LED)
859 	initr_status_led,
860 #endif
861 	/* PPC has a udelay(20) here dating from 2002. Why? */
862 #ifdef CONFIG_CMD_NET
863 	initr_ethaddr,
864 #endif
865 #ifdef CONFIG_BOARD_LATE_INIT
866 	board_late_init,
867 #endif
868 #if defined(CONFIG_CMD_AMBAPP)
869 	ambapp_init_reloc,
870 #if defined(CONFIG_SYS_AMBAPP_PRINT_ON_STARTUP)
871 	initr_ambapp_print,
872 #endif
873 #endif
874 #ifdef CONFIG_CMD_SCSI
875 	INIT_FUNC_WATCHDOG_RESET
876 	initr_scsi,
877 #endif
878 #ifdef CONFIG_CMD_DOC
879 	INIT_FUNC_WATCHDOG_RESET
880 	initr_doc,
881 #endif
882 #ifdef CONFIG_BITBANGMII
883 	initr_bbmii,
884 #endif
885 #ifdef CONFIG_CMD_NET
886 	INIT_FUNC_WATCHDOG_RESET
887 	initr_net,
888 #endif
889 #ifdef CONFIG_POST
890 	initr_post,
891 #endif
892 #if defined(CONFIG_CMD_PCMCIA) && !defined(CONFIG_CMD_IDE)
893 	initr_pcmcia,
894 #endif
895 #if defined(CONFIG_CMD_IDE)
896 	initr_ide,
897 #endif
898 #ifdef CONFIG_LAST_STAGE_INIT
899 	INIT_FUNC_WATCHDOG_RESET
900 	/*
901 	 * Some parts can be only initialized if all others (like
902 	 * Interrupts) are up and running (i.e. the PC-style ISA
903 	 * keyboard).
904 	 */
905 	last_stage_init,
906 #endif
907 #ifdef CONFIG_CMD_BEDBUG
908 	INIT_FUNC_WATCHDOG_RESET
909 	initr_bedbug,
910 #endif
911 #if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
912 	initr_mem,
913 #endif
914 #ifdef CONFIG_PS2KBD
915 	initr_kbd,
916 #endif
917 	run_main_loop,
918 };
919 
920 void board_init_r(gd_t *new_gd, ulong dest_addr)
921 {
922 #ifdef CONFIG_NEEDS_MANUAL_RELOC
923 	int i;
924 #endif
925 
926 #ifdef CONFIG_AVR32
927 	mmu_init_r(dest_addr);
928 #endif
929 
930 #if !defined(CONFIG_X86) && !defined(CONFIG_ARM) && !defined(CONFIG_ARM64)
931 	gd = new_gd;
932 #endif
933 
934 #ifdef CONFIG_NEEDS_MANUAL_RELOC
935 	for (i = 0; i < ARRAY_SIZE(init_sequence_r); i++)
936 		init_sequence_r[i] += gd->reloc_off;
937 #endif
938 
939 	if (initcall_run_list(init_sequence_r))
940 		hang();
941 
942 	/* NOTREACHED - run_main_loop() does not return */
943 	hang();
944 }
945