board.c 18 KB

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