board.c 17 KB

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