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>
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 #ifdef CONFIG_BITBANGMII
33 #if defined(CONFIG_POST)
38 DECLARE_GLOBAL_DATA_PTR;
40 const char version_string[] = U_BOOT_VERSION " ("U_BOOT_DATE" - "U_BOOT_TIME")";
42 __attribute__((always_inline))
43 static inline void serial_early_puts(const char *s)
45 #ifdef CONFIG_DEBUG_EARLY_SERIAL
46 serial_puts("Early: ");
51 static int display_banner(void)
53 printf("\n\n%s\n\n", version_string);
54 printf("CPU: ADSP " MK_STR(CONFIG_BFIN_CPU) " "
55 "(Detected Rev: 0.%d) "
58 get_bfin_boot_mode(CONFIG_BFIN_BOOT_MODE));
62 static int init_baudrate(void)
65 int i = getenv_r("baudrate", baudrate, sizeof(baudrate));
66 gd->bd->bi_baudrate = gd->baudrate = (i > 0)
67 ? simple_strtoul(baudrate, NULL, 10)
72 static void display_global_data(void)
74 #ifdef CONFIG_DEBUG_EARLY_SERIAL
77 printf(" gd: %p\n", gd);
78 printf(" |-flags: %lx\n", gd->flags);
79 printf(" |-board_type: %lx\n", gd->board_type);
80 printf(" |-baudrate: %lu\n", gd->baudrate);
81 printf(" |-have_console: %lx\n", gd->have_console);
82 printf(" |-ram_size: %lx\n", gd->ram_size);
83 printf(" |-reloc_off: %lx\n", gd->reloc_off);
84 printf(" |-env_addr: %lx\n", gd->env_addr);
85 printf(" |-env_valid: %lx\n", gd->env_valid);
86 printf(" |-jt(%p): %p\n", gd->jt, *(gd->jt));
87 printf(" \\-bd: %p\n", gd->bd);
88 printf(" |-bi_baudrate: %x\n", bd->bi_baudrate);
89 printf(" |-bi_ip_addr: %lx\n", bd->bi_ip_addr);
90 printf(" |-bi_boot_params: %lx\n", bd->bi_boot_params);
91 printf(" |-bi_memstart: %lx\n", bd->bi_memstart);
92 printf(" |-bi_memsize: %lx\n", bd->bi_memsize);
93 printf(" |-bi_flashstart: %lx\n", bd->bi_flashstart);
94 printf(" |-bi_flashsize: %lx\n", bd->bi_flashsize);
95 printf(" \\-bi_flashoffset: %lx\n", bd->bi_flashoffset);
99 #define CPLB_PAGE_SIZE (4 * 1024 * 1024)
100 #define CPLB_PAGE_MASK (~(CPLB_PAGE_SIZE - 1))
101 void init_cplbtables(void)
103 volatile uint32_t *ICPLB_ADDR, *ICPLB_DATA;
104 volatile uint32_t *DCPLB_ADDR, *DCPLB_DATA;
105 uint32_t extern_memory;
108 void icplb_add(uint32_t addr, uint32_t data)
110 *(ICPLB_ADDR + i) = addr;
111 *(ICPLB_DATA + i) = data;
113 void dcplb_add(uint32_t addr, uint32_t data)
115 *(DCPLB_ADDR + i) = addr;
116 *(DCPLB_DATA + i) = data;
119 /* populate a few common entries ... we'll let
120 * the memory map and cplb exception handler do
121 * the rest of the work.
124 ICPLB_ADDR = (uint32_t *)ICPLB_ADDR0;
125 ICPLB_DATA = (uint32_t *)ICPLB_DATA0;
126 DCPLB_ADDR = (uint32_t *)DCPLB_ADDR0;
127 DCPLB_DATA = (uint32_t *)DCPLB_DATA0;
129 icplb_add(0xFFA00000, L1_IMEMORY);
130 dcplb_add(0xFF800000, L1_DMEMORY);
133 icplb_add(CONFIG_SYS_MONITOR_BASE & CPLB_PAGE_MASK, SDRAM_IKERNEL);
134 dcplb_add(CONFIG_SYS_MONITOR_BASE & CPLB_PAGE_MASK, SDRAM_DKERNEL);
137 /* If the monitor crosses a 4 meg boundary, we'll need
138 * to lock two entries for it.
140 if ((CONFIG_SYS_MONITOR_BASE & CPLB_PAGE_MASK) != ((CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN) & CPLB_PAGE_MASK)) {
141 icplb_add((CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN) & CPLB_PAGE_MASK, SDRAM_IKERNEL);
142 dcplb_add((CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN) & CPLB_PAGE_MASK, SDRAM_DKERNEL);
146 icplb_add(0x20000000, SDRAM_INON_CHBL);
147 dcplb_add(0x20000000, SDRAM_EBIU);
150 /* Add entries for the rest of external RAM up to the bootrom */
153 #ifdef CONFIG_DEBUG_NULL_PTR
154 icplb_add(extern_memory, (SDRAM_IKERNEL & ~PAGE_SIZE_MASK) | PAGE_SIZE_1KB);
155 dcplb_add(extern_memory, (SDRAM_DKERNEL & ~PAGE_SIZE_MASK) | PAGE_SIZE_1KB);
157 icplb_add(extern_memory, SDRAM_IKERNEL);
158 dcplb_add(extern_memory, SDRAM_DKERNEL);
159 extern_memory += CPLB_PAGE_SIZE;
163 while (i < 16 && extern_memory < (CONFIG_SYS_MONITOR_BASE & CPLB_PAGE_MASK)) {
164 icplb_add(extern_memory, SDRAM_IGENERIC);
165 dcplb_add(extern_memory, SDRAM_DGENERIC);
166 extern_memory += CPLB_PAGE_SIZE;
177 * All attempts to come up with a "common" initialization sequence
178 * that works for all boards and architectures failed: some of the
179 * requirements are just _too_ different. To get rid of the resulting
180 * mess of board dependend #ifdef'ed code we now make the whole
181 * initialization sequence configurable to the user.
183 * The requirements for any new initalization function is simple: it
184 * receives a pointer to the "global data" structure as it's only
185 * argument, and returns an integer return code, where 0 means
186 * "continue" and != 0 means "fatal error, hang the system".
189 extern int exception_init(void);
190 extern int irq_init(void);
191 extern int timer_init(void);
193 void board_init_f(ulong bootflag)
199 #ifdef CONFIG_BOARD_EARLY_INIT_F
200 serial_early_puts("Board early init flash\n");
201 board_early_init_f();
204 serial_early_puts("Init CPLB tables\n");
207 serial_early_puts("Exceptions setup\n");
210 #ifndef CONFIG_ICACHE_OFF
211 serial_early_puts("Turn on ICACHE\n");
214 #ifndef CONFIG_DCACHE_OFF
215 serial_early_puts("Turn on DCACHE\n");
220 if (CONFIG_SYS_GBL_DATA_SIZE < sizeof(*gd))
223 serial_early_puts("Init global data\n");
224 gd = (gd_t *) (CONFIG_SYS_GBL_DATA_ADDR);
225 memset((void *)gd, 0, CONFIG_SYS_GBL_DATA_SIZE);
227 /* Board data initialization */
228 addr = (CONFIG_SYS_GBL_DATA_ADDR + sizeof(gd_t));
230 /* Align to 4 byte boundary */
234 memset((void *)bd, 0, sizeof(bd_t));
236 bd->bi_r_version = version_string;
237 bd->bi_cpu = MK_STR(CONFIG_BFIN_CPU);
238 bd->bi_board_name = BFIN_BOARD_NAME;
239 bd->bi_vco = get_vco();
240 bd->bi_cclk = get_cclk();
241 bd->bi_sclk = get_sclk();
242 bd->bi_memstart = CONFIG_SYS_SDRAM_BASE;
243 bd->bi_memsize = CONFIG_SYS_MAX_RAM_SIZE;
246 serial_early_puts("IRQ init\n");
248 serial_early_puts("Environment init\n");
250 serial_early_puts("Baudrate init\n");
252 serial_early_puts("Serial init\n");
254 serial_early_puts("Console init flash\n");
256 serial_early_puts("End of early debugging\n");
262 printf("Clock: VCO: %s MHz, ", strmhz(buf, get_vco()));
263 printf("Core: %s MHz, ", strmhz(buf, get_cclk()));
264 printf("System: %s MHz\n", strmhz(buf, get_sclk()));
267 print_size(bd->bi_memsize, "\n");
268 #if defined(CONFIG_POST)
270 post_bootmode_init();
271 post_run(NULL, POST_ROM | post_bootmode_get(0));
274 board_init_r((gd_t *) gd, 0x20000010);
277 static void board_net_init_r(bd_t *bd)
279 #ifdef CONFIG_BITBANGMII
282 #ifdef CONFIG_CMD_NET
285 if ((s = getenv("bootfile")) != NULL)
286 copy_filename(BootFile, s, sizeof(BootFile));
288 bd->bi_ip_addr = getenv_IPaddr("ipaddr");
291 eth_initialize(gd->bd);
295 void board_init_r(gd_t * id, ulong dest_addr)
300 gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
303 #if defined(CONFIG_POST)
304 post_output_backlog();
308 /* initialize malloc() area */
309 mem_malloc_init(CONFIG_SYS_MALLOC_BASE, CONFIG_SYS_MALLOC_LEN);
311 #if !defined(CONFIG_SYS_NO_FLASH)
312 /* Initialize the flash and protect u-boot by default */
313 extern flash_info_t flash_info[];
315 ulong size = flash_init();
316 print_size(size, "\n");
317 flash_protect(FLAG_PROTECT_SET, CONFIG_SYS_FLASH_BASE,
318 CONFIG_SYS_FLASH_BASE + CONFIG_SYS_MONITOR_LEN - 1,
320 bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
321 bd->bi_flashsize = size;
322 bd->bi_flashoffset = 0;
324 bd->bi_flashstart = 0;
325 bd->bi_flashsize = 0;
326 bd->bi_flashoffset = 0;
329 #ifdef CONFIG_CMD_NAND
331 nand_init(); /* go init the NAND */
334 /* relocate environment function pointers etc. */
337 /* Initialize stdio devices */
341 /* Initialize the console (after the relocation and devices init) */
344 #ifdef CONFIG_STATUS_LED
345 status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING);
346 status_led_set(STATUS_LED_CRASH, STATUS_LED_OFF);
349 /* Initialize from environment */
350 if ((s = getenv("loadaddr")) != NULL)
351 load_addr = simple_strtoul(s, NULL, 16);
353 #if defined(CONFIG_MISC_INIT_R)
354 /* miscellaneous platform dependent initialisations */
358 board_net_init_r(bd);
360 display_global_data();
362 #if defined(CONFIG_POST)
364 post_run(NULL, POST_RAM | post_bootmode_get(0));
367 if (bfin_os_log_check()) {
368 puts("\nLog buffer from operating system:\n");
373 /* main_loop() can return to retry autoboot, if so just run it again. */
380 #ifdef CONFIG_STATUS_LED
381 status_led_set(STATUS_LED_BOOT, STATUS_LED_OFF);
382 status_led_set(STATUS_LED_CRASH, STATUS_LED_BLINKING);
384 puts("### ERROR ### Please RESET the board ###\n");
386 /* If a JTAG emulator is hooked up, we'll automatically trigger
387 * a breakpoint in it. If one isn't, this is just a NOP.