board.c 26 KB

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