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