board.c 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. /*
  2. * U-boot - board.c First C file to be called contains init routines
  3. *
  4. * Copyright (c) 2005-2008 Analog Devices Inc.
  5. *
  6. * (C) Copyright 2000-2004
  7. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  8. *
  9. * Licensed under the GPL-2 or later.
  10. */
  11. #include <common.h>
  12. #include <command.h>
  13. #include <stdio_dev.h>
  14. #include <environment.h>
  15. #include <malloc.h>
  16. #include <mmc.h>
  17. #include <net.h>
  18. #include <timestamp.h>
  19. #include <status_led.h>
  20. #include <version.h>
  21. #include <asm/cplb.h>
  22. #include <asm/mach-common/bits/mpu.h>
  23. #ifdef CONFIG_CMD_NAND
  24. #include <nand.h> /* cannot even include nand.h if it isnt configured */
  25. #endif
  26. #ifdef CONFIG_BITBANGMII
  27. #include <miiphy.h>
  28. #endif
  29. #if defined(CONFIG_POST)
  30. #include <post.h>
  31. int post_flag;
  32. #endif
  33. DECLARE_GLOBAL_DATA_PTR;
  34. const char version_string[] = U_BOOT_VERSION " ("U_BOOT_DATE" - "U_BOOT_TIME")";
  35. __attribute__((always_inline))
  36. static inline void serial_early_puts(const char *s)
  37. {
  38. #ifdef CONFIG_DEBUG_EARLY_SERIAL
  39. serial_puts("Early: ");
  40. serial_puts(s);
  41. #endif
  42. }
  43. static int display_banner(void)
  44. {
  45. printf("\n\n%s\n\n", version_string);
  46. printf("CPU: ADSP " MK_STR(CONFIG_BFIN_CPU) " "
  47. "(Detected Rev: 0.%d) "
  48. "(%s boot)\n",
  49. bfin_revid(),
  50. get_bfin_boot_mode(CONFIG_BFIN_BOOT_MODE));
  51. return 0;
  52. }
  53. static int init_baudrate(void)
  54. {
  55. char baudrate[15];
  56. int i = getenv_r("baudrate", baudrate, sizeof(baudrate));
  57. gd->bd->bi_baudrate = gd->baudrate = (i > 0)
  58. ? simple_strtoul(baudrate, NULL, 10)
  59. : CONFIG_BAUDRATE;
  60. return 0;
  61. }
  62. static void display_global_data(void)
  63. {
  64. #ifdef CONFIG_DEBUG_EARLY_SERIAL
  65. bd_t *bd;
  66. bd = gd->bd;
  67. printf(" gd: %p\n", gd);
  68. printf(" |-flags: %lx\n", gd->flags);
  69. printf(" |-board_type: %lx\n", gd->board_type);
  70. printf(" |-baudrate: %lu\n", gd->baudrate);
  71. printf(" |-have_console: %lx\n", gd->have_console);
  72. printf(" |-ram_size: %lx\n", gd->ram_size);
  73. printf(" |-reloc_off: %lx\n", gd->reloc_off);
  74. printf(" |-env_addr: %lx\n", gd->env_addr);
  75. printf(" |-env_valid: %lx\n", gd->env_valid);
  76. printf(" |-jt(%p): %p\n", gd->jt, *(gd->jt));
  77. printf(" \\-bd: %p\n", gd->bd);
  78. printf(" |-bi_baudrate: %x\n", bd->bi_baudrate);
  79. printf(" |-bi_ip_addr: %lx\n", bd->bi_ip_addr);
  80. printf(" |-bi_boot_params: %lx\n", bd->bi_boot_params);
  81. printf(" |-bi_memstart: %lx\n", bd->bi_memstart);
  82. printf(" |-bi_memsize: %lx\n", bd->bi_memsize);
  83. printf(" |-bi_flashstart: %lx\n", bd->bi_flashstart);
  84. printf(" |-bi_flashsize: %lx\n", bd->bi_flashsize);
  85. printf(" \\-bi_flashoffset: %lx\n", bd->bi_flashoffset);
  86. #endif
  87. }
  88. #define CPLB_PAGE_SIZE (4 * 1024 * 1024)
  89. #define CPLB_PAGE_MASK (~(CPLB_PAGE_SIZE - 1))
  90. void init_cplbtables(void)
  91. {
  92. volatile uint32_t *ICPLB_ADDR, *ICPLB_DATA;
  93. volatile uint32_t *DCPLB_ADDR, *DCPLB_DATA;
  94. uint32_t extern_memory;
  95. size_t i;
  96. void icplb_add(uint32_t addr, uint32_t data)
  97. {
  98. *(ICPLB_ADDR + i) = addr;
  99. *(ICPLB_DATA + i) = data;
  100. }
  101. void dcplb_add(uint32_t addr, uint32_t data)
  102. {
  103. *(DCPLB_ADDR + i) = addr;
  104. *(DCPLB_DATA + i) = data;
  105. }
  106. /* populate a few common entries ... we'll let
  107. * the memory map and cplb exception handler do
  108. * the rest of the work.
  109. */
  110. i = 0;
  111. ICPLB_ADDR = (uint32_t *)ICPLB_ADDR0;
  112. ICPLB_DATA = (uint32_t *)ICPLB_DATA0;
  113. DCPLB_ADDR = (uint32_t *)DCPLB_ADDR0;
  114. DCPLB_DATA = (uint32_t *)DCPLB_DATA0;
  115. icplb_add(0xFFA00000, L1_IMEMORY);
  116. dcplb_add(0xFF800000, L1_DMEMORY);
  117. ++i;
  118. if (CONFIG_MEM_SIZE) {
  119. uint32_t mbase = CONFIG_SYS_MONITOR_BASE;
  120. uint32_t mend = mbase + CONFIG_SYS_MONITOR_LEN;
  121. mbase &= CPLB_PAGE_MASK;
  122. mend &= CPLB_PAGE_MASK;
  123. icplb_add(mbase, SDRAM_IKERNEL);
  124. dcplb_add(mbase, SDRAM_DKERNEL);
  125. ++i;
  126. /*
  127. * If the monitor crosses a 4 meg boundary, we'll need
  128. * to lock two entries for it. We assume it doesn't
  129. * cross two 4 meg boundaries ...
  130. */
  131. if (mbase != mend) {
  132. icplb_add(mend, SDRAM_IKERNEL);
  133. dcplb_add(mend, SDRAM_DKERNEL);
  134. ++i;
  135. }
  136. }
  137. icplb_add(0x20000000, SDRAM_INON_CHBL);
  138. dcplb_add(0x20000000, SDRAM_EBIU);
  139. ++i;
  140. /* Add entries for the rest of external RAM up to the bootrom */
  141. extern_memory = 0;
  142. #ifdef CONFIG_DEBUG_NULL_PTR
  143. icplb_add(extern_memory, (SDRAM_IKERNEL & ~PAGE_SIZE_MASK) | PAGE_SIZE_1KB);
  144. dcplb_add(extern_memory, (SDRAM_DKERNEL & ~PAGE_SIZE_MASK) | PAGE_SIZE_1KB);
  145. ++i;
  146. icplb_add(extern_memory, SDRAM_IKERNEL);
  147. dcplb_add(extern_memory, SDRAM_DKERNEL);
  148. extern_memory += CPLB_PAGE_SIZE;
  149. ++i;
  150. #endif
  151. while (i < 16 && extern_memory < (CONFIG_SYS_MONITOR_BASE & CPLB_PAGE_MASK)) {
  152. icplb_add(extern_memory, SDRAM_IGENERIC);
  153. dcplb_add(extern_memory, SDRAM_DGENERIC);
  154. extern_memory += CPLB_PAGE_SIZE;
  155. ++i;
  156. }
  157. while (i < 16) {
  158. icplb_add(0, 0);
  159. dcplb_add(0, 0);
  160. ++i;
  161. }
  162. }
  163. /*
  164. * All attempts to come up with a "common" initialization sequence
  165. * that works for all boards and architectures failed: some of the
  166. * requirements are just _too_ different. To get rid of the resulting
  167. * mess of board dependend #ifdef'ed code we now make the whole
  168. * initialization sequence configurable to the user.
  169. *
  170. * The requirements for any new initalization function is simple: it
  171. * receives a pointer to the "global data" structure as it's only
  172. * argument, and returns an integer return code, where 0 means
  173. * "continue" and != 0 means "fatal error, hang the system".
  174. */
  175. extern int exception_init(void);
  176. extern int irq_init(void);
  177. extern int timer_init(void);
  178. void board_init_f(ulong bootflag)
  179. {
  180. ulong addr;
  181. bd_t *bd;
  182. char buf[32];
  183. #ifdef CONFIG_BOARD_EARLY_INIT_F
  184. serial_early_puts("Board early init flash\n");
  185. board_early_init_f();
  186. #endif
  187. serial_early_puts("Init CPLB tables\n");
  188. init_cplbtables();
  189. serial_early_puts("Exceptions setup\n");
  190. exception_init();
  191. #ifndef CONFIG_ICACHE_OFF
  192. serial_early_puts("Turn on ICACHE\n");
  193. icache_enable();
  194. #endif
  195. #ifndef CONFIG_DCACHE_OFF
  196. serial_early_puts("Turn on DCACHE\n");
  197. dcache_enable();
  198. #endif
  199. #ifdef DEBUG
  200. if (CONFIG_SYS_GBL_DATA_SIZE < sizeof(*gd))
  201. hang();
  202. #endif
  203. serial_early_puts("Init global data\n");
  204. gd = (gd_t *) (CONFIG_SYS_GBL_DATA_ADDR);
  205. memset((void *)gd, 0, CONFIG_SYS_GBL_DATA_SIZE);
  206. /* Board data initialization */
  207. addr = (CONFIG_SYS_GBL_DATA_ADDR + sizeof(gd_t));
  208. /* Align to 4 byte boundary */
  209. addr &= ~(4 - 1);
  210. bd = (bd_t *) addr;
  211. gd->bd = bd;
  212. memset((void *)bd, 0, sizeof(bd_t));
  213. bd->bi_r_version = version_string;
  214. bd->bi_cpu = MK_STR(CONFIG_BFIN_CPU);
  215. bd->bi_board_name = BFIN_BOARD_NAME;
  216. bd->bi_vco = get_vco();
  217. bd->bi_cclk = get_cclk();
  218. bd->bi_sclk = get_sclk();
  219. bd->bi_memstart = CONFIG_SYS_SDRAM_BASE;
  220. bd->bi_memsize = CONFIG_SYS_MAX_RAM_SIZE;
  221. /* Initialize */
  222. serial_early_puts("IRQ init\n");
  223. irq_init();
  224. serial_early_puts("Environment init\n");
  225. env_init();
  226. serial_early_puts("Baudrate init\n");
  227. init_baudrate();
  228. serial_early_puts("Serial init\n");
  229. serial_init();
  230. serial_early_puts("Console init flash\n");
  231. console_init_f();
  232. serial_early_puts("End of early debugging\n");
  233. display_banner();
  234. checkboard();
  235. timer_init();
  236. printf("Clock: VCO: %s MHz, ", strmhz(buf, get_vco()));
  237. printf("Core: %s MHz, ", strmhz(buf, get_cclk()));
  238. printf("System: %s MHz\n", strmhz(buf, get_sclk()));
  239. printf("RAM: ");
  240. print_size(bd->bi_memsize, "\n");
  241. #if defined(CONFIG_POST)
  242. post_init_f();
  243. post_bootmode_init();
  244. post_run(NULL, POST_ROM | post_bootmode_get(0));
  245. #endif
  246. board_init_r((gd_t *) gd, 0x20000010);
  247. }
  248. static void board_net_init_r(bd_t *bd)
  249. {
  250. #ifdef CONFIG_BITBANGMII
  251. bb_miiphy_init();
  252. #endif
  253. #ifdef CONFIG_CMD_NET
  254. char *s;
  255. if ((s = getenv("bootfile")) != NULL)
  256. copy_filename(BootFile, s, sizeof(BootFile));
  257. bd->bi_ip_addr = getenv_IPaddr("ipaddr");
  258. printf("Net: ");
  259. eth_initialize(gd->bd);
  260. #endif
  261. }
  262. void board_init_r(gd_t * id, ulong dest_addr)
  263. {
  264. char *s;
  265. bd_t *bd;
  266. gd = id;
  267. gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
  268. bd = gd->bd;
  269. #if defined(CONFIG_POST)
  270. post_output_backlog();
  271. post_reloc();
  272. #endif
  273. /* initialize malloc() area */
  274. mem_malloc_init(CONFIG_SYS_MALLOC_BASE, CONFIG_SYS_MALLOC_LEN);
  275. #if !defined(CONFIG_SYS_NO_FLASH)
  276. /* Initialize the flash and protect u-boot by default */
  277. extern flash_info_t flash_info[];
  278. puts("Flash: ");
  279. ulong size = flash_init();
  280. print_size(size, "\n");
  281. flash_protect(FLAG_PROTECT_SET, CONFIG_SYS_FLASH_BASE,
  282. CONFIG_SYS_FLASH_BASE + CONFIG_SYS_MONITOR_LEN - 1,
  283. &flash_info[0]);
  284. bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
  285. bd->bi_flashsize = size;
  286. bd->bi_flashoffset = 0;
  287. #else
  288. bd->bi_flashstart = 0;
  289. bd->bi_flashsize = 0;
  290. bd->bi_flashoffset = 0;
  291. #endif
  292. #ifdef CONFIG_CMD_NAND
  293. puts("NAND: ");
  294. nand_init(); /* go init the NAND */
  295. #endif
  296. #ifdef CONFIG_GENERIC_MMC
  297. puts("MMC: ");
  298. mmc_initialize(bd);
  299. #endif
  300. /* relocate environment function pointers etc. */
  301. env_relocate();
  302. /* Initialize stdio devices */
  303. stdio_init();
  304. jumptable_init();
  305. /* Initialize the console (after the relocation and devices init) */
  306. console_init_r();
  307. #ifdef CONFIG_STATUS_LED
  308. status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING);
  309. status_led_set(STATUS_LED_CRASH, STATUS_LED_OFF);
  310. #endif
  311. /* Initialize from environment */
  312. if ((s = getenv("loadaddr")) != NULL)
  313. load_addr = simple_strtoul(s, NULL, 16);
  314. #if defined(CONFIG_MISC_INIT_R)
  315. /* miscellaneous platform dependent initialisations */
  316. misc_init_r();
  317. #endif
  318. board_net_init_r(bd);
  319. display_global_data();
  320. #if defined(CONFIG_POST)
  321. if (post_flag)
  322. post_run(NULL, POST_RAM | post_bootmode_get(0));
  323. #endif
  324. if (bfin_os_log_check()) {
  325. puts("\nLog buffer from operating system:\n");
  326. bfin_os_log_dump();
  327. puts("\n");
  328. }
  329. /* main_loop() can return to retry autoboot, if so just run it again. */
  330. for (;;)
  331. main_loop();
  332. }
  333. void hang(void)
  334. {
  335. #ifdef CONFIG_STATUS_LED
  336. status_led_set(STATUS_LED_BOOT, STATUS_LED_OFF);
  337. status_led_set(STATUS_LED_CRASH, STATUS_LED_BLINKING);
  338. #endif
  339. puts("### ERROR ### Please RESET the board ###\n");
  340. while (1)
  341. /* If a JTAG emulator is hooked up, we'll automatically trigger
  342. * a breakpoint in it. If one isn't, this is just a NOP.
  343. */
  344. asm("emuexcpt;");
  345. }