board.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  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_DRIVER_SMC91111
  51. #include "../drivers/net/smc91111.h"
  52. #endif
  53. #ifdef CONFIG_DRIVER_LAN91C96
  54. #include "../drivers/net/lan91c96.h"
  55. #endif
  56. DECLARE_GLOBAL_DATA_PTR;
  57. ulong monitor_flash_len;
  58. #ifdef CONFIG_HAS_DATAFLASH
  59. extern int AT91F_DataflashInit(void);
  60. extern void dataflash_print_info(void);
  61. #endif
  62. #ifndef CONFIG_IDENT_STRING
  63. #define CONFIG_IDENT_STRING ""
  64. #endif
  65. const char version_string[] =
  66. U_BOOT_VERSION" (" U_BOOT_DATE " - " U_BOOT_TIME ")"CONFIG_IDENT_STRING;
  67. #ifdef CONFIG_DRIVER_RTL8019
  68. extern void rtl8019_get_enetaddr (uchar * addr);
  69. #endif
  70. #if defined(CONFIG_HARD_I2C) || \
  71. defined(CONFIG_SOFT_I2C)
  72. #include <i2c.h>
  73. #endif
  74. /*
  75. * Begin and End of memory area for malloc(), and current "brk"
  76. */
  77. static ulong mem_malloc_start = 0;
  78. static ulong mem_malloc_end = 0;
  79. static ulong mem_malloc_brk = 0;
  80. static
  81. void mem_malloc_init (ulong dest_addr)
  82. {
  83. mem_malloc_start = dest_addr;
  84. mem_malloc_end = dest_addr + CONFIG_SYS_MALLOC_LEN;
  85. mem_malloc_brk = mem_malloc_start;
  86. memset ((void *) mem_malloc_start, 0,
  87. mem_malloc_end - mem_malloc_start);
  88. }
  89. void *sbrk (ptrdiff_t increment)
  90. {
  91. ulong old = mem_malloc_brk;
  92. ulong new = old + increment;
  93. if ((new < mem_malloc_start) || (new > mem_malloc_end)) {
  94. return (NULL);
  95. }
  96. mem_malloc_brk = new;
  97. return ((void *) old);
  98. }
  99. /************************************************************************
  100. * Coloured LED functionality
  101. ************************************************************************
  102. * May be supplied by boards if desired
  103. */
  104. void inline __coloured_LED_init (void) {}
  105. void inline coloured_LED_init (void) __attribute__((weak, alias("__coloured_LED_init")));
  106. void inline __red_LED_on (void) {}
  107. void inline red_LED_on (void) __attribute__((weak, alias("__red_LED_on")));
  108. void inline __red_LED_off(void) {}
  109. void inline red_LED_off(void) __attribute__((weak, alias("__red_LED_off")));
  110. void inline __green_LED_on(void) {}
  111. void inline green_LED_on(void) __attribute__((weak, alias("__green_LED_on")));
  112. void inline __green_LED_off(void) {}
  113. void inline green_LED_off(void)__attribute__((weak, alias("__green_LED_off")));
  114. void inline __yellow_LED_on(void) {}
  115. void inline yellow_LED_on(void)__attribute__((weak, alias("__yellow_LED_on")));
  116. void inline __yellow_LED_off(void) {}
  117. void inline yellow_LED_off(void)__attribute__((weak, alias("__yellow_LED_off")));
  118. void inline __blue_LED_on(void) {}
  119. void inline blue_LED_on(void)__attribute__((weak, alias("__blue_LED_on")));
  120. void inline __blue_LED_off(void) {}
  121. void inline blue_LED_off(void)__attribute__((weak, alias("__blue_LED_off")));
  122. /************************************************************************
  123. * Init Utilities *
  124. ************************************************************************
  125. * Some of this code should be moved into the core functions,
  126. * or dropped completely,
  127. * but let's get it working (again) first...
  128. */
  129. #if defined(CONFIG_ARM_DCC) && !defined(CONFIG_BAUDRATE)
  130. #define CONFIG_BAUDRATE 115200
  131. #endif
  132. static int init_baudrate (void)
  133. {
  134. char tmp[64]; /* long enough for environment variables */
  135. int i = getenv_r ("baudrate", tmp, sizeof (tmp));
  136. gd->bd->bi_baudrate = gd->baudrate = (i > 0)
  137. ? (int) simple_strtoul (tmp, NULL, 10)
  138. : CONFIG_BAUDRATE;
  139. return (0);
  140. }
  141. static int display_banner (void)
  142. {
  143. printf ("\n\n%s\n\n", version_string);
  144. debug ("U-Boot code: %08lX -> %08lX BSS: -> %08lX\n",
  145. _armboot_start, _bss_start, _bss_end);
  146. #ifdef CONFIG_MODEM_SUPPORT
  147. debug ("Modem Support enabled\n");
  148. #endif
  149. #ifdef CONFIG_USE_IRQ
  150. debug ("IRQ Stack: %08lx\n", IRQ_STACK_START);
  151. debug ("FIQ Stack: %08lx\n", FIQ_STACK_START);
  152. #endif
  153. return (0);
  154. }
  155. /*
  156. * WARNING: this code looks "cleaner" than the PowerPC version, but
  157. * has the disadvantage that you either get nothing, or everything.
  158. * On PowerPC, you might see "DRAM: " before the system hangs - which
  159. * gives a simple yet clear indication which part of the
  160. * initialization if failing.
  161. */
  162. static int display_dram_config (void)
  163. {
  164. int i;
  165. #ifdef DEBUG
  166. puts ("RAM Configuration:\n");
  167. for(i=0; i<CONFIG_NR_DRAM_BANKS; i++) {
  168. printf ("Bank #%d: %08lx ", i, gd->bd->bi_dram[i].start);
  169. print_size (gd->bd->bi_dram[i].size, "\n");
  170. }
  171. #else
  172. ulong size = 0;
  173. for (i=0; i<CONFIG_NR_DRAM_BANKS; i++) {
  174. size += gd->bd->bi_dram[i].size;
  175. }
  176. puts("DRAM: ");
  177. print_size(size, "\n");
  178. #endif
  179. return (0);
  180. }
  181. #ifndef CONFIG_SYS_NO_FLASH
  182. static void display_flash_config (ulong size)
  183. {
  184. puts ("Flash: ");
  185. print_size (size, "\n");
  186. }
  187. #endif /* CONFIG_SYS_NO_FLASH */
  188. #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
  189. static int init_func_i2c (void)
  190. {
  191. puts ("I2C: ");
  192. i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
  193. puts ("ready\n");
  194. return (0);
  195. }
  196. #endif
  197. #if defined(CONFIG_CMD_PCI) || defined (CONFIG_PCI)
  198. #include <pci.h>
  199. static int arm_pci_init(void)
  200. {
  201. pci_init();
  202. return 0;
  203. }
  204. #endif /* CONFIG_CMD_PCI || CONFIG_PCI */
  205. /*
  206. * Breathe some life into the board...
  207. *
  208. * Initialize a serial port as console, and carry out some hardware
  209. * tests.
  210. *
  211. * The first part of initialization is running from Flash memory;
  212. * its main purpose is to initialize the RAM so that we
  213. * can relocate the monitor code to RAM.
  214. */
  215. /*
  216. * All attempts to come up with a "common" initialization sequence
  217. * that works for all boards and architectures failed: some of the
  218. * requirements are just _too_ different. To get rid of the resulting
  219. * mess of board dependent #ifdef'ed code we now make the whole
  220. * initialization sequence configurable to the user.
  221. *
  222. * The requirements for any new initalization function is simple: it
  223. * receives a pointer to the "global data" structure as it's only
  224. * argument, and returns an integer return code, where 0 means
  225. * "continue" and != 0 means "fatal error, hang the system".
  226. */
  227. typedef int (init_fnc_t) (void);
  228. int print_cpuinfo (void);
  229. init_fnc_t *init_sequence[] = {
  230. #if defined(CONFIG_ARCH_CPU_INIT)
  231. arch_cpu_init, /* basic arch cpu dependent setup */
  232. #endif
  233. board_init, /* basic board dependent setup */
  234. #if defined(CONFIG_USE_IRQ)
  235. interrupt_init, /* set up exceptions */
  236. #endif
  237. timer_init, /* initialize timer */
  238. env_init, /* initialize environment */
  239. init_baudrate, /* initialze baudrate settings */
  240. serial_init, /* serial communications setup */
  241. console_init_f, /* stage 1 init of console */
  242. display_banner, /* say that we are here */
  243. #if defined(CONFIG_DISPLAY_CPUINFO)
  244. print_cpuinfo, /* display cpu info (and speed) */
  245. #endif
  246. #if defined(CONFIG_DISPLAY_BOARDINFO)
  247. checkboard, /* display board info */
  248. #endif
  249. #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
  250. init_func_i2c,
  251. #endif
  252. dram_init, /* configure available RAM banks */
  253. #if defined(CONFIG_CMD_PCI) || defined (CONFIG_PCI)
  254. arm_pci_init,
  255. #endif
  256. display_dram_config,
  257. NULL,
  258. };
  259. void start_armboot (void)
  260. {
  261. init_fnc_t **init_fnc_ptr;
  262. char *s;
  263. #if defined(CONFIG_VFD) || defined(CONFIG_LCD)
  264. unsigned long addr;
  265. #endif
  266. /* Pointer is writable since we allocated a register for it */
  267. gd = (gd_t*)(_armboot_start - CONFIG_SYS_MALLOC_LEN - sizeof(gd_t));
  268. /* compiler optimization barrier needed for GCC >= 3.4 */
  269. __asm__ __volatile__("": : :"memory");
  270. memset ((void*)gd, 0, sizeof (gd_t));
  271. gd->bd = (bd_t*)((char*)gd - sizeof(bd_t));
  272. memset (gd->bd, 0, sizeof (bd_t));
  273. gd->flags |= GD_FLG_RELOC;
  274. monitor_flash_len = _bss_start - _armboot_start;
  275. for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
  276. if ((*init_fnc_ptr)() != 0) {
  277. hang ();
  278. }
  279. }
  280. /* armboot_start is defined in the board-specific linker script */
  281. mem_malloc_init (_armboot_start - CONFIG_SYS_MALLOC_LEN);
  282. #ifndef CONFIG_SYS_NO_FLASH
  283. /* configure available FLASH banks */
  284. display_flash_config (flash_init ());
  285. #endif /* CONFIG_SYS_NO_FLASH */
  286. #ifdef CONFIG_VFD
  287. # ifndef PAGE_SIZE
  288. # define PAGE_SIZE 4096
  289. # endif
  290. /*
  291. * reserve memory for VFD display (always full pages)
  292. */
  293. /* bss_end is defined in the board-specific linker script */
  294. addr = (_bss_end + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
  295. vfd_setmem (addr);
  296. gd->fb_base = addr;
  297. #endif /* CONFIG_VFD */
  298. #ifdef CONFIG_LCD
  299. /* board init may have inited fb_base */
  300. if (!gd->fb_base) {
  301. # ifndef PAGE_SIZE
  302. # define PAGE_SIZE 4096
  303. # endif
  304. /*
  305. * reserve memory for LCD display (always full pages)
  306. */
  307. /* bss_end is defined in the board-specific linker script */
  308. addr = (_bss_end + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
  309. lcd_setmem (addr);
  310. gd->fb_base = addr;
  311. }
  312. #endif /* CONFIG_LCD */
  313. #if defined(CONFIG_CMD_NAND)
  314. puts ("NAND: ");
  315. nand_init(); /* go init the NAND */
  316. #endif
  317. #if defined(CONFIG_CMD_ONENAND)
  318. onenand_init();
  319. #endif
  320. #ifdef CONFIG_HAS_DATAFLASH
  321. AT91F_DataflashInit();
  322. dataflash_print_info();
  323. #endif
  324. /* initialize environment */
  325. env_relocate ();
  326. #ifdef CONFIG_VFD
  327. /* must do this after the framebuffer is allocated */
  328. drv_vfd_init();
  329. #endif /* CONFIG_VFD */
  330. #ifdef CONFIG_SERIAL_MULTI
  331. serial_initialize();
  332. #endif
  333. /* IP Address */
  334. gd->bd->bi_ip_addr = getenv_IPaddr ("ipaddr");
  335. stdio_init (); /* get the devices list going. */
  336. jumptable_init ();
  337. #if defined(CONFIG_API)
  338. /* Initialize API */
  339. api_init ();
  340. #endif
  341. console_init_r (); /* fully init console as a device */
  342. #if defined(CONFIG_ARCH_MISC_INIT)
  343. /* miscellaneous arch dependent initialisations */
  344. arch_misc_init ();
  345. #endif
  346. #if defined(CONFIG_MISC_INIT_R)
  347. /* miscellaneous platform dependent initialisations */
  348. misc_init_r ();
  349. #endif
  350. /* enable exceptions */
  351. enable_interrupts ();
  352. /* Perform network card initialisation if necessary */
  353. #ifdef CONFIG_DRIVER_TI_EMAC
  354. /* XXX: this needs to be moved to board init */
  355. extern void davinci_eth_set_mac_addr (const u_int8_t *addr);
  356. if (getenv ("ethaddr")) {
  357. uchar enetaddr[6];
  358. eth_getenv_enetaddr("ethaddr", enetaddr);
  359. davinci_eth_set_mac_addr(enetaddr);
  360. }
  361. #endif
  362. #if defined(CONFIG_DRIVER_SMC91111) || defined (CONFIG_DRIVER_LAN91C96)
  363. /* XXX: this needs to be moved to board init */
  364. if (getenv ("ethaddr")) {
  365. uchar enetaddr[6];
  366. eth_getenv_enetaddr("ethaddr", enetaddr);
  367. smc_set_mac_addr(enetaddr);
  368. }
  369. #endif /* CONFIG_DRIVER_SMC91111 || CONFIG_DRIVER_LAN91C96 */
  370. /* Initialize from environment */
  371. if ((s = getenv ("loadaddr")) != NULL) {
  372. load_addr = simple_strtoul (s, NULL, 16);
  373. }
  374. #if defined(CONFIG_CMD_NET)
  375. if ((s = getenv ("bootfile")) != NULL) {
  376. copy_filename (BootFile, s, sizeof (BootFile));
  377. }
  378. #endif
  379. #ifdef BOARD_LATE_INIT
  380. board_late_init ();
  381. #endif
  382. #ifdef CONFIG_GENERIC_MMC
  383. puts ("MMC: ");
  384. mmc_initialize (gd->bd);
  385. #endif
  386. #if defined(CONFIG_CMD_NET)
  387. #if defined(CONFIG_NET_MULTI)
  388. puts ("Net: ");
  389. #endif
  390. eth_initialize(gd->bd);
  391. #if defined(CONFIG_RESET_PHY_R)
  392. debug ("Reset Ethernet PHY\n");
  393. reset_phy();
  394. #endif
  395. #endif
  396. /* main_loop() can return to retry autoboot, if so just run it again. */
  397. for (;;) {
  398. main_loop ();
  399. }
  400. /* NOTREACHED - no way out of command loop except booting */
  401. }
  402. void hang (void)
  403. {
  404. puts ("### ERROR ### Please RESET the board ###\n");
  405. for (;;);
  406. }