board.c 18 KB

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