board.c 10 KB

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