board.c 19 KB

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