]>
Commit | Line | Data |
---|---|---|
6cb142fa WD |
1 | /* |
2 | * U-boot - board.c First C file to be called contains init routines | |
3 | * | |
d5bffeb8 | 4 | * Copyright (c) 2005-2008 Analog Devices Inc. |
6cb142fa WD |
5 | * |
6 | * (C) Copyright 2000-2004 | |
7 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. | |
8 | * | |
d5bffeb8 | 9 | * Licensed under the GPL-2 or later. |
6cb142fa WD |
10 | */ |
11 | ||
12 | #include <common.h> | |
13 | #include <command.h> | |
52cb4d4f | 14 | #include <stdio_dev.h> |
6cb142fa | 15 | #include <environment.h> |
d5bffeb8 MF |
16 | #include <malloc.h> |
17 | #include <net.h> | |
561858ee | 18 | #include <timestamp.h> |
01815c2d | 19 | #include <status_led.h> |
d5bffeb8 MF |
20 | #include <version.h> |
21 | ||
3f0606ad | 22 | #include <asm/cplb.h> |
d5bffeb8 MF |
23 | #include <asm/mach-common/bits/mpu.h> |
24 | ||
25 | #ifdef CONFIG_CMD_NAND | |
26 | #include <nand.h> /* cannot even include nand.h if it isnt configured */ | |
27 | #endif | |
6cb142fa | 28 | |
9171fc81 | 29 | #if defined(CONFIG_POST) |
3f0606ad AL |
30 | #include <post.h> |
31 | int post_flag; | |
32 | #endif | |
d87080b7 | 33 | |
1218abf1 WD |
34 | DECLARE_GLOBAL_DATA_PTR; |
35 | ||
561858ee | 36 | const char version_string[] = U_BOOT_VERSION " ("U_BOOT_DATE" - "U_BOOT_TIME")"; |
d5bffeb8 MF |
37 | |
38 | __attribute__((always_inline)) | |
39 | static inline void serial_early_puts(const char *s) | |
40 | { | |
41 | #ifdef CONFIG_DEBUG_EARLY_SERIAL | |
42 | serial_puts("Early: "); | |
43 | serial_puts(s); | |
3f0606ad | 44 | #endif |
d5bffeb8 | 45 | } |
6cb142fa | 46 | |
d5bffeb8 MF |
47 | static void *mem_malloc_start, *mem_malloc_end, *mem_malloc_brk; |
48 | ||
6cb142fa WD |
49 | static void mem_malloc_init(void) |
50 | { | |
6d0f6bcf JCPV |
51 | mem_malloc_start = (void *)CONFIG_SYS_MALLOC_BASE; |
52 | mem_malloc_end = (void *)(CONFIG_SYS_MALLOC_BASE + CONFIG_SYS_MALLOC_LEN); | |
6cb142fa | 53 | mem_malloc_brk = mem_malloc_start; |
d5bffeb8 | 54 | memset(mem_malloc_start, 0, mem_malloc_end - mem_malloc_start); |
6cb142fa WD |
55 | } |
56 | ||
57 | void *sbrk(ptrdiff_t increment) | |
58 | { | |
d5bffeb8 MF |
59 | void *old = mem_malloc_brk; |
60 | void *new = old + increment; | |
61 | ||
62 | if (new < mem_malloc_start || new > mem_malloc_end) | |
63 | return NULL; | |
6cb142fa | 64 | |
6cb142fa WD |
65 | mem_malloc_brk = new; |
66 | ||
d5bffeb8 | 67 | return old; |
6cb142fa WD |
68 | } |
69 | ||
70 | static int display_banner(void) | |
71 | { | |
d5bffeb8 | 72 | printf("\n\n%s\n\n", version_string); |
fc68f9f8 MF |
73 | printf("CPU: ADSP " MK_STR(CONFIG_BFIN_CPU) " " |
74 | "(Detected Rev: 0.%d) " | |
75 | "(%s boot)\n", | |
76 | bfin_revid(), | |
77 | get_bfin_boot_mode(CONFIG_BFIN_BOOT_MODE)); | |
d5bffeb8 | 78 | return 0; |
6cb142fa WD |
79 | } |
80 | ||
81 | static int init_baudrate(void) | |
82 | { | |
d5bffeb8 MF |
83 | char baudrate[15]; |
84 | int i = getenv_r("baudrate", baudrate, sizeof(baudrate)); | |
6cb142fa | 85 | gd->bd->bi_baudrate = gd->baudrate = (i > 0) |
d5bffeb8 | 86 | ? simple_strtoul(baudrate, NULL, 10) |
3f0606ad | 87 | : CONFIG_BAUDRATE; |
d5bffeb8 | 88 | return 0; |
6cb142fa WD |
89 | } |
90 | ||
6cb142fa WD |
91 | static void display_global_data(void) |
92 | { | |
d5bffeb8 | 93 | #ifdef CONFIG_DEBUG_EARLY_SERIAL |
6cb142fa WD |
94 | bd_t *bd; |
95 | bd = gd->bd; | |
d5bffeb8 MF |
96 | printf(" gd: %x\n", gd); |
97 | printf(" |-flags: %x\n", gd->flags); | |
98 | printf(" |-board_type: %x\n", gd->board_type); | |
99 | printf(" |-baudrate: %i\n", gd->baudrate); | |
100 | printf(" |-have_console: %x\n", gd->have_console); | |
101 | printf(" |-ram_size: %x\n", gd->ram_size); | |
102 | printf(" |-reloc_off: %x\n", gd->reloc_off); | |
103 | printf(" |-env_addr: %x\n", gd->env_addr); | |
104 | printf(" |-env_valid: %x\n", gd->env_valid); | |
105 | printf(" |-jt(%x): %x\n", gd->jt, *(gd->jt)); | |
106 | printf(" \\-bd: %x\n", gd->bd); | |
107 | printf(" |-bi_baudrate: %x\n", bd->bi_baudrate); | |
108 | printf(" |-bi_ip_addr: %x\n", bd->bi_ip_addr); | |
d5bffeb8 MF |
109 | printf(" |-bi_boot_params: %x\n", bd->bi_boot_params); |
110 | printf(" |-bi_memstart: %x\n", bd->bi_memstart); | |
111 | printf(" |-bi_memsize: %x\n", bd->bi_memsize); | |
112 | printf(" |-bi_flashstart: %x\n", bd->bi_flashstart); | |
113 | printf(" |-bi_flashsize: %x\n", bd->bi_flashsize); | |
114 | printf(" \\-bi_flashoffset: %x\n", bd->bi_flashoffset); | |
6cb142fa | 115 | #endif |
d5bffeb8 | 116 | } |
6cb142fa | 117 | |
d5bffeb8 MF |
118 | #define CPLB_PAGE_SIZE (4 * 1024 * 1024) |
119 | #define CPLB_PAGE_MASK (~(CPLB_PAGE_SIZE - 1)) | |
3f0606ad AL |
120 | void init_cplbtables(void) |
121 | { | |
d5bffeb8 MF |
122 | volatile uint32_t *ICPLB_ADDR, *ICPLB_DATA; |
123 | volatile uint32_t *DCPLB_ADDR, *DCPLB_DATA; | |
124 | uint32_t extern_memory; | |
125 | size_t i; | |
126 | ||
127 | void icplb_add(uint32_t addr, uint32_t data) | |
128 | { | |
129 | *(ICPLB_ADDR + i) = addr; | |
130 | *(ICPLB_DATA + i) = data; | |
3f0606ad | 131 | } |
d5bffeb8 MF |
132 | void dcplb_add(uint32_t addr, uint32_t data) |
133 | { | |
134 | *(DCPLB_ADDR + i) = addr; | |
135 | *(DCPLB_DATA + i) = data; | |
3f0606ad AL |
136 | } |
137 | ||
d5bffeb8 MF |
138 | /* populate a few common entries ... we'll let |
139 | * the memory map and cplb exception handler do | |
140 | * the rest of the work. | |
141 | */ | |
142 | i = 0; | |
143 | ICPLB_ADDR = (uint32_t *)ICPLB_ADDR0; | |
144 | ICPLB_DATA = (uint32_t *)ICPLB_DATA0; | |
145 | DCPLB_ADDR = (uint32_t *)DCPLB_ADDR0; | |
146 | DCPLB_DATA = (uint32_t *)DCPLB_DATA0; | |
147 | ||
148 | icplb_add(0xFFA00000, L1_IMEMORY); | |
149 | dcplb_add(0xFF800000, L1_DMEMORY); | |
150 | ++i; | |
151 | ||
6d0f6bcf JCPV |
152 | icplb_add(CONFIG_SYS_MONITOR_BASE & CPLB_PAGE_MASK, SDRAM_IKERNEL); |
153 | dcplb_add(CONFIG_SYS_MONITOR_BASE & CPLB_PAGE_MASK, SDRAM_DKERNEL); | |
d5bffeb8 MF |
154 | ++i; |
155 | ||
156 | /* If the monitor crosses a 4 meg boundary, we'll need | |
157 | * to lock two entries for it. | |
158 | */ | |
6d0f6bcf JCPV |
159 | if ((CONFIG_SYS_MONITOR_BASE & CPLB_PAGE_MASK) != ((CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN) & CPLB_PAGE_MASK)) { |
160 | icplb_add((CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN) & CPLB_PAGE_MASK, SDRAM_IKERNEL); | |
161 | dcplb_add((CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN) & CPLB_PAGE_MASK, SDRAM_DKERNEL); | |
d5bffeb8 MF |
162 | ++i; |
163 | } | |
164 | ||
165 | icplb_add(0x20000000, SDRAM_INON_CHBL); | |
166 | dcplb_add(0x20000000, SDRAM_EBIU); | |
167 | ++i; | |
168 | ||
169 | /* Add entries for the rest of external RAM up to the bootrom */ | |
170 | extern_memory = 0; | |
171 | ||
172 | #ifdef CONFIG_DEBUG_NULL_PTR | |
173 | icplb_add(extern_memory, (SDRAM_IKERNEL & ~PAGE_SIZE_MASK) | PAGE_SIZE_1KB); | |
174 | dcplb_add(extern_memory, (SDRAM_DKERNEL & ~PAGE_SIZE_MASK) | PAGE_SIZE_1KB); | |
175 | ++i; | |
176 | icplb_add(extern_memory, SDRAM_IKERNEL); | |
177 | dcplb_add(extern_memory, SDRAM_DKERNEL); | |
178 | extern_memory += CPLB_PAGE_SIZE; | |
179 | ++i; | |
180 | #endif | |
181 | ||
6d0f6bcf | 182 | while (i < 16 && extern_memory < (CONFIG_SYS_MONITOR_BASE & CPLB_PAGE_MASK)) { |
d5bffeb8 MF |
183 | icplb_add(extern_memory, SDRAM_IGENERIC); |
184 | dcplb_add(extern_memory, SDRAM_DGENERIC); | |
185 | extern_memory += CPLB_PAGE_SIZE; | |
186 | ++i; | |
187 | } | |
188 | while (i < 16) { | |
189 | icplb_add(0, 0); | |
190 | dcplb_add(0, 0); | |
191 | ++i; | |
192 | } | |
3f0606ad AL |
193 | } |
194 | ||
6cb142fa WD |
195 | /* |
196 | * All attempts to come up with a "common" initialization sequence | |
197 | * that works for all boards and architectures failed: some of the | |
198 | * requirements are just _too_ different. To get rid of the resulting | |
199 | * mess of board dependend #ifdef'ed code we now make the whole | |
200 | * initialization sequence configurable to the user. | |
201 | * | |
202 | * The requirements for any new initalization function is simple: it | |
203 | * receives a pointer to the "global data" structure as it's only | |
204 | * argument, and returns an integer return code, where 0 means | |
205 | * "continue" and != 0 means "fatal error, hang the system". | |
206 | */ | |
207 | ||
d5bffeb8 MF |
208 | extern int exception_init(void); |
209 | extern int irq_init(void); | |
d5bffeb8 MF |
210 | extern int timer_init(void); |
211 | ||
6cb142fa WD |
212 | void board_init_f(ulong bootflag) |
213 | { | |
6cb142fa WD |
214 | ulong addr; |
215 | bd_t *bd; | |
6dadc919 | 216 | char buf[32]; |
3f0606ad | 217 | |
d5bffeb8 MF |
218 | #ifdef CONFIG_BOARD_EARLY_INIT_F |
219 | serial_early_puts("Board early init flash\n"); | |
220 | board_early_init_f(); | |
221 | #endif | |
222 | ||
223 | serial_early_puts("Init CPLB tables\n"); | |
3f0606ad | 224 | init_cplbtables(); |
6cb142fa | 225 | |
d5bffeb8 MF |
226 | serial_early_puts("Exceptions setup\n"); |
227 | exception_init(); | |
228 | ||
229 | #ifndef CONFIG_ICACHE_OFF | |
230 | serial_early_puts("Turn on ICACHE\n"); | |
231 | icache_enable(); | |
232 | #endif | |
233 | #ifndef CONFIG_DCACHE_OFF | |
234 | serial_early_puts("Turn on DCACHE\n"); | |
235 | dcache_enable(); | |
236 | #endif | |
237 | ||
78a0ba7d MF |
238 | #ifdef DEBUG |
239 | if (CONFIG_SYS_GBL_DATA_SIZE < sizeof(*gd)) | |
240 | hang(); | |
241 | #endif | |
d5bffeb8 | 242 | serial_early_puts("Init global data\n"); |
6d0f6bcf | 243 | gd = (gd_t *) (CONFIG_SYS_GBL_DATA_ADDR); |
78a0ba7d | 244 | memset((void *)gd, 0, CONFIG_SYS_GBL_DATA_SIZE); |
6cb142fa WD |
245 | |
246 | /* Board data initialization */ | |
6d0f6bcf | 247 | addr = (CONFIG_SYS_GBL_DATA_ADDR + sizeof(gd_t)); |
6cb142fa WD |
248 | |
249 | /* Align to 4 byte boundary */ | |
8e7b703a | 250 | addr &= ~(4 - 1); |
3f0606ad | 251 | bd = (bd_t *) addr; |
6cb142fa | 252 | gd->bd = bd; |
3f0606ad | 253 | memset((void *)bd, 0, sizeof(bd_t)); |
6cb142fa | 254 | |
d5bffeb8 MF |
255 | bd->bi_r_version = version_string; |
256 | bd->bi_cpu = MK_STR(CONFIG_BFIN_CPU); | |
257 | bd->bi_board_name = BFIN_BOARD_NAME; | |
258 | bd->bi_vco = get_vco(); | |
259 | bd->bi_cclk = get_cclk(); | |
260 | bd->bi_sclk = get_sclk(); | |
261 | ||
6cb142fa | 262 | /* Initialize */ |
d5bffeb8 | 263 | serial_early_puts("IRQ init\n"); |
9171fc81 | 264 | irq_init(); |
d5bffeb8 MF |
265 | serial_early_puts("Environment init\n"); |
266 | env_init(); | |
267 | serial_early_puts("Baudrate init\n"); | |
268 | init_baudrate(); | |
269 | serial_early_puts("Serial init\n"); | |
270 | serial_init(); | |
271 | serial_early_puts("Console init flash\n"); | |
6cb142fa | 272 | console_init_f(); |
d5bffeb8 MF |
273 | serial_early_puts("End of early debugging\n"); |
274 | display_banner(); | |
3f0606ad | 275 | |
6cb142fa | 276 | checkboard(); |
6cb142fa | 277 | timer_init(); |
d5bffeb8 | 278 | |
6dadc919 MF |
279 | printf("Clock: VCO: %s MHz, ", strmhz(buf, get_vco())); |
280 | printf("Core: %s MHz, ", strmhz(buf, get_cclk())); | |
281 | printf("System: %s MHz\n", strmhz(buf, get_sclk())); | |
d5bffeb8 MF |
282 | |
283 | printf("RAM: "); | |
6cb142fa | 284 | print_size(initdram(0), "\n"); |
9171fc81 | 285 | #if defined(CONFIG_POST) |
3f0606ad AL |
286 | post_init_f(); |
287 | post_bootmode_init(); | |
288 | post_run(NULL, POST_ROM | post_bootmode_get(0)); | |
289 | #endif | |
d5bffeb8 | 290 | |
6cb142fa WD |
291 | board_init_r((gd_t *) gd, 0x20000010); |
292 | } | |
293 | ||
8996d160 MF |
294 | static void board_net_init_r(bd_t *bd) |
295 | { | |
296 | #ifdef CONFIG_CMD_NET | |
297 | uchar enetaddr[6]; | |
298 | char *s; | |
299 | ||
300 | if ((s = getenv("bootfile")) != NULL) | |
301 | copy_filename(BootFile, s, sizeof(BootFile)); | |
302 | ||
303 | bd->bi_ip_addr = getenv_IPaddr("ipaddr"); | |
304 | ||
305 | printf("Net: "); | |
306 | eth_initialize(gd->bd); | |
307 | ||
308 | eth_getenv_enetaddr("ethaddr", enetaddr); | |
309 | printf("MAC: %pM\n", enetaddr); | |
310 | #endif | |
311 | } | |
312 | ||
6cb142fa WD |
313 | void board_init_r(gd_t * id, ulong dest_addr) |
314 | { | |
6cb142fa | 315 | extern void malloc_bin_reloc(void); |
d5bffeb8 | 316 | char *s; |
6cb142fa | 317 | bd_t *bd; |
6cb142fa WD |
318 | gd = id; |
319 | gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */ | |
320 | bd = gd->bd; | |
321 | ||
9171fc81 | 322 | #if defined(CONFIG_POST) |
3f0606ad AL |
323 | post_output_backlog(); |
324 | post_reloc(); | |
325 | #endif | |
326 | ||
c790b04d SR |
327 | /* initialize malloc() area */ |
328 | mem_malloc_init(); | |
329 | malloc_bin_reloc(); | |
330 | ||
6d0f6bcf | 331 | #if !defined(CONFIG_SYS_NO_FLASH) |
b6edc719 | 332 | /* Initialize the flash and protect u-boot by default */ |
d5bffeb8 | 333 | extern flash_info_t flash_info[]; |
d5bffeb8 | 334 | puts("Flash: "); |
45c48953 | 335 | ulong size = flash_init(); |
d5bffeb8 | 336 | print_size(size, "\n"); |
6d0f6bcf | 337 | flash_protect(FLAG_PROTECT_SET, CONFIG_SYS_FLASH_BASE, |
b6edc719 MF |
338 | CONFIG_SYS_FLASH_BASE + CONFIG_SYS_MONITOR_LEN - 1, |
339 | &flash_info[0]); | |
6d0f6bcf | 340 | bd->bi_flashstart = CONFIG_SYS_FLASH_BASE; |
6cb142fa WD |
341 | bd->bi_flashsize = size; |
342 | bd->bi_flashoffset = 0; | |
343 | #else | |
344 | bd->bi_flashstart = 0; | |
345 | bd->bi_flashsize = 0; | |
346 | bd->bi_flashoffset = 0; | |
347 | #endif | |
6cb142fa | 348 | |
39782727 MF |
349 | #ifdef CONFIG_CMD_NAND |
350 | puts("NAND: "); | |
351 | nand_init(); /* go init the NAND */ | |
352 | #endif | |
353 | ||
6cb142fa WD |
354 | /* relocate environment function pointers etc. */ |
355 | env_relocate(); | |
356 | ||
52cb4d4f JCPV |
357 | /* Initialize stdio devices */ |
358 | stdio_init(); | |
6cb142fa WD |
359 | jumptable_init(); |
360 | ||
361 | /* Initialize the console (after the relocation and devices init) */ | |
362 | console_init_r(); | |
363 | ||
01815c2d MF |
364 | #ifdef CONFIG_STATUS_LED |
365 | status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING); | |
366 | status_led_set(STATUS_LED_CRASH, STATUS_LED_OFF); | |
367 | #endif | |
368 | ||
6cb142fa | 369 | /* Initialize from environment */ |
d5bffeb8 | 370 | if ((s = getenv("loadaddr")) != NULL) |
6cb142fa | 371 | load_addr = simple_strtoul(s, NULL, 16); |
3f0606ad | 372 | |
6cb142fa WD |
373 | #if defined(CONFIG_MISC_INIT_R) |
374 | /* miscellaneous platform dependent initialisations */ | |
375 | misc_init_r(); | |
376 | #endif | |
377 | ||
8996d160 | 378 | board_net_init_r(bd); |
6cb142fa | 379 | |
3f0606ad | 380 | display_global_data(); |
3f0606ad | 381 | |
9171fc81 | 382 | #if defined(CONFIG_POST) |
3f0606ad AL |
383 | if (post_flag) |
384 | post_run(NULL, POST_RAM | post_bootmode_get(0)); | |
6cb142fa WD |
385 | #endif |
386 | ||
909878fd MF |
387 | if (bfin_os_log_check()) { |
388 | puts("\nLog buffer from operating system:\n"); | |
389 | bfin_os_log_dump(); | |
390 | puts("\n"); | |
391 | } | |
392 | ||
6cb142fa | 393 | /* main_loop() can return to retry autoboot, if so just run it again. */ |
d5bffeb8 | 394 | for (;;) |
6cb142fa | 395 | main_loop(); |
6cb142fa WD |
396 | } |
397 | ||
6cb142fa WD |
398 | void hang(void) |
399 | { | |
01815c2d MF |
400 | #ifdef CONFIG_STATUS_LED |
401 | status_led_set(STATUS_LED_BOOT, STATUS_LED_OFF); | |
402 | status_led_set(STATUS_LED_CRASH, STATUS_LED_BLINKING); | |
403 | #endif | |
6cb142fa | 404 | puts("### ERROR ### Please RESET the board ###\n"); |
d5bffeb8 MF |
405 | while (1) |
406 | /* If a JTAG emulator is hooked up, we'll automatically trigger | |
407 | * a breakpoint in it. If one isn't, this is just a NOP. | |
408 | */ | |
409 | asm("emuexcpt;"); | |
6cb142fa | 410 | } |