board.c 10.0 KB

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