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.
14 #include <stdio_dev.h>
16 #include <environment.h>
20 #include <status_led.h>
25 #include <asm/mach-common/bits/mpu.h>
28 #ifdef CONFIG_CMD_NAND
29 #include <nand.h> /* cannot even include nand.h if it isnt configured */
32 #ifdef CONFIG_BITBANGMII
36 #if defined(CONFIG_POST)
41 #if defined(CONFIG_SYS_I2C)
45 DECLARE_GLOBAL_DATA_PTR;
47 __attribute__((always_inline))
48 static inline void serial_early_puts(const char *s)
50 #ifdef CONFIG_DEBUG_EARLY_SERIAL
51 serial_puts("Early: ");
56 static int display_banner(void)
59 printf("CPU: ADSP %s "
60 "(Detected Rev: 0.%d) "
64 get_bfin_boot_mode(CONFIG_BFIN_BOOT_MODE));
68 static int init_baudrate(void)
70 gd->baudrate = getenv_ulong("baudrate", 10, CONFIG_BAUDRATE);
71 gd->bd->bi_baudrate = gd->baudrate;
75 static void display_global_data(void)
79 #ifndef CONFIG_DEBUG_EARLY_SERIAL
84 printf(" gd: %p\n", gd);
85 printf(" |-flags: %lx\n", gd->flags);
86 printf(" |-board_type: %lx\n", gd->arch.board_type);
87 printf(" |-baudrate: %u\n", gd->baudrate);
88 printf(" |-have_console: %lx\n", gd->have_console);
89 printf(" |-ram_size: %lx\n", gd->ram_size);
90 printf(" |-env_addr: %lx\n", gd->env_addr);
91 printf(" |-env_valid: %lx\n", gd->env_valid);
92 printf(" |-jt(%p): %p\n", gd->jt, *(gd->jt));
93 printf(" \\-bd: %p\n", gd->bd);
94 printf(" |-bi_baudrate: %x\n", bd->bi_baudrate);
95 printf(" |-bi_boot_params: %lx\n", bd->bi_boot_params);
96 printf(" |-bi_memstart: %lx\n", bd->bi_memstart);
97 printf(" |-bi_memsize: %lx\n", bd->bi_memsize);
98 printf(" |-bi_flashstart: %lx\n", bd->bi_flashstart);
99 printf(" |-bi_flashsize: %lx\n", bd->bi_flashsize);
100 printf(" \\-bi_flashoffset: %lx\n", bd->bi_flashoffset);
103 #define CPLB_PAGE_SIZE (4 * 1024 * 1024)
104 #define CPLB_PAGE_MASK (~(CPLB_PAGE_SIZE - 1))
105 #if defined(__ADSPBF60x__)
106 #define CPLB_EX_PAGE_SIZE (16 * 1024 * 1024)
107 #define CPLB_EX_PAGE_MASK (~(CPLB_EX_PAGE_SIZE - 1))
109 #define CPLB_EX_PAGE_SIZE CPLB_PAGE_SIZE
110 #define CPLB_EX_PAGE_MASK CPLB_PAGE_MASK
112 void init_cplbtables(void)
114 volatile uint32_t *ICPLB_ADDR, *ICPLB_DATA;
115 volatile uint32_t *DCPLB_ADDR, *DCPLB_DATA;
116 uint32_t extern_memory;
119 void icplb_add(uint32_t addr, uint32_t data)
121 *(ICPLB_ADDR + i) = addr;
122 *(ICPLB_DATA + i) = data;
124 void dcplb_add(uint32_t addr, uint32_t data)
126 *(DCPLB_ADDR + i) = addr;
127 *(DCPLB_DATA + i) = data;
130 /* populate a few common entries ... we'll let
131 * the memory map and cplb exception handler do
132 * the rest of the work.
135 ICPLB_ADDR = (uint32_t *)ICPLB_ADDR0;
136 ICPLB_DATA = (uint32_t *)ICPLB_DATA0;
137 DCPLB_ADDR = (uint32_t *)DCPLB_ADDR0;
138 DCPLB_DATA = (uint32_t *)DCPLB_DATA0;
140 icplb_add(0xFFA00000, L1_IMEMORY);
141 dcplb_add(0xFF800000, L1_DMEMORY);
143 #if defined(__ADSPBF60x__)
145 dcplb_add(CONFIG_SYS_FLASH_BASE, PAGE_SIZE_16MB | CPLB_DIRTY |
146 CPLB_SUPV_WR | CPLB_USER_WR | CPLB_USER_RD | CPLB_VALID);
150 if (CONFIG_MEM_SIZE) {
151 uint32_t mbase = CONFIG_SYS_MONITOR_BASE;
152 uint32_t mend = mbase + CONFIG_SYS_MONITOR_LEN;
153 mbase &= CPLB_PAGE_MASK;
154 mend &= CPLB_PAGE_MASK;
156 icplb_add(mbase, SDRAM_IKERNEL);
157 dcplb_add(mbase, SDRAM_DKERNEL);
161 * If the monitor crosses a 4 meg boundary, we'll need
162 * to lock two entries for it. We assume it doesn't
163 * cross two 4 meg boundaries ...
166 icplb_add(mend, SDRAM_IKERNEL);
167 dcplb_add(mend, SDRAM_DKERNEL);
172 #ifndef __ADSPBF60x__
173 icplb_add(0x20000000, SDRAM_INON_CHBL);
174 dcplb_add(0x20000000, SDRAM_EBIU);
178 /* Add entries for the rest of external RAM up to the bootrom */
181 #ifdef CONFIG_DEBUG_NULL_PTR
182 icplb_add(extern_memory, (SDRAM_IKERNEL & ~PAGE_SIZE_MASK) | PAGE_SIZE_1KB);
183 dcplb_add(extern_memory, (SDRAM_DKERNEL & ~PAGE_SIZE_MASK) | PAGE_SIZE_1KB);
185 icplb_add(extern_memory, SDRAM_IKERNEL);
186 dcplb_add(extern_memory, SDRAM_DKERNEL);
187 extern_memory += CPLB_PAGE_SIZE;
191 while (i < 16 && extern_memory <
192 (CONFIG_SYS_MONITOR_BASE & CPLB_EX_PAGE_MASK)) {
193 icplb_add(extern_memory, SDRAM_IGENERIC);
194 dcplb_add(extern_memory, SDRAM_DGENERIC);
195 extern_memory += CPLB_EX_PAGE_SIZE;
205 static int global_board_data_init(void)
207 #ifndef CONFIG_SYS_GBL_DATA_ADDR
208 # define CONFIG_SYS_GBL_DATA_ADDR 0
210 #ifndef CONFIG_SYS_BD_INFO_ADDR
211 # define CONFIG_SYS_BD_INFO_ADDR 0
216 if (CONFIG_SYS_GBL_DATA_ADDR) {
217 gd = (gd_t *) (CONFIG_SYS_GBL_DATA_ADDR);
218 memset((void *)gd, 0, GENERATED_GBL_DATA_SIZE);
220 static gd_t _bfin_gd;
224 if (CONFIG_SYS_BD_INFO_ADDR) {
225 bd = (bd_t *) (CONFIG_SYS_BD_INFO_ADDR);
226 memset(bd, 0, GENERATED_BD_INFO_SIZE);
228 static bd_t _bfin_bd;
233 bd->bi_r_version = version_string;
234 bd->bi_cpu = __stringify(CONFIG_BFIN_CPU);
235 bd->bi_board_name = BFIN_BOARD_NAME;
236 bd->bi_vco = get_vco();
237 bd->bi_cclk = get_cclk();
238 bd->bi_sclk = get_sclk();
239 bd->bi_memstart = CONFIG_SYS_SDRAM_BASE;
240 bd->bi_memsize = CONFIG_SYS_MAX_RAM_SIZE;
246 * All attempts to come up with a "common" initialization sequence
247 * that works for all boards and architectures failed: some of the
248 * requirements are just _too_ different. To get rid of the resulting
249 * mess of board dependend #ifdef'ed code we now make the whole
250 * initialization sequence configurable to the user.
252 * The requirements for any new initalization function is simple: it
253 * receives a pointer to the "global data" structure as it's only
254 * argument, and returns an integer return code, where 0 means
255 * "continue" and != 0 means "fatal error, hang the system".
258 extern int watchdog_init(void);
259 extern int exception_init(void);
260 extern int irq_init(void);
261 extern int timer_init(void);
263 void board_init_f(ulong bootflag)
267 #ifdef CONFIG_BOARD_EARLY_INIT_F
268 serial_early_puts("Board early init flash\n");
269 board_early_init_f();
272 serial_early_puts("Init CPLB tables\n");
275 serial_early_puts("Exceptions setup\n");
278 #ifndef CONFIG_ICACHE_OFF
279 serial_early_puts("Turn on ICACHE\n");
282 #ifndef CONFIG_DCACHE_OFF
283 serial_early_puts("Turn on DCACHE\n");
287 #ifdef CONFIG_HW_WATCHDOG
288 serial_early_puts("Setting up external watchdog\n");
293 if (GENERATED_GBL_DATA_SIZE < sizeof(*gd))
296 serial_early_puts("Init global data\n");
298 global_board_data_init();
301 serial_early_puts("IRQ init\n");
303 serial_early_puts("Environment init\n");
305 serial_early_puts("Baudrate init\n");
307 serial_early_puts("Serial init\n");
310 serial_early_puts("Console init flash\n");
312 serial_early_puts("End of early debugging\n");
318 printf("Clock: VCO: %s MHz, ", strmhz(buf, get_vco()));
319 printf("Core: %s MHz, ", strmhz(buf, get_cclk()));
320 #if defined(__ADSPBF60x__)
321 printf("System0: %s MHz, ", strmhz(buf, get_sclk0()));
322 printf("System1: %s MHz, ", strmhz(buf, get_sclk1()));
323 printf("Dclk: %s MHz\n", strmhz(buf, get_dclk()));
325 printf("System: %s MHz\n", strmhz(buf, get_sclk()));
328 if (CONFIG_MEM_SIZE) {
330 print_size(gd->bd->bi_memsize, "\n");
333 #if defined(CONFIG_POST)
335 post_bootmode_init();
336 post_run(NULL, POST_ROM | post_bootmode_get(0));
339 board_init_r((gd_t *) gd, 0x20000010);
342 static void board_net_init_r(bd_t *bd)
344 #ifdef CONFIG_BITBANGMII
347 #ifdef CONFIG_CMD_NET
353 void board_init_r(gd_t * id, ulong dest_addr)
357 gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
360 #if defined(CONFIG_POST)
361 post_output_backlog();
364 /* initialize malloc() area */
365 mem_malloc_init(CONFIG_SYS_MALLOC_BASE, CONFIG_SYS_MALLOC_LEN);
367 #if !defined(CONFIG_SYS_NO_FLASH)
368 /* Initialize the flash and protect u-boot by default */
369 extern flash_info_t flash_info[];
371 ulong size = flash_init();
372 print_size(size, "\n");
373 flash_protect(FLAG_PROTECT_SET, CONFIG_SYS_FLASH_BASE,
374 CONFIG_SYS_FLASH_BASE + CONFIG_SYS_MONITOR_LEN - 1,
376 bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
377 bd->bi_flashsize = size;
378 bd->bi_flashoffset = 0;
380 bd->bi_flashstart = 0;
381 bd->bi_flashsize = 0;
382 bd->bi_flashoffset = 0;
385 #ifdef CONFIG_CMD_NAND
387 nand_init(); /* go init the NAND */
390 #ifdef CONFIG_GENERIC_MMC
395 #if defined(CONFIG_SYS_I2C)
398 /* relocate environment function pointers etc. */
401 /* Initialize stdio devices */
405 /* Initialize the console (after the relocation and devices init) */
408 #ifdef CONFIG_CMD_KGDB
413 #ifdef CONFIG_STATUS_LED
414 status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING);
415 status_led_set(STATUS_LED_CRASH, STATUS_LED_OFF);
418 /* Initialize from environment */
419 load_addr = getenv_ulong("loadaddr", 16, load_addr);
421 #if defined(CONFIG_MISC_INIT_R)
422 /* miscellaneous platform dependent initialisations */
426 board_net_init_r(bd);
428 display_global_data();
430 #if defined(CONFIG_POST)
432 post_run(NULL, POST_RAM | post_bootmode_get(0));
435 if (CONFIG_MEM_SIZE && bfin_os_log_check()) {
436 puts("\nLog buffer from operating system:\n");
441 /* main_loop() can return to retry autoboot, if so just run it again. */