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