board.c 23 KB

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