board.c 26 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115
  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. #ifdef CONFIG_POST
  272. post_init_f,
  273. #endif
  274. INIT_FUNC_WATCHDOG_RESET
  275. init_func_ram,
  276. #if defined(CFG_DRAM_TEST)
  277. testdram,
  278. #endif /* CFG_DRAM_TEST */
  279. INIT_FUNC_WATCHDOG_RESET
  280. NULL, /* Terminate this list */
  281. };
  282. /************************************************************************
  283. *
  284. * This is the first part of the initialization sequence that is
  285. * implemented in C, but still running from ROM.
  286. *
  287. * The main purpose is to provide a (serial) console interface as
  288. * soon as possible (so we can see any error messages), and to
  289. * initialize the RAM so that we can relocate the monitor code to
  290. * RAM.
  291. *
  292. * Be aware of the restrictions: global data is read-only, BSS is not
  293. * initialized, and stack space is limited to a few kB.
  294. *
  295. ************************************************************************
  296. */
  297. void board_init_f (ulong bootflag)
  298. {
  299. DECLARE_GLOBAL_DATA_PTR;
  300. bd_t *bd;
  301. ulong len, addr, addr_sp;
  302. gd_t *id;
  303. init_fnc_t **init_fnc_ptr;
  304. #ifdef CONFIG_PRAM
  305. int i;
  306. ulong reg;
  307. uchar tmp[64]; /* long enough for environment variables */
  308. #endif
  309. /* Pointer is writable since we allocated a register for it */
  310. gd = (gd_t *) (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET);
  311. #ifndef CONFIG_8260
  312. /* Clear initial global data */
  313. memset ((void *) gd, 0, sizeof (gd_t));
  314. #endif
  315. for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
  316. if ((*init_fnc_ptr) () != 0) {
  317. hang ();
  318. }
  319. }
  320. /*
  321. * Now that we have DRAM mapped and working, we can
  322. * relocate the code and continue running from DRAM.
  323. *
  324. * Reserve memory at end of RAM for (top down in that order):
  325. * - kernel log buffer
  326. * - protected RAM
  327. * - LCD framebuffer
  328. * - monitor code
  329. * - board info struct
  330. */
  331. len = get_endaddr () - CFG_MONITOR_BASE;
  332. if (len > CFG_MONITOR_LEN) {
  333. printf ("*** U-Boot size %ld > reserved memory (%d)\n",
  334. len, CFG_MONITOR_LEN);
  335. hang ();
  336. }
  337. if (CFG_MONITOR_LEN > len)
  338. len = CFG_MONITOR_LEN;
  339. #ifndef CONFIG_VERY_BIG_RAM
  340. addr = CFG_SDRAM_BASE + gd->ram_size;
  341. #else
  342. /* only allow stack below 256M */
  343. addr = CFG_SDRAM_BASE +
  344. (gd->ram_size > 256 << 20) ? 256 << 20 : gd->ram_size;
  345. #endif
  346. #ifdef CONFIG_LOGBUFFER
  347. /* reserve kernel log buffer */
  348. addr -= (LOGBUFF_RESERVE);
  349. # ifdef DEBUG
  350. printf ("Reserving %ldk for kernel logbuffer at %08lx\n", LOGBUFF_LEN, addr);
  351. # endif
  352. #endif
  353. #ifdef CONFIG_PRAM
  354. /*
  355. * reserve protected RAM
  356. */
  357. i = getenv_r ("pram", tmp, sizeof (tmp));
  358. reg = (i > 0) ? simple_strtoul (tmp, NULL, 10) : CONFIG_PRAM;
  359. addr -= (reg << 10); /* size is in kB */
  360. # ifdef DEBUG
  361. printf ("Reserving %ldk for protected RAM at %08lx\n", reg, addr);
  362. # endif
  363. #endif /* CONFIG_PRAM */
  364. /* round down to next 4 kB limit */
  365. addr &= ~(4096 - 1);
  366. #ifdef DEBUG
  367. printf ("Top of RAM usable for U-Boot at: %08lx\n", addr);
  368. #endif
  369. #ifdef CONFIG_LCD
  370. /* reserve memory for LCD display (always full pages) */
  371. addr = lcd_setmem (addr);
  372. gd->fb_base = addr;
  373. #endif /* CONFIG_LCD */
  374. #if defined(CONFIG_VIDEO) && defined(CONFIG_8xx)
  375. /* reserve memory for video display (always full pages) */
  376. addr = video_setmem (addr);
  377. gd->fb_base = addr;
  378. #endif /* CONFIG_VIDEO */
  379. /*
  380. * reserve memory for U-Boot code, data & bss
  381. * round down to next 4 kB limit
  382. */
  383. addr -= len;
  384. addr &= ~(4096 - 1);
  385. #ifdef DEBUG
  386. printf ("Reserving %ldk for U-Boot at: %08lx\n", len >> 10, addr);
  387. #endif
  388. #ifdef CONFIG_AMIGAONEG3SE
  389. gd->relocaddr = addr;
  390. #endif
  391. /*
  392. * reserve memory for malloc() arena
  393. */
  394. addr_sp = addr - TOTAL_MALLOC_LEN;
  395. #ifdef DEBUG
  396. printf ("Reserving %dk for malloc() at: %08lx\n",
  397. TOTAL_MALLOC_LEN >> 10, addr_sp);
  398. #endif
  399. /*
  400. * (permanently) allocate a Board Info struct
  401. * and a permanent copy of the "global" data
  402. */
  403. addr_sp -= sizeof (bd_t);
  404. bd = (bd_t *) addr_sp;
  405. gd->bd = bd;
  406. #ifdef DEBUG
  407. printf ("Reserving %d Bytes for Board Info at: %08lx\n",
  408. sizeof (bd_t), addr_sp);
  409. #endif
  410. addr_sp -= sizeof (gd_t);
  411. id = (gd_t *) addr_sp;
  412. #ifdef DEBUG
  413. printf ("Reserving %d Bytes for Global Data at: %08lx\n",
  414. sizeof (gd_t), addr_sp);
  415. #endif
  416. /*
  417. * Finally, we set up a new (bigger) stack.
  418. *
  419. * Leave some safety gap for SP, force alignment on 16 byte boundary
  420. * Clear initial stack frame
  421. */
  422. addr_sp -= 16;
  423. addr_sp &= ~0xF;
  424. *((ulong *) addr_sp)-- = 0;
  425. *((ulong *) addr_sp)-- = 0;
  426. #ifdef DEBUG
  427. printf ("Stack Pointer at: %08lx\n", addr_sp);
  428. #endif
  429. /*
  430. * Save local variables to board info struct
  431. */
  432. bd->bi_memstart = CFG_SDRAM_BASE; /* start of DRAM memory */
  433. bd->bi_memsize = gd->ram_size; /* size of DRAM memory in bytes */
  434. #ifdef CONFIG_IP860
  435. bd->bi_sramstart = SRAM_BASE; /* start of SRAM memory */
  436. bd->bi_sramsize = SRAM_SIZE; /* size of SRAM memory */
  437. #else
  438. bd->bi_sramstart = 0; /* FIXME */ /* start of SRAM memory */
  439. bd->bi_sramsize = 0; /* FIXME */ /* size of SRAM memory */
  440. #endif
  441. #if defined(CONFIG_8xx) || defined(CONFIG_8260) || defined(CONFIG_5xx)
  442. bd->bi_immr_base = CFG_IMMR; /* base of IMMR register */
  443. #endif
  444. bd->bi_bootflags = bootflag; /* boot / reboot flag (for LynxOS) */
  445. WATCHDOG_RESET ();
  446. bd->bi_intfreq = gd->cpu_clk; /* Internal Freq, in Hz */
  447. bd->bi_busfreq = gd->bus_clk; /* Bus Freq, in Hz */
  448. #if defined(CONFIG_8260)
  449. bd->bi_cpmfreq = gd->cpm_clk;
  450. bd->bi_brgfreq = gd->brg_clk;
  451. bd->bi_sccfreq = gd->scc_clk;
  452. bd->bi_vco = gd->vco_out;
  453. #endif /* CONFIG_8260 */
  454. bd->bi_baudrate = gd->baudrate; /* Console Baudrate */
  455. #ifdef CFG_EXTBDINFO
  456. strncpy (bd->bi_s_version, "1.2", sizeof (bd->bi_s_version));
  457. strncpy (bd->bi_r_version, U_BOOT_VERSION, sizeof (bd->bi_r_version));
  458. bd->bi_procfreq = gd->cpu_clk; /* Processor Speed, In Hz */
  459. bd->bi_plb_busfreq = gd->bus_clk;
  460. #ifdef CONFIG_405GP
  461. bd->bi_pci_busfreq = get_PCI_freq ();
  462. #endif
  463. #endif
  464. #ifdef DEBUG
  465. printf ("New Stack Pointer is: %08lx\n", addr_sp);
  466. #endif
  467. WATCHDOG_RESET ();
  468. #ifdef CONFIG_POST
  469. post_bootmode_init();
  470. post_run (NULL, POST_ROM | post_bootmode_get(0));
  471. #endif
  472. WATCHDOG_RESET();
  473. memcpy (id, gd, sizeof (gd_t));
  474. relocate_code (addr_sp, id, addr);
  475. /* NOTREACHED - relocate_code() does not return */
  476. }
  477. /************************************************************************
  478. *
  479. * This is the next part if the initialization sequence: we are now
  480. * running from RAM and have a "normal" C environment, i. e. global
  481. * data can be written, BSS has been cleared, the stack size in not
  482. * that critical any more, etc.
  483. *
  484. ************************************************************************
  485. */
  486. void board_init_r (gd_t *id, ulong dest_addr)
  487. {
  488. DECLARE_GLOBAL_DATA_PTR;
  489. cmd_tbl_t *cmdtp;
  490. char *s, *e;
  491. bd_t *bd;
  492. int i;
  493. extern void malloc_bin_reloc (void);
  494. #ifndef CFG_ENV_IS_NOWHERE
  495. extern char * env_name_spec;
  496. #endif
  497. #ifndef CFG_NO_FLASH
  498. ulong flash_size;
  499. #endif
  500. gd = id; /* initialize RAM version of global data */
  501. bd = gd->bd;
  502. gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
  503. #ifdef DEBUG
  504. printf ("Now running in RAM - U-Boot at: %08lx\n", dest_addr);
  505. #endif
  506. WATCHDOG_RESET ();
  507. gd->reloc_off = dest_addr - CFG_MONITOR_BASE;
  508. /*
  509. * We have to relocate the command table manually
  510. */
  511. for (cmdtp = &cmd_tbl[0]; cmdtp->name; cmdtp++) {
  512. ulong addr;
  513. addr = (ulong) (cmdtp->cmd) + gd->reloc_off;
  514. #if 0
  515. printf ("Command \"%s\": 0x%08lx => 0x%08lx\n",
  516. cmdtp->name, (ulong) (cmdtp->cmd), addr);
  517. #endif
  518. cmdtp->cmd =
  519. (int (*)(struct cmd_tbl_s *, int, int, char *[]))addr;
  520. addr = (ulong)(cmdtp->name) + gd->reloc_off;
  521. cmdtp->name = (char *)addr;
  522. if (cmdtp->usage) {
  523. addr = (ulong)(cmdtp->usage) + gd->reloc_off;
  524. cmdtp->usage = (char *)addr;
  525. }
  526. #ifdef CFG_LONGHELP
  527. if (cmdtp->help) {
  528. addr = (ulong)(cmdtp->help) + gd->reloc_off;
  529. cmdtp->help = (char *)addr;
  530. }
  531. #endif
  532. }
  533. /* there are some other pointer constants we must deal with */
  534. #ifndef CFG_ENV_IS_NOWHERE
  535. env_name_spec += gd->reloc_off;
  536. #endif
  537. WATCHDOG_RESET ();
  538. #ifdef CONFIG_LOGBUFFER
  539. logbuff_init_ptrs ();
  540. #endif
  541. #ifdef CONFIG_POST
  542. post_output_backlog ();
  543. post_reloc ();
  544. #endif
  545. WATCHDOG_RESET();
  546. #if defined(CONFIG_IP860) || defined(CONFIG_PCU_E) || defined (CONFIG_FLAGADM)
  547. icache_enable (); /* it's time to enable the instruction cache */
  548. #endif
  549. #if defined(CONFIG_BAB7xx) || defined(CONFIG_CPC45)
  550. /*
  551. * Do PCI configuration on BAB7xx and CPC45 _before_ the flash
  552. * gets initialised, because we need the ISA resp. PCI_to_LOCAL bus
  553. * bridge there.
  554. */
  555. pci_init ();
  556. #endif
  557. #if defined(CONFIG_BAB7xx)
  558. /*
  559. * Initialise the ISA bridge
  560. */
  561. initialise_w83c553f ();
  562. #endif
  563. asm ("sync ; isync");
  564. /*
  565. * Setup trap handlers
  566. */
  567. trap_init (dest_addr);
  568. #if !defined(CFG_NO_FLASH)
  569. puts ("FLASH: ");
  570. if ((flash_size = flash_init ()) > 0) {
  571. #ifdef CFG_FLASH_CHECKSUM
  572. print_size (flash_size, "");
  573. /*
  574. * Compute and print flash CRC if flashchecksum is set to 'y'
  575. *
  576. * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
  577. */
  578. s = getenv ("flashchecksum");
  579. if (s && (*s == 'y')) {
  580. printf (" CRC: %08lX",
  581. crc32 (0,
  582. (const unsigned char *) CFG_FLASH_BASE,
  583. flash_size)
  584. );
  585. }
  586. putc ('\n');
  587. #else
  588. print_size (flash_size, "\n");
  589. #endif /* CFG_FLASH_CHECKSUM */
  590. } else {
  591. puts (failed);
  592. hang ();
  593. }
  594. bd->bi_flashstart = CFG_FLASH_BASE; /* update start of FLASH memory */
  595. bd->bi_flashsize = flash_size; /* size of FLASH memory (final value) */
  596. #if defined(CONFIG_PCU_E) || defined(CONFIG_OXC)
  597. bd->bi_flashoffset = 0;
  598. #elif CFG_MONITOR_BASE == CFG_FLASH_BASE
  599. bd->bi_flashoffset = CFG_MONITOR_LEN; /* reserved area for startup monitor */
  600. #else
  601. bd->bi_flashoffset = 0;
  602. #endif
  603. #else
  604. bd->bi_flashsize = 0;
  605. bd->bi_flashstart = 0;
  606. bd->bi_flashoffset = 0;
  607. #endif /* !CFG_NO_FLASH */
  608. WATCHDOG_RESET ();
  609. /* initialize higher level parts of CPU like time base and timers */
  610. cpu_init_r ();
  611. WATCHDOG_RESET ();
  612. /* initialize malloc() area */
  613. mem_malloc_init ();
  614. malloc_bin_reloc ();
  615. #ifdef CONFIG_SPI
  616. # if !defined(CFG_ENV_IS_IN_EEPROM)
  617. spi_init_f ();
  618. # endif
  619. spi_init_r ();
  620. #endif
  621. /* relocate environment function pointers etc. */
  622. env_relocate ();
  623. /*
  624. * Fill in missing fields of bd_info.
  625. * We do this here, where we have "normal" access to the
  626. * environment; we used to do this still running from ROM,
  627. * where had to use getenv_r(), which can be pretty slow when
  628. * the environment is in EEPROM.
  629. */
  630. s = getenv ("ethaddr");
  631. #if defined (CONFIG_MBX) || defined (CONFIG_RPXCLASSIC) || defined(CONFIG_IAD210)
  632. if (s == NULL)
  633. board_get_enetaddr (bd->bi_enetaddr);
  634. else
  635. #endif
  636. for (i = 0; i < 6; ++i) {
  637. bd->bi_enetaddr[i] = s ? simple_strtoul (s, &e, 16) : 0;
  638. if (s)
  639. s = (*e) ? e + 1 : e;
  640. }
  641. #ifdef CONFIG_HERMES
  642. if ((gd->board_type >> 16) == 2)
  643. bd->bi_ethspeed = gd->board_type & 0xFFFF;
  644. else
  645. bd->bi_ethspeed = 0xFFFF;
  646. #endif
  647. #ifdef CONFIG_NX823
  648. load_sernum_ethaddr ();
  649. #endif
  650. #if defined(CFG_GT_6426x) || defined(CONFIG_PN62)
  651. /* handle the 2nd ethernet address */
  652. s = getenv ("eth1addr");
  653. for (i = 0; i < 6; ++i) {
  654. bd->bi_enet1addr[i] = s ? simple_strtoul (s, &e, 16) : 0;
  655. if (s)
  656. s = (*e) ? e + 1 : e;
  657. }
  658. #endif
  659. #if defined(CFG_GT_6426x)
  660. /* handle the 3rd ethernet address */
  661. s = getenv ("eth2addr");
  662. for (i = 0; i < 6; ++i) {
  663. bd->bi_enet2addr[i] = s ? simple_strtoul (s, &e, 16) : 0;
  664. if (s)
  665. s = (*e) ? e + 1 : e;
  666. }
  667. #endif
  668. #if defined(CONFIG_TQM8xxL) || defined(CONFIG_TQM8260) || \
  669. defined(CONFIG_CCM)
  670. load_sernum_ethaddr ();
  671. #endif
  672. /* IP Address */
  673. bd->bi_ip_addr = getenv_IPaddr ("ipaddr");
  674. WATCHDOG_RESET ();
  675. #if defined(CONFIG_PCI) && !defined(CONFIG_BAB7xx)
  676. /*
  677. * Do pci configuration
  678. */
  679. pci_init ();
  680. #endif
  681. /** leave this here (after malloc(), environment and PCI are working) **/
  682. /* Initialize devices */
  683. devices_init ();
  684. /* allocate syscalls table (console_init_r will fill it in */
  685. syscall_tbl = (void **) malloc (NR_SYSCALLS * sizeof (void *));
  686. /* Initialize the console (after the relocation and devices init) */
  687. console_init_r ();
  688. /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/
  689. syscalls_init ();
  690. #if defined(CONFIG_CCM) || \
  691. defined(CONFIG_COGENT) || \
  692. defined(CONFIG_CPCI405) || \
  693. defined(CONFIG_EVB64260) || \
  694. defined(CONFIG_HYMOD) || \
  695. defined(CONFIG_KUP4K) || \
  696. defined(CONFIG_LWMON) || \
  697. defined(CONFIG_PCU_E) || \
  698. defined(CONFIG_W7O) || \
  699. defined(CONFIG_MISC_INIT_R)
  700. /* miscellaneous platform dependent initialisations */
  701. misc_init_r ();
  702. #endif
  703. #ifdef CONFIG_HERMES
  704. if (bd->bi_ethspeed != 0xFFFF)
  705. hermes_start_lxt980 ((int) bd->bi_ethspeed);
  706. #endif
  707. #if (CONFIG_COMMANDS & CFG_CMD_NET) && ( \
  708. defined(CONFIG_CCM) || \
  709. defined(CONFIG_ELPT860) || \
  710. defined(CONFIG_EP8260) || \
  711. defined(CONFIG_IP860) || \
  712. defined(CONFIG_IVML24) || \
  713. defined(CONFIG_IVMS8) || \
  714. defined(CONFIG_LWMON) || \
  715. defined(CONFIG_MPC8260ADS) || \
  716. defined(CONFIG_PCU_E) || \
  717. defined(CONFIG_RPXSUPER) || \
  718. defined(CONFIG_SPD823TS) )
  719. WATCHDOG_RESET ();
  720. # ifdef DEBUG
  721. puts ("Reset Ethernet PHY\n");
  722. # endif
  723. reset_phy ();
  724. #endif
  725. #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
  726. WATCHDOG_RESET ();
  727. puts ("KGDB: ");
  728. kgdb_init ();
  729. #endif
  730. #ifdef DEBUG
  731. printf ("U-Boot relocated to %08lx\n", dest_addr);
  732. #endif
  733. /*
  734. * Enable Interrupts
  735. */
  736. interrupt_init ();
  737. /* Must happen after interrupts are initialized since
  738. * an irq handler gets installed
  739. */
  740. #ifdef CONFIG_SERIAL_SOFTWARE_FIFO
  741. serial_buffered_init();
  742. #endif
  743. #ifdef CONFIG_STATUS_LED
  744. status_led_set (STATUS_LED_BOOT, STATUS_LED_BLINKING);
  745. #endif
  746. udelay (20);
  747. set_timer (0);
  748. /* Insert function pointers now that we have relocated the code */
  749. /* Initialize from environment */
  750. if ((s = getenv ("loadaddr")) != NULL) {
  751. load_addr = simple_strtoul (s, NULL, 16);
  752. }
  753. #if (CONFIG_COMMANDS & CFG_CMD_NET)
  754. if ((s = getenv ("bootfile")) != NULL) {
  755. copy_filename (BootFile, s, sizeof (BootFile));
  756. }
  757. #endif /* CFG_CMD_NET */
  758. WATCHDOG_RESET ();
  759. #if (CONFIG_COMMANDS & CFG_CMD_SCSI)
  760. WATCHDOG_RESET ();
  761. puts ("SCSI: ");
  762. scsi_init ();
  763. #endif
  764. #if (CONFIG_COMMANDS & CFG_CMD_DOC)
  765. WATCHDOG_RESET ();
  766. puts ("DOC: ");
  767. doc_init ();
  768. #endif
  769. #if (CONFIG_COMMANDS & CFG_CMD_NET) && defined(CONFIG_NET_MULTI)
  770. WATCHDOG_RESET ();
  771. puts ("Net: ");
  772. eth_initialize (bd);
  773. #endif
  774. #ifdef CONFIG_POST
  775. post_run (NULL, POST_RAM | post_bootmode_get(0));
  776. if (post_bootmode_get(0) & POST_POWERFAIL) {
  777. post_bootmode_clear();
  778. board_poweroff();
  779. }
  780. #endif
  781. #if (CONFIG_COMMANDS & CFG_CMD_PCMCIA) && !(CONFIG_COMMANDS & CFG_CMD_IDE)
  782. WATCHDOG_RESET ();
  783. puts ("PCMCIA:");
  784. pcmcia_init ();
  785. #endif
  786. #if (CONFIG_COMMANDS & CFG_CMD_IDE)
  787. WATCHDOG_RESET ();
  788. # ifdef CONFIG_IDE_8xx_PCCARD
  789. puts ("PCMCIA:");
  790. # else
  791. puts ("IDE: ");
  792. #endif
  793. ide_init ();
  794. #endif /* CFG_CMD_IDE */
  795. #ifdef CONFIG_LAST_STAGE_INIT
  796. WATCHDOG_RESET ();
  797. /*
  798. * Some parts can be only initialized if all others (like
  799. * Interrupts) are up and running (i.e. the PC-style ISA
  800. * keyboard).
  801. */
  802. last_stage_init ();
  803. #endif
  804. #if (CONFIG_COMMANDS & CFG_CMD_BEDBUG)
  805. WATCHDOG_RESET ();
  806. bedbug_init ();
  807. #endif
  808. #if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
  809. /*
  810. * Export available size of memory for Linux,
  811. * taking into account the protected RAM at top of memory
  812. */
  813. {
  814. ulong pram;
  815. uchar memsz[32];
  816. #ifdef CONFIG_PRAM
  817. char *s;
  818. if ((s = getenv ("pram")) != NULL) {
  819. pram = simple_strtoul (s, NULL, 10);
  820. } else {
  821. pram = CONFIG_PRAM;
  822. }
  823. #else
  824. pram=0;
  825. #endif
  826. #ifdef CONFIG_LOGBUFFER
  827. /* Also take the logbuffer into account (pram is in kB) */
  828. pram += (LOGBUFF_LEN+LOGBUFF_OVERHEAD)/1024;
  829. #endif
  830. sprintf (memsz, "%ldk", (bd->bi_memsize / 1024) - pram);
  831. setenv ("mem", memsz);
  832. }
  833. #endif
  834. #ifdef CONFIG_MODEM_SUPPORT
  835. {
  836. extern int do_mdm_init;
  837. do_mdm_init = gd->do_mdm_init;
  838. }
  839. #endif
  840. /* Initialization complete - start the monitor */
  841. /* main_loop() can return to retry autoboot, if so just run it again. */
  842. for (;;) {
  843. WATCHDOG_RESET ();
  844. main_loop ();
  845. }
  846. /* NOTREACHED - no way out of command loop except booting */
  847. }
  848. void hang (void)
  849. {
  850. puts ("### ERROR ### Please RESET the board ###\n");
  851. for (;;);
  852. }
  853. #ifdef CONFIG_MODEM_SUPPORT
  854. /* called from main loop (common/main.c) */
  855. extern void dbg(const char *fmt, ...);
  856. int mdm_init (void)
  857. {
  858. char env_str[16];
  859. char *init_str;
  860. int i;
  861. extern char console_buffer[];
  862. static inline void mdm_readline(char *buf, int bufsiz);
  863. extern void enable_putc(void);
  864. extern int hwflow_onoff(int);
  865. enable_putc(); /* enable serial_putc() */
  866. #ifdef CONFIG_HWFLOW
  867. init_str = getenv("mdm_flow_control");
  868. if (init_str && (strcmp(init_str, "rts/cts") == 0))
  869. hwflow_onoff (1);
  870. else
  871. hwflow_onoff(-1);
  872. #endif
  873. for (i = 1;;i++) {
  874. sprintf(env_str, "mdm_init%d", i);
  875. if ((init_str = getenv(env_str)) != NULL) {
  876. serial_puts(init_str);
  877. serial_puts("\n");
  878. for(;;) {
  879. mdm_readline(console_buffer, CFG_CBSIZE);
  880. dbg("ini%d: [%s]", i, console_buffer);
  881. if ((strcmp(console_buffer, "OK") == 0) ||
  882. (strcmp(console_buffer, "ERROR") == 0)) {
  883. dbg("ini%d: cmd done", i);
  884. break;
  885. } else /* in case we are originating call ... */
  886. if (strncmp(console_buffer, "CONNECT", 7) == 0) {
  887. dbg("ini%d: connect", i);
  888. return 0;
  889. }
  890. }
  891. } else
  892. break; /* no init string - stop modem init */
  893. udelay(100000);
  894. }
  895. udelay(100000);
  896. /* final stage - wait for connect */
  897. for(;i > 1;) { /* if 'i' > 1 - wait for connection
  898. message from modem */
  899. mdm_readline(console_buffer, CFG_CBSIZE);
  900. dbg("ini_f: [%s]", console_buffer);
  901. if (strncmp(console_buffer, "CONNECT", 7) == 0) {
  902. dbg("ini_f: connected");
  903. return 0;
  904. }
  905. }
  906. return 0;
  907. }
  908. /* 'inline' - We have to do it fast */
  909. static inline void mdm_readline(char *buf, int bufsiz)
  910. {
  911. char c;
  912. char *p;
  913. int n;
  914. n = 0;
  915. p = buf;
  916. for(;;) {
  917. c = serial_getc();
  918. /* dbg("(%c)", c); */
  919. switch(c) {
  920. case '\r':
  921. break;
  922. case '\n':
  923. *p = '\0';
  924. return;
  925. default:
  926. if(n++ > bufsiz) {
  927. *p = '\0';
  928. return; /* sanity check */
  929. }
  930. *p = c;
  931. p++;
  932. break;
  933. }
  934. }
  935. }
  936. #endif
  937. #if 0 /* We could use plain global data, but the resulting code is bigger */
  938. /*
  939. * Pointer to initial global data area
  940. *
  941. * Here we initialize it.
  942. */
  943. #undef XTRN_DECLARE_GLOBAL_DATA_PTR
  944. #define XTRN_DECLARE_GLOBAL_DATA_PTR /* empty = allocate here */
  945. DECLARE_GLOBAL_DATA_PTR = (gd_t *) (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET);
  946. #endif /* 0 */
  947. /************************************************************************/