2 * U-boot - board.c First C file to be called contains init routines
4 * Copyright (c) 2005-2008 Analog Devices Inc.
6 * (C) Copyright 2000-2004
7 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
9 * Licensed under the GPL-2 or later.
15 #include <environment.h>
18 #include <timestamp.h>
19 #include <status_led.h>
23 #include <asm/mach-common/bits/mpu.h>
25 #ifdef CONFIG_CMD_NAND
26 #include <nand.h> /* cannot even include nand.h if it isnt configured */
29 #if defined(CONFIG_POST)
34 DECLARE_GLOBAL_DATA_PTR;
36 const char version_string[] = U_BOOT_VERSION " ("U_BOOT_DATE" - "U_BOOT_TIME")";
38 __attribute__((always_inline))
39 static inline void serial_early_puts(const char *s)
41 #ifdef CONFIG_DEBUG_EARLY_SERIAL
42 serial_puts("Early: ");
47 /* Get the input voltage */
48 static u_long get_vco(void)
53 msel = (*pPLL_CTL >> 9) & 0x3F;
57 vco = CONFIG_CLKIN_HZ;
58 vco >>= (1 & *pPLL_CTL); /* DF bit */
63 /* Get the Core clock */
68 return CONFIG_CLKIN_HZ;
71 csel = ((ssel >> 4) & 0x03);
73 if (ssel && ssel < (1 << csel)) /* SCLK > CCLK */
74 return get_vco() / ssel;
75 return get_vco() >> csel;
78 /* Get the System clock */
84 return CONFIG_CLKIN_HZ;
86 ssel = (*pPLL_DIV & 0xf);
88 return get_vco() / ssel;
91 static void *mem_malloc_start, *mem_malloc_end, *mem_malloc_brk;
93 static void mem_malloc_init(void)
95 mem_malloc_start = (void *)CONFIG_SYS_MALLOC_BASE;
96 mem_malloc_end = (void *)(CONFIG_SYS_MALLOC_BASE + CONFIG_SYS_MALLOC_LEN);
97 mem_malloc_brk = mem_malloc_start;
98 memset(mem_malloc_start, 0, mem_malloc_end - mem_malloc_start);
101 void *sbrk(ptrdiff_t increment)
103 void *old = mem_malloc_brk;
104 void *new = old + increment;
106 if (new < mem_malloc_start || new > mem_malloc_end)
109 mem_malloc_brk = new;
114 static int display_banner(void)
116 printf("\n\n%s\n\n", version_string);
117 printf("CPU: ADSP " MK_STR(CONFIG_BFIN_CPU) " (Detected Rev: 0.%d)\n", bfin_revid());
121 static int init_baudrate(void)
124 int i = getenv_r("baudrate", baudrate, sizeof(baudrate));
125 gd->bd->bi_baudrate = gd->baudrate = (i > 0)
126 ? simple_strtoul(baudrate, NULL, 10)
131 static void display_global_data(void)
133 #ifdef CONFIG_DEBUG_EARLY_SERIAL
136 printf(" gd: %x\n", gd);
137 printf(" |-flags: %x\n", gd->flags);
138 printf(" |-board_type: %x\n", gd->board_type);
139 printf(" |-baudrate: %i\n", gd->baudrate);
140 printf(" |-have_console: %x\n", gd->have_console);
141 printf(" |-ram_size: %x\n", gd->ram_size);
142 printf(" |-reloc_off: %x\n", gd->reloc_off);
143 printf(" |-env_addr: %x\n", gd->env_addr);
144 printf(" |-env_valid: %x\n", gd->env_valid);
145 printf(" |-jt(%x): %x\n", gd->jt, *(gd->jt));
146 printf(" \\-bd: %x\n", gd->bd);
147 printf(" |-bi_baudrate: %x\n", bd->bi_baudrate);
148 printf(" |-bi_ip_addr: %x\n", bd->bi_ip_addr);
149 printf(" |-bi_enetaddr: %x %x %x %x %x %x\n",
150 bd->bi_enetaddr[0], bd->bi_enetaddr[1],
151 bd->bi_enetaddr[2], bd->bi_enetaddr[3],
152 bd->bi_enetaddr[4], bd->bi_enetaddr[5]);
153 printf(" |-bi_boot_params: %x\n", bd->bi_boot_params);
154 printf(" |-bi_memstart: %x\n", bd->bi_memstart);
155 printf(" |-bi_memsize: %x\n", bd->bi_memsize);
156 printf(" |-bi_flashstart: %x\n", bd->bi_flashstart);
157 printf(" |-bi_flashsize: %x\n", bd->bi_flashsize);
158 printf(" \\-bi_flashoffset: %x\n", bd->bi_flashoffset);
162 #define CPLB_PAGE_SIZE (4 * 1024 * 1024)
163 #define CPLB_PAGE_MASK (~(CPLB_PAGE_SIZE - 1))
164 void init_cplbtables(void)
166 volatile uint32_t *ICPLB_ADDR, *ICPLB_DATA;
167 volatile uint32_t *DCPLB_ADDR, *DCPLB_DATA;
168 uint32_t extern_memory;
171 void icplb_add(uint32_t addr, uint32_t data)
173 *(ICPLB_ADDR + i) = addr;
174 *(ICPLB_DATA + i) = data;
176 void dcplb_add(uint32_t addr, uint32_t data)
178 *(DCPLB_ADDR + i) = addr;
179 *(DCPLB_DATA + i) = data;
182 /* populate a few common entries ... we'll let
183 * the memory map and cplb exception handler do
184 * the rest of the work.
187 ICPLB_ADDR = (uint32_t *)ICPLB_ADDR0;
188 ICPLB_DATA = (uint32_t *)ICPLB_DATA0;
189 DCPLB_ADDR = (uint32_t *)DCPLB_ADDR0;
190 DCPLB_DATA = (uint32_t *)DCPLB_DATA0;
192 icplb_add(0xFFA00000, L1_IMEMORY);
193 dcplb_add(0xFF800000, L1_DMEMORY);
196 icplb_add(CONFIG_SYS_MONITOR_BASE & CPLB_PAGE_MASK, SDRAM_IKERNEL);
197 dcplb_add(CONFIG_SYS_MONITOR_BASE & CPLB_PAGE_MASK, SDRAM_DKERNEL);
200 /* If the monitor crosses a 4 meg boundary, we'll need
201 * to lock two entries for it.
203 if ((CONFIG_SYS_MONITOR_BASE & CPLB_PAGE_MASK) != ((CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN) & CPLB_PAGE_MASK)) {
204 icplb_add((CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN) & CPLB_PAGE_MASK, SDRAM_IKERNEL);
205 dcplb_add((CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN) & CPLB_PAGE_MASK, SDRAM_DKERNEL);
209 icplb_add(0x20000000, SDRAM_INON_CHBL);
210 dcplb_add(0x20000000, SDRAM_EBIU);
213 /* Add entries for the rest of external RAM up to the bootrom */
216 #ifdef CONFIG_DEBUG_NULL_PTR
217 icplb_add(extern_memory, (SDRAM_IKERNEL & ~PAGE_SIZE_MASK) | PAGE_SIZE_1KB);
218 dcplb_add(extern_memory, (SDRAM_DKERNEL & ~PAGE_SIZE_MASK) | PAGE_SIZE_1KB);
220 icplb_add(extern_memory, SDRAM_IKERNEL);
221 dcplb_add(extern_memory, SDRAM_DKERNEL);
222 extern_memory += CPLB_PAGE_SIZE;
226 while (i < 16 && extern_memory < (CONFIG_SYS_MONITOR_BASE & CPLB_PAGE_MASK)) {
227 icplb_add(extern_memory, SDRAM_IGENERIC);
228 dcplb_add(extern_memory, SDRAM_DGENERIC);
229 extern_memory += CPLB_PAGE_SIZE;
240 * All attempts to come up with a "common" initialization sequence
241 * that works for all boards and architectures failed: some of the
242 * requirements are just _too_ different. To get rid of the resulting
243 * mess of board dependend #ifdef'ed code we now make the whole
244 * initialization sequence configurable to the user.
246 * The requirements for any new initalization function is simple: it
247 * receives a pointer to the "global data" structure as it's only
248 * argument, and returns an integer return code, where 0 means
249 * "continue" and != 0 means "fatal error, hang the system".
252 extern int exception_init(void);
253 extern int irq_init(void);
254 extern int timer_init(void);
256 void board_init_f(ulong bootflag)
262 #ifdef CONFIG_BOARD_EARLY_INIT_F
263 serial_early_puts("Board early init flash\n");
264 board_early_init_f();
267 serial_early_puts("Init CPLB tables\n");
270 serial_early_puts("Exceptions setup\n");
273 #ifndef CONFIG_ICACHE_OFF
274 serial_early_puts("Turn on ICACHE\n");
277 #ifndef CONFIG_DCACHE_OFF
278 serial_early_puts("Turn on DCACHE\n");
283 if (CONFIG_SYS_GBL_DATA_SIZE < sizeof(*gd))
286 serial_early_puts("Init global data\n");
287 gd = (gd_t *) (CONFIG_SYS_GBL_DATA_ADDR);
288 memset((void *)gd, 0, CONFIG_SYS_GBL_DATA_SIZE);
290 /* Board data initialization */
291 addr = (CONFIG_SYS_GBL_DATA_ADDR + sizeof(gd_t));
293 /* Align to 4 byte boundary */
297 memset((void *)bd, 0, sizeof(bd_t));
299 bd->bi_r_version = version_string;
300 bd->bi_cpu = MK_STR(CONFIG_BFIN_CPU);
301 bd->bi_board_name = BFIN_BOARD_NAME;
302 bd->bi_vco = get_vco();
303 bd->bi_cclk = get_cclk();
304 bd->bi_sclk = get_sclk();
307 serial_early_puts("IRQ init\n");
309 serial_early_puts("Environment init\n");
311 serial_early_puts("Baudrate init\n");
313 serial_early_puts("Serial init\n");
315 serial_early_puts("Console init flash\n");
317 serial_early_puts("End of early debugging\n");
323 printf("Clock: VCO: %s MHz, ", strmhz(buf, get_vco()));
324 printf("Core: %s MHz, ", strmhz(buf, get_cclk()));
325 printf("System: %s MHz\n", strmhz(buf, get_sclk()));
328 print_size(initdram(0), "\n");
329 #if defined(CONFIG_POST)
331 post_bootmode_init();
332 post_run(NULL, POST_ROM | post_bootmode_get(0));
335 board_init_r((gd_t *) gd, 0x20000010);
338 void board_init_r(gd_t * id, ulong dest_addr)
340 extern void malloc_bin_reloc(void);
344 gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
347 #if defined(CONFIG_POST)
348 post_output_backlog();
352 #if !defined(CONFIG_SYS_NO_FLASH)
353 /* Initialize the flash and protect u-boot by default */
354 extern flash_info_t flash_info[];
355 ulong size = flash_init();
357 print_size(size, "\n");
358 flash_protect(FLAG_PROTECT_SET, CONFIG_SYS_FLASH_BASE,
359 CONFIG_SYS_FLASH_BASE + CONFIG_SYS_MONITOR_LEN - 1,
361 bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
362 bd->bi_flashsize = size;
363 bd->bi_flashoffset = 0;
365 bd->bi_flashstart = 0;
366 bd->bi_flashsize = 0;
367 bd->bi_flashoffset = 0;
369 /* initialize malloc() area */
373 #ifdef CONFIG_CMD_NAND
375 nand_init(); /* go init the NAND */
378 /* relocate environment function pointers etc. */
381 #ifdef CONFIG_CMD_NET
382 /* board MAC address */
383 s = getenv("ethaddr");
385 # ifndef CONFIG_ETHADDR
387 if (!board_get_enetaddr(bd->bi_enetaddr)) {
389 sprintf(nid, "%02X:%02X:%02X:%02X:%02X:%02X",
390 bd->bi_enetaddr[0], bd->bi_enetaddr[1],
391 bd->bi_enetaddr[2], bd->bi_enetaddr[3],
392 bd->bi_enetaddr[4], bd->bi_enetaddr[5]);
393 setenv("ethaddr", nid);
400 for (i = 0; i < 6; ++i) {
401 bd->bi_enetaddr[i] = simple_strtoul(s, &e, 16);
402 s = (*e) ? e + 1 : e;
407 bd->bi_ip_addr = getenv_IPaddr("ipaddr");
410 /* Initialize devices */
414 /* Initialize the console (after the relocation and devices init) */
417 #ifdef CONFIG_STATUS_LED
418 status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING);
419 status_led_set(STATUS_LED_CRASH, STATUS_LED_OFF);
422 /* Initialize from environment */
423 if ((s = getenv("loadaddr")) != NULL)
424 load_addr = simple_strtoul(s, NULL, 16);
425 #ifdef CONFIG_CMD_NET
426 if ((s = getenv("bootfile")) != NULL)
427 copy_filename(BootFile, s, sizeof(BootFile));
430 #if defined(CONFIG_MISC_INIT_R)
431 /* miscellaneous platform dependent initialisations */
435 #ifdef CONFIG_CMD_NET
437 eth_initialize(gd->bd);
438 if (getenv("ethaddr"))
439 printf("MAC: %02X:%02X:%02X:%02X:%02X:%02X\n",
440 bd->bi_enetaddr[0], bd->bi_enetaddr[1], bd->bi_enetaddr[2],
441 bd->bi_enetaddr[3], bd->bi_enetaddr[4], bd->bi_enetaddr[5]);
444 display_global_data();
446 #if defined(CONFIG_POST)
448 post_run(NULL, POST_RAM | post_bootmode_get(0));
451 /* main_loop() can return to retry autoboot, if so just run it again. */
458 #ifdef CONFIG_STATUS_LED
459 status_led_set(STATUS_LED_BOOT, STATUS_LED_OFF);
460 status_led_set(STATUS_LED_CRASH, STATUS_LED_BLINKING);
462 puts("### ERROR ### Please RESET the board ###\n");
464 /* If a JTAG emulator is hooked up, we'll automatically trigger
465 * a breakpoint in it. If one isn't, this is just a NOP.