board.c 18 KB

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