board.c 24 KB

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