board.c 19 KB

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