board.c 10 KB

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