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