board.c 26 KB

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