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