board.c 23 KB

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