board.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. /* SPARC Board initialization
  2. *
  3. * (C) Copyright 2000-2006
  4. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  5. *
  6. * (C) Copyright 2007
  7. * Daniel Hellstrom, Gaisler Research, daniel@gaisler.com.
  8. *
  9. * SPDX-License-Identifier: GPL-2.0+
  10. */
  11. #include <common.h>
  12. #include <command.h>
  13. #include <malloc.h>
  14. #include <stdio_dev.h>
  15. #include <config.h>
  16. #if defined(CONFIG_CMD_IDE)
  17. #include <ide.h>
  18. #endif
  19. #ifdef CONFIG_STATUS_LED
  20. #include <status_led.h>
  21. #endif
  22. #include <net.h>
  23. #include <serial.h>
  24. #include <version.h>
  25. #if defined(CONFIG_POST)
  26. #include <post.h>
  27. #endif
  28. #ifdef CONFIG_PS2KBD
  29. #include <keyboard.h>
  30. #endif
  31. #ifdef CONFIG_CMD_AMBAPP
  32. #include <ambapp.h>
  33. #endif
  34. #ifdef CONFIG_BITBANGMII
  35. #include <miiphy.h>
  36. #endif
  37. DECLARE_GLOBAL_DATA_PTR;
  38. /* Debug options
  39. #define DEBUG_INIT_SEQUENCE
  40. #define DEBUG_MEM_LAYOUT
  41. #define DEBUG_COMMANDS
  42. */
  43. extern void timer_interrupt_init(void);
  44. extern int do_ambapp_print(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]);
  45. extern int prom_init(void);
  46. #if defined(CONFIG__CMD_DOC)
  47. void doc_init(void);
  48. #endif
  49. #if !defined(CONFIG_SYS_NO_FLASH)
  50. static char *failed = "*** failed ***\n";
  51. #endif
  52. #include <environment.h>
  53. ulong monitor_flash_len;
  54. /************************************************************************
  55. * Init Utilities *
  56. ************************************************************************
  57. * Some of this code should be moved into the core functions,
  58. * but let's get it working (again) first...
  59. */
  60. static int init_baudrate(void)
  61. {
  62. gd->baudrate = getenv_ulong("baudrate", 10, CONFIG_BAUDRATE);
  63. return 0;
  64. }
  65. /***********************************************************************/
  66. /*
  67. * All attempts to come up with a "common" initialization sequence
  68. * that works for all boards and architectures failed: some of the
  69. * requirements are just _too_ different. To get rid of the resulting
  70. * mess of board dependend #ifdef'ed code we now make the whole
  71. * initialization sequence configurable to the user.
  72. *
  73. * The requirements for any new initalization function is simple: it
  74. * receives a pointer to the "global data" structure as it's only
  75. * argument, and returns an integer return code, where 0 means
  76. * "continue" and != 0 means "fatal error, hang the system".
  77. */
  78. typedef int (init_fnc_t) (void);
  79. #define WATCHDOG_RESET(x)
  80. /************************************************************************
  81. * Initialization sequence *
  82. ************************************************************************
  83. */
  84. init_fnc_t *init_sequence[] = {
  85. #if defined(CONFIG_BOARD_EARLY_INIT_F)
  86. board_early_init_f,
  87. #endif
  88. serial_init,
  89. init_timebase,
  90. #if defined(CONFIG_CMD_AMBAPP)
  91. ambapp_init_reloc,
  92. #endif
  93. env_init,
  94. init_baudrate,
  95. console_init_f,
  96. display_options,
  97. checkcpu,
  98. checkboard,
  99. #if defined(CONFIG_MISC_INIT_F)
  100. misc_init_f,
  101. #endif
  102. #ifdef CONFIG_POST
  103. post_init_f,
  104. #endif
  105. NULL, /* Terminate this list,
  106. * beware: this list will be relocated
  107. * which means that NULL will become
  108. * NULL+RELOC_OFFSET. We simply make
  109. * NULL be -RELOC_OFFSET instead.
  110. */
  111. };
  112. /************************************************************************
  113. *
  114. * This is the SPARC board initialization routine, running from RAM.
  115. *
  116. ************************************************************************
  117. */
  118. #ifdef DEBUG_INIT_SEQUENCE
  119. char *str_init_seq = "INIT_SEQ 00\n";
  120. char *str_init_seq_done = "\n\rInit sequence done...\r\n\r\n";
  121. #endif
  122. void board_init_f(ulong bootflag)
  123. {
  124. bd_t *bd;
  125. init_fnc_t **init_fnc_ptr;
  126. int j;
  127. #ifndef CONFIG_SYS_NO_FLASH
  128. ulong flash_size;
  129. #endif
  130. gd = (gd_t *) (CONFIG_SYS_GBL_DATA_OFFSET);
  131. /* Clear initial global data */
  132. memset((void *)gd, 0, sizeof(gd_t));
  133. gd->bd = (bd_t *) (gd + 1); /* At end of global data */
  134. gd->baudrate = CONFIG_BAUDRATE;
  135. gd->cpu_clk = CONFIG_SYS_CLK_FREQ;
  136. bd = gd->bd;
  137. bd->bi_memstart = CONFIG_SYS_RAM_BASE;
  138. bd->bi_memsize = CONFIG_SYS_RAM_SIZE;
  139. bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
  140. #if defined(CONFIG_SYS_SRAM_BASE) && defined(CONFIG_SYS_SRAM_SIZE)
  141. bd->bi_sramstart = CONFIG_SYS_SRAM_BASE;
  142. bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE;
  143. #endif
  144. bd->bi_baudrate = CONFIG_BAUDRATE;
  145. bd->bi_bootflags = bootflag; /* boot / reboot flag (for LynxOS) */
  146. gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
  147. gd->reloc_off = CONFIG_SYS_RELOC_MONITOR_BASE - CONFIG_SYS_MONITOR_BASE;
  148. for (init_fnc_ptr = init_sequence, j = 0; *init_fnc_ptr;
  149. ++init_fnc_ptr, j++) {
  150. #ifdef DEBUG_INIT_SEQUENCE
  151. if (j > 9)
  152. str_init_seq[9] = '0' + (j / 10);
  153. str_init_seq[10] = '0' + (j - (j / 10) * 10);
  154. serial_puts(str_init_seq);
  155. #endif
  156. if ((*init_fnc_ptr + gd->reloc_off) () != 0) {
  157. hang();
  158. }
  159. }
  160. #ifdef DEBUG_INIT_SEQUENCE
  161. serial_puts(str_init_seq_done);
  162. #endif
  163. /*
  164. * Now that we have DRAM mapped and working, we can
  165. * relocate the code and continue running from DRAM.
  166. *
  167. * Reserve memory at end of RAM for (top down in that order):
  168. * - kernel log buffer
  169. * - protected RAM
  170. * - LCD framebuffer
  171. * - monitor code
  172. * - board info struct
  173. */
  174. #ifdef DEBUG_MEM_LAYOUT
  175. printf("CONFIG_SYS_MONITOR_BASE: 0x%lx\n", CONFIG_SYS_MONITOR_BASE);
  176. printf("CONFIG_ENV_ADDR: 0x%lx\n", CONFIG_ENV_ADDR);
  177. printf("CONFIG_SYS_RELOC_MONITOR_BASE: 0x%lx (%d)\n", CONFIG_SYS_RELOC_MONITOR_BASE,
  178. CONFIG_SYS_MONITOR_LEN);
  179. printf("CONFIG_SYS_MALLOC_BASE: 0x%lx (%d)\n", CONFIG_SYS_MALLOC_BASE,
  180. CONFIG_SYS_MALLOC_LEN);
  181. printf("CONFIG_SYS_INIT_SP_OFFSET: 0x%lx (%d)\n", CONFIG_SYS_INIT_SP_OFFSET,
  182. CONFIG_SYS_STACK_SIZE);
  183. printf("CONFIG_SYS_PROM_OFFSET: 0x%lx (%d)\n", CONFIG_SYS_PROM_OFFSET,
  184. CONFIG_SYS_PROM_SIZE);
  185. printf("CONFIG_SYS_GBL_DATA_OFFSET: 0x%lx (%d)\n", CONFIG_SYS_GBL_DATA_OFFSET,
  186. GENERATED_GBL_DATA_SIZE);
  187. #endif
  188. #ifdef CONFIG_POST
  189. post_bootmode_init();
  190. post_run(NULL, POST_ROM | post_bootmode_get(0));
  191. #endif
  192. #if defined(CONFIG_NEEDS_MANUAL_RELOC)
  193. /*
  194. * We have to relocate the command table manually
  195. */
  196. fixup_cmdtable(ll_entry_start(cmd_tbl_t, cmd),
  197. ll_entry_count(cmd_tbl_t, cmd));
  198. #endif /* defined(CONFIG_NEEDS_MANUAL_RELOC) */
  199. #if defined(CONFIG_CMD_AMBAPP) && defined(CONFIG_SYS_AMBAPP_PRINT_ON_STARTUP)
  200. puts("AMBA:\n");
  201. do_ambapp_print(NULL, 0, 0, NULL);
  202. #endif
  203. /* initialize higher level parts of CPU like time base and timers */
  204. cpu_init_r();
  205. /* start timer */
  206. timer_interrupt_init();
  207. /*
  208. * Enable Interrupts before any calls to udelay,
  209. * the flash driver may use udelay resulting in
  210. * a hang if not timer0 IRQ is enabled.
  211. */
  212. interrupt_init();
  213. /* The Malloc area is immediately below the monitor copy in RAM */
  214. mem_malloc_init(CONFIG_SYS_MALLOC_BASE,
  215. CONFIG_SYS_MALLOC_END - CONFIG_SYS_MALLOC_BASE);
  216. #if !defined(CONFIG_SYS_NO_FLASH)
  217. puts("Flash: ");
  218. if ((flash_size = flash_init()) > 0) {
  219. # ifdef CONFIG_SYS_FLASH_CHECKSUM
  220. print_size(flash_size, "");
  221. /*
  222. * Compute and print flash CRC if flashchecksum is set to 'y'
  223. *
  224. * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
  225. */
  226. if (getenv_yesno("flashchecksum") == 1) {
  227. printf(" CRC: %08lX",
  228. crc32(0, (const unsigned char *)CONFIG_SYS_FLASH_BASE,
  229. flash_size)
  230. );
  231. }
  232. putc('\n');
  233. # else /* !CONFIG_SYS_FLASH_CHECKSUM */
  234. print_size(flash_size, "\n");
  235. # endif /* CONFIG_SYS_FLASH_CHECKSUM */
  236. } else {
  237. puts(failed);
  238. hang();
  239. }
  240. bd->bi_flashstart = CONFIG_SYS_FLASH_BASE; /* update start of FLASH memory */
  241. bd->bi_flashsize = flash_size; /* size of FLASH memory (final value) */
  242. #if CONFIG_SYS_MONITOR_BASE == CONFIG_SYS_FLASH_BASE
  243. bd->bi_flashoffset = monitor_flash_len; /* reserved area for startup monitor */
  244. #else
  245. bd->bi_flashoffset = 0;
  246. #endif
  247. #else /* CONFIG_SYS_NO_FLASH */
  248. bd->bi_flashsize = 0;
  249. bd->bi_flashstart = 0;
  250. bd->bi_flashoffset = 0;
  251. #endif /* !CONFIG_SYS_NO_FLASH */
  252. #ifdef CONFIG_SPI
  253. # if !defined(CONFIG_ENV_IS_IN_EEPROM)
  254. spi_init_f();
  255. # endif
  256. spi_init_r();
  257. #endif
  258. /* relocate environment function pointers etc. */
  259. env_relocate();
  260. #if defined(CONFIG_BOARD_LATE_INIT)
  261. board_late_init();
  262. #endif
  263. #ifdef CONFIG_ID_EEPROM
  264. mac_read_from_eeprom();
  265. #endif
  266. #if defined(CONFIG_PCI)
  267. /*
  268. * Do pci configuration
  269. */
  270. pci_init();
  271. #endif
  272. /* Initialize stdio devices */
  273. stdio_init();
  274. /* Initialize the jump table for applications */
  275. jumptable_init();
  276. /* Initialize the console (after the relocation and devices init) */
  277. console_init_r();
  278. #ifdef CONFIG_STATUS_LED
  279. status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING);
  280. #endif
  281. udelay(20);
  282. /* Initialize from environment */
  283. load_addr = getenv_ulong("loadaddr", 16, load_addr);
  284. WATCHDOG_RESET();
  285. #if defined(CONFIG_CMD_DOC)
  286. WATCHDOG_RESET();
  287. puts("DOC: ");
  288. doc_init();
  289. #endif
  290. #ifdef CONFIG_BITBANGMII
  291. bb_miiphy_init();
  292. #endif
  293. #if defined(CONFIG_CMD_NET)
  294. WATCHDOG_RESET();
  295. puts("Net: ");
  296. eth_initialize(bd);
  297. #endif
  298. #if defined(CONFIG_CMD_NET) && defined(CONFIG_RESET_PHY_R)
  299. WATCHDOG_RESET();
  300. debug("Reset Ethernet PHY\n");
  301. reset_phy();
  302. #endif
  303. #ifdef CONFIG_POST
  304. post_run(NULL, POST_RAM | post_bootmode_get(0));
  305. #endif
  306. #if defined(CONFIG_CMD_IDE)
  307. WATCHDOG_RESET();
  308. puts("IDE: ");
  309. ide_init();
  310. #endif /* CONFIG_CMD_IDE */
  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_PS2KBD
  321. puts("PS/2: ");
  322. kbd_init();
  323. #endif
  324. prom_init();
  325. /* main_loop */
  326. for (;;) {
  327. WATCHDOG_RESET();
  328. main_loop();
  329. }
  330. }
  331. /************************************************************************/