board.c 28 KB

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