board.c 24 KB

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