board.c 9.6 KB

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