board.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808
  1. /*
  2. * (C) Copyright 2003
  3. * Josef Baumgartner <josef.baumgartner@telex.de>
  4. *
  5. * (C) Copyright 2000-2002
  6. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  7. *
  8. * See file CREDITS for list of people who contributed to this
  9. * project.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of
  14. * the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  24. * MA 02111-1307 USA
  25. */
  26. #include <common.h>
  27. #include <watchdog.h>
  28. #include <command.h>
  29. #include <malloc.h>
  30. #include <devices.h>
  31. #include <asm/immap.h>
  32. #if defined(CONFIG_CMD_IDE)
  33. #include <ide.h>
  34. #endif
  35. #if defined(CONFIG_CMD_SCSI)
  36. #include <scsi.h>
  37. #endif
  38. #if defined(CONFIG_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 defined(CONFIG_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_HARD_I2C) || \
  53. defined(CONFIG_SOFT_I2C)
  54. #include <i2c.h>
  55. #endif
  56. DECLARE_GLOBAL_DATA_PTR;
  57. static char *failed = "*** failed ***\n";
  58. #ifdef CONFIG_PCU_E
  59. extern flash_info_t flash_info[];
  60. #endif
  61. #include <environment.h>
  62. #if ( ((CFG_ENV_ADDR+CFG_ENV_SIZE) < CFG_MONITOR_BASE) || \
  63. (CFG_ENV_ADDR >= (CFG_MONITOR_BASE + CFG_MONITOR_LEN)) ) || \
  64. defined(CFG_ENV_IS_IN_NVRAM)
  65. #define TOTAL_MALLOC_LEN (CFG_MALLOC_LEN + CFG_ENV_SIZE)
  66. #else
  67. #define TOTAL_MALLOC_LEN CFG_MALLOC_LEN
  68. #endif
  69. extern ulong __init_end;
  70. extern ulong _end;
  71. extern void timer_init(void);
  72. #if defined(CONFIG_WATCHDOG)
  73. # define INIT_FUNC_WATCHDOG_INIT watchdog_init,
  74. # define WATCHDOG_DISABLE watchdog_disable
  75. extern int watchdog_init(void);
  76. extern int watchdog_disable(void);
  77. #else
  78. # define INIT_FUNC_WATCHDOG_INIT /* undef */
  79. # define WATCHDOG_DISABLE /* undef */
  80. #endif /* CONFIG_WATCHDOG */
  81. ulong monitor_flash_len;
  82. /*
  83. * Begin and End of memory area for malloc(), and current "brk"
  84. */
  85. static ulong mem_malloc_start = 0;
  86. static ulong mem_malloc_end = 0;
  87. static ulong mem_malloc_brk = 0;
  88. /************************************************************************
  89. * Utilities *
  90. ************************************************************************
  91. */
  92. /*
  93. * The Malloc area is immediately below the monitor copy in DRAM
  94. */
  95. static void mem_malloc_init (void)
  96. {
  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) ||
  110. (new > mem_malloc_end) ) {
  111. return (NULL);
  112. }
  113. mem_malloc_brk = new;
  114. return ((void *)old);
  115. }
  116. char *strmhz(char *buf, long hz)
  117. {
  118. long l, n;
  119. long m;
  120. n = hz / 1000000L;
  121. l = sprintf (buf, "%ld", n);
  122. m = (hz % 1000000L) / 1000L;
  123. if (m != 0)
  124. sprintf (buf+l, ".%03ld", m);
  125. return (buf);
  126. }
  127. /*
  128. * All attempts to come up with a "common" initialization sequence
  129. * that works for all boards and architectures failed: some of the
  130. * requirements are just _too_ different. To get rid of the resulting
  131. * mess of board dependend #ifdef'ed code we now make the whole
  132. * initialization sequence configurable to the user.
  133. *
  134. * The requirements for any new initalization function is simple: it
  135. * receives a pointer to the "global data" structure as it's only
  136. * argument, and returns an integer return code, where 0 means
  137. * "continue" and != 0 means "fatal error, hang the system".
  138. */
  139. typedef int (init_fnc_t) (void);
  140. /************************************************************************
  141. * Init Utilities
  142. ************************************************************************
  143. * Some of this code should be moved into the core functions,
  144. * but let's get it working (again) first...
  145. */
  146. static int init_baudrate (void)
  147. {
  148. uchar tmp[64]; /* long enough for environment variables */
  149. int i = getenv_r ("baudrate", tmp, sizeof (tmp));
  150. gd->baudrate = (i > 0)
  151. ? (int) simple_strtoul (tmp, NULL, 10)
  152. : CONFIG_BAUDRATE;
  153. return (0);
  154. }
  155. /***********************************************************************/
  156. static int init_func_ram (void)
  157. {
  158. int board_type = 0; /* use dummy arg */
  159. puts ("DRAM: ");
  160. if ((gd->ram_size = initdram (board_type)) > 0) {
  161. print_size (gd->ram_size, "\n");
  162. return (0);
  163. }
  164. puts (failed);
  165. return (1);
  166. }
  167. /***********************************************************************/
  168. #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
  169. static int init_func_i2c (void)
  170. {
  171. puts ("I2C: ");
  172. i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE);
  173. puts ("ready\n");
  174. return (0);
  175. }
  176. #endif
  177. /***********************************************************************/
  178. /************************************************************************
  179. * Initialization sequence *
  180. ************************************************************************
  181. */
  182. init_fnc_t *init_sequence[] = {
  183. get_clocks,
  184. env_init,
  185. init_baudrate,
  186. serial_init,
  187. console_init_f,
  188. display_options,
  189. checkcpu,
  190. checkboard,
  191. #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
  192. init_func_i2c,
  193. #endif
  194. init_func_ram,
  195. #if defined(CFG_DRAM_TEST)
  196. testdram,
  197. #endif /* CFG_DRAM_TEST */
  198. INIT_FUNC_WATCHDOG_INIT
  199. NULL, /* Terminate this list */
  200. };
  201. /************************************************************************
  202. *
  203. * This is the first part of the initialization sequence that is
  204. * implemented in C, but still running from ROM.
  205. *
  206. * The main purpose is to provide a (serial) console interface as
  207. * soon as possible (so we can see any error messages), and to
  208. * initialize the RAM so that we can relocate the monitor code to
  209. * RAM.
  210. *
  211. * Be aware of the restrictions: global data is read-only, BSS is not
  212. * initialized, and stack space is limited to a few kB.
  213. *
  214. ************************************************************************
  215. */
  216. void
  217. board_init_f (ulong bootflag)
  218. {
  219. bd_t *bd;
  220. ulong len, addr, addr_sp;
  221. ulong *paddr;
  222. gd_t *id;
  223. init_fnc_t **init_fnc_ptr;
  224. #ifdef CONFIG_PRAM
  225. int i;
  226. ulong reg;
  227. uchar tmp[64]; /* long enough for environment variables */
  228. #endif
  229. /* Pointer is writable since we allocated a register for it */
  230. gd = (gd_t *) (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET);
  231. /* compiler optimization barrier needed for GCC >= 3.4 */
  232. __asm__ __volatile__("": : :"memory");
  233. /* Clear initial global data */
  234. memset ((void *) gd, 0, sizeof (gd_t));
  235. for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
  236. if ((*init_fnc_ptr)() != 0) {
  237. hang ();
  238. }
  239. }
  240. /*
  241. * Now that we have DRAM mapped and working, we can
  242. * relocate the code and continue running from DRAM.
  243. *
  244. * Reserve memory at end of RAM for (top down in that order):
  245. * - protected RAM
  246. * - LCD framebuffer
  247. * - monitor code
  248. * - board info struct
  249. */
  250. len = (ulong)&_end - CFG_MONITOR_BASE;
  251. addr = CFG_SDRAM_BASE + gd->ram_size;
  252. #ifdef CONFIG_LOGBUFFER
  253. /* reserve kernel log buffer */
  254. addr -= (LOGBUFF_RESERVE);
  255. debug ("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN, addr);
  256. #endif
  257. #ifdef CONFIG_PRAM
  258. /*
  259. * reserve protected RAM
  260. */
  261. i = getenv_r ("pram", tmp, sizeof (tmp));
  262. reg = (i > 0) ? simple_strtoul (tmp, NULL, 10) : CONFIG_PRAM;
  263. addr -= (reg << 10); /* size is in kB */
  264. debug ("Reserving %ldk for protected RAM at %08lx\n", reg, addr);
  265. #endif /* CONFIG_PRAM */
  266. /* round down to next 4 kB limit */
  267. addr &= ~(4096 - 1);
  268. debug ("Top of RAM usable for U-Boot at: %08lx\n", addr);
  269. #ifdef CONFIG_LCD
  270. /* reserve memory for LCD display (always full pages) */
  271. addr = lcd_setmem (addr);
  272. gd->fb_base = addr;
  273. #endif /* CONFIG_LCD */
  274. /*
  275. * reserve memory for U-Boot code, data & bss
  276. * round down to next 4 kB limit
  277. */
  278. addr -= len;
  279. addr &= ~(4096 - 1);
  280. debug ("Reserving %ldk for U-Boot at: %08lx\n", len >> 10, addr);
  281. /*
  282. * reserve memory for malloc() arena
  283. */
  284. addr_sp = addr - TOTAL_MALLOC_LEN;
  285. debug ("Reserving %dk for malloc() at: %08lx\n",
  286. TOTAL_MALLOC_LEN >> 10, addr_sp);
  287. /*
  288. * (permanently) allocate a Board Info struct
  289. * and a permanent copy of the "global" data
  290. */
  291. addr_sp -= sizeof (bd_t);
  292. bd = (bd_t *) addr_sp;
  293. gd->bd = bd;
  294. debug ("Reserving %d Bytes for Board Info at: %08lx\n",
  295. sizeof (bd_t), addr_sp);
  296. addr_sp -= sizeof (gd_t);
  297. id = (gd_t *) addr_sp;
  298. debug ("Reserving %d Bytes for Global Data at: %08lx\n",
  299. sizeof (gd_t), addr_sp);
  300. /* Reserve memory for boot params. */
  301. addr_sp -= CFG_BOOTPARAMS_LEN;
  302. bd->bi_boot_params = addr_sp;
  303. debug ("Reserving %dk for boot parameters at: %08lx\n",
  304. CFG_BOOTPARAMS_LEN >> 10, addr_sp);
  305. /*
  306. * Finally, we set up a new (bigger) stack.
  307. *
  308. * Leave some safety gap for SP, force alignment on 16 byte boundary
  309. * Clear initial stack frame
  310. */
  311. addr_sp -= 16;
  312. addr_sp &= ~0xF;
  313. paddr = (ulong *)addr_sp;
  314. *paddr-- = 0;
  315. *paddr-- = 0;
  316. addr_sp = (ulong)paddr;
  317. debug ("Stack Pointer at: %08lx\n", addr_sp);
  318. /*
  319. * Save local variables to board info struct
  320. */
  321. bd->bi_memstart = CFG_SDRAM_BASE; /* start of DRAM memory */
  322. bd->bi_memsize = gd->ram_size; /* size of DRAM memory in bytes */
  323. #ifdef CFG_INIT_RAM_ADDR
  324. bd->bi_sramstart = CFG_INIT_RAM_ADDR; /* start of SRAM memory */
  325. bd->bi_sramsize = CFG_INIT_RAM_END; /* size of SRAM memory */
  326. #endif
  327. bd->bi_mbar_base = CFG_MBAR; /* base of internal registers */
  328. bd->bi_bootflags = bootflag; /* boot / reboot flag (for LynxOS) */
  329. WATCHDOG_RESET ();
  330. bd->bi_intfreq = gd->cpu_clk; /* Internal Freq, in Hz */
  331. bd->bi_busfreq = gd->bus_clk; /* Bus Freq, in Hz */
  332. #ifdef CONFIG_PCI
  333. bd->bi_pcifreq = gd->pci_clk; /* PCI Freq in Hz */
  334. #endif
  335. #ifdef CONFIG_EXTRA_CLOCK
  336. bd->bi_inpfreq = gd->inp_clk; /* input Freq in Hz */
  337. bd->bi_vcofreq = gd->vco_clk; /* vco Freq in Hz */
  338. bd->bi_flbfreq = gd->flb_clk; /* flexbus Freq in Hz */
  339. #endif
  340. bd->bi_baudrate = gd->baudrate; /* Console Baudrate */
  341. #ifdef CFG_EXTBDINFO
  342. strncpy (bd->bi_s_version, "1.2", sizeof (bd->bi_s_version));
  343. strncpy (bd->bi_r_version, U_BOOT_VERSION, sizeof (bd->bi_r_version));
  344. #endif
  345. WATCHDOG_RESET ();
  346. #ifdef CONFIG_POST
  347. post_bootmode_init();
  348. post_run (NULL, POST_ROM | post_bootmode_get(0));
  349. #endif
  350. WATCHDOG_RESET();
  351. memcpy (id, (void *)gd, sizeof (gd_t));
  352. debug ("Start relocate of code from %08x to %08lx\n", CFG_MONITOR_BASE, addr);
  353. relocate_code (addr_sp, id, addr);
  354. /* NOTREACHED - jump_to_ram() does not return */
  355. }
  356. /************************************************************************
  357. *
  358. * This is the next part if the initialization sequence: we are now
  359. * running from RAM and have a "normal" C environment, i. e. global
  360. * data can be written, BSS has been cleared, the stack size in not
  361. * that critical any more, etc.
  362. *
  363. ************************************************************************
  364. */
  365. void board_init_r (gd_t *id, ulong dest_addr)
  366. {
  367. cmd_tbl_t *cmdtp;
  368. char *s, *e;
  369. bd_t *bd;
  370. int i;
  371. extern void malloc_bin_reloc (void);
  372. #ifndef CFG_ENV_IS_NOWHERE
  373. extern char * env_name_spec;
  374. #endif
  375. #ifndef CFG_NO_FLASH
  376. ulong flash_size;
  377. #endif
  378. gd = id; /* initialize RAM version of global data */
  379. bd = gd->bd;
  380. gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
  381. #ifdef CONFIG_SERIAL_MULTI
  382. serial_initialize();
  383. #endif
  384. debug ("Now running in RAM - U-Boot at: %08lx\n", dest_addr);
  385. WATCHDOG_RESET ();
  386. gd->reloc_off = dest_addr - CFG_MONITOR_BASE;
  387. monitor_flash_len = (ulong)&__init_end - dest_addr;
  388. /*
  389. * We have to relocate the command table manually
  390. */
  391. for (cmdtp = &__u_boot_cmd_start; cmdtp != &__u_boot_cmd_end; cmdtp++) {
  392. ulong addr;
  393. addr = (ulong) (cmdtp->cmd) + gd->reloc_off;
  394. #if 0
  395. printf ("Command \"%s\": 0x%08lx => 0x%08lx\n",
  396. cmdtp->name, (ulong) (cmdtp->cmd), addr);
  397. #endif
  398. cmdtp->cmd =
  399. (int (*)(struct cmd_tbl_s *, int, int, char *[]))addr;
  400. addr = (ulong)(cmdtp->name) + gd->reloc_off;
  401. cmdtp->name = (char *)addr;
  402. if (cmdtp->usage) {
  403. addr = (ulong)(cmdtp->usage) + gd->reloc_off;
  404. cmdtp->usage = (char *)addr;
  405. }
  406. #ifdef CFG_LONGHELP
  407. if (cmdtp->help) {
  408. addr = (ulong)(cmdtp->help) + gd->reloc_off;
  409. cmdtp->help = (char *)addr;
  410. }
  411. #endif
  412. }
  413. /* there are some other pointer constants we must deal with */
  414. #ifndef CFG_ENV_IS_NOWHERE
  415. env_name_spec += gd->reloc_off;
  416. #endif
  417. WATCHDOG_RESET ();
  418. #ifdef CONFIG_LOGBUFFER
  419. logbuff_init_ptrs ();
  420. #endif
  421. #ifdef CONFIG_POST
  422. post_output_backlog ();
  423. post_reloc ();
  424. #endif
  425. WATCHDOG_RESET();
  426. #if 0
  427. /* instruction cache enabled in cpu_init_f() for faster relocation */
  428. icache_enable (); /* it's time to enable the instruction cache */
  429. #endif
  430. /*
  431. * Setup trap handlers
  432. */
  433. trap_init (CFG_SDRAM_BASE);
  434. #if !defined(CFG_NO_FLASH)
  435. puts ("FLASH: ");
  436. if ((flash_size = flash_init ()) > 0) {
  437. # ifdef CFG_FLASH_CHECKSUM
  438. print_size (flash_size, "");
  439. /*
  440. * Compute and print flash CRC if flashchecksum is set to 'y'
  441. *
  442. * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
  443. */
  444. s = getenv ("flashchecksum");
  445. if (s && (*s == 'y')) {
  446. printf (" CRC: %08lX",
  447. crc32 (0,
  448. (const unsigned char *) CFG_FLASH_BASE,
  449. flash_size)
  450. );
  451. }
  452. putc ('\n');
  453. # else /* !CFG_FLASH_CHECKSUM */
  454. print_size (flash_size, "\n");
  455. # endif /* CFG_FLASH_CHECKSUM */
  456. } else {
  457. puts (failed);
  458. hang ();
  459. }
  460. bd->bi_flashstart = CFG_FLASH_BASE; /* update start of FLASH memory */
  461. bd->bi_flashsize = flash_size; /* size of FLASH memory (final value) */
  462. bd->bi_flashoffset = 0;
  463. #else /* CFG_NO_FLASH */
  464. bd->bi_flashsize = 0;
  465. bd->bi_flashstart = 0;
  466. bd->bi_flashoffset = 0;
  467. #endif /* !CFG_NO_FLASH */
  468. WATCHDOG_RESET ();
  469. /* initialize higher level parts of CPU like time base and timers */
  470. cpu_init_r ();
  471. WATCHDOG_RESET ();
  472. /* initialize malloc() area */
  473. mem_malloc_init ();
  474. malloc_bin_reloc ();
  475. #ifdef CONFIG_SPI
  476. # if !defined(CFG_ENV_IS_IN_EEPROM)
  477. spi_init_f ();
  478. # endif
  479. spi_init_r ();
  480. #endif
  481. /* relocate environment function pointers etc. */
  482. env_relocate ();
  483. /*
  484. * Fill in missing fields of bd_info.
  485. * We do this here, where we have "normal" access to the
  486. * environment; we used to do this still running from ROM,
  487. * where had to use getenv_r(), which can be pretty slow when
  488. * the environment is in EEPROM.
  489. */
  490. s = getenv ("ethaddr");
  491. for (i = 0; i < 6; ++i) {
  492. bd->bi_enetaddr[i] = s ? simple_strtoul (s, &e, 16) : 0;
  493. if (s)
  494. s = (*e) ? e + 1 : e;
  495. }
  496. #ifdef CONFIG_HAS_ETH1
  497. /* handle the 2nd ethernet address */
  498. s = getenv ("eth1addr");
  499. for (i = 0; i < 6; ++i) {
  500. bd->bi_enet1addr[i] = s ? simple_strtoul (s, &e, 16) : 0;
  501. if (s)
  502. s = (*e) ? e + 1 : e;
  503. }
  504. #endif
  505. #ifdef CONFIG_HAS_ETH2
  506. /* handle the 3rd ethernet address */
  507. s = getenv ("eth2addr");
  508. for (i = 0; i < 6; ++i) {
  509. bd->bi_enet2addr[i] = s ? simple_strtoul (s, &e, 16) : 0;
  510. if (s)
  511. s = (*e) ? e + 1 : e;
  512. }
  513. #endif
  514. #ifdef CONFIG_HAS_ETH3
  515. /* handle 4th ethernet address */
  516. s = getenv("eth3addr");
  517. for (i = 0; i < 6; ++i) {
  518. bd->bi_enet3addr[i] = s ? simple_strtoul (s, &e, 16) : 0;
  519. if (s)
  520. s = (*e) ? e + 1 : e;
  521. }
  522. #endif
  523. /* IP Address */
  524. bd->bi_ip_addr = getenv_IPaddr ("ipaddr");
  525. WATCHDOG_RESET ();
  526. #if defined(CONFIG_PCI)
  527. /*
  528. * Do pci configuration
  529. */
  530. pci_init ();
  531. #endif
  532. /** leave this here (after malloc(), environment and PCI are working) **/
  533. /* Initialize devices */
  534. devices_init ();
  535. /* Initialize the jump table for applications */
  536. jumptable_init ();
  537. /* Initialize the console (after the relocation and devices init) */
  538. console_init_r ();
  539. #if defined(CONFIG_MISC_INIT_R)
  540. /* miscellaneous platform dependent initialisations */
  541. misc_init_r ();
  542. #endif
  543. #if defined(CONFIG_CMD_KGDB)
  544. WATCHDOG_RESET ();
  545. puts ("KGDB: ");
  546. kgdb_init ();
  547. #endif
  548. debug ("U-Boot relocated to %08lx\n", dest_addr);
  549. /*
  550. * Enable Interrupts
  551. */
  552. interrupt_init ();
  553. /* Must happen after interrupts are initialized since
  554. * an irq handler gets installed
  555. */
  556. timer_init();
  557. #ifdef CONFIG_SERIAL_SOFTWARE_FIFO
  558. serial_buffered_init();
  559. #endif
  560. #ifdef CONFIG_STATUS_LED
  561. status_led_set (STATUS_LED_BOOT, STATUS_LED_BLINKING);
  562. #endif
  563. udelay (20);
  564. set_timer (0);
  565. /* Insert function pointers now that we have relocated the code */
  566. /* Initialize from environment */
  567. if ((s = getenv ("loadaddr")) != NULL) {
  568. load_addr = simple_strtoul (s, NULL, 16);
  569. }
  570. #if defined(CONFIG_CMD_NET)
  571. if ((s = getenv ("bootfile")) != NULL) {
  572. copy_filename (BootFile, s, sizeof (BootFile));
  573. }
  574. #endif
  575. WATCHDOG_RESET ();
  576. #if defined(CONFIG_CMD_DOC)
  577. WATCHDOG_RESET ();
  578. puts ("DOC: ");
  579. doc_init ();
  580. #endif
  581. #if defined(CONFIG_CMD_NAND)
  582. WATCHDOG_RESET ();
  583. puts ("NAND: ");
  584. nand_init(); /* go init the NAND */
  585. #endif
  586. #if defined(CONFIG_CMD_NET)
  587. WATCHDOG_RESET();
  588. #if defined(FEC_ENET)
  589. eth_init(bd);
  590. #endif
  591. #if defined(CONFIG_NET_MULTI)
  592. puts ("Net: ");
  593. eth_initialize (bd);
  594. #endif
  595. #endif
  596. #ifdef CONFIG_POST
  597. post_run (NULL, POST_RAM | post_bootmode_get(0));
  598. #endif
  599. #if defined(CONFIG_CMD_PCMCIA) \
  600. && !defined(CONFIG_CMD_IDE)
  601. WATCHDOG_RESET ();
  602. puts ("PCMCIA:");
  603. pcmcia_init ();
  604. #endif
  605. #if defined(CONFIG_CMD_IDE)
  606. WATCHDOG_RESET ();
  607. puts ("IDE: ");
  608. ide_init ();
  609. #endif
  610. #ifdef CONFIG_LAST_STAGE_INIT
  611. WATCHDOG_RESET ();
  612. /*
  613. * Some parts can be only initialized if all others (like
  614. * Interrupts) are up and running (i.e. the PC-style ISA
  615. * keyboard).
  616. */
  617. last_stage_init ();
  618. #endif
  619. #if defined(CONFIG_CMD_BEDBUG)
  620. WATCHDOG_RESET ();
  621. bedbug_init ();
  622. #endif
  623. #if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
  624. /*
  625. * Export available size of memory for Linux,
  626. * taking into account the protected RAM at top of memory
  627. */
  628. {
  629. ulong pram;
  630. uchar memsz[32];
  631. #ifdef CONFIG_PRAM
  632. char *s;
  633. if ((s = getenv ("pram")) != NULL) {
  634. pram = simple_strtoul (s, NULL, 10);
  635. } else {
  636. pram = CONFIG_PRAM;
  637. }
  638. #else
  639. pram=0;
  640. #endif
  641. #ifdef CONFIG_LOGBUFFER
  642. /* Also take the logbuffer into account (pram is in kB) */
  643. pram += (LOGBUFF_LEN+LOGBUFF_OVERHEAD)/1024;
  644. #endif
  645. sprintf (memsz, "%ldk", (bd->bi_memsize / 1024) - pram);
  646. setenv ("mem", memsz);
  647. }
  648. #endif
  649. #ifdef CONFIG_MODEM_SUPPORT
  650. {
  651. extern int do_mdm_init;
  652. do_mdm_init = gd->do_mdm_init;
  653. }
  654. #endif
  655. #ifdef CONFIG_WATCHDOG
  656. /* disable watchdog if environment is set */
  657. if ((s = getenv ("watchdog")) != NULL) {
  658. if (strncmp (s, "off", 3) == 0) {
  659. WATCHDOG_DISABLE ();
  660. }
  661. }
  662. #endif /* CONFIG_WATCHDOG*/
  663. /* Initialization complete - start the monitor */
  664. /* main_loop() can return to retry autoboot, if so just run it again. */
  665. for (;;) {
  666. WATCHDOG_RESET ();
  667. main_loop ();
  668. }
  669. /* NOTREACHED - no way out of command loop except booting */
  670. }
  671. void hang(void)
  672. {
  673. puts ("### ERROR ### Please RESET the board ###\n");
  674. for (;;);
  675. }