board_r.c 19 KB

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