board.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904
  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 <malloc.h>
  42. #include <stdio_dev.h>
  43. #include <timestamp.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. #ifdef CONFIG_BITBANGMII
  51. #include <miiphy.h>
  52. #endif
  53. #ifdef CONFIG_DRIVER_SMC91111
  54. #include "../drivers/net/smc91111.h"
  55. #endif
  56. #ifdef CONFIG_DRIVER_LAN91C96
  57. #include "../drivers/net/lan91c96.h"
  58. #endif
  59. DECLARE_GLOBAL_DATA_PTR;
  60. ulong monitor_flash_len;
  61. #ifdef CONFIG_HAS_DATAFLASH
  62. extern int AT91F_DataflashInit(void);
  63. extern void dataflash_print_info(void);
  64. #endif
  65. #ifndef CONFIG_IDENT_STRING
  66. #define CONFIG_IDENT_STRING ""
  67. #endif
  68. const char version_string[] =
  69. U_BOOT_VERSION" (" U_BOOT_DATE " - " U_BOOT_TIME ")"CONFIG_IDENT_STRING;
  70. #ifdef CONFIG_DRIVER_RTL8019
  71. extern void rtl8019_get_enetaddr (uchar * addr);
  72. #endif
  73. #if defined(CONFIG_HARD_I2C) || \
  74. defined(CONFIG_SOFT_I2C)
  75. #include <i2c.h>
  76. #endif
  77. /************************************************************************
  78. * Coloured LED functionality
  79. ************************************************************************
  80. * May be supplied by boards if desired
  81. */
  82. void inline __coloured_LED_init (void) {}
  83. void coloured_LED_init (void) __attribute__((weak, alias("__coloured_LED_init")));
  84. void inline __red_LED_on (void) {}
  85. void red_LED_on (void) __attribute__((weak, alias("__red_LED_on")));
  86. void inline __red_LED_off(void) {}
  87. void red_LED_off(void) __attribute__((weak, alias("__red_LED_off")));
  88. void inline __green_LED_on(void) {}
  89. void green_LED_on(void) __attribute__((weak, alias("__green_LED_on")));
  90. void inline __green_LED_off(void) {}
  91. void green_LED_off(void) __attribute__((weak, alias("__green_LED_off")));
  92. void inline __yellow_LED_on(void) {}
  93. void yellow_LED_on(void) __attribute__((weak, alias("__yellow_LED_on")));
  94. void inline __yellow_LED_off(void) {}
  95. void yellow_LED_off(void) __attribute__((weak, alias("__yellow_LED_off")));
  96. void inline __blue_LED_on(void) {}
  97. void blue_LED_on(void) __attribute__((weak, alias("__blue_LED_on")));
  98. void inline __blue_LED_off(void) {}
  99. void blue_LED_off(void) __attribute__((weak, alias("__blue_LED_off")));
  100. /************************************************************************
  101. * Init Utilities *
  102. ************************************************************************
  103. * Some of this code should be moved into the core functions,
  104. * or dropped completely,
  105. * but let's get it working (again) first...
  106. */
  107. #if defined(CONFIG_ARM_DCC) && !defined(CONFIG_BAUDRATE)
  108. #define CONFIG_BAUDRATE 115200
  109. #endif
  110. static int init_baudrate (void)
  111. {
  112. char tmp[64]; /* long enough for environment variables */
  113. int i = getenv_f("baudrate", tmp, sizeof (tmp));
  114. #if !defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
  115. gd->baudrate = (i > 0)
  116. #else
  117. gd->bd->bi_baudrate = gd->baudrate = (i > 0)
  118. #endif
  119. ? (int) simple_strtoul (tmp, NULL, 10)
  120. : CONFIG_BAUDRATE;
  121. return (0);
  122. }
  123. static int display_banner (void)
  124. {
  125. printf ("\n\n%s\n\n", version_string);
  126. debug ("U-Boot code: %08lX -> %08lX BSS: -> %08lX\n",
  127. #if !defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
  128. _TEXT_BASE,
  129. #else
  130. _armboot_start,
  131. #endif
  132. _bss_start, _bss_end);
  133. #ifdef CONFIG_MODEM_SUPPORT
  134. debug ("Modem Support enabled\n");
  135. #endif
  136. #ifdef CONFIG_USE_IRQ
  137. debug ("IRQ Stack: %08lx\n", IRQ_STACK_START);
  138. debug ("FIQ Stack: %08lx\n", FIQ_STACK_START);
  139. #endif
  140. return (0);
  141. }
  142. /*
  143. * WARNING: this code looks "cleaner" than the PowerPC version, but
  144. * has the disadvantage that you either get nothing, or everything.
  145. * On PowerPC, you might see "DRAM: " before the system hangs - which
  146. * gives a simple yet clear indication which part of the
  147. * initialization if failing.
  148. */
  149. static int display_dram_config (void)
  150. {
  151. int i;
  152. #ifdef DEBUG
  153. puts ("RAM Configuration:\n");
  154. for(i=0; i<CONFIG_NR_DRAM_BANKS; i++) {
  155. printf ("Bank #%d: %08lx ", i, gd->bd->bi_dram[i].start);
  156. print_size (gd->bd->bi_dram[i].size, "\n");
  157. }
  158. #else
  159. ulong size = 0;
  160. for (i=0; i<CONFIG_NR_DRAM_BANKS; i++) {
  161. size += gd->bd->bi_dram[i].size;
  162. }
  163. puts("DRAM: ");
  164. print_size(size, "\n");
  165. #endif
  166. return (0);
  167. }
  168. #if defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
  169. #ifndef CONFIG_SYS_NO_FLASH
  170. static void display_flash_config (ulong size)
  171. {
  172. puts ("Flash: ");
  173. print_size (size, "\n");
  174. }
  175. #endif /* CONFIG_SYS_NO_FLASH */
  176. #endif
  177. #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
  178. static int init_func_i2c (void)
  179. {
  180. puts ("I2C: ");
  181. i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
  182. puts ("ready\n");
  183. return (0);
  184. }
  185. #endif
  186. #if defined(CONFIG_CMD_PCI) || defined (CONFIG_PCI)
  187. #include <pci.h>
  188. static int arm_pci_init(void)
  189. {
  190. pci_init();
  191. return 0;
  192. }
  193. #endif /* CONFIG_CMD_PCI || CONFIG_PCI */
  194. /*
  195. * Breathe some life into the board...
  196. *
  197. * Initialize a serial port as console, and carry out some hardware
  198. * tests.
  199. *
  200. * The first part of initialization is running from Flash memory;
  201. * its main purpose is to initialize the RAM so that we
  202. * can relocate the monitor code to RAM.
  203. */
  204. /*
  205. * All attempts to come up with a "common" initialization sequence
  206. * that works for all boards and architectures failed: some of the
  207. * requirements are just _too_ different. To get rid of the resulting
  208. * mess of board dependent #ifdef'ed code we now make the whole
  209. * initialization sequence configurable to the user.
  210. *
  211. * The requirements for any new initalization function is simple: it
  212. * receives a pointer to the "global data" structure as it's only
  213. * argument, and returns an integer return code, where 0 means
  214. * "continue" and != 0 means "fatal error, hang the system".
  215. */
  216. typedef int (init_fnc_t) (void);
  217. int print_cpuinfo (void);
  218. #if defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
  219. init_fnc_t *init_sequence[] = {
  220. #if defined(CONFIG_ARCH_CPU_INIT)
  221. arch_cpu_init, /* basic arch cpu dependent setup */
  222. #endif
  223. board_init, /* basic board dependent setup */
  224. #if defined(CONFIG_USE_IRQ)
  225. interrupt_init, /* set up exceptions */
  226. #endif
  227. timer_init, /* initialize timer */
  228. #ifdef CONFIG_FSL_ESDHC
  229. get_clocks,
  230. #endif
  231. env_init, /* initialize environment */
  232. init_baudrate, /* initialze baudrate settings */
  233. serial_init, /* serial communications setup */
  234. console_init_f, /* stage 1 init of console */
  235. display_banner, /* say that we are here */
  236. #if defined(CONFIG_DISPLAY_CPUINFO)
  237. print_cpuinfo, /* display cpu info (and speed) */
  238. #endif
  239. #if defined(CONFIG_DISPLAY_BOARDINFO)
  240. checkboard, /* display board info */
  241. #endif
  242. #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
  243. init_func_i2c,
  244. #endif
  245. dram_init, /* configure available RAM banks */
  246. #if defined(CONFIG_CMD_PCI) || defined (CONFIG_PCI)
  247. arm_pci_init,
  248. #endif
  249. display_dram_config,
  250. NULL,
  251. };
  252. void start_armboot (void)
  253. {
  254. init_fnc_t **init_fnc_ptr;
  255. char *s;
  256. #if defined(CONFIG_VFD) || defined(CONFIG_LCD)
  257. unsigned long addr;
  258. #endif
  259. /* Pointer is writable since we allocated a register for it */
  260. gd = (gd_t*)(_armboot_start - CONFIG_SYS_MALLOC_LEN - sizeof(gd_t));
  261. /* compiler optimization barrier needed for GCC >= 3.4 */
  262. __asm__ __volatile__("": : :"memory");
  263. memset ((void*)gd, 0, sizeof (gd_t));
  264. gd->bd = (bd_t*)((char*)gd - sizeof(bd_t));
  265. memset (gd->bd, 0, sizeof (bd_t));
  266. gd->flags |= GD_FLG_RELOC;
  267. monitor_flash_len = _bss_start - _armboot_start;
  268. for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
  269. if ((*init_fnc_ptr)() != 0) {
  270. hang ();
  271. }
  272. }
  273. /* armboot_start is defined in the board-specific linker script */
  274. mem_malloc_init (_armboot_start - CONFIG_SYS_MALLOC_LEN,
  275. CONFIG_SYS_MALLOC_LEN);
  276. #ifndef CONFIG_SYS_NO_FLASH
  277. /* configure available FLASH banks */
  278. display_flash_config (flash_init ());
  279. #endif /* CONFIG_SYS_NO_FLASH */
  280. #ifdef CONFIG_VFD
  281. # ifndef PAGE_SIZE
  282. # define PAGE_SIZE 4096
  283. # endif
  284. /*
  285. * reserve memory for VFD display (always full pages)
  286. */
  287. /* bss_end is defined in the board-specific linker script */
  288. addr = (_bss_end + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
  289. vfd_setmem (addr);
  290. gd->fb_base = addr;
  291. #endif /* CONFIG_VFD */
  292. #ifdef CONFIG_LCD
  293. /* board init may have inited fb_base */
  294. if (!gd->fb_base) {
  295. # ifndef PAGE_SIZE
  296. # define PAGE_SIZE 4096
  297. # endif
  298. /*
  299. * reserve memory for LCD display (always full pages)
  300. */
  301. /* bss_end is defined in the board-specific linker script */
  302. addr = (_bss_end + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
  303. lcd_setmem (addr);
  304. gd->fb_base = addr;
  305. }
  306. #endif /* CONFIG_LCD */
  307. #if defined(CONFIG_CMD_NAND)
  308. puts ("NAND: ");
  309. nand_init(); /* go init the NAND */
  310. #endif
  311. #if defined(CONFIG_CMD_ONENAND)
  312. onenand_init();
  313. #endif
  314. #ifdef CONFIG_HAS_DATAFLASH
  315. AT91F_DataflashInit();
  316. dataflash_print_info();
  317. #endif
  318. #ifdef CONFIG_GENERIC_MMC
  319. /*
  320. * MMC initialization is called before relocating env.
  321. * Thus It is required that operations like pin multiplexer
  322. * be put in board_init.
  323. */
  324. puts ("MMC: ");
  325. mmc_initialize (gd->bd);
  326. #endif
  327. /* initialize environment */
  328. env_relocate ();
  329. #ifdef CONFIG_VFD
  330. /* must do this after the framebuffer is allocated */
  331. drv_vfd_init();
  332. #endif /* CONFIG_VFD */
  333. #ifdef CONFIG_SERIAL_MULTI
  334. serial_initialize();
  335. #endif
  336. /* IP Address */
  337. gd->bd->bi_ip_addr = getenv_IPaddr ("ipaddr");
  338. stdio_init (); /* get the devices list going. */
  339. jumptable_init ();
  340. #if defined(CONFIG_API)
  341. /* Initialize API */
  342. api_init ();
  343. #endif
  344. console_init_r (); /* fully init console as a device */
  345. #if defined(CONFIG_ARCH_MISC_INIT)
  346. /* miscellaneous arch dependent initialisations */
  347. arch_misc_init ();
  348. #endif
  349. #if defined(CONFIG_MISC_INIT_R)
  350. /* miscellaneous platform dependent initialisations */
  351. misc_init_r ();
  352. #endif
  353. /* enable exceptions */
  354. enable_interrupts ();
  355. /* Perform network card initialisation if necessary */
  356. #if defined(CONFIG_DRIVER_SMC91111) || defined (CONFIG_DRIVER_LAN91C96)
  357. /* XXX: this needs to be moved to board init */
  358. if (getenv ("ethaddr")) {
  359. uchar enetaddr[6];
  360. eth_getenv_enetaddr("ethaddr", enetaddr);
  361. smc_set_mac_addr(enetaddr);
  362. }
  363. #endif /* CONFIG_DRIVER_SMC91111 || CONFIG_DRIVER_LAN91C96 */
  364. /* Initialize from environment */
  365. if ((s = getenv ("loadaddr")) != NULL) {
  366. load_addr = simple_strtoul (s, NULL, 16);
  367. }
  368. #if defined(CONFIG_CMD_NET)
  369. if ((s = getenv ("bootfile")) != NULL) {
  370. copy_filename (BootFile, s, sizeof (BootFile));
  371. }
  372. #endif
  373. #ifdef BOARD_LATE_INIT
  374. board_late_init ();
  375. #endif
  376. #ifdef CONFIG_BITBANGMII
  377. bb_miiphy_init();
  378. #endif
  379. #if defined(CONFIG_CMD_NET)
  380. #if defined(CONFIG_NET_MULTI)
  381. puts ("Net: ");
  382. #endif
  383. eth_initialize(gd->bd);
  384. #if defined(CONFIG_RESET_PHY_R)
  385. debug ("Reset Ethernet PHY\n");
  386. reset_phy();
  387. #endif
  388. #endif
  389. /* main_loop() can return to retry autoboot, if so just run it again. */
  390. for (;;) {
  391. main_loop ();
  392. }
  393. /* NOTREACHED - no way out of command loop except booting */
  394. }
  395. #else
  396. void __dram_init_banksize(void)
  397. {
  398. gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
  399. gd->bd->bi_dram[0].size = gd->ram_size;
  400. }
  401. void dram_init_banksize(void)
  402. __attribute__((weak, alias("__dram_init_banksize")));
  403. init_fnc_t *init_sequence[] = {
  404. #if defined(CONFIG_ARCH_CPU_INIT)
  405. arch_cpu_init, /* basic arch cpu dependent setup */
  406. #endif
  407. #if defined(CONFIG_BOARD_EARLY_INIT_F)
  408. board_early_init_f,
  409. #endif
  410. timer_init, /* initialize timer */
  411. #ifdef CONFIG_FSL_ESDHC
  412. get_clocks,
  413. #endif
  414. env_init, /* initialize environment */
  415. init_baudrate, /* initialze baudrate settings */
  416. serial_init, /* serial communications setup */
  417. console_init_f, /* stage 1 init of console */
  418. display_banner, /* say that we are here */
  419. #if defined(CONFIG_DISPLAY_CPUINFO)
  420. print_cpuinfo, /* display cpu info (and speed) */
  421. #endif
  422. #if defined(CONFIG_DISPLAY_BOARDINFO)
  423. checkboard, /* display board info */
  424. #endif
  425. #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
  426. init_func_i2c,
  427. #endif
  428. dram_init, /* configure available RAM banks */
  429. #if defined(CONFIG_CMD_PCI) || defined (CONFIG_PCI)
  430. arm_pci_init,
  431. #endif
  432. NULL,
  433. };
  434. void board_init_f (ulong bootflag)
  435. {
  436. bd_t *bd;
  437. init_fnc_t **init_fnc_ptr;
  438. gd_t *id;
  439. ulong addr, addr_sp;
  440. /* Pointer is writable since we allocated a register for it */
  441. gd = (gd_t *) (CONFIG_SYS_INIT_SP_ADDR);
  442. /* compiler optimization barrier needed for GCC >= 3.4 */
  443. __asm__ __volatile__("": : :"memory");
  444. memset ((void*)gd, 0, sizeof (gd_t));
  445. gd->mon_len = _bss_end - _TEXT_BASE;
  446. for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
  447. if ((*init_fnc_ptr)() != 0) {
  448. hang ();
  449. }
  450. }
  451. debug ("monitor len: %08lX\n", gd->mon_len);
  452. /*
  453. * Ram is setup, size stored in gd !!
  454. */
  455. debug ("ramsize: %08lX\n", gd->ram_size);
  456. #if defined(CONFIG_SYS_MEM_TOP_HIDE)
  457. /*
  458. * Subtract specified amount of memory to hide so that it won't
  459. * get "touched" at all by U-Boot. By fixing up gd->ram_size
  460. * the Linux kernel should now get passed the now "corrected"
  461. * memory size and won't touch it either. This should work
  462. * for arch/ppc and arch/powerpc. Only Linux board ports in
  463. * arch/powerpc with bootwrapper support, that recalculate the
  464. * memory size from the SDRAM controller setup will have to
  465. * get fixed.
  466. */
  467. gd->ram_size -= CONFIG_SYS_MEM_TOP_HIDE;
  468. #endif
  469. addr = CONFIG_SYS_SDRAM_BASE + gd->ram_size;
  470. #ifdef CONFIG_LOGBUFFER
  471. #ifndef CONFIG_ALT_LB_ADDR
  472. /* reserve kernel log buffer */
  473. addr -= (LOGBUFF_RESERVE);
  474. debug ("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN, addr);
  475. #endif
  476. #endif
  477. #ifdef CONFIG_PRAM
  478. /*
  479. * reserve protected RAM
  480. */
  481. i = getenv_r ("pram", (char *)tmp, sizeof (tmp));
  482. reg = (i > 0) ? simple_strtoul ((const char *)tmp, NULL, 10) : CONFIG_PRAM;
  483. addr -= (reg << 10); /* size is in kB */
  484. debug ("Reserving %ldk for protected RAM at %08lx\n", reg, addr);
  485. #endif /* CONFIG_PRAM */
  486. #if !(defined(CONFIG_SYS_NO_ICACHE) && defined(CONFIG_SYS_NO_DCACHE))
  487. /* reserve TLB table */
  488. addr -= (4096 * 4);
  489. /* round down to next 64 kB limit */
  490. addr &= ~(0x10000 - 1);
  491. gd->tlb_addr = addr;
  492. debug ("TLB table at: %08lx\n", addr);
  493. #endif
  494. /* round down to next 4 kB limit */
  495. addr &= ~(4096 - 1);
  496. debug ("Top of RAM usable for U-Boot at: %08lx\n", addr);
  497. #ifdef CONFIG_VFD
  498. # ifndef PAGE_SIZE
  499. # define PAGE_SIZE 4096
  500. # endif
  501. /*
  502. * reserve memory for VFD display (always full pages)
  503. */
  504. addr -= vfd_setmem (addr);
  505. gd->fb_base = addr;
  506. #endif /* CONFIG_VFD */
  507. #ifdef CONFIG_LCD
  508. /* reserve memory for LCD display (always full pages) */
  509. addr = lcd_setmem (addr);
  510. gd->fb_base = addr;
  511. #endif /* CONFIG_LCD */
  512. /*
  513. * reserve memory for U-Boot code, data & bss
  514. * round down to next 4 kB limit
  515. */
  516. addr -= gd->mon_len;
  517. addr &= ~(4096 - 1);
  518. debug ("Reserving %ldk for U-Boot at: %08lx\n", gd->mon_len >> 10, addr);
  519. #ifndef CONFIG_PRELOADER
  520. /*
  521. * reserve memory for malloc() arena
  522. */
  523. addr_sp = addr - TOTAL_MALLOC_LEN;
  524. debug ("Reserving %dk for malloc() at: %08lx\n",
  525. TOTAL_MALLOC_LEN >> 10, addr_sp);
  526. /*
  527. * (permanently) allocate a Board Info struct
  528. * and a permanent copy of the "global" data
  529. */
  530. addr_sp -= sizeof (bd_t);
  531. bd = (bd_t *) addr_sp;
  532. gd->bd = bd;
  533. debug ("Reserving %zu Bytes for Board Info at: %08lx\n",
  534. sizeof (bd_t), addr_sp);
  535. addr_sp -= sizeof (gd_t);
  536. id = (gd_t *) addr_sp;
  537. debug ("Reserving %zu Bytes for Global Data at: %08lx\n",
  538. sizeof (gd_t), addr_sp);
  539. /* setup stackpointer for exeptions */
  540. gd->irq_sp = addr_sp;
  541. #ifdef CONFIG_USE_IRQ
  542. addr_sp -= (CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ);
  543. debug ("Reserving %zu Bytes for IRQ stack at: %08lx\n",
  544. CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ, addr_sp);
  545. #endif
  546. /* leave 3 words for abort-stack */
  547. addr_sp -= 3;
  548. /* 8-byte alignment for ABI compliance */
  549. addr_sp &= ~0x07;
  550. #else
  551. addr_sp += 128; /* leave 32 words for abort-stack */
  552. gd->irq_sp = addr_sp;
  553. #endif
  554. debug ("New Stack Pointer is: %08lx\n", addr_sp);
  555. #ifdef CONFIG_POST
  556. post_bootmode_init();
  557. post_run (NULL, POST_ROM | post_bootmode_get(0));
  558. #endif
  559. gd->bd->bi_baudrate = gd->baudrate;
  560. /* Ram ist board specific, so move it to board code ... */
  561. dram_init_banksize();
  562. display_dram_config(); /* and display it */
  563. gd->relocaddr = addr;
  564. gd->start_addr_sp = addr_sp;
  565. gd->reloc_off = addr - _TEXT_BASE;
  566. debug ("relocation Offset is: %08lx\n", gd->reloc_off);
  567. memcpy (id, (void *)gd, sizeof (gd_t));
  568. relocate_code (addr_sp, id, addr);
  569. /* NOTREACHED - relocate_code() does not return */
  570. }
  571. #if !defined(CONFIG_SYS_NO_FLASH)
  572. static char *failed = "*** failed ***\n";
  573. #endif
  574. /************************************************************************
  575. *
  576. * This is the next part if the initialization sequence: we are now
  577. * running from RAM and have a "normal" C environment, i. e. global
  578. * data can be written, BSS has been cleared, the stack size in not
  579. * that critical any more, etc.
  580. *
  581. ************************************************************************
  582. */
  583. void board_init_r (gd_t *id, ulong dest_addr)
  584. {
  585. char *s;
  586. bd_t *bd;
  587. ulong malloc_start;
  588. #if !defined(CONFIG_SYS_NO_FLASH)
  589. ulong flash_size;
  590. #endif
  591. #if !defined(CONFIG_RELOC_FIXUP_WORKS)
  592. extern void malloc_bin_reloc (void);
  593. #if defined(CONFIG_CMD_BMP)
  594. extern void bmp_reloc(void);
  595. #endif
  596. #if defined(CONFIG_CMD_I2C)
  597. extern void i2c_reloc(void);
  598. #endif
  599. #endif
  600. gd = id;
  601. bd = gd->bd;
  602. gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
  603. monitor_flash_len = _bss_start - _TEXT_BASE;
  604. debug ("monitor flash len: %08lX\n", monitor_flash_len);
  605. board_init(); /* Setup chipselects */
  606. #ifdef CONFIG_SERIAL_MULTI
  607. serial_initialize();
  608. #endif
  609. debug ("Now running in RAM - U-Boot at: %08lx\n", dest_addr);
  610. #if !defined(CONFIG_RELOC_FIXUP_WORKS)
  611. /*
  612. * We have to relocate the command table manually
  613. */
  614. fixup_cmdtable(&__u_boot_cmd_start,
  615. (ulong)(&__u_boot_cmd_end - &__u_boot_cmd_start));
  616. #if defined(CONFIG_CMD_BMP)
  617. bmp_reloc();
  618. #endif
  619. #if defined(CONFIG_CMD_I2C)
  620. i2c_reloc();
  621. #endif
  622. #endif /* !defined(CONFIG_RELOC_FIXUP_WORKS) */
  623. #ifdef CONFIG_LOGBUFFER
  624. logbuff_init_ptrs ();
  625. #endif
  626. #ifdef CONFIG_POST
  627. post_output_backlog ();
  628. #ifndef CONFIG_RELOC_FIXUP_WORKS
  629. post_reloc ();
  630. #endif
  631. #endif
  632. /* The Malloc area is immediately below the monitor copy in DRAM */
  633. malloc_start = dest_addr - TOTAL_MALLOC_LEN;
  634. mem_malloc_init (malloc_start, TOTAL_MALLOC_LEN);
  635. #if !defined(CONFIG_RELOC_FIXUP_WORKS)
  636. malloc_bin_reloc ();
  637. #endif
  638. #if !defined(CONFIG_SYS_NO_FLASH)
  639. puts ("FLASH: ");
  640. if ((flash_size = flash_init ()) > 0) {
  641. # ifdef CONFIG_SYS_FLASH_CHECKSUM
  642. print_size (flash_size, "");
  643. /*
  644. * Compute and print flash CRC if flashchecksum is set to 'y'
  645. *
  646. * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
  647. */
  648. s = getenv ("flashchecksum");
  649. if (s && (*s == 'y')) {
  650. printf (" CRC: %08X",
  651. crc32 (0, (const unsigned char *) CONFIG_SYS_FLASH_BASE, flash_size)
  652. );
  653. }
  654. putc ('\n');
  655. # else /* !CONFIG_SYS_FLASH_CHECKSUM */
  656. print_size (flash_size, "\n");
  657. # endif /* CONFIG_SYS_FLASH_CHECKSUM */
  658. } else {
  659. puts (failed);
  660. hang ();
  661. }
  662. #endif
  663. #if defined(CONFIG_CMD_NAND)
  664. puts ("NAND: ");
  665. nand_init(); /* go init the NAND */
  666. #endif
  667. #if defined(CONFIG_CMD_ONENAND)
  668. onenand_init();
  669. #endif
  670. #ifdef CONFIG_GENERIC_MMC
  671. puts("MMC: ");
  672. mmc_initialize(bd);
  673. #endif
  674. #ifdef CONFIG_HAS_DATAFLASH
  675. AT91F_DataflashInit();
  676. dataflash_print_info();
  677. #endif
  678. /* initialize environment */
  679. env_relocate ();
  680. #ifdef CONFIG_VFD
  681. /* must do this after the framebuffer is allocated */
  682. drv_vfd_init();
  683. #endif /* CONFIG_VFD */
  684. /* IP Address */
  685. gd->bd->bi_ip_addr = getenv_IPaddr ("ipaddr");
  686. stdio_init (); /* get the devices list going. */
  687. jumptable_init ();
  688. #if defined(CONFIG_API)
  689. /* Initialize API */
  690. api_init ();
  691. #endif
  692. console_init_r (); /* fully init console as a device */
  693. #if defined(CONFIG_ARCH_MISC_INIT)
  694. /* miscellaneous arch dependent initialisations */
  695. arch_misc_init ();
  696. #endif
  697. #if defined(CONFIG_MISC_INIT_R)
  698. /* miscellaneous platform dependent initialisations */
  699. misc_init_r ();
  700. #endif
  701. /* set up exceptions */
  702. interrupt_init ();
  703. /* enable exceptions */
  704. enable_interrupts ();
  705. /* Perform network card initialisation if necessary */
  706. #if defined(CONFIG_DRIVER_SMC91111) || defined (CONFIG_DRIVER_LAN91C96)
  707. /* XXX: this needs to be moved to board init */
  708. if (getenv ("ethaddr")) {
  709. uchar enetaddr[6];
  710. eth_getenv_enetaddr("ethaddr", enetaddr);
  711. smc_set_mac_addr(enetaddr);
  712. }
  713. #endif /* CONFIG_DRIVER_SMC91111 || CONFIG_DRIVER_LAN91C96 */
  714. /* Initialize from environment */
  715. if ((s = getenv ("loadaddr")) != NULL) {
  716. load_addr = simple_strtoul (s, NULL, 16);
  717. }
  718. #if defined(CONFIG_CMD_NET)
  719. if ((s = getenv ("bootfile")) != NULL) {
  720. copy_filename (BootFile, s, sizeof (BootFile));
  721. }
  722. #endif
  723. #ifdef BOARD_LATE_INIT
  724. board_late_init ();
  725. #endif
  726. #ifdef CONFIG_BITBANGMII
  727. bb_miiphy_init();
  728. #endif
  729. #if defined(CONFIG_CMD_NET)
  730. #if defined(CONFIG_NET_MULTI)
  731. puts ("Net: ");
  732. #endif
  733. eth_initialize(gd->bd);
  734. #if defined(CONFIG_RESET_PHY_R)
  735. debug ("Reset Ethernet PHY\n");
  736. reset_phy();
  737. #endif
  738. #endif
  739. #ifdef CONFIG_POST
  740. post_run (NULL, POST_RAM | post_bootmode_get(0));
  741. #endif
  742. #if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
  743. /*
  744. * Export available size of memory for Linux,
  745. * taking into account the protected RAM at top of memory
  746. */
  747. {
  748. ulong pram;
  749. uchar memsz[32];
  750. #ifdef CONFIG_PRAM
  751. char *s;
  752. if ((s = getenv ("pram")) != NULL) {
  753. pram = simple_strtoul (s, NULL, 10);
  754. } else {
  755. pram = CONFIG_PRAM;
  756. }
  757. #else
  758. pram=0;
  759. #endif
  760. #ifdef CONFIG_LOGBUFFER
  761. #ifndef CONFIG_ALT_LB_ADDR
  762. /* Also take the logbuffer into account (pram is in kB) */
  763. pram += (LOGBUFF_LEN+LOGBUFF_OVERHEAD)/1024;
  764. #endif
  765. #endif
  766. sprintf ((char *)memsz, "%ldk", (bd->bi_memsize / 1024) - pram);
  767. setenv ("mem", (char *)memsz);
  768. }
  769. #endif
  770. /* main_loop() can return to retry autoboot, if so just run it again. */
  771. for (;;) {
  772. main_loop ();
  773. }
  774. /* NOTREACHED - no way out of command loop except booting */
  775. }
  776. #endif /* defined(CONFIG_SYS_ARM_WITHOUT_RELOC) */
  777. void hang (void)
  778. {
  779. puts ("### ERROR ### Please RESET the board ###\n");
  780. for (;;);
  781. }