board_r.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823
  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. #include <common.h>
  12. #include <api.h>
  13. #include <bootstage.h>
  14. #include <cpu_func.h>
  15. #include <cyclic.h>
  16. #include <display_options.h>
  17. #include <exports.h>
  18. #ifdef CONFIG_MTD_NOR_FLASH
  19. #include <flash.h>
  20. #endif
  21. #include <hang.h>
  22. #include <image.h>
  23. #include <irq_func.h>
  24. #include <log.h>
  25. #include <net.h>
  26. #include <asm/cache.h>
  27. #include <asm/global_data.h>
  28. #include <u-boot/crc.h>
  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. #include <kgdb.h>
  40. #include <irq_func.h>
  41. #include <malloc.h>
  42. #include <mapmem.h>
  43. #include <miiphy.h>
  44. #include <mmc.h>
  45. #include <mux.h>
  46. #include <nand.h>
  47. #include <of_live.h>
  48. #include <onenand_uboot.h>
  49. #include <pvblock.h>
  50. #include <scsi.h>
  51. #include <serial.h>
  52. #include <status_led.h>
  53. #include <stdio_dev.h>
  54. #include <timer.h>
  55. #include <trace.h>
  56. #include <watchdog.h>
  57. #include <xen.h>
  58. #include <asm/sections.h>
  59. #include <dm/root.h>
  60. #include <dm/ofnode.h>
  61. #include <linux/compiler.h>
  62. #include <linux/err.h>
  63. #include <efi_loader.h>
  64. #include <wdt.h>
  65. #include <asm-generic/gpio.h>
  66. #include <efi_loader.h>
  67. #include <relocate.h>
  68. DECLARE_GLOBAL_DATA_PTR;
  69. ulong monitor_flash_len;
  70. __weak int board_flash_wp_on(void)
  71. {
  72. /*
  73. * Most flashes can't be detected when write protection is enabled,
  74. * so provide a way to let U-Boot gracefully ignore write protected
  75. * devices.
  76. */
  77. return 0;
  78. }
  79. __weak int cpu_secondary_init_r(void)
  80. {
  81. return 0;
  82. }
  83. static int initr_trace(void)
  84. {
  85. #ifdef CONFIG_TRACE
  86. trace_init(gd->trace_buff, CONFIG_TRACE_BUFFER_SIZE);
  87. #endif
  88. return 0;
  89. }
  90. static int initr_reloc(void)
  91. {
  92. /* tell others: relocation done */
  93. gd->flags |= GD_FLG_RELOC | GD_FLG_FULL_MALLOC_INIT;
  94. return 0;
  95. }
  96. #if defined(CONFIG_ARM) || defined(CONFIG_RISCV)
  97. /*
  98. * Some of these functions are needed purely because the functions they
  99. * call return void. If we change them to return 0, these stubs can go away.
  100. */
  101. static int initr_caches(void)
  102. {
  103. /* Enable caches */
  104. enable_caches();
  105. return 0;
  106. }
  107. #endif
  108. __weak int fixup_cpu(void)
  109. {
  110. return 0;
  111. }
  112. static int initr_reloc_global_data(void)
  113. {
  114. #ifdef __ARM__
  115. monitor_flash_len = _end - __image_copy_start;
  116. #elif defined(CONFIG_RISCV)
  117. monitor_flash_len = (ulong)&_end - (ulong)&_start;
  118. #elif !defined(CONFIG_SANDBOX) && !defined(CONFIG_NIOS2)
  119. monitor_flash_len = (ulong)&__init_end - gd->relocaddr;
  120. #endif
  121. #if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx)
  122. /*
  123. * The gd->cpu pointer is set to an address in flash before relocation.
  124. * We need to update it to point to the same CPU entry in RAM.
  125. * TODO: why not just add gd->reloc_ofs?
  126. */
  127. gd->arch.cpu += gd->relocaddr - CONFIG_SYS_MONITOR_BASE;
  128. /*
  129. * If we didn't know the cpu mask & # cores, we can save them of
  130. * now rather than 'computing' them constantly
  131. */
  132. fixup_cpu();
  133. #endif
  134. #ifdef CONFIG_SYS_RELOC_GD_ENV_ADDR
  135. /*
  136. * Relocate the early env_addr pointer unless we know it is not inside
  137. * the binary. Some systems need this and for the rest, it doesn't hurt.
  138. */
  139. gd->env_addr += gd->reloc_off;
  140. #endif
  141. /*
  142. * The fdt_blob needs to be moved to new relocation address
  143. * incase of FDT blob is embedded with in image
  144. */
  145. if (IS_ENABLED(CONFIG_OF_EMBED) && IS_ENABLED(CONFIG_NEEDS_MANUAL_RELOC))
  146. gd->fdt_blob += gd->reloc_off;
  147. #ifdef CONFIG_EFI_LOADER
  148. /*
  149. * On the ARM architecture gd is mapped to a fixed register (r9 or x18).
  150. * As this register may be overwritten by an EFI payload we save it here
  151. * and restore it on every callback entered.
  152. */
  153. efi_save_gd();
  154. efi_runtime_relocate(gd->relocaddr, NULL);
  155. #endif
  156. return 0;
  157. }
  158. __weak int arch_initr_trap(void)
  159. {
  160. return 0;
  161. }
  162. #if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500)
  163. static int initr_unlock_ram_in_cache(void)
  164. {
  165. unlock_ram_in_cache(); /* it's time to unlock D-cache in e500 */
  166. return 0;
  167. }
  168. #endif
  169. static int initr_barrier(void)
  170. {
  171. #ifdef CONFIG_PPC
  172. /* TODO: Can we not use dmb() macros for this? */
  173. asm("sync ; isync");
  174. #endif
  175. return 0;
  176. }
  177. static int initr_malloc(void)
  178. {
  179. ulong start;
  180. #if CONFIG_VAL(SYS_MALLOC_F_LEN)
  181. debug("Pre-reloc malloc() used %#lx bytes (%ld KB)\n", gd->malloc_ptr,
  182. gd->malloc_ptr / 1024);
  183. #endif
  184. /* The malloc area is immediately below the monitor copy in DRAM */
  185. /*
  186. * This value MUST match the value of gd->start_addr_sp in board_f.c:
  187. * reserve_noncached().
  188. */
  189. start = gd->relocaddr - TOTAL_MALLOC_LEN;
  190. gd_set_malloc_start(start);
  191. mem_malloc_init((ulong)map_sysmem(start, TOTAL_MALLOC_LEN),
  192. TOTAL_MALLOC_LEN);
  193. return 0;
  194. }
  195. static int initr_of_live(void)
  196. {
  197. if (CONFIG_IS_ENABLED(OF_LIVE)) {
  198. int ret;
  199. bootstage_start(BOOTSTAGE_ID_ACCUM_OF_LIVE, "of_live");
  200. ret = of_live_build(gd->fdt_blob,
  201. (struct device_node **)gd_of_root_ptr());
  202. bootstage_accum(BOOTSTAGE_ID_ACCUM_OF_LIVE);
  203. if (ret)
  204. return ret;
  205. }
  206. return 0;
  207. }
  208. #ifdef CONFIG_DM
  209. static int initr_dm(void)
  210. {
  211. int ret;
  212. oftree_reset();
  213. /* Save the pre-reloc driver model and start a new one */
  214. gd->dm_root_f = gd->dm_root;
  215. gd->dm_root = NULL;
  216. #ifdef CONFIG_TIMER
  217. gd->timer = NULL;
  218. #endif
  219. bootstage_start(BOOTSTAGE_ID_ACCUM_DM_R, "dm_r");
  220. ret = dm_init_and_scan(false);
  221. bootstage_accum(BOOTSTAGE_ID_ACCUM_DM_R);
  222. if (ret)
  223. return ret;
  224. return 0;
  225. }
  226. #endif
  227. static int initr_dm_devices(void)
  228. {
  229. int ret;
  230. if (IS_ENABLED(CONFIG_TIMER_EARLY)) {
  231. ret = dm_timer_init();
  232. if (ret)
  233. return ret;
  234. }
  235. if (IS_ENABLED(CONFIG_MULTIPLEXER)) {
  236. /*
  237. * Initialize the multiplexer controls to their default state.
  238. * This must be done early as other drivers may unknowingly
  239. * rely on it.
  240. */
  241. ret = dm_mux_init();
  242. if (ret)
  243. return ret;
  244. }
  245. return 0;
  246. }
  247. static int initr_bootstage(void)
  248. {
  249. bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_R, "board_init_r");
  250. return 0;
  251. }
  252. __weak int power_init_board(void)
  253. {
  254. return 0;
  255. }
  256. static int initr_announce(void)
  257. {
  258. debug("Now running in RAM - U-Boot at: %08lx\n", gd->relocaddr);
  259. return 0;
  260. }
  261. #ifdef CONFIG_NEEDS_MANUAL_RELOC
  262. static int initr_manual_reloc_cmdtable(void)
  263. {
  264. fixup_cmdtable(ll_entry_start(struct cmd_tbl, cmd),
  265. ll_entry_count(struct cmd_tbl, cmd));
  266. return 0;
  267. }
  268. #endif
  269. static int initr_binman(void)
  270. {
  271. int ret;
  272. if (!CONFIG_IS_ENABLED(BINMAN_FDT))
  273. return 0;
  274. ret = binman_init();
  275. if (ret)
  276. printf("binman_init failed:%d\n", ret);
  277. return ret;
  278. }
  279. #if defined(CONFIG_MTD_NOR_FLASH)
  280. __weak int is_flash_available(void)
  281. {
  282. return 1;
  283. }
  284. static int initr_flash(void)
  285. {
  286. ulong flash_size = 0;
  287. struct bd_info *bd = gd->bd;
  288. if (!is_flash_available())
  289. return 0;
  290. puts("Flash: ");
  291. if (board_flash_wp_on())
  292. printf("Uninitialized - Write Protect On\n");
  293. else
  294. flash_size = flash_init();
  295. print_size(flash_size, "");
  296. #ifdef CONFIG_SYS_FLASH_CHECKSUM
  297. /*
  298. * Compute and print flash CRC if flashchecksum is set to 'y'
  299. *
  300. * NOTE: Maybe we should add some schedule()? XXX
  301. */
  302. if (env_get_yesno("flashchecksum") == 1) {
  303. const uchar *flash_base = (const uchar *)CFG_SYS_FLASH_BASE;
  304. printf(" CRC: %08X", crc32(0,
  305. flash_base,
  306. flash_size));
  307. }
  308. #endif /* CONFIG_SYS_FLASH_CHECKSUM */
  309. putc('\n');
  310. /* update start of FLASH memory */
  311. #ifdef CFG_SYS_FLASH_BASE
  312. bd->bi_flashstart = CFG_SYS_FLASH_BASE;
  313. #endif
  314. /* size of FLASH memory (final value) */
  315. bd->bi_flashsize = flash_size;
  316. #if defined(CONFIG_SYS_UPDATE_FLASH_SIZE)
  317. /* Make a update of the Memctrl. */
  318. update_flash_size(flash_size);
  319. #endif
  320. #if defined(CONFIG_OXC) || defined(CONFIG_RMU)
  321. /* flash mapped at end of memory map */
  322. bd->bi_flashoffset = CONFIG_TEXT_BASE + flash_size;
  323. #elif CONFIG_SYS_MONITOR_BASE == CFG_SYS_FLASH_BASE
  324. bd->bi_flashoffset = monitor_flash_len; /* reserved area for monitor */
  325. #endif
  326. return 0;
  327. }
  328. #endif
  329. #ifdef CONFIG_CMD_NAND
  330. /* go init the NAND */
  331. static int initr_nand(void)
  332. {
  333. puts("NAND: ");
  334. nand_init();
  335. printf("%lu MiB\n", nand_size() / 1024);
  336. return 0;
  337. }
  338. #endif
  339. #if defined(CONFIG_CMD_ONENAND)
  340. /* go init the NAND */
  341. static int initr_onenand(void)
  342. {
  343. puts("NAND: ");
  344. onenand_init();
  345. return 0;
  346. }
  347. #endif
  348. #ifdef CONFIG_MMC
  349. static int initr_mmc(void)
  350. {
  351. puts("MMC: ");
  352. mmc_initialize(gd->bd);
  353. return 0;
  354. }
  355. #endif
  356. #ifdef CONFIG_PVBLOCK
  357. static int initr_pvblock(void)
  358. {
  359. puts("PVBLOCK: ");
  360. pvblock_init();
  361. return 0;
  362. }
  363. #endif
  364. /*
  365. * Tell if it's OK to load the environment early in boot.
  366. *
  367. * If CONFIG_OF_CONTROL is defined, we'll check with the FDT to see
  368. * if this is OK (defaulting to saying it's OK).
  369. *
  370. * NOTE: Loading the environment early can be a bad idea if security is
  371. * important, since no verification is done on the environment.
  372. *
  373. * Return: 0 if environment should not be loaded, !=0 if it is ok to load
  374. */
  375. static int should_load_env(void)
  376. {
  377. if (IS_ENABLED(CONFIG_OF_CONTROL))
  378. return ofnode_conf_read_int("load-environment", 1);
  379. if (IS_ENABLED(CONFIG_DELAY_ENVIRONMENT))
  380. return 0;
  381. return 1;
  382. }
  383. static int initr_env(void)
  384. {
  385. /* initialize environment */
  386. if (should_load_env())
  387. env_relocate();
  388. else
  389. env_set_default(NULL, 0);
  390. env_import_fdt();
  391. if (IS_ENABLED(CONFIG_OF_CONTROL))
  392. env_set_hex("fdtcontroladdr",
  393. (unsigned long)map_to_sysmem(gd->fdt_blob));
  394. #if (IS_ENABLED(CONFIG_SAVE_PREV_BL_INITRAMFS_START_ADDR) || \
  395. IS_ENABLED(CONFIG_SAVE_PREV_BL_FDT_ADDR))
  396. save_prev_bl_data();
  397. #endif
  398. /* Initialize from environment */
  399. image_load_addr = env_get_ulong("loadaddr", 16, image_load_addr);
  400. return 0;
  401. }
  402. #ifdef CONFIG_SYS_MALLOC_BOOTPARAMS
  403. static int initr_malloc_bootparams(void)
  404. {
  405. gd->bd->bi_boot_params = (ulong)malloc(CONFIG_SYS_BOOTPARAMS_LEN);
  406. if (!gd->bd->bi_boot_params) {
  407. puts("WARNING: Cannot allocate space for boot parameters\n");
  408. return -ENOMEM;
  409. }
  410. return 0;
  411. }
  412. #endif
  413. #if defined(CONFIG_LED_STATUS)
  414. static int initr_status_led(void)
  415. {
  416. #if defined(CONFIG_LED_STATUS_BOOT)
  417. status_led_set(CONFIG_LED_STATUS_BOOT, CONFIG_LED_STATUS_BLINKING);
  418. #else
  419. status_led_init();
  420. #endif
  421. return 0;
  422. }
  423. #endif
  424. #if defined(CONFIG_SCSI) && !defined(CONFIG_DM_SCSI)
  425. static int initr_scsi(void)
  426. {
  427. puts("SCSI: ");
  428. scsi_init();
  429. puts("\n");
  430. return 0;
  431. }
  432. #endif
  433. #ifdef CONFIG_CMD_NET
  434. static int initr_net(void)
  435. {
  436. puts("Net: ");
  437. eth_initialize();
  438. #if defined(CONFIG_RESET_PHY_R)
  439. debug("Reset Ethernet PHY\n");
  440. reset_phy();
  441. #endif
  442. return 0;
  443. }
  444. #endif
  445. #ifdef CONFIG_POST
  446. static int initr_post(void)
  447. {
  448. post_run(NULL, POST_RAM | post_bootmode_get(0));
  449. return 0;
  450. }
  451. #endif
  452. #if defined(CFG_PRAM)
  453. /*
  454. * Export available size of memory for Linux, taking into account the
  455. * protected RAM at top of memory
  456. */
  457. int initr_mem(void)
  458. {
  459. ulong pram = 0;
  460. char memsz[32];
  461. pram = env_get_ulong("pram", 10, CFG_PRAM);
  462. sprintf(memsz, "%ldk", (long int)((gd->ram_size / 1024) - pram));
  463. env_set("mem", memsz);
  464. return 0;
  465. }
  466. #endif
  467. static int dm_announce(void)
  468. {
  469. int device_count;
  470. int uclass_count;
  471. if (IS_ENABLED(CONFIG_DM)) {
  472. dm_get_stats(&device_count, &uclass_count);
  473. printf("Core: %d devices, %d uclasses", device_count,
  474. uclass_count);
  475. if (CONFIG_IS_ENABLED(OF_REAL))
  476. printf(", devicetree: %s", fdtdec_get_srcname());
  477. printf("\n");
  478. if (IS_ENABLED(CONFIG_OF_HAS_PRIOR_STAGE) &&
  479. (gd->fdt_src == FDTSRC_SEPARATE ||
  480. gd->fdt_src == FDTSRC_EMBED)) {
  481. printf("Warning: Unexpected devicetree source (not from a prior stage)");
  482. printf("Warning: U-Boot may not function properly\n");
  483. }
  484. if (IS_ENABLED(CONFIG_OF_TAG_MIGRATE) &&
  485. (gd->flags & GD_FLG_OF_TAG_MIGRATE))
  486. /*
  487. * U-Boot will silently fail to work after 2023.07 if
  488. * there are old tags present
  489. */
  490. printf("Warning: Device tree includes old 'u-boot,dm-' tags: please fix by 2023.07!\n");
  491. }
  492. return 0;
  493. }
  494. static int run_main_loop(void)
  495. {
  496. #ifdef CONFIG_SANDBOX
  497. sandbox_main_loop_init();
  498. #endif
  499. event_notify_null(EVT_MAIN_LOOP);
  500. /* main_loop() can return to retry autoboot, if so just run it again */
  501. for (;;)
  502. main_loop();
  503. return 0;
  504. }
  505. /*
  506. * We hope to remove most of the driver-related init and do it if/when
  507. * the driver is later used.
  508. *
  509. * TODO: perhaps reset the watchdog in the initcall function after each call?
  510. */
  511. static init_fnc_t init_sequence_r[] = {
  512. initr_trace,
  513. initr_reloc,
  514. event_init,
  515. /* TODO: could x86/PPC have this also perhaps? */
  516. #if defined(CONFIG_ARM) || defined(CONFIG_RISCV)
  517. initr_caches,
  518. /* Note: For Freescale LS2 SoCs, new MMU table is created in DDR.
  519. * A temporary mapping of IFC high region is since removed,
  520. * so environmental variables in NOR flash is not available
  521. * until board_init() is called below to remap IFC to high
  522. * region.
  523. */
  524. #endif
  525. initr_reloc_global_data,
  526. #if IS_ENABLED(CONFIG_NEEDS_MANUAL_RELOC) && CONFIG_IS_ENABLED(EVENT)
  527. event_manual_reloc,
  528. #endif
  529. #if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500)
  530. initr_unlock_ram_in_cache,
  531. #endif
  532. initr_barrier,
  533. initr_malloc,
  534. log_init,
  535. initr_bootstage, /* Needs malloc() but has its own timer */
  536. #if defined(CONFIG_CONSOLE_RECORD)
  537. console_record_init,
  538. #endif
  539. #ifdef CONFIG_SYS_NONCACHED_MEMORY
  540. noncached_init,
  541. #endif
  542. initr_of_live,
  543. #ifdef CONFIG_DM
  544. initr_dm,
  545. #endif
  546. #ifdef CONFIG_ADDR_MAP
  547. init_addr_map,
  548. #endif
  549. #if defined(CONFIG_ARM) || defined(CONFIG_RISCV) || defined(CONFIG_SANDBOX)
  550. board_init, /* Setup chipselects */
  551. #endif
  552. /*
  553. * TODO: printing of the clock inforamtion of the board is now
  554. * implemented as part of bdinfo command. Currently only support for
  555. * davinci SOC's is added. Remove this check once all the board
  556. * implement this.
  557. */
  558. #ifdef CONFIG_CLOCKS
  559. set_cpu_clk_info, /* Setup clock information */
  560. #endif
  561. #ifdef CONFIG_EFI_LOADER
  562. efi_memory_init,
  563. #endif
  564. initr_binman,
  565. #ifdef CONFIG_FSP_VERSION2
  566. arch_fsp_init_r,
  567. #endif
  568. initr_dm_devices,
  569. stdio_init_tables,
  570. serial_initialize,
  571. initr_announce,
  572. dm_announce,
  573. #if CONFIG_IS_ENABLED(WDT)
  574. initr_watchdog,
  575. #endif
  576. INIT_FUNC_WATCHDOG_RESET
  577. #if defined(CONFIG_NEEDS_MANUAL_RELOC) && defined(CONFIG_BLOCK_CACHE)
  578. blkcache_init,
  579. #endif
  580. #ifdef CONFIG_NEEDS_MANUAL_RELOC
  581. initr_manual_reloc_cmdtable,
  582. #endif
  583. arch_initr_trap,
  584. #if defined(CONFIG_BOARD_EARLY_INIT_R)
  585. board_early_init_r,
  586. #endif
  587. INIT_FUNC_WATCHDOG_RESET
  588. #ifdef CONFIG_POST
  589. post_output_backlog,
  590. #endif
  591. INIT_FUNC_WATCHDOG_RESET
  592. #if defined(CONFIG_PCI_INIT_R) && defined(CONFIG_SYS_EARLY_PCI_INIT)
  593. /*
  594. * Do early PCI configuration _before_ the flash gets initialised,
  595. * because PCU resources are crucial for flash access on some boards.
  596. */
  597. pci_init,
  598. #endif
  599. #ifdef CONFIG_ARCH_EARLY_INIT_R
  600. arch_early_init_r,
  601. #endif
  602. power_init_board,
  603. #ifdef CONFIG_MTD_NOR_FLASH
  604. initr_flash,
  605. #endif
  606. INIT_FUNC_WATCHDOG_RESET
  607. #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_X86)
  608. /* initialize higher level parts of CPU like time base and timers */
  609. cpu_init_r,
  610. #endif
  611. #ifdef CONFIG_EFI_LOADER
  612. efi_init_early,
  613. #endif
  614. #ifdef CONFIG_CMD_NAND
  615. initr_nand,
  616. #endif
  617. #ifdef CONFIG_CMD_ONENAND
  618. initr_onenand,
  619. #endif
  620. #ifdef CONFIG_MMC
  621. initr_mmc,
  622. #endif
  623. #ifdef CONFIG_XEN
  624. xen_init,
  625. #endif
  626. #ifdef CONFIG_PVBLOCK
  627. initr_pvblock,
  628. #endif
  629. initr_env,
  630. #ifdef CONFIG_SYS_MALLOC_BOOTPARAMS
  631. initr_malloc_bootparams,
  632. #endif
  633. INIT_FUNC_WATCHDOG_RESET
  634. cpu_secondary_init_r,
  635. #if defined(CONFIG_ID_EEPROM)
  636. mac_read_from_eeprom,
  637. #endif
  638. INIT_FUNC_WATCHDOG_RESET
  639. #if defined(CONFIG_PCI_INIT_R) && !defined(CONFIG_SYS_EARLY_PCI_INIT)
  640. /*
  641. * Do pci configuration
  642. */
  643. pci_init,
  644. #endif
  645. stdio_add_devices,
  646. jumptable_init,
  647. #ifdef CONFIG_API
  648. api_init,
  649. #endif
  650. console_init_r, /* fully init console as a device */
  651. #ifdef CONFIG_DISPLAY_BOARDINFO_LATE
  652. console_announce_r,
  653. show_board_info,
  654. #endif
  655. #ifdef CONFIG_ARCH_MISC_INIT
  656. arch_misc_init, /* miscellaneous arch-dependent init */
  657. #endif
  658. #ifdef CONFIG_MISC_INIT_R
  659. misc_init_r, /* miscellaneous platform-dependent init */
  660. #endif
  661. INIT_FUNC_WATCHDOG_RESET
  662. #ifdef CONFIG_CMD_KGDB
  663. kgdb_init,
  664. #endif
  665. interrupt_init,
  666. #if defined(CONFIG_MICROBLAZE) || defined(CONFIG_M68K)
  667. timer_init, /* initialize timer */
  668. #endif
  669. #if defined(CONFIG_LED_STATUS)
  670. initr_status_led,
  671. #endif
  672. /* PPC has a udelay(20) here dating from 2002. Why? */
  673. #ifdef CONFIG_BOARD_LATE_INIT
  674. board_late_init,
  675. #endif
  676. #if defined(CONFIG_SCSI) && !defined(CONFIG_DM_SCSI)
  677. INIT_FUNC_WATCHDOG_RESET
  678. initr_scsi,
  679. #endif
  680. #ifdef CONFIG_BITBANGMII
  681. bb_miiphy_init,
  682. #endif
  683. #ifdef CONFIG_PCI_ENDPOINT
  684. pci_ep_init,
  685. #endif
  686. #ifdef CONFIG_CMD_NET
  687. INIT_FUNC_WATCHDOG_RESET
  688. initr_net,
  689. #endif
  690. #ifdef CONFIG_POST
  691. initr_post,
  692. #endif
  693. #ifdef CONFIG_LAST_STAGE_INIT
  694. INIT_FUNC_WATCHDOG_RESET
  695. /*
  696. * Some parts can be only initialized if all others (like
  697. * Interrupts) are up and running (i.e. the PC-style ISA
  698. * keyboard).
  699. */
  700. last_stage_init,
  701. #endif
  702. #if defined(CFG_PRAM)
  703. initr_mem,
  704. #endif
  705. run_main_loop,
  706. };
  707. void board_init_r(gd_t *new_gd, ulong dest_addr)
  708. {
  709. /*
  710. * The pre-relocation drivers may be using memory that has now gone
  711. * away. Mark serial as unavailable - this will fall back to the debug
  712. * UART if available.
  713. *
  714. * Do the same with log drivers since the memory may not be available.
  715. */
  716. gd->flags &= ~(GD_FLG_SERIAL_READY | GD_FLG_LOG_READY);
  717. /*
  718. * Set up the new global data pointer. So far only x86 does this
  719. * here.
  720. * TODO(sjg@chromium.org): Consider doing this for all archs, or
  721. * dropping the new_gd parameter.
  722. */
  723. if (CONFIG_IS_ENABLED(X86_64) && !IS_ENABLED(CONFIG_EFI_APP))
  724. arch_setup_gd(new_gd);
  725. #if !defined(CONFIG_X86) && !defined(CONFIG_ARM) && !defined(CONFIG_ARM64)
  726. gd = new_gd;
  727. #endif
  728. gd->flags &= ~GD_FLG_LOG_READY;
  729. if (IS_ENABLED(CONFIG_NEEDS_MANUAL_RELOC)) {
  730. for (int i = 0; i < ARRAY_SIZE(init_sequence_r); i++)
  731. MANUAL_RELOC(init_sequence_r[i]);
  732. }
  733. if (initcall_run_list(init_sequence_r))
  734. hang();
  735. /* NOTREACHED - run_main_loop() does not return */
  736. hang();
  737. }