X-Git-Url: https://git.kernelconcepts.de/?p=karo-tx-uboot.git;a=blobdiff_plain;f=lib_blackfin%2Fboard.c;h=b957a9d8b9a62bf8bb94b13e77207d481aed62a6;hp=d9dc2b6d0cf9a254bf422b7375cfe256c65eae2f;hb=bdf5e20a263d1a8485835c991b4f0a2ecd9fd60f;hpb=335591c27a1224466272d46549159f2ca4eac0c2 diff --git a/lib_blackfin/board.c b/lib_blackfin/board.c index d9dc2b6d0c..b957a9d8b9 100755 --- a/lib_blackfin/board.c +++ b/lib_blackfin/board.c @@ -1,125 +1,197 @@ /* * U-boot - board.c First C file to be called contains init routines * - * Copyright (c) 2005 blackfin.uclinux.org + * Copyright (c) 2005-2008 Analog Devices Inc. * * (C) Copyright 2000-2004 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. * - * See file CREDITS for list of people who contributed to this - * project. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA + * Licensed under the GPL-2 or later. */ #include #include +#include +#include #include -#include -#include #include -#include -#include "blackfin_board.h" -#include "../drivers/smc91111.h" +#include +#include +#include + +#include +#include + +#ifdef CONFIG_CMD_NAND +#include /* cannot even include nand.h if it isnt configured */ +#endif + +#if defined(CONFIG_POST) +#include +int post_flag; +#endif DECLARE_GLOBAL_DATA_PTR; -extern flash_info_t flash_info[]; +const char version_string[] = U_BOOT_VERSION " ("U_BOOT_DATE" - "U_BOOT_TIME")"; +__attribute__((always_inline)) +static inline void serial_early_puts(const char *s) +{ +#ifdef CONFIG_DEBUG_EARLY_SERIAL + serial_puts("Early: "); + serial_puts(s); +#endif +} + +static void *mem_malloc_start, *mem_malloc_end, *mem_malloc_brk; static void mem_malloc_init(void) { - mem_malloc_start = CFG_MALLOC_BASE; - mem_malloc_end = (CFG_MALLOC_BASE + CFG_MALLOC_LEN); + mem_malloc_start = (void *)CONFIG_SYS_MALLOC_BASE; + mem_malloc_end = (void *)(CONFIG_SYS_MALLOC_BASE + CONFIG_SYS_MALLOC_LEN); mem_malloc_brk = mem_malloc_start; - memset((void *) mem_malloc_start, 0, - mem_malloc_end - mem_malloc_start); + memset(mem_malloc_start, 0, mem_malloc_end - mem_malloc_start); } void *sbrk(ptrdiff_t increment) { - ulong old = mem_malloc_brk; - ulong new = old + increment; + void *old = mem_malloc_brk; + void *new = old + increment; + + if (new < mem_malloc_start || new > mem_malloc_end) + return NULL; - if ((new < mem_malloc_start) || (new > mem_malloc_end)) { - return (NULL); - } mem_malloc_brk = new; - return ((void *) old); + return old; } static int display_banner(void) { - sprintf(version_string, VERSION_STRING_FORMAT, VERSION_STRING); - printf("%s\n", version_string); - return (0); -} - -static void display_flash_config(ulong size) -{ - puts("FLASH: "); - print_size(size, "\n"); - return; + printf("\n\n%s\n\n", version_string); + printf("CPU: ADSP " MK_STR(CONFIG_BFIN_CPU) " " + "(Detected Rev: 0.%d) " + "(%s boot)\n", + bfin_revid(), + get_bfin_boot_mode(CONFIG_BFIN_BOOT_MODE)); + return 0; } static int init_baudrate(void) { - uchar tmp[64]; - int i = getenv_r("baudrate", tmp, sizeof(tmp)); + char baudrate[15]; + int i = getenv_r("baudrate", baudrate, sizeof(baudrate)); gd->bd->bi_baudrate = gd->baudrate = (i > 0) - ? (int) simple_strtoul(tmp, NULL, 10) - : CONFIG_BAUDRATE; - return (0); + ? simple_strtoul(baudrate, NULL, 10) + : CONFIG_BAUDRATE; + return 0; } -#ifdef DEBUG static void display_global_data(void) { +#ifdef CONFIG_DEBUG_EARLY_SERIAL bd_t *bd; bd = gd->bd; - printf("--flags:%x\n", gd->flags); - printf("--board_type:%x\n", gd->board_type); - printf("--baudrate:%x\n", gd->baudrate); - printf("--have_console:%x\n", gd->have_console); - printf("--ram_size:%x\n", gd->ram_size); - printf("--reloc_off:%x\n", gd->reloc_off); - printf("--env_addr:%x\n", gd->env_addr); - printf("--env_valid:%x\n", gd->env_valid); - printf("--bd:%x %x\n", gd->bd, bd); - printf("---bi_baudrate:%x\n", bd->bi_baudrate); - printf("---bi_ip_addr:%x\n", bd->bi_ip_addr); - printf("---bi_enetaddr:%x %x %x %x %x %x\n", - bd->bi_enetaddr[0], - bd->bi_enetaddr[1], - bd->bi_enetaddr[2], - bd->bi_enetaddr[3], - bd->bi_enetaddr[4], - bd->bi_enetaddr[5]); - printf("---bi_arch_number:%x\n", bd->bi_arch_number); - printf("---bi_boot_params:%x\n", bd->bi_boot_params); - printf("---bi_memstart:%x\n", bd->bi_memstart); - printf("---bi_memsize:%x\n", bd->bi_memsize); - printf("---bi_flashstart:%x\n", bd->bi_flashstart); - printf("---bi_flashsize:%x\n", bd->bi_flashsize); - printf("---bi_flashoffset:%x\n", bd->bi_flashoffset); - printf("--jt:%x *:%x\n", gd->jt, *(gd->jt)); + printf(" gd: %x\n", gd); + printf(" |-flags: %x\n", gd->flags); + printf(" |-board_type: %x\n", gd->board_type); + printf(" |-baudrate: %i\n", gd->baudrate); + printf(" |-have_console: %x\n", gd->have_console); + printf(" |-ram_size: %x\n", gd->ram_size); + printf(" |-reloc_off: %x\n", gd->reloc_off); + printf(" |-env_addr: %x\n", gd->env_addr); + printf(" |-env_valid: %x\n", gd->env_valid); + printf(" |-jt(%x): %x\n", gd->jt, *(gd->jt)); + printf(" \\-bd: %x\n", gd->bd); + printf(" |-bi_baudrate: %x\n", bd->bi_baudrate); + printf(" |-bi_ip_addr: %x\n", bd->bi_ip_addr); + printf(" |-bi_boot_params: %x\n", bd->bi_boot_params); + printf(" |-bi_memstart: %x\n", bd->bi_memstart); + printf(" |-bi_memsize: %x\n", bd->bi_memsize); + printf(" |-bi_flashstart: %x\n", bd->bi_flashstart); + printf(" |-bi_flashsize: %x\n", bd->bi_flashsize); + printf(" \\-bi_flashoffset: %x\n", bd->bi_flashoffset); +#endif } + +#define CPLB_PAGE_SIZE (4 * 1024 * 1024) +#define CPLB_PAGE_MASK (~(CPLB_PAGE_SIZE - 1)) +void init_cplbtables(void) +{ + volatile uint32_t *ICPLB_ADDR, *ICPLB_DATA; + volatile uint32_t *DCPLB_ADDR, *DCPLB_DATA; + uint32_t extern_memory; + size_t i; + + void icplb_add(uint32_t addr, uint32_t data) + { + *(ICPLB_ADDR + i) = addr; + *(ICPLB_DATA + i) = data; + } + void dcplb_add(uint32_t addr, uint32_t data) + { + *(DCPLB_ADDR + i) = addr; + *(DCPLB_DATA + i) = data; + } + + /* populate a few common entries ... we'll let + * the memory map and cplb exception handler do + * the rest of the work. + */ + i = 0; + ICPLB_ADDR = (uint32_t *)ICPLB_ADDR0; + ICPLB_DATA = (uint32_t *)ICPLB_DATA0; + DCPLB_ADDR = (uint32_t *)DCPLB_ADDR0; + DCPLB_DATA = (uint32_t *)DCPLB_DATA0; + + icplb_add(0xFFA00000, L1_IMEMORY); + dcplb_add(0xFF800000, L1_DMEMORY); + ++i; + + icplb_add(CONFIG_SYS_MONITOR_BASE & CPLB_PAGE_MASK, SDRAM_IKERNEL); + dcplb_add(CONFIG_SYS_MONITOR_BASE & CPLB_PAGE_MASK, SDRAM_DKERNEL); + ++i; + + /* If the monitor crosses a 4 meg boundary, we'll need + * to lock two entries for it. + */ + if ((CONFIG_SYS_MONITOR_BASE & CPLB_PAGE_MASK) != ((CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN) & CPLB_PAGE_MASK)) { + icplb_add((CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN) & CPLB_PAGE_MASK, SDRAM_IKERNEL); + dcplb_add((CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN) & CPLB_PAGE_MASK, SDRAM_DKERNEL); + ++i; + } + + icplb_add(0x20000000, SDRAM_INON_CHBL); + dcplb_add(0x20000000, SDRAM_EBIU); + ++i; + + /* Add entries for the rest of external RAM up to the bootrom */ + extern_memory = 0; + +#ifdef CONFIG_DEBUG_NULL_PTR + icplb_add(extern_memory, (SDRAM_IKERNEL & ~PAGE_SIZE_MASK) | PAGE_SIZE_1KB); + dcplb_add(extern_memory, (SDRAM_DKERNEL & ~PAGE_SIZE_MASK) | PAGE_SIZE_1KB); + ++i; + icplb_add(extern_memory, SDRAM_IKERNEL); + dcplb_add(extern_memory, SDRAM_DKERNEL); + extern_memory += CPLB_PAGE_SIZE; + ++i; #endif + while (i < 16 && extern_memory < (CONFIG_SYS_MONITOR_BASE & CPLB_PAGE_MASK)) { + icplb_add(extern_memory, SDRAM_IGENERIC); + dcplb_add(extern_memory, SDRAM_DGENERIC); + extern_memory += CPLB_PAGE_SIZE; + ++i; + } + while (i < 16) { + icplb_add(0, 0); + dcplb_add(0, 0); + ++i; + } +} + /* * All attempts to come up with a "common" initialization sequence * that works for all boards and architectures failed: some of the @@ -133,60 +205,139 @@ static void display_global_data(void) * "continue" and != 0 means "fatal error, hang the system". */ +extern int exception_init(void); +extern int irq_init(void); +extern int timer_init(void); + void board_init_f(ulong bootflag) { ulong addr; bd_t *bd; + char buf[32]; + +#ifdef CONFIG_BOARD_EARLY_INIT_F + serial_early_puts("Board early init flash\n"); + board_early_init_f(); +#endif - gd = (gd_t *) (CFG_GBL_DATA_ADDR); - memset((void *) gd, 0, sizeof(gd_t)); + serial_early_puts("Init CPLB tables\n"); + init_cplbtables(); + + serial_early_puts("Exceptions setup\n"); + exception_init(); + +#ifndef CONFIG_ICACHE_OFF + serial_early_puts("Turn on ICACHE\n"); + icache_enable(); +#endif +#ifndef CONFIG_DCACHE_OFF + serial_early_puts("Turn on DCACHE\n"); + dcache_enable(); +#endif + +#ifdef DEBUG + if (CONFIG_SYS_GBL_DATA_SIZE < sizeof(*gd)) + hang(); +#endif + serial_early_puts("Init global data\n"); + gd = (gd_t *) (CONFIG_SYS_GBL_DATA_ADDR); + memset((void *)gd, 0, CONFIG_SYS_GBL_DATA_SIZE); /* Board data initialization */ - addr = (CFG_GBL_DATA_ADDR + sizeof(gd_t)); + addr = (CONFIG_SYS_GBL_DATA_ADDR + sizeof(gd_t)); /* Align to 4 byte boundary */ addr &= ~(4 - 1); - bd = (bd_t*)addr; + bd = (bd_t *) addr; gd->bd = bd; - memset((void *) bd, 0, sizeof(bd_t)); + memset((void *)bd, 0, sizeof(bd_t)); + + bd->bi_r_version = version_string; + bd->bi_cpu = MK_STR(CONFIG_BFIN_CPU); + bd->bi_board_name = BFIN_BOARD_NAME; + bd->bi_vco = get_vco(); + bd->bi_cclk = get_cclk(); + bd->bi_sclk = get_sclk(); /* Initialize */ - init_IRQ(); - env_init(); /* initialize environment */ - init_baudrate(); /* initialze baudrate settings */ - serial_init(); /* serial communications setup */ + serial_early_puts("IRQ init\n"); + irq_init(); + serial_early_puts("Environment init\n"); + env_init(); + serial_early_puts("Baudrate init\n"); + init_baudrate(); + serial_early_puts("Serial init\n"); + serial_init(); + serial_early_puts("Console init flash\n"); console_init_f(); - display_banner(); /* say that we are here */ + serial_early_puts("End of early debugging\n"); + display_banner(); + checkboard(); -#if defined(CONFIG_RTC_BF533) && (CONFIG_COMMANDS & CFG_CMD_DATE) - rtc_init(); -#endif timer_init(); - printf("Clock: VCO: %lu MHz, Core: %lu MHz, System: %lu MHz\n", \ - CONFIG_VCO_HZ/1000000, CONFIG_CCLK_HZ/1000000, CONFIG_SCLK_HZ/1000000); - printf("SDRAM: "); + + printf("Clock: VCO: %s MHz, ", strmhz(buf, get_vco())); + printf("Core: %s MHz, ", strmhz(buf, get_cclk())); + printf("System: %s MHz\n", strmhz(buf, get_sclk())); + + printf("RAM: "); print_size(initdram(0), "\n"); +#if defined(CONFIG_POST) + post_init_f(); + post_bootmode_init(); + post_run(NULL, POST_ROM | post_bootmode_get(0)); +#endif + board_init_r((gd_t *) gd, 0x20000010); } +static void board_net_init_r(bd_t *bd) +{ +#ifdef CONFIG_CMD_NET + uchar enetaddr[6]; + char *s; + + if ((s = getenv("bootfile")) != NULL) + copy_filename(BootFile, s, sizeof(BootFile)); + + bd->bi_ip_addr = getenv_IPaddr("ipaddr"); + + printf("Net: "); + eth_initialize(gd->bd); + + eth_getenv_enetaddr("ethaddr", enetaddr); + printf("MAC: %pM\n", enetaddr); +#endif +} + void board_init_r(gd_t * id, ulong dest_addr) { - ulong size; extern void malloc_bin_reloc(void); - char *s, *e; + char *s; bd_t *bd; - int i; gd = id; gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */ bd = gd->bd; -#if CONFIG_STAMP - /* There are some other pointer constants we must deal with */ - /* configure available FLASH banks */ - size = flash_init(); - display_flash_config(size); - flash_protect(FLAG_PROTECT_SET, CFG_FLASH_BASE, CFG_FLASH_BASE + 0x1ffff, &flash_info[0]); - bd->bi_flashstart = CFG_FLASH_BASE; +#if defined(CONFIG_POST) + post_output_backlog(); + post_reloc(); +#endif + + /* initialize malloc() area */ + mem_malloc_init(); + malloc_bin_reloc(); + +#if !defined(CONFIG_SYS_NO_FLASH) + /* Initialize the flash and protect u-boot by default */ + extern flash_info_t flash_info[]; + puts("Flash: "); + ulong size = flash_init(); + print_size(size, "\n"); + flash_protect(FLAG_PROTECT_SET, CONFIG_SYS_FLASH_BASE, + CONFIG_SYS_FLASH_BASE + CONFIG_SYS_MONITOR_LEN - 1, + &flash_info[0]); + bd->bi_flashstart = CONFIG_SYS_FLASH_BASE; bd->bi_flashsize = size; bd->bi_flashoffset = 0; #else @@ -194,86 +345,66 @@ void board_init_r(gd_t * id, ulong dest_addr) bd->bi_flashsize = 0; bd->bi_flashoffset = 0; #endif - /* initialize malloc() area */ - mem_malloc_init(); - malloc_bin_reloc(); + +#ifdef CONFIG_CMD_NAND + puts("NAND: "); + nand_init(); /* go init the NAND */ +#endif /* relocate environment function pointers etc. */ env_relocate(); - /* board MAC address */ - s = getenv("ethaddr"); - for (i = 0; i < 6; ++i) { - bd->bi_enetaddr[i] = s ? simple_strtoul(s, &e, 16) : 0; - if (s) - s = (*e) ? e + 1 : e; - } - - /* IP Address */ - bd->bi_ip_addr = getenv_IPaddr("ipaddr"); - - /* Initialize devices */ - devices_init(); + /* Initialize stdio devices */ + stdio_init(); jumptable_init(); /* Initialize the console (after the relocation and devices init) */ console_init_r(); +#ifdef CONFIG_STATUS_LED + status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING); + status_led_set(STATUS_LED_CRASH, STATUS_LED_OFF); +#endif + /* Initialize from environment */ - if ((s = getenv("loadaddr")) != NULL) { + if ((s = getenv("loadaddr")) != NULL) load_addr = simple_strtoul(s, NULL, 16); - } -#if (CONFIG_COMMANDS & CFG_CMD_NET) - if ((s = getenv("bootfile")) != NULL) { - copy_filename(BootFile, s, sizeof(BootFile)); - } -#endif + #if defined(CONFIG_MISC_INIT_R) /* miscellaneous platform dependent initialisations */ misc_init_r(); #endif -#ifdef CONFIG_DRIVER_SMC91111 -#ifdef SHARED_RESOURCES - /* Switch to Ethernet */ - swap_to(ETHERNET); -#endif - if ( (SMC_inw(BANK_SELECT) & UPPER_BYTE_MASK) != SMC_IDENT ) { - printf("ERROR: Can't find SMC91111 at address %x\n", SMC_BASE_ADDRESS); - } else { - printf("Net: SMC91111 at 0x%08X\n", SMC_BASE_ADDRESS); - } + board_net_init_r(bd); -#ifdef SHARED_RESOURCES - swap_to(FLASH); -#endif -#endif -#ifdef CONFIG_SOFT_I2C - init_func_i2c(); -#endif + display_global_data(); -#ifdef DEBUG - display_global_data(void); +#if defined(CONFIG_POST) + if (post_flag) + post_run(NULL, POST_RAM | post_bootmode_get(0)); #endif - /* main_loop() can return to retry autoboot, if so just run it again. */ - for (;;) { - main_loop(); + if (bfin_os_log_check()) { + puts("\nLog buffer from operating system:\n"); + bfin_os_log_dump(); + puts("\n"); } -} -#ifdef CONFIG_SOFT_I2C -static int init_func_i2c (void) -{ - puts ("I2C: "); - i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE); - puts ("ready\n"); - return (0); + /* main_loop() can return to retry autoboot, if so just run it again. */ + for (;;) + main_loop(); } -#endif void hang(void) { +#ifdef CONFIG_STATUS_LED + status_led_set(STATUS_LED_BOOT, STATUS_LED_OFF); + status_led_set(STATUS_LED_CRASH, STATUS_LED_BLINKING); +#endif puts("### ERROR ### Please RESET the board ###\n"); - for (;;); + while (1) + /* If a JTAG emulator is hooked up, we'll automatically trigger + * a breakpoint in it. If one isn't, this is just a NOP. + */ + asm("emuexcpt;"); }