board.c 10.0 KB

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