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