board.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. /*
  2. * (C) Copyright 2002
  3. * Daniel Engstr�m, Omicron Ceti AB, daniel@omicron.se
  4. *
  5. * (C) Copyright 2002
  6. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  7. *
  8. * (C) Copyright 2002
  9. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  10. * Marius Groeger <mgroeger@sysgo.de>
  11. *
  12. * See file CREDITS for list of people who contributed to this
  13. * project.
  14. *
  15. * This program is free software; you can redistribute it and/or
  16. * modify it under the terms of the GNU General Public License as
  17. * published by the Free Software Foundation; either version 2 of
  18. * the License, or (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program; if not, write to the Free Software
  27. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  28. * MA 02111-1307 USA
  29. */
  30. #include <common.h>
  31. #include <watchdog.h>
  32. #include <command.h>
  33. #include <stdio_dev.h>
  34. #include <timestamp.h>
  35. #include <version.h>
  36. #include <malloc.h>
  37. #include <net.h>
  38. #include <ide.h>
  39. #include <asm/u-boot-i386.h>
  40. #ifdef CONFIG_BITBANGMII
  41. #include <miiphy.h>
  42. #endif
  43. DECLARE_GLOBAL_DATA_PTR;
  44. extern long _i386boot_start;
  45. extern long _i386boot_end;
  46. extern long _i386boot_romdata_start;
  47. extern long _i386boot_romdata_dest;
  48. extern long _i386boot_romdata_size;
  49. extern long _i386boot_bss_start;
  50. extern long _i386boot_bss_size;
  51. extern long _i386boot_realmode;
  52. extern long _i386boot_realmode_size;
  53. extern long _i386boot_bios;
  54. extern long _i386boot_bios_size;
  55. /* The symbols defined by the linker script becomes pointers
  56. * which is somewhat inconveient ... */
  57. ulong i386boot_start = (ulong)&_i386boot_start; /* code start (in flash) defined in start.S */
  58. ulong i386boot_end = (ulong)&_i386boot_end; /* code end (in flash) */
  59. ulong i386boot_romdata_start = (ulong)&_i386boot_romdata_start; /* datasegment in flash (also code+rodata end) */
  60. ulong i386boot_romdata_dest = (ulong)&_i386boot_romdata_dest; /* data location segment in ram */
  61. ulong i386boot_romdata_size = (ulong)&_i386boot_romdata_size; /* size of data segment */
  62. ulong i386boot_bss_start = (ulong)&_i386boot_bss_start; /* bss start */
  63. ulong i386boot_bss_size = (ulong)&_i386boot_bss_size; /* bss size */
  64. ulong i386boot_realmode = (ulong)&_i386boot_realmode; /* start of realmode entry code */
  65. ulong i386boot_realmode_size = (ulong)&_i386boot_realmode_size; /* size of realmode entry code */
  66. ulong i386boot_bios = (ulong)&_i386boot_bios; /* start of BIOS emulation code */
  67. ulong i386boot_bios_size = (ulong)&_i386boot_bios_size; /* size of BIOS emulation code */
  68. const char version_string[] =
  69. U_BOOT_VERSION" (" U_BOOT_DATE " - " U_BOOT_TIME ")";
  70. static int mem_malloc_init(void)
  71. {
  72. /* start malloc area right after the stack */
  73. mem_malloc_start = i386boot_bss_start +
  74. i386boot_bss_size + CONFIG_SYS_STACK_SIZE;
  75. mem_malloc_start = (mem_malloc_start+3)&~3;
  76. /* Use all available RAM for malloc() */
  77. mem_malloc_end = gd->ram_size;
  78. mem_malloc_brk = mem_malloc_start;
  79. return 0;
  80. }
  81. /************************************************************************
  82. * Init Utilities *
  83. ************************************************************************
  84. * Some of this code should be moved into the core functions,
  85. * or dropped completely,
  86. * but let's get it working (again) first...
  87. */
  88. static int init_baudrate (void)
  89. {
  90. char tmp[64]; /* long enough for environment variables */
  91. int i = getenv_r("baudrate", tmp, 64);
  92. gd->baudrate = (i != 0)
  93. ? (int) simple_strtoul (tmp, NULL, 10)
  94. : CONFIG_BAUDRATE;
  95. return (0);
  96. }
  97. static int display_banner (void)
  98. {
  99. printf ("\n\n%s\n\n", version_string);
  100. printf ("U-Boot code: %08lX -> %08lX data: %08lX -> %08lX\n"
  101. " BSS: %08lX -> %08lX stack: %08lX -> %08lX\n",
  102. i386boot_start, i386boot_romdata_start-1,
  103. i386boot_romdata_dest, i386boot_romdata_dest+i386boot_romdata_size-1,
  104. i386boot_bss_start, i386boot_bss_start+i386boot_bss_size-1,
  105. i386boot_bss_start+i386boot_bss_size,
  106. i386boot_bss_start+i386boot_bss_size+CONFIG_SYS_STACK_SIZE-1);
  107. return (0);
  108. }
  109. /*
  110. * WARNING: this code looks "cleaner" than the PowerPC version, but
  111. * has the disadvantage that you either get nothing, or everything.
  112. * On PowerPC, you might see "DRAM: " before the system hangs - which
  113. * gives a simple yet clear indication which part of the
  114. * initialization if failing.
  115. */
  116. static int display_dram_config (void)
  117. {
  118. int i;
  119. puts ("DRAM Configuration:\n");
  120. for (i=0; i<CONFIG_NR_DRAM_BANKS; i++) {
  121. printf ("Bank #%d: %08lx ", i, gd->bd->bi_dram[i].start);
  122. print_size (gd->bd->bi_dram[i].size, "\n");
  123. }
  124. return (0);
  125. }
  126. static void display_flash_config (ulong size)
  127. {
  128. puts ("Flash: ");
  129. print_size (size, "\n");
  130. }
  131. /*
  132. * Breath some life into the board...
  133. *
  134. * Initialize an SMC for serial comms, and carry out some hardware
  135. * tests.
  136. *
  137. * The first part of initialization is running from Flash memory;
  138. * its main purpose is to initialize the RAM so that we
  139. * can relocate the monitor code to RAM.
  140. */
  141. /*
  142. * All attempts to come up with a "common" initialization sequence
  143. * that works for all boards and architectures failed: some of the
  144. * requirements are just _too_ different. To get rid of the resulting
  145. * mess of board dependend #ifdef'ed code we now make the whole
  146. * initialization sequence configurable to the user.
  147. *
  148. * The requirements for any new initalization function is simple: it
  149. * receives a pointer to the "global data" structure as it's only
  150. * argument, and returns an integer return code, where 0 means
  151. * "continue" and != 0 means "fatal error, hang the system".
  152. */
  153. typedef int (init_fnc_t) (void);
  154. init_fnc_t *init_sequence[] = {
  155. cpu_init, /* basic cpu dependent setup */
  156. board_init, /* basic board dependent setup */
  157. dram_init, /* configure available RAM banks */
  158. mem_malloc_init, /* dependant on dram_init */
  159. interrupt_init, /* set up exceptions */
  160. timer_init,
  161. serial_init,
  162. env_init, /* initialize environment */
  163. init_baudrate, /* initialze baudrate settings */
  164. serial_init, /* serial communications setup */
  165. display_banner,
  166. display_dram_config,
  167. NULL,
  168. };
  169. gd_t *gd;
  170. void start_i386boot (void)
  171. {
  172. char *s;
  173. int i;
  174. ulong size;
  175. static gd_t gd_data;
  176. static bd_t bd_data;
  177. init_fnc_t **init_fnc_ptr;
  178. #ifndef CONFIG_SKIP_RELOCATE_UBOOT
  179. cmd_tbl_t *p;
  180. #endif
  181. show_boot_progress(0x21);
  182. gd = &gd_data;
  183. /* compiler optimization barrier needed for GCC >= 3.4 */
  184. __asm__ __volatile__("": : :"memory");
  185. memset (gd, 0, sizeof (gd_t));
  186. gd->bd = &bd_data;
  187. memset (gd->bd, 0, sizeof (bd_t));
  188. show_boot_progress(0x22);
  189. gd->baudrate = CONFIG_BAUDRATE;
  190. #ifndef CONFIG_SKIP_RELOCATE_UBOOT
  191. /* Need to set relocation offset here for interrupt initialization */
  192. gd->reloc_off = CONFIG_SYS_BL_START_RAM - TEXT_BASE;
  193. #endif
  194. for (init_fnc_ptr = init_sequence, i=0; *init_fnc_ptr; ++init_fnc_ptr, i++) {
  195. show_boot_progress(0xa130|i);
  196. if ((*init_fnc_ptr)() != 0) {
  197. hang ();
  198. }
  199. }
  200. show_boot_progress(0x23);
  201. #ifndef CONFIG_SKIP_RELOCATE_UBOOT
  202. for (p = &__u_boot_cmd_start; p != &__u_boot_cmd_end; p++) {
  203. ulong addr;
  204. addr = (ulong) (p->cmd) + gd->reloc_off;
  205. p->cmd = (int (*)(struct cmd_tbl_s *, int, int, char *[]))addr;
  206. addr = (ulong)(p->name) + gd->reloc_off;
  207. p->name = (char *)addr;
  208. if (p->usage != NULL) {
  209. addr = (ulong)(p->usage) + gd->reloc_off;
  210. p->usage = (char *)addr;
  211. }
  212. #ifdef CONFIG_SYS_LONGHELP
  213. if (p->help != NULL) {
  214. addr = (ulong)(p->help) + gd->reloc_off;
  215. p->help = (char *)addr;
  216. }
  217. #endif
  218. }
  219. #endif
  220. /* configure available FLASH banks */
  221. size = flash_init();
  222. display_flash_config(size);
  223. show_boot_progress(0x24);
  224. show_boot_progress(0x25);
  225. /* initialize environment */
  226. env_relocate ();
  227. show_boot_progress(0x26);
  228. /* IP Address */
  229. bd_data.bi_ip_addr = getenv_IPaddr ("ipaddr");
  230. #if defined(CONFIG_PCI)
  231. /*
  232. * Do pci configuration
  233. */
  234. pci_init();
  235. #endif
  236. show_boot_progress(0x27);
  237. stdio_init ();
  238. jumptable_init ();
  239. /* Initialize the console (after the relocation and devices init) */
  240. console_init_r();
  241. #ifdef CONFIG_MISC_INIT_R
  242. /* miscellaneous platform dependent initialisations */
  243. misc_init_r();
  244. #endif
  245. #if defined(CONFIG_CMD_PCMCIA) && !defined(CONFIG_CMD_IDE)
  246. WATCHDOG_RESET();
  247. puts ("PCMCIA:");
  248. pcmcia_init();
  249. #endif
  250. #if defined(CONFIG_CMD_KGDB)
  251. WATCHDOG_RESET();
  252. puts("KGDB: ");
  253. kgdb_init();
  254. #endif
  255. /* enable exceptions */
  256. enable_interrupts();
  257. show_boot_progress(0x28);
  258. /* Must happen after interrupts are initialized since
  259. * an irq handler gets installed
  260. */
  261. #ifdef CONFIG_SERIAL_SOFTWARE_FIFO
  262. serial_buffered_init();
  263. #endif
  264. #ifdef CONFIG_STATUS_LED
  265. status_led_set (STATUS_LED_BOOT, STATUS_LED_BLINKING);
  266. #endif
  267. udelay(20);
  268. set_timer (0);
  269. /* Initialize from environment */
  270. if ((s = getenv ("loadaddr")) != NULL) {
  271. load_addr = simple_strtoul (s, NULL, 16);
  272. }
  273. #if defined(CONFIG_CMD_NET)
  274. if ((s = getenv ("bootfile")) != NULL) {
  275. copy_filename (BootFile, s, sizeof (BootFile));
  276. }
  277. #endif
  278. WATCHDOG_RESET();
  279. #if defined(CONFIG_CMD_IDE)
  280. WATCHDOG_RESET();
  281. puts("IDE: ");
  282. ide_init();
  283. #endif
  284. #if defined(CONFIG_CMD_SCSI)
  285. WATCHDOG_RESET();
  286. puts("SCSI: ");
  287. scsi_init();
  288. #endif
  289. #if defined(CONFIG_CMD_DOC)
  290. WATCHDOG_RESET();
  291. puts("DOC: ");
  292. doc_init();
  293. #endif
  294. #ifdef CONFIG_BITBANGMII
  295. bb_miiphy_init();
  296. #endif
  297. #if defined(CONFIG_CMD_NET)
  298. #if defined(CONFIG_NET_MULTI)
  299. WATCHDOG_RESET();
  300. puts("Net: ");
  301. #endif
  302. eth_initialize(gd->bd);
  303. #endif
  304. #if ( defined(CONFIG_CMD_NET)) && (0)
  305. WATCHDOG_RESET();
  306. # ifdef DEBUG
  307. puts ("Reset Ethernet PHY\n");
  308. # endif
  309. reset_phy();
  310. #endif
  311. #ifdef CONFIG_LAST_STAGE_INIT
  312. WATCHDOG_RESET();
  313. /*
  314. * Some parts can be only initialized if all others (like
  315. * Interrupts) are up and running (i.e. the PC-style ISA
  316. * keyboard).
  317. */
  318. last_stage_init();
  319. #endif
  320. #ifdef CONFIG_POST
  321. post_run (NULL, POST_RAM | post_bootmode_get(0));
  322. #endif
  323. show_boot_progress(0x29);
  324. /* main_loop() can return to retry autoboot, if so just run it again. */
  325. for (;;) {
  326. main_loop();
  327. }
  328. /* NOTREACHED - no way out of command loop except booting */
  329. }
  330. void hang (void)
  331. {
  332. puts ("### ERROR ### Please RESET the board ###\n");
  333. for (;;);
  334. }
  335. unsigned long do_go_exec (ulong (*entry)(int, char *[]), int argc, char *argv[])
  336. {
  337. /*
  338. * TODO: Test this function - changed to fix compiler error.
  339. * Original code was:
  340. * return (entry >> 1) (argc, argv);
  341. * with a comment about Nios function pointers are address >> 1
  342. */
  343. return (entry) (argc, argv);
  344. }