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