board.c 9.8 KB

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