board.c 28 KB

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