board.c 17 KB

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