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