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 #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 static int display_banner(void)
49 printf("\n\n%s\n\n", version_string);
50 printf("CPU: ADSP " MK_STR(CONFIG_BFIN_CPU) " "
51 "(Detected Rev: 0.%d) "
54 get_bfin_boot_mode(CONFIG_BFIN_BOOT_MODE));
58 static int init_baudrate(void)
61 int i = getenv_r("baudrate", baudrate, sizeof(baudrate));
62 gd->bd->bi_baudrate = gd->baudrate = (i > 0)
63 ? simple_strtoul(baudrate, NULL, 10)
68 static void display_global_data(void)
70 #ifdef CONFIG_DEBUG_EARLY_SERIAL
73 printf(" gd: %p\n", gd);
74 printf(" |-flags: %lx\n", gd->flags);
75 printf(" |-board_type: %lx\n", gd->board_type);
76 printf(" |-baudrate: %lu\n", gd->baudrate);
77 printf(" |-have_console: %lx\n", gd->have_console);
78 printf(" |-ram_size: %lx\n", gd->ram_size);
79 printf(" |-reloc_off: %lx\n", gd->reloc_off);
80 printf(" |-env_addr: %lx\n", gd->env_addr);
81 printf(" |-env_valid: %lx\n", gd->env_valid);
82 printf(" |-jt(%p): %p\n", gd->jt, *(gd->jt));
83 printf(" \\-bd: %p\n", gd->bd);
84 printf(" |-bi_baudrate: %x\n", bd->bi_baudrate);
85 printf(" |-bi_ip_addr: %lx\n", bd->bi_ip_addr);
86 printf(" |-bi_boot_params: %lx\n", bd->bi_boot_params);
87 printf(" |-bi_memstart: %lx\n", bd->bi_memstart);
88 printf(" |-bi_memsize: %lx\n", bd->bi_memsize);
89 printf(" |-bi_flashstart: %lx\n", bd->bi_flashstart);
90 printf(" |-bi_flashsize: %lx\n", bd->bi_flashsize);
91 printf(" \\-bi_flashoffset: %lx\n", bd->bi_flashoffset);
95 #define CPLB_PAGE_SIZE (4 * 1024 * 1024)
96 #define CPLB_PAGE_MASK (~(CPLB_PAGE_SIZE - 1))
97 void init_cplbtables(void)
99 volatile uint32_t *ICPLB_ADDR, *ICPLB_DATA;
100 volatile uint32_t *DCPLB_ADDR, *DCPLB_DATA;
101 uint32_t extern_memory;
104 void icplb_add(uint32_t addr, uint32_t data)
106 *(ICPLB_ADDR + i) = addr;
107 *(ICPLB_DATA + i) = data;
109 void dcplb_add(uint32_t addr, uint32_t data)
111 *(DCPLB_ADDR + i) = addr;
112 *(DCPLB_DATA + i) = data;
115 /* populate a few common entries ... we'll let
116 * the memory map and cplb exception handler do
117 * the rest of the work.
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;
125 icplb_add(0xFFA00000, L1_IMEMORY);
126 dcplb_add(0xFF800000, L1_DMEMORY);
129 icplb_add(CONFIG_SYS_MONITOR_BASE & CPLB_PAGE_MASK, SDRAM_IKERNEL);
130 dcplb_add(CONFIG_SYS_MONITOR_BASE & CPLB_PAGE_MASK, SDRAM_DKERNEL);
133 /* If the monitor crosses a 4 meg boundary, we'll need
134 * to lock two entries for it.
136 if ((CONFIG_SYS_MONITOR_BASE & CPLB_PAGE_MASK) != ((CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN) & CPLB_PAGE_MASK)) {
137 icplb_add((CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN) & CPLB_PAGE_MASK, SDRAM_IKERNEL);
138 dcplb_add((CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN) & CPLB_PAGE_MASK, SDRAM_DKERNEL);
142 icplb_add(0x20000000, SDRAM_INON_CHBL);
143 dcplb_add(0x20000000, SDRAM_EBIU);
146 /* Add entries for the rest of external RAM up to the bootrom */
149 #ifdef CONFIG_DEBUG_NULL_PTR
150 icplb_add(extern_memory, (SDRAM_IKERNEL & ~PAGE_SIZE_MASK) | PAGE_SIZE_1KB);
151 dcplb_add(extern_memory, (SDRAM_DKERNEL & ~PAGE_SIZE_MASK) | PAGE_SIZE_1KB);
153 icplb_add(extern_memory, SDRAM_IKERNEL);
154 dcplb_add(extern_memory, SDRAM_DKERNEL);
155 extern_memory += CPLB_PAGE_SIZE;
159 while (i < 16 && extern_memory < (CONFIG_SYS_MONITOR_BASE & CPLB_PAGE_MASK)) {
160 icplb_add(extern_memory, SDRAM_IGENERIC);
161 dcplb_add(extern_memory, SDRAM_DGENERIC);
162 extern_memory += CPLB_PAGE_SIZE;
173 * All attempts to come up with a "common" initialization sequence
174 * that works for all boards and architectures failed: some of the
175 * requirements are just _too_ different. To get rid of the resulting
176 * mess of board dependend #ifdef'ed code we now make the whole
177 * initialization sequence configurable to the user.
179 * The requirements for any new initalization function is simple: it
180 * receives a pointer to the "global data" structure as it's only
181 * argument, and returns an integer return code, where 0 means
182 * "continue" and != 0 means "fatal error, hang the system".
185 extern int exception_init(void);
186 extern int irq_init(void);
187 extern int timer_init(void);
189 void board_init_f(ulong bootflag)
195 #ifdef CONFIG_BOARD_EARLY_INIT_F
196 serial_early_puts("Board early init flash\n");
197 board_early_init_f();
200 serial_early_puts("Init CPLB tables\n");
203 serial_early_puts("Exceptions setup\n");
206 #ifndef CONFIG_ICACHE_OFF
207 serial_early_puts("Turn on ICACHE\n");
210 #ifndef CONFIG_DCACHE_OFF
211 serial_early_puts("Turn on DCACHE\n");
216 if (CONFIG_SYS_GBL_DATA_SIZE < sizeof(*gd))
219 serial_early_puts("Init global data\n");
220 gd = (gd_t *) (CONFIG_SYS_GBL_DATA_ADDR);
221 memset((void *)gd, 0, CONFIG_SYS_GBL_DATA_SIZE);
223 /* Board data initialization */
224 addr = (CONFIG_SYS_GBL_DATA_ADDR + sizeof(gd_t));
226 /* Align to 4 byte boundary */
230 memset((void *)bd, 0, sizeof(bd_t));
232 bd->bi_r_version = version_string;
233 bd->bi_cpu = MK_STR(CONFIG_BFIN_CPU);
234 bd->bi_board_name = BFIN_BOARD_NAME;
235 bd->bi_vco = get_vco();
236 bd->bi_cclk = get_cclk();
237 bd->bi_sclk = get_sclk();
240 serial_early_puts("IRQ init\n");
242 serial_early_puts("Environment init\n");
244 serial_early_puts("Baudrate init\n");
246 serial_early_puts("Serial init\n");
248 serial_early_puts("Console init flash\n");
250 serial_early_puts("End of early debugging\n");
256 printf("Clock: VCO: %s MHz, ", strmhz(buf, get_vco()));
257 printf("Core: %s MHz, ", strmhz(buf, get_cclk()));
258 printf("System: %s MHz\n", strmhz(buf, get_sclk()));
261 print_size(initdram(0), "\n");
262 #if defined(CONFIG_POST)
264 post_bootmode_init();
265 post_run(NULL, POST_ROM | post_bootmode_get(0));
268 board_init_r((gd_t *) gd, 0x20000010);
271 static void board_net_init_r(bd_t *bd)
273 #ifdef CONFIG_CMD_NET
277 if ((s = getenv("bootfile")) != NULL)
278 copy_filename(BootFile, s, sizeof(BootFile));
280 bd->bi_ip_addr = getenv_IPaddr("ipaddr");
283 eth_initialize(gd->bd);
285 eth_getenv_enetaddr("ethaddr", enetaddr);
286 printf("MAC: %pM\n", enetaddr);
290 void board_init_r(gd_t * id, ulong dest_addr)
292 extern void malloc_bin_reloc(void);
296 gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
299 #if defined(CONFIG_POST)
300 post_output_backlog();
304 /* initialize malloc() area */
305 mem_malloc_init(CONFIG_SYS_MALLOC_BASE, CONFIG_SYS_MALLOC_LEN);
308 #if !defined(CONFIG_SYS_NO_FLASH)
309 /* Initialize the flash and protect u-boot by default */
310 extern flash_info_t flash_info[];
312 ulong size = flash_init();
313 print_size(size, "\n");
314 flash_protect(FLAG_PROTECT_SET, CONFIG_SYS_FLASH_BASE,
315 CONFIG_SYS_FLASH_BASE + CONFIG_SYS_MONITOR_LEN - 1,
317 bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
318 bd->bi_flashsize = size;
319 bd->bi_flashoffset = 0;
321 bd->bi_flashstart = 0;
322 bd->bi_flashsize = 0;
323 bd->bi_flashoffset = 0;
326 #ifdef CONFIG_CMD_NAND
328 nand_init(); /* go init the NAND */
331 /* relocate environment function pointers etc. */
334 /* Initialize stdio devices */
338 /* Initialize the console (after the relocation and devices init) */
341 #ifdef CONFIG_STATUS_LED
342 status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING);
343 status_led_set(STATUS_LED_CRASH, STATUS_LED_OFF);
346 /* Initialize from environment */
347 if ((s = getenv("loadaddr")) != NULL)
348 load_addr = simple_strtoul(s, NULL, 16);
350 #if defined(CONFIG_MISC_INIT_R)
351 /* miscellaneous platform dependent initialisations */
355 board_net_init_r(bd);
357 display_global_data();
359 #if defined(CONFIG_POST)
361 post_run(NULL, POST_RAM | post_bootmode_get(0));
364 if (bfin_os_log_check()) {
365 puts("\nLog buffer from operating system:\n");
370 /* main_loop() can return to retry autoboot, if so just run it again. */
377 #ifdef CONFIG_STATUS_LED
378 status_led_set(STATUS_LED_BOOT, STATUS_LED_OFF);
379 status_led_set(STATUS_LED_CRASH, STATUS_LED_BLINKING);
381 puts("### ERROR ### Please RESET the board ###\n");
383 /* If a JTAG emulator is hooked up, we'll automatically trigger
384 * a breakpoint in it. If one isn't, this is just a NOP.