board.c 27 KB

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