board_r.c 18 KB

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