board.c 26 KB

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