board.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  1. /*
  2. * (C) Copyright 2002-2006
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * (C) Copyright 2002
  6. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  7. * Marius Groeger <mgroeger@sysgo.de>
  8. *
  9. * See file CREDITS for list of people who contributed to this
  10. * project.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation; either version 2 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  25. * MA 02111-1307 USA
  26. */
  27. /*
  28. * To match the U-Boot user interface on ARM platforms to the U-Boot
  29. * standard (as on PPC platforms), some messages with debug character
  30. * are removed from the default U-Boot build.
  31. *
  32. * Define DEBUG here if you want additional info as shown below
  33. * printed upon startup:
  34. *
  35. * U-Boot code: 00F00000 -> 00F3C774 BSS: -> 00FC3274
  36. * IRQ Stack: 00ebff7c
  37. * FIQ Stack: 00ebef7c
  38. */
  39. #include <common.h>
  40. #include <command.h>
  41. #include <malloc.h>
  42. #include <stdio_dev.h>
  43. #include <version.h>
  44. #include <net.h>
  45. #include <serial.h>
  46. #include <nand.h>
  47. #include <onenand_uboot.h>
  48. #include <mmc.h>
  49. #include <libfdt.h>
  50. #include <fdtdec.h>
  51. #include <post.h>
  52. #include <logbuff.h>
  53. #ifdef CONFIG_BITBANGMII
  54. #include <miiphy.h>
  55. #endif
  56. DECLARE_GLOBAL_DATA_PTR;
  57. ulong monitor_flash_len;
  58. #ifdef CONFIG_HAS_DATAFLASH
  59. extern int AT91F_DataflashInit(void);
  60. extern void dataflash_print_info(void);
  61. #endif
  62. #if defined(CONFIG_HARD_I2C) || \
  63. defined(CONFIG_SOFT_I2C)
  64. #include <i2c.h>
  65. #endif
  66. /************************************************************************
  67. * Coloured LED functionality
  68. ************************************************************************
  69. * May be supplied by boards if desired
  70. */
  71. inline void __coloured_LED_init(void) {}
  72. void coloured_LED_init(void)
  73. __attribute__((weak, alias("__coloured_LED_init")));
  74. inline void __red_led_on(void) {}
  75. void red_led_on(void) __attribute__((weak, alias("__red_led_on")));
  76. inline void __red_led_off(void) {}
  77. void red_led_off(void) __attribute__((weak, alias("__red_led_off")));
  78. inline void __green_led_on(void) {}
  79. void green_led_on(void) __attribute__((weak, alias("__green_led_on")));
  80. inline void __green_led_off(void) {}
  81. void green_led_off(void) __attribute__((weak, alias("__green_led_off")));
  82. inline void __yellow_led_on(void) {}
  83. void yellow_led_on(void) __attribute__((weak, alias("__yellow_led_on")));
  84. inline void __yellow_led_off(void) {}
  85. void yellow_led_off(void) __attribute__((weak, alias("__yellow_led_off")));
  86. inline void __blue_led_on(void) {}
  87. void blue_led_on(void) __attribute__((weak, alias("__blue_led_on")));
  88. inline void __blue_led_off(void) {}
  89. void blue_led_off(void) __attribute__((weak, alias("__blue_led_off")));
  90. /*
  91. ************************************************************************
  92. * Init Utilities *
  93. ************************************************************************
  94. * Some of this code should be moved into the core functions,
  95. * or dropped completely,
  96. * but let's get it working (again) first...
  97. */
  98. #if defined(CONFIG_ARM_DCC) && !defined(CONFIG_BAUDRATE)
  99. #define CONFIG_BAUDRATE 115200
  100. #endif
  101. static int init_baudrate(void)
  102. {
  103. gd->baudrate = getenv_ulong("baudrate", 10, CONFIG_BAUDRATE);
  104. return 0;
  105. }
  106. static int display_banner(void)
  107. {
  108. printf("\n\n%s\n\n", version_string);
  109. debug("U-Boot code: %08lX -> %08lX BSS: -> %08lX\n",
  110. _TEXT_BASE,
  111. _bss_start_ofs + _TEXT_BASE, _bss_end_ofs + _TEXT_BASE);
  112. #ifdef CONFIG_MODEM_SUPPORT
  113. debug("Modem Support enabled\n");
  114. #endif
  115. #ifdef CONFIG_USE_IRQ
  116. debug("IRQ Stack: %08lx\n", IRQ_STACK_START);
  117. debug("FIQ Stack: %08lx\n", FIQ_STACK_START);
  118. #endif
  119. return (0);
  120. }
  121. /*
  122. * WARNING: this code looks "cleaner" than the PowerPC version, but
  123. * has the disadvantage that you either get nothing, or everything.
  124. * On PowerPC, you might see "DRAM: " before the system hangs - which
  125. * gives a simple yet clear indication which part of the
  126. * initialization if failing.
  127. */
  128. static int display_dram_config(void)
  129. {
  130. int i;
  131. #ifdef DEBUG
  132. puts("RAM Configuration:\n");
  133. for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
  134. printf("Bank #%d: %08lx ", i, gd->bd->bi_dram[i].start);
  135. print_size(gd->bd->bi_dram[i].size, "\n");
  136. }
  137. #else
  138. ulong size = 0;
  139. for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
  140. size += gd->bd->bi_dram[i].size;
  141. puts("DRAM: ");
  142. print_size(size, "\n");
  143. #endif
  144. return (0);
  145. }
  146. #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
  147. static int init_func_i2c(void)
  148. {
  149. puts("I2C: ");
  150. i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
  151. puts("ready\n");
  152. return (0);
  153. }
  154. #endif
  155. #if defined(CONFIG_CMD_PCI) || defined (CONFIG_PCI)
  156. #include <pci.h>
  157. static int arm_pci_init(void)
  158. {
  159. pci_init();
  160. return 0;
  161. }
  162. #endif /* CONFIG_CMD_PCI || CONFIG_PCI */
  163. /*
  164. * Breathe some life into the board...
  165. *
  166. * Initialize a serial port as console, and carry out some hardware
  167. * tests.
  168. *
  169. * The first part of initialization is running from Flash memory;
  170. * its main purpose is to initialize the RAM so that we
  171. * can relocate the monitor code to RAM.
  172. */
  173. /*
  174. * All attempts to come up with a "common" initialization sequence
  175. * that works for all boards and architectures failed: some of the
  176. * requirements are just _too_ different. To get rid of the resulting
  177. * mess of board dependent #ifdef'ed code we now make the whole
  178. * initialization sequence configurable to the user.
  179. *
  180. * The requirements for any new initalization function is simple: it
  181. * receives a pointer to the "global data" structure as it's only
  182. * argument, and returns an integer return code, where 0 means
  183. * "continue" and != 0 means "fatal error, hang the system".
  184. */
  185. typedef int (init_fnc_t) (void);
  186. int print_cpuinfo(void);
  187. void __dram_init_banksize(void)
  188. {
  189. gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
  190. gd->bd->bi_dram[0].size = gd->ram_size;
  191. }
  192. void dram_init_banksize(void)
  193. __attribute__((weak, alias("__dram_init_banksize")));
  194. int __arch_cpu_init(void)
  195. {
  196. return 0;
  197. }
  198. int arch_cpu_init(void)
  199. __attribute__((weak, alias("__arch_cpu_init")));
  200. int __power_init_board(void)
  201. {
  202. return 0;
  203. }
  204. int power_init_board(void)
  205. __attribute__((weak, alias("__power_init_board")));
  206. init_fnc_t *init_sequence[] = {
  207. arch_cpu_init, /* basic arch cpu dependent setup */
  208. #if defined(CONFIG_BOARD_EARLY_INIT_F)
  209. board_early_init_f,
  210. #endif
  211. #ifdef CONFIG_OF_CONTROL
  212. fdtdec_check_fdt,
  213. #endif
  214. timer_init, /* initialize timer */
  215. #ifdef CONFIG_BOARD_POSTCLK_INIT
  216. board_postclk_init,
  217. #endif
  218. #ifdef CONFIG_FSL_ESDHC
  219. get_clocks,
  220. #endif
  221. env_init, /* initialize environment */
  222. init_baudrate, /* initialze baudrate settings */
  223. serial_init, /* serial communications setup */
  224. console_init_f, /* stage 1 init of console */
  225. display_banner, /* say that we are here */
  226. #if defined(CONFIG_DISPLAY_CPUINFO)
  227. print_cpuinfo, /* display cpu info (and speed) */
  228. #endif
  229. #if defined(CONFIG_DISPLAY_BOARDINFO)
  230. checkboard, /* display board info */
  231. #endif
  232. #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
  233. init_func_i2c,
  234. #endif
  235. dram_init, /* configure available RAM banks */
  236. NULL,
  237. };
  238. void board_init_f(ulong bootflag)
  239. {
  240. bd_t *bd;
  241. init_fnc_t **init_fnc_ptr;
  242. gd_t *id;
  243. ulong addr, addr_sp;
  244. #ifdef CONFIG_PRAM
  245. ulong reg;
  246. #endif
  247. void *new_fdt = NULL;
  248. size_t fdt_size = 0;
  249. bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_F, "board_init_f");
  250. /* Pointer is writable since we allocated a register for it */
  251. gd = (gd_t *) ((CONFIG_SYS_INIT_SP_ADDR) & ~0x07);
  252. /* compiler optimization barrier needed for GCC >= 3.4 */
  253. __asm__ __volatile__("": : :"memory");
  254. memset((void *)gd, 0, sizeof(gd_t));
  255. gd->mon_len = _bss_end_ofs;
  256. #ifdef CONFIG_OF_EMBED
  257. /* Get a pointer to the FDT */
  258. gd->fdt_blob = _binary_dt_dtb_start;
  259. #elif defined CONFIG_OF_SEPARATE
  260. /* FDT is at end of image */
  261. gd->fdt_blob = (void *)(_end_ofs + _TEXT_BASE);
  262. #endif
  263. /* Allow the early environment to override the fdt address */
  264. gd->fdt_blob = (void *)getenv_ulong("fdtcontroladdr", 16,
  265. (uintptr_t)gd->fdt_blob);
  266. for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
  267. if ((*init_fnc_ptr)() != 0) {
  268. hang ();
  269. }
  270. }
  271. #ifdef CONFIG_OF_CONTROL
  272. /* For now, put this check after the console is ready */
  273. if (fdtdec_prepare_fdt()) {
  274. panic("** CONFIG_OF_CONTROL defined but no FDT - please see "
  275. "doc/README.fdt-control");
  276. }
  277. #endif
  278. debug("monitor len: %08lX\n", gd->mon_len);
  279. /*
  280. * Ram is setup, size stored in gd !!
  281. */
  282. debug("ramsize: %08lX\n", gd->ram_size);
  283. #if defined(CONFIG_SYS_MEM_TOP_HIDE)
  284. /*
  285. * Subtract specified amount of memory to hide so that it won't
  286. * get "touched" at all by U-Boot. By fixing up gd->ram_size
  287. * the Linux kernel should now get passed the now "corrected"
  288. * memory size and won't touch it either. This should work
  289. * for arch/ppc and arch/powerpc. Only Linux board ports in
  290. * arch/powerpc with bootwrapper support, that recalculate the
  291. * memory size from the SDRAM controller setup will have to
  292. * get fixed.
  293. */
  294. gd->ram_size -= CONFIG_SYS_MEM_TOP_HIDE;
  295. #endif
  296. addr = CONFIG_SYS_SDRAM_BASE + gd->ram_size;
  297. #ifdef CONFIG_LOGBUFFER
  298. #ifndef CONFIG_ALT_LB_ADDR
  299. /* reserve kernel log buffer */
  300. addr -= (LOGBUFF_RESERVE);
  301. debug("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN,
  302. addr);
  303. #endif
  304. #endif
  305. #ifdef CONFIG_PRAM
  306. /*
  307. * reserve protected RAM
  308. */
  309. reg = getenv_ulong("pram", 10, CONFIG_PRAM);
  310. addr -= (reg << 10); /* size is in kB */
  311. debug("Reserving %ldk for protected RAM at %08lx\n", reg, addr);
  312. #endif /* CONFIG_PRAM */
  313. #if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF))
  314. /* reserve TLB table */
  315. addr -= (4096 * 4);
  316. /* round down to next 64 kB limit */
  317. addr &= ~(0x10000 - 1);
  318. gd->tlb_addr = addr;
  319. debug("TLB table at: %08lx\n", addr);
  320. #endif
  321. /* round down to next 4 kB limit */
  322. addr &= ~(4096 - 1);
  323. debug("Top of RAM usable for U-Boot at: %08lx\n", addr);
  324. #ifdef CONFIG_LCD
  325. #ifdef CONFIG_FB_ADDR
  326. gd->fb_base = CONFIG_FB_ADDR;
  327. #else
  328. /* reserve memory for LCD display (always full pages) */
  329. addr = lcd_setmem(addr);
  330. gd->fb_base = addr;
  331. #endif /* CONFIG_FB_ADDR */
  332. #endif /* CONFIG_LCD */
  333. /*
  334. * reserve memory for U-Boot code, data & bss
  335. * round down to next 4 kB limit
  336. */
  337. addr -= gd->mon_len;
  338. addr &= ~(4096 - 1);
  339. debug("Reserving %ldk for U-Boot at: %08lx\n", gd->mon_len >> 10, addr);
  340. #ifndef CONFIG_SPL_BUILD
  341. /*
  342. * reserve memory for malloc() arena
  343. */
  344. addr_sp = addr - TOTAL_MALLOC_LEN;
  345. debug("Reserving %dk for malloc() at: %08lx\n",
  346. TOTAL_MALLOC_LEN >> 10, addr_sp);
  347. /*
  348. * (permanently) allocate a Board Info struct
  349. * and a permanent copy of the "global" data
  350. */
  351. addr_sp -= sizeof (bd_t);
  352. bd = (bd_t *) addr_sp;
  353. gd->bd = bd;
  354. debug("Reserving %zu Bytes for Board Info at: %08lx\n",
  355. sizeof (bd_t), addr_sp);
  356. #ifdef CONFIG_MACH_TYPE
  357. gd->bd->bi_arch_number = CONFIG_MACH_TYPE; /* board id for Linux */
  358. #endif
  359. addr_sp -= sizeof (gd_t);
  360. id = (gd_t *) addr_sp;
  361. debug("Reserving %zu Bytes for Global Data at: %08lx\n",
  362. sizeof (gd_t), addr_sp);
  363. #if defined(CONFIG_OF_SEPARATE) && defined(CONFIG_OF_CONTROL)
  364. /*
  365. * If the device tree is sitting immediate above our image then we
  366. * must relocate it. If it is embedded in the data section, then it
  367. * will be relocated with other data.
  368. */
  369. if (gd->fdt_blob) {
  370. fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob) + 0x1000, 32);
  371. addr_sp -= fdt_size;
  372. new_fdt = (void *)addr_sp;
  373. debug("Reserving %zu Bytes for FDT at: %08lx\n",
  374. fdt_size, addr_sp);
  375. }
  376. #endif
  377. /* setup stackpointer for exeptions */
  378. gd->irq_sp = addr_sp;
  379. #ifdef CONFIG_USE_IRQ
  380. addr_sp -= (CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ);
  381. debug("Reserving %zu Bytes for IRQ stack at: %08lx\n",
  382. CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ, addr_sp);
  383. #endif
  384. /* leave 3 words for abort-stack */
  385. addr_sp -= 12;
  386. /* 8-byte alignment for ABI compliance */
  387. addr_sp &= ~0x07;
  388. #else
  389. addr_sp += 128; /* leave 32 words for abort-stack */
  390. gd->irq_sp = addr_sp;
  391. #endif
  392. debug("New Stack Pointer is: %08lx\n", addr_sp);
  393. #ifdef CONFIG_POST
  394. post_bootmode_init();
  395. post_run(NULL, POST_ROM | post_bootmode_get(0));
  396. #endif
  397. gd->bd->bi_baudrate = gd->baudrate;
  398. /* Ram ist board specific, so move it to board code ... */
  399. dram_init_banksize();
  400. display_dram_config(); /* and display it */
  401. gd->relocaddr = addr;
  402. gd->start_addr_sp = addr_sp;
  403. gd->reloc_off = addr - _TEXT_BASE;
  404. debug("relocation Offset is: %08lx\n", gd->reloc_off);
  405. if (new_fdt) {
  406. memcpy(new_fdt, gd->fdt_blob, fdt_size);
  407. gd->fdt_blob = new_fdt;
  408. }
  409. memcpy(id, (void *)gd, sizeof(gd_t));
  410. relocate_code(addr_sp, id, addr);
  411. /* NOTREACHED - relocate_code() does not return */
  412. }
  413. #if !defined(CONFIG_SYS_NO_FLASH)
  414. static char *failed = "*** failed ***\n";
  415. #endif
  416. /*
  417. ************************************************************************
  418. *
  419. * This is the next part if the initialization sequence: we are now
  420. * running from RAM and have a "normal" C environment, i. e. global
  421. * data can be written, BSS has been cleared, the stack size in not
  422. * that critical any more, etc.
  423. *
  424. ************************************************************************
  425. */
  426. void board_init_r(gd_t *id, ulong dest_addr)
  427. {
  428. ulong malloc_start;
  429. #if !defined(CONFIG_SYS_NO_FLASH)
  430. ulong flash_size;
  431. #endif
  432. gd = id;
  433. gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
  434. bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_R, "board_init_r");
  435. monitor_flash_len = _end_ofs;
  436. /* Enable caches */
  437. enable_caches();
  438. debug("monitor flash len: %08lX\n", monitor_flash_len);
  439. board_init(); /* Setup chipselects */
  440. /*
  441. * TODO: printing of the clock inforamtion of the board is now
  442. * implemented as part of bdinfo command. Currently only support for
  443. * davinci SOC's is added. Remove this check once all the board
  444. * implement this.
  445. */
  446. #ifdef CONFIG_CLOCKS
  447. set_cpu_clk_info(); /* Setup clock information */
  448. #endif
  449. serial_initialize();
  450. debug("Now running in RAM - U-Boot at: %08lx\n", dest_addr);
  451. #ifdef CONFIG_LOGBUFFER
  452. logbuff_init_ptrs();
  453. #endif
  454. #ifdef CONFIG_POST
  455. post_output_backlog();
  456. #endif
  457. /* The Malloc area is immediately below the monitor copy in DRAM */
  458. malloc_start = dest_addr - TOTAL_MALLOC_LEN;
  459. mem_malloc_init (malloc_start, TOTAL_MALLOC_LEN);
  460. #ifdef CONFIG_ARCH_EARLY_INIT_R
  461. arch_early_init_r();
  462. #endif
  463. power_init_board();
  464. #if !defined(CONFIG_SYS_NO_FLASH)
  465. puts("Flash: ");
  466. flash_size = flash_init();
  467. if (flash_size > 0) {
  468. # ifdef CONFIG_SYS_FLASH_CHECKSUM
  469. char *s = getenv("flashchecksum");
  470. print_size(flash_size, "");
  471. /*
  472. * Compute and print flash CRC if flashchecksum is set to 'y'
  473. *
  474. * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
  475. */
  476. if (s && (*s == 'y')) {
  477. printf(" CRC: %08X", crc32(0,
  478. (const unsigned char *) CONFIG_SYS_FLASH_BASE,
  479. flash_size));
  480. }
  481. putc('\n');
  482. # else /* !CONFIG_SYS_FLASH_CHECKSUM */
  483. print_size(flash_size, "\n");
  484. # endif /* CONFIG_SYS_FLASH_CHECKSUM */
  485. } else {
  486. puts(failed);
  487. hang();
  488. }
  489. #endif
  490. #if defined(CONFIG_CMD_NAND)
  491. puts("NAND: ");
  492. nand_init(); /* go init the NAND */
  493. #endif
  494. #if defined(CONFIG_CMD_ONENAND)
  495. onenand_init();
  496. #endif
  497. #ifdef CONFIG_GENERIC_MMC
  498. puts("MMC: ");
  499. mmc_initialize(gd->bd);
  500. #endif
  501. #ifdef CONFIG_HAS_DATAFLASH
  502. AT91F_DataflashInit();
  503. dataflash_print_info();
  504. #endif
  505. /* initialize environment */
  506. env_relocate();
  507. #if defined(CONFIG_CMD_PCI) || defined(CONFIG_PCI)
  508. arm_pci_init();
  509. #endif
  510. stdio_init(); /* get the devices list going. */
  511. jumptable_init();
  512. #if defined(CONFIG_API)
  513. /* Initialize API */
  514. api_init();
  515. #endif
  516. console_init_r(); /* fully init console as a device */
  517. #if defined(CONFIG_ARCH_MISC_INIT)
  518. /* miscellaneous arch dependent initialisations */
  519. arch_misc_init();
  520. #endif
  521. #if defined(CONFIG_MISC_INIT_R)
  522. /* miscellaneous platform dependent initialisations */
  523. misc_init_r();
  524. #endif
  525. /* set up exceptions */
  526. interrupt_init();
  527. /* enable exceptions */
  528. enable_interrupts();
  529. /* Initialize from environment */
  530. load_addr = getenv_ulong("loadaddr", 16, load_addr);
  531. #ifdef CONFIG_BOARD_LATE_INIT
  532. board_late_init();
  533. #endif
  534. #ifdef CONFIG_BITBANGMII
  535. bb_miiphy_init();
  536. #endif
  537. #if defined(CONFIG_CMD_NET)
  538. puts("Net: ");
  539. eth_initialize(gd->bd);
  540. #if defined(CONFIG_RESET_PHY_R)
  541. debug("Reset Ethernet PHY\n");
  542. reset_phy();
  543. #endif
  544. #endif
  545. #ifdef CONFIG_POST
  546. post_run(NULL, POST_RAM | post_bootmode_get(0));
  547. #endif
  548. #if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
  549. /*
  550. * Export available size of memory for Linux,
  551. * taking into account the protected RAM at top of memory
  552. */
  553. {
  554. ulong pram = 0;
  555. uchar memsz[32];
  556. #ifdef CONFIG_PRAM
  557. pram = getenv_ulong("pram", 10, CONFIG_PRAM);
  558. #endif
  559. #ifdef CONFIG_LOGBUFFER
  560. #ifndef CONFIG_ALT_LB_ADDR
  561. /* Also take the logbuffer into account (pram is in kB) */
  562. pram += (LOGBUFF_LEN + LOGBUFF_OVERHEAD) / 1024;
  563. #endif
  564. #endif
  565. sprintf((char *)memsz, "%ldk", (gd->ram_size / 1024) - pram);
  566. setenv("mem", (char *)memsz);
  567. }
  568. #endif
  569. /* main_loop() can return to retry autoboot, if so just run it again. */
  570. for (;;) {
  571. main_loop();
  572. }
  573. /* NOTREACHED - no way out of command loop except booting */
  574. }
  575. void hang(void)
  576. {
  577. puts("### ERROR ### Please RESET the board ###\n");
  578. for (;;);
  579. }