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