board.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998
  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. * - kernel log buffer
  316. * - protected RAM
  317. * - LCD framebuffer
  318. * - monitor code
  319. * - board info struct
  320. */
  321. len = get_endaddr () - CFG_MONITOR_BASE;
  322. if (len > CFG_MONITOR_LEN) {
  323. printf ("*** U-Boot size %ld > reserved memory (%d)\n",
  324. len, CFG_MONITOR_LEN);
  325. hang ();
  326. }
  327. if (CFG_MONITOR_LEN > len)
  328. len = CFG_MONITOR_LEN;
  329. #ifndef CONFIG_VERY_BIG_RAM
  330. addr = CFG_SDRAM_BASE + gd->ram_size;
  331. #else
  332. /* only allow stack below 256M */
  333. addr = CFG_SDRAM_BASE +
  334. (gd->ram_size > 256 << 20) ? 256 << 20 : gd->ram_size;
  335. #endif
  336. #ifdef CONFIG_LOGBUFFER
  337. /* reserve kernel log buffer */
  338. addr -= (LOGBUFF_RESERVE);
  339. # ifdef DEBUG
  340. printf ("Reserving %ldk for kernel logbuffer at %08lx\n", LOGBUFF_LEN, addr);
  341. # endif
  342. #endif
  343. #ifdef CONFIG_PRAM
  344. /*
  345. * reserve protected RAM
  346. */
  347. i = getenv_r ("pram", tmp, sizeof (tmp));
  348. reg = (i > 0) ? simple_strtoul (tmp, NULL, 10) : CONFIG_PRAM;
  349. addr -= (reg << 10); /* size is in kB */
  350. # ifdef DEBUG
  351. printf ("Reserving %ldk for protected RAM at %08lx\n", reg, addr);
  352. # endif
  353. #endif /* CONFIG_PRAM */
  354. /* round down to next 4 kB limit */
  355. addr &= ~(4096 - 1);
  356. #ifdef DEBUG
  357. printf ("Top of RAM usable for U-Boot at: %08lx\n", addr);
  358. #endif
  359. #ifdef CONFIG_LCD
  360. /* reserve memory for LCD display (always full pages) */
  361. addr = lcd_setmem (addr);
  362. gd->fb_base = addr;
  363. #endif /* CONFIG_LCD */
  364. #if defined(CONFIG_VIDEO) && defined(CONFIG_8xx)
  365. /* reserve memory for video display (always full pages) */
  366. addr = video_setmem (addr);
  367. gd->fb_base = addr;
  368. #endif /* CONFIG_VIDEO */
  369. /*
  370. * reserve memory for U-Boot code, data & bss
  371. * round down to next 4 kB limit
  372. */
  373. addr -= len;
  374. addr &= ~(4096 - 1);
  375. #ifdef DEBUG
  376. printf ("Reserving %ldk for U-Boot at: %08lx\n", len >> 10, addr);
  377. #endif
  378. #ifdef CONFIG_AMIGAONEG3SE
  379. gd->relocaddr = addr;
  380. #endif
  381. /*
  382. * reserve memory for malloc() arena
  383. */
  384. addr_sp = addr - TOTAL_MALLOC_LEN;
  385. #ifdef DEBUG
  386. printf ("Reserving %dk for malloc() at: %08lx\n",
  387. TOTAL_MALLOC_LEN >> 10, addr_sp);
  388. #endif
  389. /*
  390. * (permanently) allocate a Board Info struct
  391. * and a permanent copy of the "global" data
  392. */
  393. addr_sp -= sizeof (bd_t);
  394. bd = (bd_t *) addr_sp;
  395. gd->bd = bd;
  396. #ifdef DEBUG
  397. printf ("Reserving %d Bytes for Board Info at: %08lx\n",
  398. sizeof (bd_t), addr_sp);
  399. #endif
  400. addr_sp -= sizeof (gd_t);
  401. id = (gd_t *) addr_sp;
  402. #ifdef DEBUG
  403. printf ("Reserving %d Bytes for Global Data at: %08lx\n",
  404. sizeof (gd_t), addr_sp);
  405. #endif
  406. /*
  407. * Finally, we set up a new (bigger) stack.
  408. *
  409. * Leave some safety gap for SP, force alignment on 16 byte boundary
  410. * Clear initial stack frame
  411. */
  412. addr_sp -= 16;
  413. addr_sp &= ~0xF;
  414. *((ulong *) addr_sp)-- = 0;
  415. *((ulong *) addr_sp)-- = 0;
  416. #ifdef DEBUG
  417. printf ("Stack Pointer at: %08lx\n", addr_sp);
  418. #endif
  419. /*
  420. * Save local variables to board info struct
  421. */
  422. bd->bi_memstart = CFG_SDRAM_BASE; /* start of DRAM memory */
  423. bd->bi_memsize = gd->ram_size; /* size of DRAM memory in bytes */
  424. #ifdef CONFIG_IP860
  425. bd->bi_sramstart = SRAM_BASE; /* start of SRAM memory */
  426. bd->bi_sramsize = SRAM_SIZE; /* size of SRAM memory */
  427. #else
  428. bd->bi_sramstart = 0; /* FIXME */ /* start of SRAM memory */
  429. bd->bi_sramsize = 0; /* FIXME */ /* size of SRAM memory */
  430. #endif
  431. #if defined(CONFIG_8xx) || defined(CONFIG_8260)
  432. bd->bi_immr_base = CFG_IMMR; /* base of IMMR register */
  433. #endif
  434. bd->bi_bootflags = bootflag; /* boot / reboot flag (for LynxOS) */
  435. WATCHDOG_RESET ();
  436. bd->bi_intfreq = gd->cpu_clk; /* Internal Freq, in Hz */
  437. bd->bi_busfreq = gd->bus_clk; /* Bus Freq, in Hz */
  438. #if defined(CONFIG_8260)
  439. bd->bi_cpmfreq = gd->cpm_clk;
  440. bd->bi_brgfreq = gd->brg_clk;
  441. bd->bi_sccfreq = gd->scc_clk;
  442. bd->bi_vco = gd->vco_out;
  443. #endif /* CONFIG_8260 */
  444. bd->bi_baudrate = gd->baudrate; /* Console Baudrate */
  445. #ifdef CFG_EXTBDINFO
  446. strncpy (bd->bi_s_version, "1.2", sizeof (bd->bi_s_version));
  447. strncpy (bd->bi_r_version, U_BOOT_VERSION, sizeof (bd->bi_r_version));
  448. bd->bi_procfreq = gd->cpu_clk; /* Processor Speed, In Hz */
  449. bd->bi_plb_busfreq = gd->bus_clk;
  450. #ifdef CONFIG_405GP
  451. bd->bi_pci_busfreq = get_PCI_freq ();
  452. #endif
  453. #endif
  454. #ifdef DEBUG
  455. printf ("New Stack Pointer is: %08lx\n", addr_sp);
  456. #endif
  457. WATCHDOG_RESET ();
  458. #ifdef CONFIG_POST
  459. post_bootmode_init();
  460. post_run (NULL, POST_ROM | post_bootmode_get(0));
  461. #endif
  462. WATCHDOG_RESET();
  463. memcpy (id, gd, sizeof (gd_t));
  464. relocate_code (addr_sp, id, addr);
  465. /* NOTREACHED - relocate_code() does not return */
  466. }
  467. /************************************************************************
  468. *
  469. * This is the next part if the initialization sequence: we are now
  470. * running from RAM and have a "normal" C environment, i. e. global
  471. * data can be written, BSS has been cleared, the stack size in not
  472. * that critical any more, etc.
  473. *
  474. ************************************************************************
  475. */
  476. void board_init_r (gd_t *id, ulong dest_addr)
  477. {
  478. DECLARE_GLOBAL_DATA_PTR;
  479. cmd_tbl_t *cmdtp;
  480. char *s, *e;
  481. bd_t *bd;
  482. int i;
  483. extern void malloc_bin_reloc (void);
  484. #ifndef CFG_ENV_IS_NOWHERE
  485. extern char * env_name_spec;
  486. #endif
  487. #ifndef CFG_NO_FLASH
  488. ulong flash_size;
  489. #endif
  490. gd = id; /* initialize RAM version of global data */
  491. bd = gd->bd;
  492. gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
  493. #ifdef DEBUG
  494. printf ("Now running in RAM - U-Boot at: %08lx\n", dest_addr);
  495. #endif
  496. WATCHDOG_RESET ();
  497. gd->reloc_off = dest_addr - CFG_MONITOR_BASE;
  498. /*
  499. * We have to relocate the command table manually
  500. */
  501. for (cmdtp = &cmd_tbl[0]; cmdtp->name; cmdtp++) {
  502. ulong addr;
  503. addr = (ulong) (cmdtp->cmd) + gd->reloc_off;
  504. #if 0
  505. printf ("Command \"%s\": 0x%08lx => 0x%08lx\n",
  506. cmdtp->name, (ulong) (cmdtp->cmd), addr);
  507. #endif
  508. cmdtp->cmd =
  509. (int (*)(struct cmd_tbl_s *, int, int, char *[]))addr;
  510. addr = (ulong)(cmdtp->name) + gd->reloc_off;
  511. cmdtp->name = (char *)addr;
  512. if (cmdtp->usage) {
  513. addr = (ulong)(cmdtp->usage) + gd->reloc_off;
  514. cmdtp->usage = (char *)addr;
  515. }
  516. #ifdef CFG_LONGHELP
  517. if (cmdtp->help) {
  518. addr = (ulong)(cmdtp->help) + gd->reloc_off;
  519. cmdtp->help = (char *)addr;
  520. }
  521. #endif
  522. }
  523. /* there are some other pointer constants we must deal with */
  524. #ifndef CFG_ENV_IS_NOWHERE
  525. env_name_spec += gd->reloc_off;
  526. #endif
  527. WATCHDOG_RESET ();
  528. #ifdef CONFIG_LOGBUFFER
  529. logbuff_init_ptrs ();
  530. #endif
  531. #ifdef CONFIG_POST
  532. post_output_backlog ();
  533. post_reloc ();
  534. #endif
  535. WATCHDOG_RESET();
  536. #if defined(CONFIG_IP860) || defined(CONFIG_PCU_E) || defined (CONFIG_FLAGADM)
  537. icache_enable (); /* it's time to enable the instruction cache */
  538. #endif
  539. #if defined(CONFIG_BAB7xx)
  540. /*
  541. * Do pci configuration on BAB 7xx _before_ the flash
  542. * is initialised, because we need the ISA bridge there.
  543. */
  544. pci_init ();
  545. /*
  546. * Initialise the ISA bridge
  547. */
  548. initialise_w83c553f ();
  549. #endif
  550. asm ("sync ; isync");
  551. /*
  552. * Setup trap handlers
  553. */
  554. trap_init (dest_addr);
  555. #if !defined(CFG_NO_FLASH)
  556. puts ("FLASH: ");
  557. if ((flash_size = flash_init ()) > 0) {
  558. #ifdef CFG_FLASH_CHECKSUM
  559. print_size (flash_size, "");
  560. /*
  561. * Compute and print flash CRC if flashchecksum is set to 'y'
  562. *
  563. * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
  564. */
  565. s = getenv ("flashchecksum");
  566. if (s && (*s == 'y')) {
  567. printf (" CRC: %08lX",
  568. crc32 (0,
  569. (const unsigned char *) CFG_FLASH_BASE,
  570. flash_size)
  571. );
  572. }
  573. putc ('\n');
  574. #else
  575. print_size (flash_size, "\n");
  576. #endif /* CFG_FLASH_CHECKSUM */
  577. } else {
  578. puts (failed);
  579. hang ();
  580. }
  581. bd->bi_flashstart = CFG_FLASH_BASE; /* update start of FLASH memory */
  582. bd->bi_flashsize = flash_size; /* size of FLASH memory (final value) */
  583. #if defined(CONFIG_PCU_E) || defined(CONFIG_OXC)
  584. bd->bi_flashoffset = 0;
  585. #elif CFG_MONITOR_BASE == CFG_FLASH_BASE
  586. bd->bi_flashoffset = CFG_MONITOR_LEN; /* reserved area for startup monitor */
  587. #else
  588. bd->bi_flashoffset = 0;
  589. #endif
  590. #else
  591. bd->bi_flashsize = 0;
  592. bd->bi_flashstart = 0;
  593. bd->bi_flashoffset = 0;
  594. #endif /* !CFG_NO_FLASH */
  595. WATCHDOG_RESET ();
  596. /* initialize higher level parts of CPU like time base and timers */
  597. cpu_init_r ();
  598. WATCHDOG_RESET ();
  599. /* initialize malloc() area */
  600. mem_malloc_init ();
  601. malloc_bin_reloc ();
  602. #ifdef CONFIG_SPI
  603. # if !defined(CFG_ENV_IS_IN_EEPROM)
  604. spi_init_f ();
  605. # endif
  606. spi_init_r ();
  607. #endif
  608. /* relocate environment function pointers etc. */
  609. env_relocate ();
  610. /*
  611. * Fill in missing fields of bd_info.
  612. * We do this here, where we have "normal" access to the
  613. * environment; we used to do this still running from ROM,
  614. * where had to use getenv_r(), which can be pretty slow when
  615. * the environment is in EEPROM.
  616. */
  617. s = getenv ("ethaddr");
  618. #if defined (CONFIG_MBX) || defined (CONFIG_RPXCLASSIC) || defined(CONFIG_IAD210)
  619. if (s == NULL)
  620. board_get_enetaddr (bd->bi_enetaddr);
  621. else
  622. #endif
  623. for (i = 0; i < 6; ++i) {
  624. bd->bi_enetaddr[i] = s ? simple_strtoul (s, &e, 16) : 0;
  625. if (s)
  626. s = (*e) ? e + 1 : e;
  627. }
  628. #ifdef CONFIG_HERMES
  629. if ((gd->board_type >> 16) == 2)
  630. bd->bi_ethspeed = gd->board_type & 0xFFFF;
  631. else
  632. bd->bi_ethspeed = 0xFFFF;
  633. #endif
  634. #ifdef CONFIG_NX823
  635. load_sernum_ethaddr ();
  636. #endif
  637. #if defined(CFG_GT_6426x) || defined(CONFIG_PN62)
  638. /* handle the 2nd ethernet address */
  639. s = getenv ("eth1addr");
  640. for (i = 0; i < 6; ++i) {
  641. bd->bi_enet1addr[i] = s ? simple_strtoul (s, &e, 16) : 0;
  642. if (s)
  643. s = (*e) ? e + 1 : e;
  644. }
  645. #endif
  646. #if defined(CFG_GT_6426x)
  647. /* handle the 3rd ethernet address */
  648. s = getenv ("eth2addr");
  649. for (i = 0; i < 6; ++i) {
  650. bd->bi_enet2addr[i] = s ? simple_strtoul (s, &e, 16) : 0;
  651. if (s)
  652. s = (*e) ? e + 1 : e;
  653. }
  654. #endif
  655. #if defined(CONFIG_TQM8xxL) || defined(CONFIG_TQM8260) || \
  656. defined(CONFIG_CCM)
  657. load_sernum_ethaddr ();
  658. #endif
  659. /* IP Address */
  660. bd->bi_ip_addr = getenv_IPaddr ("ipaddr");
  661. WATCHDOG_RESET ();
  662. #if defined(CONFIG_PCI) && !defined(CONFIG_BAB7xx)
  663. /*
  664. * Do pci configuration
  665. */
  666. pci_init ();
  667. #endif
  668. /** leave this here (after malloc(), environment and PCI are working) **/
  669. /* Initialize devices */
  670. devices_init ();
  671. /* allocate syscalls table (console_init_r will fill it in */
  672. syscall_tbl = (void **) malloc (NR_SYSCALLS * sizeof (void *));
  673. /* Initialize the console (after the relocation and devices init) */
  674. console_init_r ();
  675. /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/
  676. syscalls_init ();
  677. #if defined(CONFIG_CCM) || \
  678. defined(CONFIG_COGENT) || \
  679. defined(CONFIG_CPCI405) || \
  680. defined(CONFIG_EVB64260) || \
  681. defined(CONFIG_HYMOD) || \
  682. defined(CONFIG_KUP4K) || \
  683. defined(CONFIG_LWMON) || \
  684. defined(CONFIG_PCU_E) || \
  685. defined(CONFIG_W7O) || \
  686. defined(CONFIG_MISC_INIT_R)
  687. /* miscellaneous platform dependent initialisations */
  688. misc_init_r ();
  689. #endif
  690. #ifdef CONFIG_HERMES
  691. if (bd->bi_ethspeed != 0xFFFF)
  692. hermes_start_lxt980 ((int) bd->bi_ethspeed);
  693. #endif
  694. #if (CONFIG_COMMANDS & CFG_CMD_NET) && ( \
  695. defined(CONFIG_CCM) || \
  696. defined(CONFIG_EP8260) || \
  697. defined(CONFIG_IP860) || \
  698. defined(CONFIG_IVML24) || \
  699. defined(CONFIG_IVMS8) || \
  700. defined(CONFIG_LWMON) || \
  701. defined(CONFIG_MPC8260ADS) || \
  702. defined(CONFIG_PCU_E) || \
  703. defined(CONFIG_RPXSUPER) || \
  704. defined(CONFIG_SPD823TS) )
  705. WATCHDOG_RESET ();
  706. # ifdef DEBUG
  707. puts ("Reset Ethernet PHY\n");
  708. # endif
  709. reset_phy ();
  710. #endif
  711. #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
  712. WATCHDOG_RESET ();
  713. puts ("KGDB: ");
  714. kgdb_init ();
  715. #endif
  716. #ifdef DEBUG
  717. printf ("U-Boot relocated to %08lx\n", dest_addr);
  718. #endif
  719. /*
  720. * Enable Interrupts
  721. */
  722. interrupt_init ();
  723. /* Must happen after interrupts are initialized since
  724. * an irq handler gets installed
  725. */
  726. #ifdef CONFIG_SERIAL_SOFTWARE_FIFO
  727. serial_buffered_init();
  728. #endif
  729. #ifdef CONFIG_STATUS_LED
  730. status_led_set (STATUS_LED_BOOT, STATUS_LED_BLINKING);
  731. #endif
  732. udelay (20);
  733. set_timer (0);
  734. /* Insert function pointers now that we have relocated the code */
  735. /* Initialize from environment */
  736. if ((s = getenv ("loadaddr")) != NULL) {
  737. load_addr = simple_strtoul (s, NULL, 16);
  738. }
  739. #if (CONFIG_COMMANDS & CFG_CMD_NET)
  740. if ((s = getenv ("bootfile")) != NULL) {
  741. copy_filename (BootFile, s, sizeof (BootFile));
  742. }
  743. #endif /* CFG_CMD_NET */
  744. WATCHDOG_RESET ();
  745. #if (CONFIG_COMMANDS & CFG_CMD_SCSI)
  746. WATCHDOG_RESET ();
  747. puts ("SCSI: ");
  748. scsi_init ();
  749. #endif
  750. #if (CONFIG_COMMANDS & CFG_CMD_DOC)
  751. WATCHDOG_RESET ();
  752. puts ("DOC: ");
  753. doc_init ();
  754. #endif
  755. #if (CONFIG_COMMANDS & CFG_CMD_NET) && defined(CONFIG_NET_MULTI)
  756. WATCHDOG_RESET ();
  757. puts ("Net: ");
  758. eth_initialize (bd);
  759. #endif
  760. #ifdef CONFIG_POST
  761. post_run (NULL, POST_RAM | post_bootmode_get(0));
  762. if (post_bootmode_get(0) & POST_POWERFAIL) {
  763. post_bootmode_clear();
  764. board_poweroff();
  765. }
  766. #endif
  767. #if (CONFIG_COMMANDS & CFG_CMD_PCMCIA) && !(CONFIG_COMMANDS & CFG_CMD_IDE)
  768. WATCHDOG_RESET ();
  769. puts ("PCMCIA:");
  770. pcmcia_init ();
  771. #endif
  772. #if (CONFIG_COMMANDS & CFG_CMD_IDE)
  773. WATCHDOG_RESET ();
  774. # ifdef CONFIG_IDE_8xx_PCCARD
  775. puts ("PCMCIA:");
  776. # else
  777. puts ("IDE: ");
  778. #endif
  779. ide_init ();
  780. #endif /* CFG_CMD_IDE */
  781. #ifdef CONFIG_LAST_STAGE_INIT
  782. WATCHDOG_RESET ();
  783. /*
  784. * Some parts can be only initialized if all others (like
  785. * Interrupts) are up and running (i.e. the PC-style ISA
  786. * keyboard).
  787. */
  788. last_stage_init ();
  789. #endif
  790. #if (CONFIG_COMMANDS & CFG_CMD_BEDBUG)
  791. WATCHDOG_RESET ();
  792. bedbug_init ();
  793. #endif
  794. #if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
  795. /*
  796. * Export available size of memory for Linux,
  797. * taking into account the protected RAM at top of memory
  798. */
  799. {
  800. ulong pram;
  801. uchar memsz[32];
  802. #ifdef CONFIG_PRAM
  803. char *s;
  804. if ((s = getenv ("pram")) != NULL) {
  805. pram = simple_strtoul (s, NULL, 10);
  806. } else {
  807. pram = CONFIG_PRAM;
  808. }
  809. #else
  810. pram=0;
  811. #endif
  812. #ifdef CONFIG_LOGBUFFER
  813. /* Also take the logbuffer into account (pram is in kB) */
  814. pram += (LOGBUFF_LEN+LOGBUFF_OVERHEAD)/1024;
  815. #endif
  816. sprintf (memsz, "%ldk", (bd->bi_memsize / 1024) - pram);
  817. setenv ("mem", memsz);
  818. }
  819. #endif
  820. /* Initialization complete - start the monitor */
  821. /* main_loop() can return to retry autoboot, if so just run it again. */
  822. for (;;) {
  823. WATCHDOG_RESET ();
  824. main_loop ();
  825. }
  826. /* NOTREACHED - no way out of command loop except booting */
  827. }
  828. void hang (void)
  829. {
  830. puts ("### ERROR ### Please RESET the board ###\n");
  831. for (;;);
  832. }
  833. #if 0 /* We could use plain global data, but the resulting code is bigger */
  834. /*
  835. * Pointer to initial global data area
  836. *
  837. * Here we initialize it.
  838. */
  839. #undef XTRN_DECLARE_GLOBAL_DATA_PTR
  840. #define XTRN_DECLARE_GLOBAL_DATA_PTR /* empty = allocate here */
  841. DECLARE_GLOBAL_DATA_PTR = (gd_t *) (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET);
  842. #endif /* 0 */
  843. /************************************************************************/