board_r.c 19 KB

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