board.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  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 <devices.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. DECLARE_GLOBAL_DATA_PTR;
  41. extern long _i386boot_start;
  42. extern long _i386boot_end;
  43. extern long _i386boot_romdata_start;
  44. extern long _i386boot_romdata_dest;
  45. extern long _i386boot_romdata_size;
  46. extern long _i386boot_bss_start;
  47. extern long _i386boot_bss_size;
  48. extern long _i386boot_realmode;
  49. extern long _i386boot_realmode_size;
  50. extern long _i386boot_bios;
  51. extern long _i386boot_bios_size;
  52. /* The symbols defined by the linker script becomes pointers
  53. * which is somewhat inconveient ... */
  54. ulong i386boot_start = (ulong)&_i386boot_start; /* code start (in flash) defined in start.S */
  55. ulong i386boot_end = (ulong)&_i386boot_end; /* code end (in flash) */
  56. ulong i386boot_romdata_start = (ulong)&_i386boot_romdata_start; /* datasegment in flash (also code+rodata end) */
  57. ulong i386boot_romdata_dest = (ulong)&_i386boot_romdata_dest; /* data location segment in ram */
  58. ulong i386boot_romdata_size = (ulong)&_i386boot_romdata_size; /* size of data segment */
  59. ulong i386boot_bss_start = (ulong)&_i386boot_bss_start; /* bss start */
  60. ulong i386boot_bss_size = (ulong)&_i386boot_bss_size; /* bss size */
  61. ulong i386boot_realmode = (ulong)&_i386boot_realmode; /* start of realmode entry code */
  62. ulong i386boot_realmode_size = (ulong)&_i386boot_realmode_size; /* size of realmode entry code */
  63. ulong i386boot_bios = (ulong)&_i386boot_bios; /* start of BIOS emulation code */
  64. ulong i386boot_bios_size = (ulong)&_i386boot_bios_size; /* size of BIOS emulation code */
  65. const char version_string[] =
  66. U_BOOT_VERSION" (" U_BOOT_DATE " - " U_BOOT_TIME ")";
  67. /*
  68. * Begin and End of memory area for malloc(), and current "brk"
  69. */
  70. static ulong mem_malloc_start = 0;
  71. static ulong mem_malloc_end = 0;
  72. static ulong mem_malloc_brk = 0;
  73. static int mem_malloc_init(void)
  74. {
  75. /* start malloc area right after the stack */
  76. mem_malloc_start = i386boot_bss_start +
  77. i386boot_bss_size + CONFIG_SYS_STACK_SIZE;
  78. mem_malloc_start = (mem_malloc_start+3)&~3;
  79. /* Use all available RAM for malloc() */
  80. mem_malloc_end = gd->ram_size;
  81. mem_malloc_brk = mem_malloc_start;
  82. return 0;
  83. }
  84. void *sbrk (ptrdiff_t increment)
  85. {
  86. ulong old = mem_malloc_brk;
  87. ulong new = old + increment;
  88. if ((new < mem_malloc_start) || (new > mem_malloc_end)) {
  89. return (NULL);
  90. }
  91. mem_malloc_brk = new;
  92. return ((void *) old);
  93. }
  94. /************************************************************************
  95. * Init Utilities *
  96. ************************************************************************
  97. * Some of this code should be moved into the core functions,
  98. * or dropped completely,
  99. * but let's get it working (again) first...
  100. */
  101. static int init_baudrate (void)
  102. {
  103. char tmp[64]; /* long enough for environment variables */
  104. int i = getenv_r("baudrate", tmp, 64);
  105. gd->baudrate = (i != 0)
  106. ? (int) simple_strtoul (tmp, NULL, 10)
  107. : CONFIG_BAUDRATE;
  108. return (0);
  109. }
  110. static int display_banner (void)
  111. {
  112. printf ("\n\n%s\n\n", version_string);
  113. printf ("U-Boot code: %08lX -> %08lX data: %08lX -> %08lX\n"
  114. " BSS: %08lX -> %08lX stack: %08lX -> %08lX\n",
  115. i386boot_start, i386boot_romdata_start-1,
  116. i386boot_romdata_dest, i386boot_romdata_dest+i386boot_romdata_size-1,
  117. i386boot_bss_start, i386boot_bss_start+i386boot_bss_size-1,
  118. i386boot_bss_start+i386boot_bss_size,
  119. i386boot_bss_start+i386boot_bss_size+CONFIG_SYS_STACK_SIZE-1);
  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. puts ("DRAM Configuration:\n");
  133. for (i=0; i<CONFIG_NR_DRAM_BANKS; i++) {
  134. printf ("Bank #%d: %08lx ", i, gd->bd->bi_dram[i].start);
  135. print_size (gd->bd->bi_dram[i].size, "\n");
  136. }
  137. return (0);
  138. }
  139. static void display_flash_config (ulong size)
  140. {
  141. puts ("Flash: ");
  142. print_size (size, "\n");
  143. }
  144. /*
  145. * Breath some life into the board...
  146. *
  147. * Initialize an SMC for serial comms, and carry out some hardware
  148. * tests.
  149. *
  150. * The first part of initialization is running from Flash memory;
  151. * its main purpose is to initialize the RAM so that we
  152. * can relocate the monitor code to RAM.
  153. */
  154. /*
  155. * All attempts to come up with a "common" initialization sequence
  156. * that works for all boards and architectures failed: some of the
  157. * requirements are just _too_ different. To get rid of the resulting
  158. * mess of board dependend #ifdef'ed code we now make the whole
  159. * initialization sequence configurable to the user.
  160. *
  161. * The requirements for any new initalization function is simple: it
  162. * receives a pointer to the "global data" structure as it's only
  163. * argument, and returns an integer return code, where 0 means
  164. * "continue" and != 0 means "fatal error, hang the system".
  165. */
  166. typedef int (init_fnc_t) (void);
  167. init_fnc_t *init_sequence[] = {
  168. cpu_init, /* basic cpu dependent setup */
  169. board_init, /* basic board dependent setup */
  170. dram_init, /* configure available RAM banks */
  171. mem_malloc_init, /* dependant on dram_init */
  172. interrupt_init, /* set up exceptions */
  173. timer_init,
  174. serial_init,
  175. env_init, /* initialize environment */
  176. init_baudrate, /* initialze baudrate settings */
  177. serial_init, /* serial communications setup */
  178. display_banner,
  179. display_dram_config,
  180. NULL,
  181. };
  182. gd_t *gd;
  183. void start_i386boot (void)
  184. {
  185. char *s;
  186. int i;
  187. ulong size;
  188. static gd_t gd_data;
  189. static bd_t bd_data;
  190. init_fnc_t **init_fnc_ptr;
  191. #ifndef CONFIG_SKIP_RELOCATE_UBOOT
  192. cmd_tbl_t *p;
  193. #endif
  194. show_boot_progress(0x21);
  195. gd = &gd_data;
  196. /* compiler optimization barrier needed for GCC >= 3.4 */
  197. __asm__ __volatile__("": : :"memory");
  198. memset (gd, 0, sizeof (gd_t));
  199. gd->bd = &bd_data;
  200. memset (gd->bd, 0, sizeof (bd_t));
  201. show_boot_progress(0x22);
  202. gd->baudrate = CONFIG_BAUDRATE;
  203. #ifndef CONFIG_SKIP_RELOCATE_UBOOT
  204. /* Need to set relocation offset here for interrupt initialization */
  205. gd->reloc_off = CONFIG_SYS_BL_START_RAM - TEXT_BASE;
  206. #endif
  207. for (init_fnc_ptr = init_sequence, i=0; *init_fnc_ptr; ++init_fnc_ptr, i++) {
  208. show_boot_progress(0xa130|i);
  209. if ((*init_fnc_ptr)() != 0) {
  210. hang ();
  211. }
  212. }
  213. show_boot_progress(0x23);
  214. #ifndef CONFIG_SKIP_RELOCATE_UBOOT
  215. for (p = &__u_boot_cmd_start; p != &__u_boot_cmd_end; p++) {
  216. ulong addr;
  217. addr = (ulong) (p->cmd) + gd->reloc_off;
  218. p->cmd = (int (*)(struct cmd_tbl_s *, int, int, char *[]))addr;
  219. addr = (ulong)(p->name) + gd->reloc_off;
  220. p->name = (char *)addr;
  221. if (p->usage != NULL) {
  222. addr = (ulong)(p->usage) + gd->reloc_off;
  223. p->usage = (char *)addr;
  224. }
  225. #ifdef CONFIG_SYS_LONGHELP
  226. if (p->help != NULL) {
  227. addr = (ulong)(p->help) + gd->reloc_off;
  228. p->help = (char *)addr;
  229. }
  230. #endif
  231. }
  232. #endif
  233. /* configure available FLASH banks */
  234. size = flash_init();
  235. display_flash_config(size);
  236. show_boot_progress(0x24);
  237. show_boot_progress(0x25);
  238. /* initialize environment */
  239. env_relocate ();
  240. show_boot_progress(0x26);
  241. /* IP Address */
  242. bd_data.bi_ip_addr = getenv_IPaddr ("ipaddr");
  243. #if defined(CONFIG_PCI)
  244. /*
  245. * Do pci configuration
  246. */
  247. pci_init();
  248. #endif
  249. show_boot_progress(0x27);
  250. devices_init ();
  251. jumptable_init ();
  252. /* Initialize the console (after the relocation and devices init) */
  253. console_init_r();
  254. #ifdef CONFIG_MISC_INIT_R
  255. /* miscellaneous platform dependent initialisations */
  256. misc_init_r();
  257. #endif
  258. #if defined(CONFIG_CMD_PCMCIA) && !defined(CONFIG_CMD_IDE)
  259. WATCHDOG_RESET();
  260. puts ("PCMCIA:");
  261. pcmcia_init();
  262. #endif
  263. #if defined(CONFIG_CMD_KGDB)
  264. WATCHDOG_RESET();
  265. puts("KGDB: ");
  266. kgdb_init();
  267. #endif
  268. /* enable exceptions */
  269. enable_interrupts();
  270. show_boot_progress(0x28);
  271. /* Must happen after interrupts are initialized since
  272. * an irq handler gets installed
  273. */
  274. #ifdef CONFIG_SERIAL_SOFTWARE_FIFO
  275. serial_buffered_init();
  276. #endif
  277. #ifdef CONFIG_STATUS_LED
  278. status_led_set (STATUS_LED_BOOT, STATUS_LED_BLINKING);
  279. #endif
  280. udelay(20);
  281. set_timer (0);
  282. /* Initialize from environment */
  283. if ((s = getenv ("loadaddr")) != NULL) {
  284. load_addr = simple_strtoul (s, NULL, 16);
  285. }
  286. #if defined(CONFIG_CMD_NET)
  287. if ((s = getenv ("bootfile")) != NULL) {
  288. copy_filename (BootFile, s, sizeof (BootFile));
  289. }
  290. #endif
  291. WATCHDOG_RESET();
  292. #if defined(CONFIG_CMD_IDE)
  293. WATCHDOG_RESET();
  294. puts("IDE: ");
  295. ide_init();
  296. #endif
  297. #if defined(CONFIG_CMD_SCSI)
  298. WATCHDOG_RESET();
  299. puts("SCSI: ");
  300. scsi_init();
  301. #endif
  302. #if defined(CONFIG_CMD_DOC)
  303. WATCHDOG_RESET();
  304. puts("DOC: ");
  305. doc_init();
  306. #endif
  307. #if defined(CONFIG_CMD_NET)
  308. #if defined(CONFIG_NET_MULTI)
  309. WATCHDOG_RESET();
  310. puts("Net: ");
  311. #endif
  312. eth_initialize(gd->bd);
  313. #endif
  314. #if ( defined(CONFIG_CMD_NET)) && (0)
  315. WATCHDOG_RESET();
  316. # ifdef DEBUG
  317. puts ("Reset Ethernet PHY\n");
  318. # endif
  319. reset_phy();
  320. #endif
  321. #ifdef CONFIG_LAST_STAGE_INIT
  322. WATCHDOG_RESET();
  323. /*
  324. * Some parts can be only initialized if all others (like
  325. * Interrupts) are up and running (i.e. the PC-style ISA
  326. * keyboard).
  327. */
  328. last_stage_init();
  329. #endif
  330. #ifdef CONFIG_POST
  331. post_run (NULL, POST_RAM | post_bootmode_get(0));
  332. #endif
  333. show_boot_progress(0x29);
  334. /* main_loop() can return to retry autoboot, if so just run it again. */
  335. for (;;) {
  336. main_loop();
  337. }
  338. /* NOTREACHED - no way out of command loop except booting */
  339. }
  340. void hang (void)
  341. {
  342. puts ("### ERROR ### Please RESET the board ###\n");
  343. for (;;);
  344. }
  345. unsigned long do_go_exec (ulong (*entry)(int, char *[]), int argc, char *argv[])
  346. {
  347. /*
  348. * TODO: Test this function - changed to fix compiler error.
  349. * Original code was:
  350. * return (entry >> 1) (argc, argv);
  351. * with a comment about Nios function pointers are address >> 1
  352. */
  353. return (entry) (argc, argv);
  354. }