board.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  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. int print_cpuinfo(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. #if defined(CONFIG_DISPLAY_CPUINFO)
  224. print_cpuinfo, /* display cpu info (and speed) */
  225. #endif
  226. #if defined(CONFIG_DISPLAY_BOARDINFO)
  227. checkboard, /* display board info */
  228. #endif
  229. #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
  230. init_func_i2c,
  231. #endif
  232. dram_init, /* configure available RAM banks */
  233. NULL,
  234. };
  235. void board_init_f(ulong bootflag)
  236. {
  237. bd_t *bd;
  238. init_fnc_t **init_fnc_ptr;
  239. gd_t *id;
  240. ulong addr, addr_sp;
  241. #ifdef CONFIG_PRAM
  242. ulong reg;
  243. #endif
  244. void *new_fdt = NULL;
  245. size_t fdt_size = 0;
  246. memset((void *)gd, 0, sizeof(gd_t));
  247. gd->mon_len = _bss_end_ofs;
  248. #ifdef CONFIG_OF_EMBED
  249. /* Get a pointer to the FDT */
  250. gd->fdt_blob = __dtb_db_begin;
  251. #elif defined CONFIG_OF_SEPARATE
  252. /* FDT is at end of image */
  253. gd->fdt_blob = (void *)(_end_ofs + _TEXT_BASE);
  254. #endif
  255. /* Allow the early environment to override the fdt address */
  256. gd->fdt_blob = (void *)getenv_ulong("fdtcontroladdr", 16,
  257. (uintptr_t)gd->fdt_blob);
  258. for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
  259. if ((*init_fnc_ptr)() != 0) {
  260. hang ();
  261. }
  262. }
  263. #ifdef CONFIG_OF_CONTROL
  264. /* For now, put this check after the console is ready */
  265. if (fdtdec_prepare_fdt()) {
  266. panic("** CONFIG_OF_CONTROL defined but no FDT - please see "
  267. "doc/README.fdt-control");
  268. }
  269. #endif
  270. debug("monitor len: %08lX\n", gd->mon_len);
  271. /*
  272. * Ram is setup, size stored in gd !!
  273. */
  274. debug("ramsize: %08lX\n", gd->ram_size);
  275. #if defined(CONFIG_SYS_MEM_TOP_HIDE)
  276. /*
  277. * Subtract specified amount of memory to hide so that it won't
  278. * get "touched" at all by U-Boot. By fixing up gd->ram_size
  279. * the Linux kernel should now get passed the now "corrected"
  280. * memory size and won't touch it either. This should work
  281. * for arch/ppc and arch/powerpc. Only Linux board ports in
  282. * arch/powerpc with bootwrapper support, that recalculate the
  283. * memory size from the SDRAM controller setup will have to
  284. * get fixed.
  285. */
  286. gd->ram_size -= CONFIG_SYS_MEM_TOP_HIDE;
  287. #endif
  288. addr = CONFIG_SYS_SDRAM_BASE + gd->ram_size;
  289. #ifdef CONFIG_LOGBUFFER
  290. #ifndef CONFIG_ALT_LB_ADDR
  291. /* reserve kernel log buffer */
  292. addr -= (LOGBUFF_RESERVE);
  293. debug("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN,
  294. addr);
  295. #endif
  296. #endif
  297. #ifdef CONFIG_PRAM
  298. /*
  299. * reserve protected RAM
  300. */
  301. reg = getenv_ulong("pram", 10, CONFIG_PRAM);
  302. addr -= (reg << 10); /* size is in kB */
  303. debug("Reserving %ldk for protected RAM at %08lx\n", reg, addr);
  304. #endif /* CONFIG_PRAM */
  305. #if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF))
  306. /* reserve TLB table */
  307. gd->arch.tlb_size = PGTABLE_SIZE;
  308. addr -= gd->arch.tlb_size;
  309. /* round down to next 64 kB limit */
  310. addr &= ~(0x10000 - 1);
  311. gd->arch.tlb_addr = addr;
  312. debug("TLB table from %08lx to %08lx\n", addr, addr + gd->arch.tlb_size);
  313. #endif
  314. /* round down to next 4 kB limit */
  315. addr &= ~(4096 - 1);
  316. debug("Top of RAM usable for U-Boot at: %08lx\n", addr);
  317. #ifdef CONFIG_LCD
  318. #ifdef CONFIG_FB_ADDR
  319. gd->fb_base = CONFIG_FB_ADDR;
  320. #else
  321. /* reserve memory for LCD display (always full pages) */
  322. addr = lcd_setmem(addr);
  323. gd->fb_base = addr;
  324. #endif /* CONFIG_FB_ADDR */
  325. #endif /* CONFIG_LCD */
  326. /*
  327. * reserve memory for U-Boot code, data & bss
  328. * round down to next 4 kB limit
  329. */
  330. addr -= gd->mon_len;
  331. addr &= ~(4096 - 1);
  332. debug("Reserving %ldk for U-Boot at: %08lx\n", gd->mon_len >> 10, addr);
  333. #ifndef CONFIG_SPL_BUILD
  334. /*
  335. * reserve memory for malloc() arena
  336. */
  337. addr_sp = addr - TOTAL_MALLOC_LEN;
  338. debug("Reserving %dk for malloc() at: %08lx\n",
  339. TOTAL_MALLOC_LEN >> 10, addr_sp);
  340. /*
  341. * (permanently) allocate a Board Info struct
  342. * and a permanent copy of the "global" data
  343. */
  344. addr_sp -= sizeof (bd_t);
  345. bd = (bd_t *) addr_sp;
  346. gd->bd = bd;
  347. debug("Reserving %zu Bytes for Board Info at: %08lx\n",
  348. sizeof (bd_t), addr_sp);
  349. #ifdef CONFIG_MACH_TYPE
  350. gd->bd->bi_arch_number = CONFIG_MACH_TYPE; /* board id for Linux */
  351. #endif
  352. addr_sp -= sizeof (gd_t);
  353. id = (gd_t *) addr_sp;
  354. debug("Reserving %zu Bytes for Global Data at: %08lx\n",
  355. sizeof (gd_t), addr_sp);
  356. #if defined(CONFIG_OF_SEPARATE) && defined(CONFIG_OF_CONTROL)
  357. /*
  358. * If the device tree is sitting immediate above our image then we
  359. * must relocate it. If it is embedded in the data section, then it
  360. * will be relocated with other data.
  361. */
  362. if (gd->fdt_blob) {
  363. fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob) + 0x1000, 32);
  364. addr_sp -= fdt_size;
  365. new_fdt = (void *)addr_sp;
  366. debug("Reserving %zu Bytes for FDT at: %08lx\n",
  367. fdt_size, addr_sp);
  368. }
  369. #endif
  370. #ifndef CONFIG_ARM64
  371. /* setup stackpointer for exeptions */
  372. gd->irq_sp = addr_sp;
  373. #ifdef CONFIG_USE_IRQ
  374. addr_sp -= (CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ);
  375. debug("Reserving %zu Bytes for IRQ stack at: %08lx\n",
  376. CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ, addr_sp);
  377. #endif
  378. /* leave 3 words for abort-stack */
  379. addr_sp -= 12;
  380. /* 8-byte alignment for ABI compliance */
  381. addr_sp &= ~0x07;
  382. #else /* CONFIG_ARM64 */
  383. /* 16-byte alignment for ABI compliance */
  384. addr_sp &= ~0x0f;
  385. #endif /* CONFIG_ARM64 */
  386. #else
  387. addr_sp += 128; /* leave 32 words for abort-stack */
  388. gd->irq_sp = addr_sp;
  389. #endif
  390. debug("New Stack Pointer is: %08lx\n", addr_sp);
  391. #ifdef CONFIG_POST
  392. post_bootmode_init();
  393. post_run(NULL, POST_ROM | post_bootmode_get(0));
  394. #endif
  395. gd->bd->bi_baudrate = gd->baudrate;
  396. /* Ram ist board specific, so move it to board code ... */
  397. dram_init_banksize();
  398. display_dram_config(); /* and display it */
  399. gd->relocaddr = addr;
  400. gd->start_addr_sp = addr_sp;
  401. gd->reloc_off = addr - _TEXT_BASE;
  402. debug("relocation Offset is: %08lx\n", gd->reloc_off);
  403. if (new_fdt) {
  404. memcpy(new_fdt, gd->fdt_blob, fdt_size);
  405. gd->fdt_blob = new_fdt;
  406. }
  407. memcpy(id, (void *)gd, sizeof(gd_t));
  408. }
  409. #if !defined(CONFIG_SYS_NO_FLASH)
  410. static char *failed = "*** failed ***\n";
  411. #endif
  412. /*
  413. * Tell if it's OK to load the environment early in boot.
  414. *
  415. * If CONFIG_OF_CONFIG is defined, we'll check with the FDT to see
  416. * if this is OK (defaulting to saying it's not OK).
  417. *
  418. * NOTE: Loading the environment early can be a bad idea if security is
  419. * important, since no verification is done on the environment.
  420. *
  421. * @return 0 if environment should not be loaded, !=0 if it is ok to load
  422. */
  423. static int should_load_env(void)
  424. {
  425. #ifdef CONFIG_OF_CONTROL
  426. return fdtdec_get_config_int(gd->fdt_blob, "load-environment", 1);
  427. #elif defined CONFIG_DELAY_ENVIRONMENT
  428. return 0;
  429. #else
  430. return 1;
  431. #endif
  432. }
  433. #if defined(CONFIG_DISPLAY_BOARDINFO_LATE) && defined(CONFIG_OF_CONTROL)
  434. static void display_fdt_model(const void *blob)
  435. {
  436. const char *model;
  437. model = (char *)fdt_getprop(blob, 0, "model", NULL);
  438. printf("Model: %s\n", model ? model : "<unknown>");
  439. }
  440. #endif
  441. /************************************************************************
  442. *
  443. * This is the next part if the initialization sequence: we are now
  444. * running from RAM and have a "normal" C environment, i. e. global
  445. * data can be written, BSS has been cleared, the stack size in not
  446. * that critical any more, etc.
  447. *
  448. ************************************************************************
  449. */
  450. void board_init_r(gd_t *id, ulong dest_addr)
  451. {
  452. ulong malloc_start;
  453. #if !defined(CONFIG_SYS_NO_FLASH)
  454. ulong flash_size;
  455. #endif
  456. gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
  457. bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_R, "board_init_r");
  458. monitor_flash_len = _end_ofs;
  459. /* Enable caches */
  460. enable_caches();
  461. debug("monitor flash len: %08lX\n", monitor_flash_len);
  462. board_init(); /* Setup chipselects */
  463. /*
  464. * TODO: printing of the clock inforamtion of the board is now
  465. * implemented as part of bdinfo command. Currently only support for
  466. * davinci SOC's is added. Remove this check once all the board
  467. * implement this.
  468. */
  469. #ifdef CONFIG_CLOCKS
  470. set_cpu_clk_info(); /* Setup clock information */
  471. #endif
  472. serial_initialize();
  473. debug("Now running in RAM - U-Boot at: %08lx\n", dest_addr);
  474. #ifdef CONFIG_LOGBUFFER
  475. logbuff_init_ptrs();
  476. #endif
  477. #ifdef CONFIG_POST
  478. post_output_backlog();
  479. #endif
  480. /* The Malloc area is immediately below the monitor copy in DRAM */
  481. malloc_start = dest_addr - TOTAL_MALLOC_LEN;
  482. mem_malloc_init (malloc_start, TOTAL_MALLOC_LEN);
  483. #ifdef CONFIG_ARCH_EARLY_INIT_R
  484. arch_early_init_r();
  485. #endif
  486. power_init_board();
  487. #if !defined(CONFIG_SYS_NO_FLASH)
  488. puts("Flash: ");
  489. flash_size = flash_init();
  490. if (flash_size > 0) {
  491. # ifdef CONFIG_SYS_FLASH_CHECKSUM
  492. print_size(flash_size, "");
  493. /*
  494. * Compute and print flash CRC if flashchecksum is set to 'y'
  495. *
  496. * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
  497. */
  498. if (getenv_yesno("flashchecksum") == 1) {
  499. printf(" CRC: %08X", crc32(0,
  500. (const unsigned char *) CONFIG_SYS_FLASH_BASE,
  501. flash_size));
  502. }
  503. putc('\n');
  504. # else /* !CONFIG_SYS_FLASH_CHECKSUM */
  505. print_size(flash_size, "\n");
  506. # endif /* CONFIG_SYS_FLASH_CHECKSUM */
  507. } else {
  508. puts(failed);
  509. hang();
  510. }
  511. #endif
  512. #if defined(CONFIG_CMD_NAND)
  513. puts("NAND: ");
  514. nand_init(); /* go init the NAND */
  515. #endif
  516. #if defined(CONFIG_CMD_ONENAND)
  517. onenand_init();
  518. #endif
  519. #ifdef CONFIG_GENERIC_MMC
  520. puts("MMC: ");
  521. mmc_initialize(gd->bd);
  522. #endif
  523. #ifdef CONFIG_HAS_DATAFLASH
  524. AT91F_DataflashInit();
  525. dataflash_print_info();
  526. #endif
  527. /* initialize environment */
  528. if (should_load_env())
  529. env_relocate();
  530. else
  531. set_default_env(NULL);
  532. #if defined(CONFIG_CMD_PCI) || defined(CONFIG_PCI)
  533. arm_pci_init();
  534. #endif
  535. stdio_init(); /* get the devices list going. */
  536. jumptable_init();
  537. #if defined(CONFIG_API)
  538. /* Initialize API */
  539. api_init();
  540. #endif
  541. console_init_r(); /* fully init console as a device */
  542. #ifdef CONFIG_DISPLAY_BOARDINFO_LATE
  543. # ifdef CONFIG_OF_CONTROL
  544. /* Put this here so it appears on the LCD, now it is ready */
  545. display_fdt_model(gd->fdt_blob);
  546. # else
  547. checkboard();
  548. # endif
  549. #endif
  550. #if defined(CONFIG_ARCH_MISC_INIT)
  551. /* miscellaneous arch dependent initialisations */
  552. arch_misc_init();
  553. #endif
  554. #if defined(CONFIG_MISC_INIT_R)
  555. /* miscellaneous platform dependent initialisations */
  556. misc_init_r();
  557. #endif
  558. /* set up exceptions */
  559. interrupt_init();
  560. /* enable exceptions */
  561. enable_interrupts();
  562. /* Initialize from environment */
  563. load_addr = getenv_ulong("loadaddr", 16, load_addr);
  564. #ifdef CONFIG_BOARD_LATE_INIT
  565. board_late_init();
  566. #endif
  567. #ifdef CONFIG_BITBANGMII
  568. bb_miiphy_init();
  569. #endif
  570. #if defined(CONFIG_CMD_NET)
  571. puts("Net: ");
  572. eth_initialize(gd->bd);
  573. #if defined(CONFIG_RESET_PHY_R)
  574. debug("Reset Ethernet PHY\n");
  575. reset_phy();
  576. #endif
  577. #endif
  578. #ifdef CONFIG_POST
  579. post_run(NULL, POST_RAM | post_bootmode_get(0));
  580. #endif
  581. #if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
  582. /*
  583. * Export available size of memory for Linux,
  584. * taking into account the protected RAM at top of memory
  585. */
  586. {
  587. ulong pram = 0;
  588. uchar memsz[32];
  589. #ifdef CONFIG_PRAM
  590. pram = getenv_ulong("pram", 10, CONFIG_PRAM);
  591. #endif
  592. #ifdef CONFIG_LOGBUFFER
  593. #ifndef CONFIG_ALT_LB_ADDR
  594. /* Also take the logbuffer into account (pram is in kB) */
  595. pram += (LOGBUFF_LEN + LOGBUFF_OVERHEAD) / 1024;
  596. #endif
  597. #endif
  598. sprintf((char *)memsz, "%ldk", (gd->ram_size / 1024) - pram);
  599. setenv("mem", (char *)memsz);
  600. }
  601. #endif
  602. /* main_loop() can return to retry autoboot, if so just run it again. */
  603. for (;;) {
  604. main_loop();
  605. }
  606. /* NOTREACHED - no way out of command loop except booting */
  607. }