board.c 18 KB

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