board.c 23 KB

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