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