board_r.c 18 KB

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