board.c 17 KB

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