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