board.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  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. bd->bi_baudrate = (gd->baudrate > 0)
  207. ? simple_strtoul(gd->baudrate, NULL, 10) : CONFIG_BAUDRATE;
  208. return 0;
  209. }
  210. /*
  211. * All attempts to come up with a "common" initialization sequence
  212. * that works for all boards and architectures failed: some of the
  213. * requirements are just _too_ different. To get rid of the resulting
  214. * mess of board dependend #ifdef'ed code we now make the whole
  215. * initialization sequence configurable to the user.
  216. *
  217. * The requirements for any new initalization function is simple: it
  218. * receives a pointer to the "global data" structure as it's only
  219. * argument, and returns an integer return code, where 0 means
  220. * "continue" and != 0 means "fatal error, hang the system".
  221. */
  222. extern int watchdog_init(void);
  223. extern int exception_init(void);
  224. extern int irq_init(void);
  225. extern int timer_init(void);
  226. void board_init_f(ulong bootflag)
  227. {
  228. char buf[32];
  229. #ifdef CONFIG_BOARD_EARLY_INIT_F
  230. serial_early_puts("Board early init flash\n");
  231. board_early_init_f();
  232. #endif
  233. serial_early_puts("Init CPLB tables\n");
  234. init_cplbtables();
  235. serial_early_puts("Exceptions setup\n");
  236. exception_init();
  237. #ifndef CONFIG_ICACHE_OFF
  238. serial_early_puts("Turn on ICACHE\n");
  239. icache_enable();
  240. #endif
  241. #ifndef CONFIG_DCACHE_OFF
  242. serial_early_puts("Turn on DCACHE\n");
  243. dcache_enable();
  244. #endif
  245. #ifdef CONFIG_HW_WATCHDOG
  246. serial_early_puts("Setting up external watchdog\n");
  247. hw_watchdog_init();
  248. #endif
  249. #ifdef DEBUG
  250. if (GENERATED_GBL_DATA_SIZE < sizeof(*gd))
  251. hang();
  252. #endif
  253. serial_early_puts("Init global data\n");
  254. global_board_data_init();
  255. /* Initialize */
  256. serial_early_puts("IRQ init\n");
  257. irq_init();
  258. serial_early_puts("Environment init\n");
  259. env_init();
  260. serial_early_puts("Baudrate init\n");
  261. init_baudrate();
  262. serial_early_puts("Serial init\n");
  263. serial_init();
  264. serial_initialize();
  265. serial_early_puts("Console init flash\n");
  266. console_init_f();
  267. serial_early_puts("End of early debugging\n");
  268. display_banner();
  269. checkboard();
  270. timer_init();
  271. printf("Clock: VCO: %s MHz, ", strmhz(buf, get_vco()));
  272. printf("Core: %s MHz, ", strmhz(buf, get_cclk()));
  273. #if defined(__ADSPBF60x__)
  274. printf("System0: %s MHz, ", strmhz(buf, get_sclk0()));
  275. printf("System1: %s MHz, ", strmhz(buf, get_sclk1()));
  276. printf("Dclk: %s MHz\n", strmhz(buf, get_dclk()));
  277. #else
  278. printf("System: %s MHz\n", strmhz(buf, get_sclk()));
  279. #endif
  280. if (CONFIG_MEM_SIZE) {
  281. printf("RAM: ");
  282. print_size(gd->bd->bi_memsize, "\n");
  283. }
  284. #if defined(CONFIG_POST)
  285. post_init_f();
  286. post_bootmode_init();
  287. post_run(NULL, POST_ROM | post_bootmode_get(0));
  288. #endif
  289. board_init_r((gd_t *) gd, 0x20000010);
  290. }
  291. static void board_net_init_r(bd_t *bd)
  292. {
  293. #ifdef CONFIG_BITBANGMII
  294. bb_miiphy_init();
  295. #endif
  296. #ifdef CONFIG_CMD_NET
  297. printf("Net: ");
  298. eth_initialize(bd);
  299. #endif
  300. }
  301. void board_init_r(gd_t * id, ulong dest_addr)
  302. {
  303. bd_t *bd;
  304. gd = id;
  305. gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
  306. bd = gd->bd;
  307. #if defined(CONFIG_POST)
  308. post_output_backlog();
  309. #endif
  310. /* initialize malloc() area */
  311. mem_malloc_init(CONFIG_SYS_MALLOC_BASE, CONFIG_SYS_MALLOC_LEN);
  312. #if !defined(CONFIG_SYS_NO_FLASH)
  313. /* Initialize the flash and protect u-boot by default */
  314. extern flash_info_t flash_info[];
  315. puts("Flash: ");
  316. ulong size = flash_init();
  317. print_size(size, "\n");
  318. flash_protect(FLAG_PROTECT_SET, CONFIG_SYS_FLASH_BASE,
  319. CONFIG_SYS_FLASH_BASE + CONFIG_SYS_MONITOR_LEN - 1,
  320. &flash_info[0]);
  321. bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
  322. bd->bi_flashsize = size;
  323. bd->bi_flashoffset = 0;
  324. #else
  325. bd->bi_flashstart = 0;
  326. bd->bi_flashsize = 0;
  327. bd->bi_flashoffset = 0;
  328. #endif
  329. #ifdef CONFIG_CMD_NAND
  330. puts("NAND: ");
  331. nand_init(); /* go init the NAND */
  332. #endif
  333. #ifdef CONFIG_GENERIC_MMC
  334. puts("MMC: ");
  335. mmc_initialize(bd);
  336. #endif
  337. /* relocate environment function pointers etc. */
  338. env_relocate();
  339. /* Initialize stdio devices */
  340. stdio_init();
  341. jumptable_init();
  342. /* Initialize the console (after the relocation and devices init) */
  343. console_init_r();
  344. #ifdef CONFIG_CMD_KGDB
  345. puts("KGDB: ");
  346. kgdb_init();
  347. #endif
  348. #ifdef CONFIG_STATUS_LED
  349. status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING);
  350. status_led_set(STATUS_LED_CRASH, STATUS_LED_OFF);
  351. #endif
  352. /* Initialize from environment */
  353. load_addr = getenv_ulong("loadaddr", 16, load_addr);
  354. #if defined(CONFIG_MISC_INIT_R)
  355. /* miscellaneous platform dependent initialisations */
  356. misc_init_r();
  357. #endif
  358. board_net_init_r(bd);
  359. display_global_data();
  360. #if defined(CONFIG_POST)
  361. if (post_flag)
  362. post_run(NULL, POST_RAM | post_bootmode_get(0));
  363. #endif
  364. if (CONFIG_MEM_SIZE && bfin_os_log_check()) {
  365. puts("\nLog buffer from operating system:\n");
  366. bfin_os_log_dump();
  367. puts("\n");
  368. }
  369. /* main_loop() can return to retry autoboot, if so just run it again. */
  370. for (;;)
  371. main_loop();
  372. }