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