board.c 26 KB

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