board.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107
  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. #ifdef CONFIG_MPC5XXX
  36. #include <mpc5xxx.h>
  37. #endif
  38. #if (CONFIG_COMMANDS & CFG_CMD_IDE)
  39. #include <ide.h>
  40. #endif
  41. #if (CONFIG_COMMANDS & CFG_CMD_SCSI)
  42. #include <scsi.h>
  43. #endif
  44. #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
  45. #include <kgdb.h>
  46. #endif
  47. #ifdef CONFIG_STATUS_LED
  48. #include <status_led.h>
  49. #endif
  50. #include <net.h>
  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. #if (CONFIG_COMMANDS & CFG_CMD_NAND)
  75. void nand_init (void);
  76. #endif
  77. static char *failed = "*** failed ***\n";
  78. #if defined(CONFIG_PCU_E) || defined(CONFIG_OXC)
  79. extern flash_info_t flash_info[];
  80. #endif
  81. #include <environment.h>
  82. #if ( ((CFG_ENV_ADDR+CFG_ENV_SIZE) < CFG_MONITOR_BASE) || \
  83. (CFG_ENV_ADDR >= (CFG_MONITOR_BASE + CFG_MONITOR_LEN)) ) || \
  84. defined(CFG_ENV_IS_IN_NVRAM)
  85. #define TOTAL_MALLOC_LEN (CFG_MALLOC_LEN + CFG_ENV_SIZE)
  86. #else
  87. #define TOTAL_MALLOC_LEN CFG_MALLOC_LEN
  88. #endif
  89. extern ulong __init_end;
  90. extern ulong _end;
  91. ulong monitor_flash_len;
  92. #if (CONFIG_COMMANDS & CFG_CMD_BEDBUG)
  93. #include <bedbug/type.h>
  94. #endif
  95. /*
  96. * Begin and End of memory area for malloc(), and current "brk"
  97. */
  98. static ulong mem_malloc_start = 0;
  99. static ulong mem_malloc_end = 0;
  100. static ulong mem_malloc_brk = 0;
  101. /************************************************************************
  102. * Utilities *
  103. ************************************************************************
  104. */
  105. /*
  106. * The Malloc area is immediately below the monitor copy in DRAM
  107. */
  108. static void mem_malloc_init (void)
  109. {
  110. DECLARE_GLOBAL_DATA_PTR;
  111. ulong dest_addr = CFG_MONITOR_BASE + gd->reloc_off;
  112. mem_malloc_end = dest_addr;
  113. mem_malloc_start = dest_addr - TOTAL_MALLOC_LEN;
  114. mem_malloc_brk = mem_malloc_start;
  115. memset ((void *) mem_malloc_start,
  116. 0,
  117. mem_malloc_end - mem_malloc_start);
  118. }
  119. void *sbrk (ptrdiff_t increment)
  120. {
  121. ulong old = mem_malloc_brk;
  122. ulong new = old + increment;
  123. if ((new < mem_malloc_start) || (new > mem_malloc_end)) {
  124. return (NULL);
  125. }
  126. mem_malloc_brk = new;
  127. return ((void *) old);
  128. }
  129. char *strmhz (char *buf, long hz)
  130. {
  131. long l, n;
  132. long m;
  133. n = hz / 1000000L;
  134. l = sprintf (buf, "%ld", n);
  135. m = (hz % 1000000L) / 1000L;
  136. if (m != 0)
  137. sprintf (buf + l, ".%03ld", m);
  138. return (buf);
  139. }
  140. static void syscalls_init (void)
  141. {
  142. ulong *addr;
  143. syscall_tbl[SYSCALL_MALLOC] = (void *) malloc;
  144. syscall_tbl[SYSCALL_FREE] = (void *) free;
  145. syscall_tbl[SYSCALL_INSTALL_HDLR] = (void *) irq_install_handler;
  146. syscall_tbl[SYSCALL_FREE_HDLR] = (void *) irq_free_handler;
  147. syscall_tbl[SYSCALL_GET_TIMER] = (void *)get_timer;
  148. syscall_tbl[SYSCALL_UDELAY] = (void *)udelay;
  149. addr = (ulong *) 0xc00; /* syscall ISR addr */
  150. /* patch ISR code */
  151. *addr++ |= (ulong) syscall_tbl >> 16;
  152. *addr++ |= (ulong) syscall_tbl & 0xFFFF;
  153. *addr++ |= NR_SYSCALLS >> 16;
  154. *addr++ |= NR_SYSCALLS & 0xFFFF;
  155. #ifndef CONFIG_5XX
  156. flush_cache (0x0C00, 0x10);
  157. #endif
  158. /* Initialize syscalls stack pointer */
  159. addr = (ulong *) 0xCFC;
  160. *addr = (ulong)addr;
  161. #ifndef CONFIG_5xx
  162. flush_cache ((ulong)addr, 0x10);
  163. #endif
  164. }
  165. /*
  166. * All attempts to come up with a "common" initialization sequence
  167. * that works for all boards and architectures failed: some of the
  168. * requirements are just _too_ different. To get rid of the resulting
  169. * mess of board dependend #ifdef'ed code we now make the whole
  170. * initialization sequence configurable to the user.
  171. *
  172. * The requirements for any new initalization function is simple: it
  173. * receives a pointer to the "global data" structure as it's only
  174. * argument, and returns an integer return code, where 0 means
  175. * "continue" and != 0 means "fatal error, hang the system".
  176. */
  177. typedef int (init_fnc_t) (void);
  178. /************************************************************************
  179. * Init Utilities *
  180. ************************************************************************
  181. * Some of this code should be moved into the core functions,
  182. * but let's get it working (again) first...
  183. */
  184. static int init_baudrate (void)
  185. {
  186. DECLARE_GLOBAL_DATA_PTR;
  187. uchar tmp[64]; /* long enough for environment variables */
  188. int i = getenv_r ("baudrate", tmp, sizeof (tmp));
  189. gd->baudrate = (i > 0)
  190. ? (int) simple_strtoul (tmp, NULL, 10)
  191. : CONFIG_BAUDRATE;
  192. return (0);
  193. }
  194. /***********************************************************************/
  195. static int init_func_ram (void)
  196. {
  197. DECLARE_GLOBAL_DATA_PTR;
  198. #ifdef CONFIG_BOARD_TYPES
  199. int board_type = gd->board_type;
  200. #else
  201. int board_type = 0; /* use dummy arg */
  202. #endif
  203. puts ("DRAM: ");
  204. if ((gd->ram_size = initdram (board_type)) > 0) {
  205. print_size (gd->ram_size, "\n");
  206. return (0);
  207. }
  208. puts (failed);
  209. return (1);
  210. }
  211. /***********************************************************************/
  212. #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
  213. static int init_func_i2c (void)
  214. {
  215. puts ("I2C: ");
  216. i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE);
  217. puts ("ready\n");
  218. return (0);
  219. }
  220. #endif
  221. /***********************************************************************/
  222. #if defined(CONFIG_WATCHDOG)
  223. static int init_func_watchdog_init (void)
  224. {
  225. puts (" Watchdog enabled\n");
  226. WATCHDOG_RESET ();
  227. return (0);
  228. }
  229. # define INIT_FUNC_WATCHDOG_INIT init_func_watchdog_init,
  230. static int init_func_watchdog_reset (void)
  231. {
  232. WATCHDOG_RESET ();
  233. return (0);
  234. }
  235. # define INIT_FUNC_WATCHDOG_RESET init_func_watchdog_reset,
  236. #else
  237. # define INIT_FUNC_WATCHDOG_INIT /* undef */
  238. # define INIT_FUNC_WATCHDOG_RESET /* undef */
  239. #endif /* CONFIG_WATCHDOG */
  240. /************************************************************************
  241. * Initialization sequence *
  242. ************************************************************************
  243. */
  244. init_fnc_t *init_sequence[] = {
  245. #if defined(CONFIG_BOARD_PRE_INIT)
  246. board_pre_init, /* very early board init code (fpga boot, etc.) */
  247. #endif
  248. get_clocks, /* get CPU and bus clocks (etc.) */
  249. init_timebase,
  250. #ifdef CFG_ALLOC_DPRAM
  251. #if !defined(CONFIG_8260)
  252. dpram_init,
  253. #endif
  254. #endif
  255. #if defined(CONFIG_BOARD_POSTCLK_INIT)
  256. board_postclk_init,
  257. #endif
  258. env_init,
  259. init_baudrate,
  260. serial_init,
  261. console_init_f,
  262. display_options,
  263. #if defined(CONFIG_8260)
  264. prt_8260_rsr,
  265. prt_8260_clks,
  266. #endif /* CONFIG_8260 */
  267. checkcpu,
  268. #if defined(CONFIG_MPC5XXX)
  269. prt_mpc5xxx_clks,
  270. #endif /* CONFIG_MPC5XXX */
  271. checkboard,
  272. INIT_FUNC_WATCHDOG_INIT
  273. #if defined(CONFIG_BMW) || \
  274. defined(CONFIG_COGENT) || \
  275. defined(CONFIG_HYMOD) || \
  276. defined(CONFIG_RSD_PROTO) || \
  277. defined(CONFIG_W7O)
  278. misc_init_f,
  279. #endif
  280. INIT_FUNC_WATCHDOG_RESET
  281. #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
  282. init_func_i2c,
  283. #endif
  284. #if defined(CONFIG_DTT) /* Digital Thermometers and Thermostats */
  285. dtt_init,
  286. #endif
  287. #ifdef CONFIG_POST
  288. post_init_f,
  289. #endif
  290. INIT_FUNC_WATCHDOG_RESET
  291. init_func_ram,
  292. #if defined(CFG_DRAM_TEST)
  293. testdram,
  294. #endif /* CFG_DRAM_TEST */
  295. INIT_FUNC_WATCHDOG_RESET
  296. NULL, /* Terminate this list */
  297. };
  298. /************************************************************************
  299. *
  300. * This is the first part of the initialization sequence that is
  301. * implemented in C, but still running from ROM.
  302. *
  303. * The main purpose is to provide a (serial) console interface as
  304. * soon as possible (so we can see any error messages), and to
  305. * initialize the RAM so that we can relocate the monitor code to
  306. * RAM.
  307. *
  308. * Be aware of the restrictions: global data is read-only, BSS is not
  309. * initialized, and stack space is limited to a few kB.
  310. *
  311. ************************************************************************
  312. */
  313. void board_init_f (ulong bootflag)
  314. {
  315. DECLARE_GLOBAL_DATA_PTR;
  316. bd_t *bd;
  317. ulong len, addr, addr_sp;
  318. gd_t *id;
  319. init_fnc_t **init_fnc_ptr;
  320. #ifdef CONFIG_PRAM
  321. int i;
  322. ulong reg;
  323. uchar tmp[64]; /* long enough for environment variables */
  324. #endif
  325. /* Pointer is writable since we allocated a register for it */
  326. gd = (gd_t *) (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET);
  327. #ifndef CONFIG_8260
  328. /* Clear initial global data */
  329. memset ((void *) gd, 0, sizeof (gd_t));
  330. #endif
  331. for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
  332. if ((*init_fnc_ptr) () != 0) {
  333. hang ();
  334. }
  335. }
  336. /*
  337. * Now that we have DRAM mapped and working, we can
  338. * relocate the code and continue running from DRAM.
  339. *
  340. * Reserve memory at end of RAM for (top down in that order):
  341. * - kernel log buffer
  342. * - protected RAM
  343. * - LCD framebuffer
  344. * - monitor code
  345. * - board info struct
  346. */
  347. len = (ulong)&_end - CFG_MONITOR_BASE;
  348. #ifndef CONFIG_VERY_BIG_RAM
  349. addr = CFG_SDRAM_BASE + gd->ram_size;
  350. #else
  351. /* only allow stack below 256M */
  352. addr = CFG_SDRAM_BASE +
  353. (gd->ram_size > 256 << 20) ? 256 << 20 : gd->ram_size;
  354. #endif
  355. #ifdef CONFIG_LOGBUFFER
  356. /* reserve kernel log buffer */
  357. addr -= (LOGBUFF_RESERVE);
  358. debug ("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN, addr);
  359. #endif
  360. #ifdef CONFIG_PRAM
  361. /*
  362. * reserve protected RAM
  363. */
  364. i = getenv_r ("pram", tmp, sizeof (tmp));
  365. reg = (i > 0) ? simple_strtoul (tmp, NULL, 10) : CONFIG_PRAM;
  366. addr -= (reg << 10); /* size is in kB */
  367. debug ("Reserving %ldk for protected RAM at %08lx\n", reg, addr);
  368. #endif /* CONFIG_PRAM */
  369. /* round down to next 4 kB limit */
  370. addr &= ~(4096 - 1);
  371. debug ("Top of RAM usable for U-Boot at: %08lx\n", addr);
  372. #ifdef CONFIG_LCD
  373. /* reserve memory for LCD display (always full pages) */
  374. addr = lcd_setmem (addr);
  375. gd->fb_base = addr;
  376. #endif /* CONFIG_LCD */
  377. #if defined(CONFIG_VIDEO) && defined(CONFIG_8xx)
  378. /* reserve memory for video display (always full pages) */
  379. addr = video_setmem (addr);
  380. gd->fb_base = addr;
  381. #endif /* CONFIG_VIDEO */
  382. /*
  383. * reserve memory for U-Boot code, data & bss
  384. * round down to next 4 kB limit
  385. */
  386. addr -= len;
  387. addr &= ~(4096 - 1);
  388. debug ("Reserving %ldk for U-Boot at: %08lx\n", len >> 10, addr);
  389. #ifdef CONFIG_AMIGAONEG3SE
  390. gd->relocaddr = addr;
  391. #endif
  392. /*
  393. * reserve memory for malloc() arena
  394. */
  395. addr_sp = addr - TOTAL_MALLOC_LEN;
  396. debug ("Reserving %dk for malloc() at: %08lx\n",
  397. TOTAL_MALLOC_LEN >> 10, addr_sp);
  398. /*
  399. * (permanently) allocate a Board Info struct
  400. * and a permanent copy of the "global" data
  401. */
  402. addr_sp -= sizeof (bd_t);
  403. bd = (bd_t *) addr_sp;
  404. gd->bd = bd;
  405. debug ("Reserving %d Bytes for Board Info at: %08lx\n",
  406. sizeof (bd_t), addr_sp);
  407. addr_sp -= sizeof (gd_t);
  408. id = (gd_t *) addr_sp;
  409. debug ("Reserving %d Bytes for Global Data at: %08lx\n",
  410. sizeof (gd_t), addr_sp);
  411. /*
  412. * Finally, we set up a new (bigger) stack.
  413. *
  414. * Leave some safety gap for SP, force alignment on 16 byte boundary
  415. * Clear initial stack frame
  416. */
  417. addr_sp -= 16;
  418. addr_sp &= ~0xF;
  419. *((ulong *) addr_sp)-- = 0;
  420. *((ulong *) addr_sp)-- = 0;
  421. debug ("Stack Pointer at: %08lx\n", addr_sp);
  422. /*
  423. * Save local variables to board info struct
  424. */
  425. bd->bi_memstart = CFG_SDRAM_BASE; /* start of DRAM memory */
  426. bd->bi_memsize = gd->ram_size; /* size of DRAM memory in bytes */
  427. #ifdef CONFIG_IP860
  428. bd->bi_sramstart = SRAM_BASE; /* start of SRAM memory */
  429. bd->bi_sramsize = SRAM_SIZE; /* size of SRAM memory */
  430. #else
  431. bd->bi_sramstart = 0; /* FIXME */ /* start of SRAM memory */
  432. bd->bi_sramsize = 0; /* FIXME */ /* size of SRAM memory */
  433. #endif
  434. #if defined(CONFIG_8xx) || defined(CONFIG_8260) || defined(CONFIG_5xx)
  435. bd->bi_immr_base = CFG_IMMR; /* base of IMMR register */
  436. #endif
  437. #if defined(CONFIG_MPC5XXX)
  438. bd->bi_mbar_base = CFG_MBAR; /* base of internal registers */
  439. #endif
  440. bd->bi_bootflags = bootflag; /* boot / reboot flag (for LynxOS) */
  441. WATCHDOG_RESET ();
  442. bd->bi_intfreq = gd->cpu_clk; /* Internal Freq, in Hz */
  443. bd->bi_busfreq = gd->bus_clk; /* Bus Freq, in Hz */
  444. #if defined(CONFIG_8260)
  445. bd->bi_cpmfreq = gd->cpm_clk;
  446. bd->bi_brgfreq = gd->brg_clk;
  447. bd->bi_sccfreq = gd->scc_clk;
  448. bd->bi_vco = gd->vco_out;
  449. #endif /* CONFIG_8260 */
  450. #if defined(CONFIG_MPC5XXX)
  451. bd->bi_ipbfreq = gd->ipb_clk;
  452. bd->bi_pcifreq = gd->pci_clk;
  453. #endif /* CONFIG_MPC5XXX */
  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. #if defined(CONFIG_405GP) || defined(CONFIG_405EP)
  461. bd->bi_pci_busfreq = get_PCI_freq ();
  462. #endif
  463. #endif
  464. debug ("New Stack Pointer is: %08lx\n", addr_sp);
  465. WATCHDOG_RESET ();
  466. #ifdef CONFIG_POST
  467. post_bootmode_init();
  468. post_run (NULL, POST_ROM | post_bootmode_get(0));
  469. #endif
  470. WATCHDOG_RESET();
  471. memcpy (id, gd, sizeof (gd_t));
  472. relocate_code (addr_sp, id, addr);
  473. /* NOTREACHED - relocate_code() does not return */
  474. }
  475. /************************************************************************
  476. *
  477. * This is the next part if the initialization sequence: we are now
  478. * running from RAM and have a "normal" C environment, i. e. global
  479. * data can be written, BSS has been cleared, the stack size in not
  480. * that critical any more, etc.
  481. *
  482. ************************************************************************
  483. */
  484. void board_init_r (gd_t *id, ulong dest_addr)
  485. {
  486. DECLARE_GLOBAL_DATA_PTR;
  487. cmd_tbl_t *cmdtp;
  488. char *s, *e;
  489. bd_t *bd;
  490. int i;
  491. extern void malloc_bin_reloc (void);
  492. #ifndef CFG_ENV_IS_NOWHERE
  493. extern char * env_name_spec;
  494. #endif
  495. #ifndef CFG_NO_FLASH
  496. ulong flash_size;
  497. #endif
  498. gd = id; /* initialize RAM version of global data */
  499. bd = gd->bd;
  500. gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
  501. debug ("Now running in RAM - U-Boot at: %08lx\n", dest_addr);
  502. WATCHDOG_RESET ();
  503. gd->reloc_off = dest_addr - CFG_MONITOR_BASE;
  504. monitor_flash_len = (ulong)&__init_end - dest_addr;
  505. /*
  506. * We have to relocate the command table manually
  507. */
  508. for (cmdtp = &__u_boot_cmd_start; cmdtp != &__u_boot_cmd_end; 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 = monitor_flash_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_KUP4K) || \
  692. defined(CONFIG_LWMON) || \
  693. defined(CONFIG_PCU_E) || \
  694. defined(CONFIG_W7O) || \
  695. defined(CONFIG_MISC_INIT_R)
  696. /* miscellaneous platform dependent initialisations */
  697. misc_init_r ();
  698. #endif
  699. #ifdef CONFIG_HERMES
  700. if (bd->bi_ethspeed != 0xFFFF)
  701. hermes_start_lxt980 ((int) bd->bi_ethspeed);
  702. #endif
  703. #if (CONFIG_COMMANDS & CFG_CMD_NET) && ( \
  704. defined(CONFIG_CCM) || \
  705. defined(CONFIG_ELPT860) || \
  706. defined(CONFIG_EP8260) || \
  707. defined(CONFIG_IP860) || \
  708. defined(CONFIG_IVML24) || \
  709. defined(CONFIG_IVMS8) || \
  710. defined(CONFIG_LWMON) || \
  711. defined(CONFIG_MPC8260ADS) || \
  712. defined(CONFIG_MPC8266ADS) || \
  713. defined(CONFIG_PCU_E) || \
  714. defined(CONFIG_RPXSUPER) || \
  715. defined(CONFIG_SPD823TS) )
  716. WATCHDOG_RESET ();
  717. debug ("Reset Ethernet PHY\n");
  718. reset_phy ();
  719. #endif
  720. #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
  721. WATCHDOG_RESET ();
  722. puts ("KGDB: ");
  723. kgdb_init ();
  724. #endif
  725. debug ("U-Boot relocated to %08lx\n", dest_addr);
  726. /*
  727. * Enable Interrupts
  728. */
  729. interrupt_init ();
  730. /* Must happen after interrupts are initialized since
  731. * an irq handler gets installed
  732. */
  733. #ifdef CONFIG_SERIAL_SOFTWARE_FIFO
  734. serial_buffered_init();
  735. #endif
  736. #ifdef CONFIG_STATUS_LED
  737. status_led_set (STATUS_LED_BOOT, STATUS_LED_BLINKING);
  738. #endif
  739. udelay (20);
  740. set_timer (0);
  741. /* Insert function pointers now that we have relocated the code */
  742. /* Initialize from environment */
  743. if ((s = getenv ("loadaddr")) != NULL) {
  744. load_addr = simple_strtoul (s, NULL, 16);
  745. }
  746. #if (CONFIG_COMMANDS & CFG_CMD_NET)
  747. if ((s = getenv ("bootfile")) != NULL) {
  748. copy_filename (BootFile, s, sizeof (BootFile));
  749. }
  750. #endif /* CFG_CMD_NET */
  751. WATCHDOG_RESET ();
  752. #if (CONFIG_COMMANDS & CFG_CMD_SCSI)
  753. WATCHDOG_RESET ();
  754. puts ("SCSI: ");
  755. scsi_init ();
  756. #endif
  757. #if (CONFIG_COMMANDS & CFG_CMD_DOC)
  758. WATCHDOG_RESET ();
  759. puts ("DOC: ");
  760. doc_init ();
  761. #endif
  762. #if (CONFIG_COMMANDS & CFG_CMD_NAND)
  763. WATCHDOG_RESET ();
  764. nand_init(); /* go init the NAND */
  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. #endif
  774. #if (CONFIG_COMMANDS & CFG_CMD_PCMCIA) && !(CONFIG_COMMANDS & CFG_CMD_IDE)
  775. WATCHDOG_RESET ();
  776. puts ("PCMCIA:");
  777. pcmcia_init ();
  778. #endif
  779. #if (CONFIG_COMMANDS & CFG_CMD_IDE)
  780. WATCHDOG_RESET ();
  781. # ifdef CONFIG_IDE_8xx_PCCARD
  782. puts ("PCMCIA:");
  783. # else
  784. puts ("IDE: ");
  785. #endif
  786. ide_init ();
  787. #endif /* CFG_CMD_IDE */
  788. #ifdef CONFIG_LAST_STAGE_INIT
  789. WATCHDOG_RESET ();
  790. /*
  791. * Some parts can be only initialized if all others (like
  792. * Interrupts) are up and running (i.e. the PC-style ISA
  793. * keyboard).
  794. */
  795. last_stage_init ();
  796. #endif
  797. #if (CONFIG_COMMANDS & CFG_CMD_BEDBUG)
  798. WATCHDOG_RESET ();
  799. bedbug_init ();
  800. #endif
  801. #if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
  802. /*
  803. * Export available size of memory for Linux,
  804. * taking into account the protected RAM at top of memory
  805. */
  806. {
  807. ulong pram;
  808. uchar memsz[32];
  809. #ifdef CONFIG_PRAM
  810. char *s;
  811. if ((s = getenv ("pram")) != NULL) {
  812. pram = simple_strtoul (s, NULL, 10);
  813. } else {
  814. pram = CONFIG_PRAM;
  815. }
  816. #else
  817. pram=0;
  818. #endif
  819. #ifdef CONFIG_LOGBUFFER
  820. /* Also take the logbuffer into account (pram is in kB) */
  821. pram += (LOGBUFF_LEN+LOGBUFF_OVERHEAD)/1024;
  822. #endif
  823. sprintf (memsz, "%ldk", (bd->bi_memsize / 1024) - pram);
  824. setenv ("mem", memsz);
  825. }
  826. #endif
  827. #ifdef CONFIG_MODEM_SUPPORT
  828. {
  829. extern int do_mdm_init;
  830. do_mdm_init = gd->do_mdm_init;
  831. }
  832. #endif
  833. /* Initialization complete - start the monitor */
  834. /* main_loop() can return to retry autoboot, if so just run it again. */
  835. for (;;) {
  836. WATCHDOG_RESET ();
  837. main_loop ();
  838. }
  839. /* NOTREACHED - no way out of command loop except booting */
  840. }
  841. void hang (void)
  842. {
  843. puts ("### ERROR ### Please RESET the board ###\n");
  844. for (;;);
  845. }
  846. #ifdef CONFIG_MODEM_SUPPORT
  847. /* called from main loop (common/main.c) */
  848. extern void dbg(const char *fmt, ...);
  849. int mdm_init (void)
  850. {
  851. char env_str[16];
  852. char *init_str;
  853. int i;
  854. extern char console_buffer[];
  855. static inline void mdm_readline(char *buf, int bufsiz);
  856. extern void enable_putc(void);
  857. extern int hwflow_onoff(int);
  858. enable_putc(); /* enable serial_putc() */
  859. #ifdef CONFIG_HWFLOW
  860. init_str = getenv("mdm_flow_control");
  861. if (init_str && (strcmp(init_str, "rts/cts") == 0))
  862. hwflow_onoff (1);
  863. else
  864. hwflow_onoff(-1);
  865. #endif
  866. for (i = 1;;i++) {
  867. sprintf(env_str, "mdm_init%d", i);
  868. if ((init_str = getenv(env_str)) != NULL) {
  869. serial_puts(init_str);
  870. serial_puts("\n");
  871. for(;;) {
  872. mdm_readline(console_buffer, CFG_CBSIZE);
  873. dbg("ini%d: [%s]", i, console_buffer);
  874. if ((strcmp(console_buffer, "OK") == 0) ||
  875. (strcmp(console_buffer, "ERROR") == 0)) {
  876. dbg("ini%d: cmd done", i);
  877. break;
  878. } else /* in case we are originating call ... */
  879. if (strncmp(console_buffer, "CONNECT", 7) == 0) {
  880. dbg("ini%d: connect", i);
  881. return 0;
  882. }
  883. }
  884. } else
  885. break; /* no init string - stop modem init */
  886. udelay(100000);
  887. }
  888. udelay(100000);
  889. /* final stage - wait for connect */
  890. for(;i > 1;) { /* if 'i' > 1 - wait for connection
  891. message from modem */
  892. mdm_readline(console_buffer, CFG_CBSIZE);
  893. dbg("ini_f: [%s]", console_buffer);
  894. if (strncmp(console_buffer, "CONNECT", 7) == 0) {
  895. dbg("ini_f: connected");
  896. return 0;
  897. }
  898. }
  899. return 0;
  900. }
  901. /* 'inline' - We have to do it fast */
  902. static inline void mdm_readline(char *buf, int bufsiz)
  903. {
  904. char c;
  905. char *p;
  906. int n;
  907. n = 0;
  908. p = buf;
  909. for(;;) {
  910. c = serial_getc();
  911. /* dbg("(%c)", c); */
  912. switch(c) {
  913. case '\r':
  914. break;
  915. case '\n':
  916. *p = '\0';
  917. return;
  918. default:
  919. if(n++ > bufsiz) {
  920. *p = '\0';
  921. return; /* sanity check */
  922. }
  923. *p = c;
  924. p++;
  925. break;
  926. }
  927. }
  928. }
  929. #endif
  930. #if 0 /* We could use plain global data, but the resulting code is bigger */
  931. /*
  932. * Pointer to initial global data area
  933. *
  934. * Here we initialize it.
  935. */
  936. #undef XTRN_DECLARE_GLOBAL_DATA_PTR
  937. #define XTRN_DECLARE_GLOBAL_DATA_PTR /* empty = allocate here */
  938. DECLARE_GLOBAL_DATA_PTR = (gd_t *) (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET);
  939. #endif /* 0 */
  940. /************************************************************************/