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