board.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994
  1. /*
  2. * (C) Copyright 2000-2011
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <watchdog.h>
  9. #include <command.h>
  10. #include <malloc.h>
  11. #include <stdio_dev.h>
  12. #ifdef CONFIG_8xx
  13. #include <mpc8xx.h>
  14. #endif
  15. #ifdef CONFIG_5xx
  16. #include <mpc5xx.h>
  17. #endif
  18. #ifdef CONFIG_MPC5xxx
  19. #include <mpc5xxx.h>
  20. #endif
  21. #if defined(CONFIG_CMD_IDE)
  22. #include <ide.h>
  23. #endif
  24. #if defined(CONFIG_CMD_SCSI)
  25. #include <scsi.h>
  26. #endif
  27. #if defined(CONFIG_CMD_KGDB)
  28. #include <kgdb.h>
  29. #endif
  30. #ifdef CONFIG_STATUS_LED
  31. #include <status_led.h>
  32. #endif
  33. #include <net.h>
  34. #ifdef CONFIG_GENERIC_MMC
  35. #include <mmc.h>
  36. #endif
  37. #include <serial.h>
  38. #ifdef CONFIG_SYS_ALLOC_DPRAM
  39. #if !defined(CONFIG_CPM2)
  40. #include <commproc.h>
  41. #endif
  42. #endif
  43. #include <version.h>
  44. #if defined(CONFIG_BAB7xx)
  45. #include <w83c553f.h>
  46. #endif
  47. #include <dtt.h>
  48. #if defined(CONFIG_POST)
  49. #include <post.h>
  50. #endif
  51. #if defined(CONFIG_LOGBUFFER)
  52. #include <logbuff.h>
  53. #endif
  54. #if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500)
  55. #include <asm/cache.h>
  56. #endif
  57. #ifdef CONFIG_PS2KBD
  58. #include <keyboard.h>
  59. #endif
  60. #ifdef CONFIG_ADDR_MAP
  61. #include <asm/mmu.h>
  62. #endif
  63. #ifdef CONFIG_MP
  64. #include <asm/mp.h>
  65. #endif
  66. #ifdef CONFIG_BITBANGMII
  67. #include <miiphy.h>
  68. #endif
  69. #ifdef CONFIG_SYS_UPDATE_FLASH_SIZE
  70. extern int update_flash_size(int flash_size);
  71. #endif
  72. #if defined(CONFIG_SC3)
  73. extern void sc3_read_eeprom(void);
  74. #endif
  75. #if defined(CONFIG_CMD_DOC)
  76. void doc_init(void);
  77. #endif
  78. #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
  79. #include <i2c.h>
  80. #endif
  81. #include <spi.h>
  82. #include <nand.h>
  83. static char *failed = "*** failed ***\n";
  84. #if defined(CONFIG_OXC) || defined(CONFIG_RMU)
  85. extern flash_info_t flash_info[];
  86. #endif
  87. #if defined(CONFIG_START_IDE)
  88. extern int board_start_ide(void);
  89. #endif
  90. #include <environment.h>
  91. DECLARE_GLOBAL_DATA_PTR;
  92. #if !defined(CONFIG_SYS_MEM_TOP_HIDE)
  93. #define CONFIG_SYS_MEM_TOP_HIDE 0
  94. #endif
  95. extern ulong __init_end;
  96. extern ulong __bss_end;
  97. ulong monitor_flash_len;
  98. #if defined(CONFIG_CMD_BEDBUG)
  99. #include <bedbug/type.h>
  100. #endif
  101. /*
  102. * Utilities
  103. */
  104. /*
  105. * All attempts to come up with a "common" initialization sequence
  106. * that works for all boards and architectures failed: some of the
  107. * requirements are just _too_ different. To get rid of the resulting
  108. * mess of board dependend #ifdef'ed code we now make the whole
  109. * initialization sequence configurable to the user.
  110. *
  111. * The requirements for any new initalization function is simple: it
  112. * receives a pointer to the "global data" structure as it's only
  113. * argument, and returns an integer return code, where 0 means
  114. * "continue" and != 0 means "fatal error, hang the system".
  115. */
  116. typedef int (init_fnc_t)(void);
  117. /*
  118. * Init Utilities
  119. *
  120. * Some of this code should be moved into the core functions,
  121. * but let's get it working (again) first...
  122. */
  123. static int init_baudrate(void)
  124. {
  125. gd->baudrate = getenv_ulong("baudrate", 10, CONFIG_BAUDRATE);
  126. return 0;
  127. }
  128. /***********************************************************************/
  129. static void __board_add_ram_info(int use_default)
  130. {
  131. /* please define platform specific board_add_ram_info() */
  132. }
  133. void board_add_ram_info(int)
  134. __attribute__ ((weak, alias("__board_add_ram_info")));
  135. static int __board_flash_wp_on(void)
  136. {
  137. /*
  138. * Most flashes can't be detected when write protection is enabled,
  139. * so provide a way to let U-Boot gracefully ignore write protected
  140. * devices.
  141. */
  142. return 0;
  143. }
  144. int board_flash_wp_on(void)
  145. __attribute__ ((weak, alias("__board_flash_wp_on")));
  146. static void __cpu_secondary_init_r(void)
  147. {
  148. }
  149. void cpu_secondary_init_r(void)
  150. __attribute__ ((weak, alias("__cpu_secondary_init_r")));
  151. static int init_func_ram(void)
  152. {
  153. #ifdef CONFIG_BOARD_TYPES
  154. int board_type = gd->board_type;
  155. #else
  156. int board_type = 0; /* use dummy arg */
  157. #endif
  158. puts("DRAM: ");
  159. gd->ram_size = initdram(board_type);
  160. if (gd->ram_size > 0) {
  161. print_size(gd->ram_size, "");
  162. board_add_ram_info(0);
  163. putc('\n');
  164. return 0;
  165. }
  166. puts(failed);
  167. return 1;
  168. }
  169. /***********************************************************************/
  170. #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
  171. static int init_func_i2c(void)
  172. {
  173. puts("I2C: ");
  174. #ifdef CONFIG_SYS_I2C
  175. i2c_init_all();
  176. #else
  177. i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
  178. #endif
  179. puts("ready\n");
  180. return 0;
  181. }
  182. #endif
  183. #if defined(CONFIG_HARD_SPI)
  184. static int init_func_spi(void)
  185. {
  186. puts("SPI: ");
  187. spi_init();
  188. puts("ready\n");
  189. return 0;
  190. }
  191. #endif
  192. /***********************************************************************/
  193. #if defined(CONFIG_WATCHDOG)
  194. int init_func_watchdog_init(void)
  195. {
  196. #if defined(CONFIG_MPC85xx)
  197. init_85xx_watchdog();
  198. #endif
  199. puts(" Watchdog enabled\n");
  200. WATCHDOG_RESET();
  201. return 0;
  202. }
  203. int init_func_watchdog_reset(void)
  204. {
  205. WATCHDOG_RESET();
  206. return 0;
  207. }
  208. #endif /* CONFIG_WATCHDOG */
  209. /*
  210. * Initialization sequence
  211. */
  212. static init_fnc_t *init_sequence[] = {
  213. #if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx)
  214. probecpu,
  215. #endif
  216. #if defined(CONFIG_BOARD_EARLY_INIT_F)
  217. board_early_init_f,
  218. #endif
  219. #if !defined(CONFIG_8xx_CPUCLK_DEFAULT)
  220. get_clocks, /* get CPU and bus clocks (etc.) */
  221. #if defined(CONFIG_TQM8xxL) && !defined(CONFIG_TQM866M) \
  222. && !defined(CONFIG_TQM885D)
  223. adjust_sdram_tbs_8xx,
  224. #endif
  225. init_timebase,
  226. #endif
  227. #ifdef CONFIG_SYS_ALLOC_DPRAM
  228. #if !defined(CONFIG_CPM2)
  229. dpram_init,
  230. #endif
  231. #endif
  232. #if defined(CONFIG_BOARD_POSTCLK_INIT)
  233. board_postclk_init,
  234. #endif
  235. env_init,
  236. #if defined(CONFIG_8xx_CPUCLK_DEFAULT)
  237. /* get CPU and bus clocks according to the environment variable */
  238. get_clocks_866,
  239. /* adjust sdram refresh rate according to the new clock */
  240. sdram_adjust_866,
  241. init_timebase,
  242. #endif
  243. init_baudrate,
  244. serial_init,
  245. console_init_f,
  246. display_options,
  247. #if defined(CONFIG_MPC8260)
  248. prt_8260_rsr,
  249. prt_8260_clks,
  250. #endif /* CONFIG_MPC8260 */
  251. #if defined(CONFIG_MPC83xx)
  252. prt_83xx_rsr,
  253. #endif
  254. checkcpu,
  255. #if defined(CONFIG_MPC5xxx)
  256. prt_mpc5xxx_clks,
  257. #endif /* CONFIG_MPC5xxx */
  258. checkboard,
  259. INIT_FUNC_WATCHDOG_INIT
  260. #if defined(CONFIG_MISC_INIT_F)
  261. misc_init_f,
  262. #endif
  263. INIT_FUNC_WATCHDOG_RESET
  264. #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
  265. init_func_i2c,
  266. #endif
  267. #if defined(CONFIG_HARD_SPI)
  268. init_func_spi,
  269. #endif
  270. #ifdef CONFIG_POST
  271. post_init_f,
  272. #endif
  273. INIT_FUNC_WATCHDOG_RESET
  274. init_func_ram,
  275. #if defined(CONFIG_SYS_DRAM_TEST)
  276. testdram,
  277. #endif /* CONFIG_SYS_DRAM_TEST */
  278. INIT_FUNC_WATCHDOG_RESET
  279. NULL, /* Terminate this list */
  280. };
  281. static int __fixup_cpu(void)
  282. {
  283. return 0;
  284. }
  285. int fixup_cpu(void) __attribute__((weak, alias("__fixup_cpu")));
  286. /*
  287. * This is the first part of the initialization sequence that is
  288. * implemented in C, but still running from ROM.
  289. *
  290. * The main purpose is to provide a (serial) console interface as
  291. * soon as possible (so we can see any error messages), and to
  292. * initialize the RAM so that we can relocate the monitor code to
  293. * RAM.
  294. *
  295. * Be aware of the restrictions: global data is read-only, BSS is not
  296. * initialized, and stack space is limited to a few kB.
  297. */
  298. void board_init_f(ulong bootflag)
  299. {
  300. bd_t *bd;
  301. ulong len, addr, addr_sp;
  302. ulong *s;
  303. gd_t *id;
  304. init_fnc_t **init_fnc_ptr;
  305. #ifdef CONFIG_PRAM
  306. ulong reg;
  307. #endif
  308. /* Pointer is writable since we allocated a register for it */
  309. gd = (gd_t *) (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET);
  310. /* compiler optimization barrier needed for GCC >= 3.4 */
  311. __asm__ __volatile__("":::"memory");
  312. #if !defined(CONFIG_CPM2) && !defined(CONFIG_MPC512X) && \
  313. !defined(CONFIG_MPC83xx) && !defined(CONFIG_MPC85xx) && \
  314. !defined(CONFIG_MPC86xx)
  315. /* Clear initial global data */
  316. memset((void *) gd, 0, sizeof(gd_t));
  317. #endif
  318. gd->flags = bootflag;
  319. for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr)
  320. if ((*init_fnc_ptr) () != 0)
  321. hang();
  322. #ifdef CONFIG_POST
  323. post_bootmode_init();
  324. post_run(NULL, POST_ROM | post_bootmode_get(NULL));
  325. #endif
  326. WATCHDOG_RESET();
  327. /*
  328. * Now that we have DRAM mapped and working, we can
  329. * relocate the code and continue running from DRAM.
  330. *
  331. * Reserve memory at end of RAM for (top down in that order):
  332. * - area that won't get touched by U-Boot and Linux (optional)
  333. * - kernel log buffer
  334. * - protected RAM
  335. * - LCD framebuffer
  336. * - monitor code
  337. * - board info struct
  338. */
  339. len = (ulong)&__bss_end - CONFIG_SYS_MONITOR_BASE;
  340. /*
  341. * Subtract specified amount of memory to hide so that it won't
  342. * get "touched" at all by U-Boot. By fixing up gd->ram_size
  343. * the Linux kernel should now get passed the now "corrected"
  344. * memory size and won't touch it either. This should work
  345. * for arch/ppc and arch/powerpc. Only Linux board ports in
  346. * arch/powerpc with bootwrapper support, that recalculate the
  347. * memory size from the SDRAM controller setup will have to
  348. * get fixed.
  349. */
  350. gd->ram_size -= CONFIG_SYS_MEM_TOP_HIDE;
  351. addr = CONFIG_SYS_SDRAM_BASE + get_effective_memsize();
  352. #if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500))
  353. /*
  354. * We need to make sure the location we intend to put secondary core
  355. * boot code is reserved and not used by any part of u-boot
  356. */
  357. if (addr > determine_mp_bootpg(NULL)) {
  358. addr = determine_mp_bootpg(NULL);
  359. debug("Reserving MP boot page to %08lx\n", addr);
  360. }
  361. #endif
  362. #ifdef CONFIG_LOGBUFFER
  363. #ifndef CONFIG_ALT_LB_ADDR
  364. /* reserve kernel log buffer */
  365. addr -= (LOGBUFF_RESERVE);
  366. debug("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN,
  367. addr);
  368. #endif
  369. #endif
  370. #ifdef CONFIG_PRAM
  371. /*
  372. * reserve protected RAM
  373. */
  374. reg = getenv_ulong("pram", 10, CONFIG_PRAM);
  375. addr -= (reg << 10); /* size is in kB */
  376. debug("Reserving %ldk for protected RAM at %08lx\n", reg, addr);
  377. #endif /* CONFIG_PRAM */
  378. /* round down to next 4 kB limit */
  379. addr &= ~(4096 - 1);
  380. debug("Top of RAM usable for U-Boot at: %08lx\n", addr);
  381. #ifdef CONFIG_LCD
  382. #ifdef CONFIG_FB_ADDR
  383. gd->fb_base = CONFIG_FB_ADDR;
  384. #else
  385. /* reserve memory for LCD display (always full pages) */
  386. addr = lcd_setmem(addr);
  387. gd->fb_base = addr;
  388. #endif /* CONFIG_FB_ADDR */
  389. #endif /* CONFIG_LCD */
  390. #if defined(CONFIG_VIDEO) && defined(CONFIG_8xx)
  391. /* reserve memory for video display (always full pages) */
  392. addr = video_setmem(addr);
  393. gd->fb_base = addr;
  394. #endif /* CONFIG_VIDEO */
  395. /*
  396. * reserve memory for U-Boot code, data & bss
  397. * round down to next 4 kB limit
  398. */
  399. addr -= len;
  400. addr &= ~(4096 - 1);
  401. #ifdef CONFIG_E500
  402. /* round down to next 64 kB limit so that IVPR stays aligned */
  403. addr &= ~(65536 - 1);
  404. #endif
  405. debug("Reserving %ldk for U-Boot at: %08lx\n", len >> 10, addr);
  406. /*
  407. * reserve memory for malloc() arena
  408. */
  409. addr_sp = addr - TOTAL_MALLOC_LEN;
  410. debug("Reserving %dk for malloc() at: %08lx\n",
  411. TOTAL_MALLOC_LEN >> 10, addr_sp);
  412. /*
  413. * (permanently) allocate a Board Info struct
  414. * and a permanent copy of the "global" data
  415. */
  416. addr_sp -= sizeof(bd_t);
  417. bd = (bd_t *) addr_sp;
  418. memset(bd, 0, sizeof(bd_t));
  419. gd->bd = bd;
  420. debug("Reserving %zu Bytes for Board Info at: %08lx\n",
  421. sizeof(bd_t), addr_sp);
  422. addr_sp -= sizeof(gd_t);
  423. id = (gd_t *) addr_sp;
  424. debug("Reserving %zu Bytes for Global Data at: %08lx\n",
  425. sizeof(gd_t), addr_sp);
  426. /*
  427. * Finally, we set up a new (bigger) stack.
  428. *
  429. * Leave some safety gap for SP, force alignment on 16 byte boundary
  430. * Clear initial stack frame
  431. */
  432. addr_sp -= 16;
  433. addr_sp &= ~0xF;
  434. s = (ulong *) addr_sp;
  435. *s = 0; /* Terminate back chain */
  436. *++s = 0; /* NULL return address */
  437. debug("Stack Pointer at: %08lx\n", addr_sp);
  438. /*
  439. * Save local variables to board info struct
  440. */
  441. bd->bi_memstart = CONFIG_SYS_SDRAM_BASE; /* start of memory */
  442. bd->bi_memsize = gd->ram_size; /* size in bytes */
  443. #ifdef CONFIG_SYS_SRAM_BASE
  444. bd->bi_sramstart = CONFIG_SYS_SRAM_BASE; /* start of SRAM */
  445. bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE; /* size of SRAM */
  446. #endif
  447. #if defined(CONFIG_8xx) || defined(CONFIG_MPC8260) || defined(CONFIG_5xx) || \
  448. defined(CONFIG_E500) || defined(CONFIG_MPC86xx)
  449. bd->bi_immr_base = CONFIG_SYS_IMMR; /* base of IMMR register */
  450. #endif
  451. #if defined(CONFIG_MPC5xxx)
  452. bd->bi_mbar_base = CONFIG_SYS_MBAR; /* base of internal registers */
  453. #endif
  454. #if defined(CONFIG_MPC83xx)
  455. bd->bi_immrbar = CONFIG_SYS_IMMR;
  456. #endif
  457. WATCHDOG_RESET();
  458. bd->bi_intfreq = gd->cpu_clk; /* Internal Freq, in Hz */
  459. bd->bi_busfreq = gd->bus_clk; /* Bus Freq, in Hz */
  460. #if defined(CONFIG_CPM2)
  461. bd->bi_cpmfreq = gd->arch.cpm_clk;
  462. bd->bi_brgfreq = gd->arch.brg_clk;
  463. bd->bi_sccfreq = gd->arch.scc_clk;
  464. bd->bi_vco = gd->arch.vco_out;
  465. #endif /* CONFIG_CPM2 */
  466. #if defined(CONFIG_MPC512X)
  467. bd->bi_ipsfreq = gd->arch.ips_clk;
  468. #endif /* CONFIG_MPC512X */
  469. #if defined(CONFIG_MPC5xxx)
  470. bd->bi_ipbfreq = gd->arch.ipb_clk;
  471. bd->bi_pcifreq = gd->pci_clk;
  472. #endif /* CONFIG_MPC5xxx */
  473. #ifdef CONFIG_SYS_EXTBDINFO
  474. strncpy((char *) bd->bi_s_version, "1.2", sizeof(bd->bi_s_version));
  475. strncpy((char *) bd->bi_r_version, U_BOOT_VERSION,
  476. sizeof(bd->bi_r_version));
  477. bd->bi_procfreq = gd->cpu_clk; /* Processor Speed, In Hz */
  478. bd->bi_plb_busfreq = gd->bus_clk;
  479. #if defined(CONFIG_405GP) || defined(CONFIG_405EP) || \
  480. defined(CONFIG_440EP) || defined(CONFIG_440GR) || \
  481. defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
  482. bd->bi_pci_busfreq = get_PCI_freq();
  483. bd->bi_opbfreq = get_OPB_freq();
  484. #elif defined(CONFIG_XILINX_405)
  485. bd->bi_pci_busfreq = get_PCI_freq();
  486. #endif
  487. #endif
  488. debug("New Stack Pointer is: %08lx\n", addr_sp);
  489. WATCHDOG_RESET();
  490. gd->relocaddr = addr; /* Store relocation addr, useful for debug */
  491. memcpy(id, (void *) gd, sizeof(gd_t));
  492. relocate_code(addr_sp, id, addr);
  493. /* NOTREACHED - relocate_code() does not return */
  494. }
  495. /*
  496. * This is the next part if the initialization sequence: we are now
  497. * running from RAM and have a "normal" C environment, i. e. global
  498. * data can be written, BSS has been cleared, the stack size in not
  499. * that critical any more, etc.
  500. */
  501. void board_init_r(gd_t *id, ulong dest_addr)
  502. {
  503. bd_t *bd;
  504. ulong malloc_start;
  505. #ifndef CONFIG_SYS_NO_FLASH
  506. ulong flash_size;
  507. #endif
  508. gd = id; /* initialize RAM version of global data */
  509. bd = gd->bd;
  510. gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
  511. /* The Malloc area is immediately below the monitor copy in DRAM */
  512. malloc_start = dest_addr - TOTAL_MALLOC_LEN;
  513. #if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx)
  514. /*
  515. * The gd->arch.cpu pointer is set to an address in flash before
  516. * relocation. We need to update it to point to the same CPU entry
  517. * in RAM.
  518. */
  519. gd->arch.cpu += dest_addr - CONFIG_SYS_MONITOR_BASE;
  520. /*
  521. * If we didn't know the cpu mask & # cores, we can save them of
  522. * now rather than 'computing' them constantly
  523. */
  524. fixup_cpu();
  525. #endif
  526. #ifdef CONFIG_SYS_EXTRA_ENV_RELOC
  527. /*
  528. * Some systems need to relocate the env_addr pointer early because the
  529. * location it points to will get invalidated before env_relocate is
  530. * called. One example is on systems that might use a L2 or L3 cache
  531. * in SRAM mode and initialize that cache from SRAM mode back to being
  532. * a cache in cpu_init_r.
  533. */
  534. gd->env_addr += dest_addr - CONFIG_SYS_MONITOR_BASE;
  535. #endif
  536. serial_initialize();
  537. debug("Now running in RAM - U-Boot at: %08lx\n", dest_addr);
  538. WATCHDOG_RESET();
  539. /*
  540. * Setup trap handlers
  541. */
  542. trap_init(dest_addr);
  543. #ifdef CONFIG_ADDR_MAP
  544. init_addr_map();
  545. #endif
  546. #if defined(CONFIG_BOARD_EARLY_INIT_R)
  547. board_early_init_r();
  548. #endif
  549. monitor_flash_len = (ulong)&__init_end - dest_addr;
  550. WATCHDOG_RESET();
  551. #ifdef CONFIG_LOGBUFFER
  552. logbuff_init_ptrs();
  553. #endif
  554. #ifdef CONFIG_POST
  555. post_output_backlog();
  556. #endif
  557. WATCHDOG_RESET();
  558. #if defined(CONFIG_SYS_DELAYED_ICACHE)
  559. icache_enable(); /* it's time to enable the instruction cache */
  560. #endif
  561. #if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500)
  562. unlock_ram_in_cache(); /* it's time to unlock D-cache in e500 */
  563. #endif
  564. #if defined(CONFIG_PCI) && defined(CONFIG_SYS_EARLY_PCI_INIT)
  565. /*
  566. * Do early PCI configuration _before_ the flash gets initialised,
  567. * because PCU ressources are crucial for flash access on some boards.
  568. */
  569. pci_init();
  570. #endif
  571. #if defined(CONFIG_WINBOND_83C553)
  572. /*
  573. * Initialise the ISA bridge
  574. */
  575. initialise_w83c553f();
  576. #endif
  577. asm("sync ; isync");
  578. mem_malloc_init(malloc_start, TOTAL_MALLOC_LEN);
  579. #if !defined(CONFIG_SYS_NO_FLASH)
  580. puts("Flash: ");
  581. if (board_flash_wp_on()) {
  582. printf("Uninitialized - Write Protect On\n");
  583. /* Since WP is on, we can't find real size. Set to 0 */
  584. flash_size = 0;
  585. } else if ((flash_size = flash_init()) > 0) {
  586. #ifdef CONFIG_SYS_FLASH_CHECKSUM
  587. print_size(flash_size, "");
  588. /*
  589. * Compute and print flash CRC if flashchecksum is set to 'y'
  590. *
  591. * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
  592. */
  593. if (getenv_yesno("flashchecksum") == 1) {
  594. printf(" CRC: %08X",
  595. crc32(0,
  596. (const unsigned char *)
  597. CONFIG_SYS_FLASH_BASE, flash_size)
  598. );
  599. }
  600. putc('\n');
  601. #else /* !CONFIG_SYS_FLASH_CHECKSUM */
  602. print_size(flash_size, "\n");
  603. #endif /* CONFIG_SYS_FLASH_CHECKSUM */
  604. } else {
  605. puts(failed);
  606. hang();
  607. }
  608. /* update start of FLASH memory */
  609. bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
  610. /* size of FLASH memory (final value) */
  611. bd->bi_flashsize = flash_size;
  612. #if defined(CONFIG_SYS_UPDATE_FLASH_SIZE)
  613. /* Make a update of the Memctrl. */
  614. update_flash_size(flash_size);
  615. #endif
  616. #if defined(CONFIG_OXC) || defined(CONFIG_RMU)
  617. /* flash mapped at end of memory map */
  618. bd->bi_flashoffset = CONFIG_SYS_TEXT_BASE + flash_size;
  619. #elif CONFIG_SYS_MONITOR_BASE == CONFIG_SYS_FLASH_BASE
  620. bd->bi_flashoffset = monitor_flash_len; /* reserved area for monitor */
  621. #endif
  622. #endif /* !CONFIG_SYS_NO_FLASH */
  623. WATCHDOG_RESET();
  624. /* initialize higher level parts of CPU like time base and timers */
  625. cpu_init_r();
  626. WATCHDOG_RESET();
  627. #ifdef CONFIG_SPI
  628. #if !defined(CONFIG_ENV_IS_IN_EEPROM)
  629. spi_init_f();
  630. #endif
  631. spi_init_r();
  632. #endif
  633. #if defined(CONFIG_CMD_NAND)
  634. WATCHDOG_RESET();
  635. puts("NAND: ");
  636. nand_init(); /* go init the NAND */
  637. #endif
  638. #ifdef CONFIG_GENERIC_MMC
  639. /*
  640. * MMC initialization is called before relocating env.
  641. * Thus It is required that operations like pin multiplexer
  642. * be put in board_init.
  643. */
  644. WATCHDOG_RESET();
  645. puts("MMC: ");
  646. mmc_initialize(bd);
  647. #endif
  648. /* relocate environment function pointers etc. */
  649. env_relocate();
  650. /*
  651. * after non-volatile devices & environment is setup and cpu code have
  652. * another round to deal with any initialization that might require
  653. * full access to the environment or loading of some image (firmware)
  654. * from a non-volatile device
  655. */
  656. cpu_secondary_init_r();
  657. /*
  658. * Fill in missing fields of bd_info.
  659. * We do this here, where we have "normal" access to the
  660. * environment; we used to do this still running from ROM,
  661. * where had to use getenv_f(), which can be pretty slow when
  662. * the environment is in EEPROM.
  663. */
  664. #if defined(CONFIG_SYS_EXTBDINFO)
  665. #if defined(CONFIG_405GP) || defined(CONFIG_405EP)
  666. #if defined(CONFIG_I2CFAST)
  667. /*
  668. * set bi_iic_fast for linux taking environment variable
  669. * "i2cfast" into account
  670. */
  671. {
  672. if (getenv_yesno("i2cfast") == 1) {
  673. bd->bi_iic_fast[0] = 1;
  674. bd->bi_iic_fast[1] = 1;
  675. }
  676. }
  677. #endif /* CONFIG_I2CFAST */
  678. #endif /* CONFIG_405GP, CONFIG_405EP */
  679. #endif /* CONFIG_SYS_EXTBDINFO */
  680. #if defined(CONFIG_SC3)
  681. sc3_read_eeprom();
  682. #endif
  683. #if defined(CONFIG_ID_EEPROM) || defined(CONFIG_SYS_I2C_MAC_OFFSET)
  684. mac_read_from_eeprom();
  685. #endif
  686. #ifdef CONFIG_CMD_NET
  687. /* kept around for legacy kernels only ... ignore the next section */
  688. eth_getenv_enetaddr("ethaddr", bd->bi_enetaddr);
  689. #ifdef CONFIG_HAS_ETH1
  690. eth_getenv_enetaddr("eth1addr", bd->bi_enet1addr);
  691. #endif
  692. #ifdef CONFIG_HAS_ETH2
  693. eth_getenv_enetaddr("eth2addr", bd->bi_enet2addr);
  694. #endif
  695. #ifdef CONFIG_HAS_ETH3
  696. eth_getenv_enetaddr("eth3addr", bd->bi_enet3addr);
  697. #endif
  698. #ifdef CONFIG_HAS_ETH4
  699. eth_getenv_enetaddr("eth4addr", bd->bi_enet4addr);
  700. #endif
  701. #ifdef CONFIG_HAS_ETH5
  702. eth_getenv_enetaddr("eth5addr", bd->bi_enet5addr);
  703. #endif
  704. #endif /* CONFIG_CMD_NET */
  705. WATCHDOG_RESET();
  706. #if defined(CONFIG_PCI) && !defined(CONFIG_SYS_EARLY_PCI_INIT)
  707. /*
  708. * Do pci configuration
  709. */
  710. pci_init();
  711. #endif
  712. /** leave this here (after malloc(), environment and PCI are working) **/
  713. /* Initialize stdio devices */
  714. stdio_init();
  715. /* Initialize the jump table for applications */
  716. jumptable_init();
  717. #if defined(CONFIG_API)
  718. /* Initialize API */
  719. api_init();
  720. #endif
  721. /* Initialize the console (after the relocation and devices init) */
  722. console_init_r();
  723. #if defined(CONFIG_MISC_INIT_R)
  724. /* miscellaneous platform dependent initialisations */
  725. misc_init_r();
  726. #endif
  727. #if defined(CONFIG_CMD_KGDB)
  728. WATCHDOG_RESET();
  729. puts("KGDB: ");
  730. kgdb_init();
  731. #endif
  732. debug("U-Boot relocated to %08lx\n", dest_addr);
  733. /*
  734. * Enable Interrupts
  735. */
  736. interrupt_init();
  737. #if defined(CONFIG_STATUS_LED) && defined(STATUS_LED_BOOT)
  738. status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING);
  739. #endif
  740. udelay(20);
  741. /* Initialize from environment */
  742. load_addr = getenv_ulong("loadaddr", 16, load_addr);
  743. WATCHDOG_RESET();
  744. #if defined(CONFIG_CMD_SCSI)
  745. WATCHDOG_RESET();
  746. puts("SCSI: ");
  747. scsi_init();
  748. #endif
  749. #if defined(CONFIG_CMD_DOC)
  750. WATCHDOG_RESET();
  751. puts("DOC: ");
  752. doc_init();
  753. #endif
  754. #ifdef CONFIG_BITBANGMII
  755. bb_miiphy_init();
  756. #endif
  757. #if defined(CONFIG_CMD_NET)
  758. WATCHDOG_RESET();
  759. puts("Net: ");
  760. eth_initialize(bd);
  761. #endif
  762. #if defined(CONFIG_CMD_NET) && defined(CONFIG_RESET_PHY_R)
  763. WATCHDOG_RESET();
  764. debug("Reset Ethernet PHY\n");
  765. reset_phy();
  766. #endif
  767. #ifdef CONFIG_POST
  768. post_run(NULL, POST_RAM | post_bootmode_get(0));
  769. #endif
  770. #if defined(CONFIG_CMD_PCMCIA) \
  771. && !defined(CONFIG_CMD_IDE)
  772. WATCHDOG_RESET();
  773. puts("PCMCIA:");
  774. pcmcia_init();
  775. #endif
  776. #if defined(CONFIG_CMD_IDE)
  777. WATCHDOG_RESET();
  778. #ifdef CONFIG_IDE_8xx_PCCARD
  779. puts("PCMCIA:");
  780. #else
  781. puts("IDE: ");
  782. #endif
  783. #if defined(CONFIG_START_IDE)
  784. if (board_start_ide())
  785. ide_init();
  786. #else
  787. ide_init();
  788. #endif
  789. #endif
  790. #ifdef CONFIG_LAST_STAGE_INIT
  791. WATCHDOG_RESET();
  792. /*
  793. * Some parts can be only initialized if all others (like
  794. * Interrupts) are up and running (i.e. the PC-style ISA
  795. * keyboard).
  796. */
  797. last_stage_init();
  798. #endif
  799. #if defined(CONFIG_CMD_BEDBUG)
  800. WATCHDOG_RESET();
  801. bedbug_init();
  802. #endif
  803. #if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
  804. /*
  805. * Export available size of memory for Linux,
  806. * taking into account the protected RAM at top of memory
  807. */
  808. {
  809. ulong pram = 0;
  810. char memsz[32];
  811. #ifdef CONFIG_PRAM
  812. pram = getenv_ulong("pram", 10, CONFIG_PRAM);
  813. #endif
  814. #ifdef CONFIG_LOGBUFFER
  815. #ifndef CONFIG_ALT_LB_ADDR
  816. /* Also take the logbuffer into account (pram is in kB) */
  817. pram += (LOGBUFF_LEN + LOGBUFF_OVERHEAD) / 1024;
  818. #endif
  819. #endif
  820. sprintf(memsz, "%ldk", (ulong) (bd->bi_memsize / 1024) - pram);
  821. setenv("mem", memsz);
  822. }
  823. #endif
  824. #ifdef CONFIG_PS2KBD
  825. puts("PS/2: ");
  826. kbd_init();
  827. #endif
  828. /* Initialization complete - start the monitor */
  829. /* main_loop() can return to retry autoboot, if so just run it again. */
  830. for (;;) {
  831. WATCHDOG_RESET();
  832. main_loop();
  833. }
  834. /* NOTREACHED - no way out of command loop except booting */
  835. }
  836. #if 0 /* We could use plain global data, but the resulting code is bigger */
  837. /*
  838. * Pointer to initial global data area
  839. *
  840. * Here we initialize it.
  841. */
  842. #undef XTRN_DECLARE_GLOBAL_DATA_PTR
  843. #define XTRN_DECLARE_GLOBAL_DATA_PTR /* empty = allocate here */
  844. DECLARE_GLOBAL_DATA_PTR =
  845. (gd_t *) (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET);
  846. #endif /* 0 */
  847. /************************************************************************/