diff options
Diffstat (limited to 'lib_blackfin')
-rw-r--r-- | lib_blackfin/Makefile | 6 | ||||
-rw-r--r-- | lib_blackfin/bf533_string.c | 198 | ||||
-rw-r--r-- | lib_blackfin/blackfin_board.h | 64 | ||||
-rw-r--r-- | lib_blackfin/board.c | 429 | ||||
-rw-r--r-- | lib_blackfin/bootm.c | 77 | ||||
-rw-r--r-- | lib_blackfin/cache.c | 35 | ||||
-rw-r--r-- | lib_blackfin/cache.h | 35 | ||||
-rw-r--r-- | lib_blackfin/string.c | 203 |
8 files changed, 464 insertions, 583 deletions
diff --git a/lib_blackfin/Makefile b/lib_blackfin/Makefile index dfaed6d02b..36171048ac 100644 --- a/lib_blackfin/Makefile +++ b/lib_blackfin/Makefile @@ -1,7 +1,7 @@ # # U-boot Makefile # -# Copyright (c) 2005-2007 Analog Devices Inc. +# Copyright (c) 2005-2008 Analog Devices Inc. # # (C) Copyright 2000-2006 # Wolfgang Denk, DENX Software Engineering, wd@denx.de. @@ -27,6 +27,8 @@ include $(TOPDIR)/config.mk +CFLAGS += -DBFIN_BOARD_NAME='"$(BOARD)"' + LIB = $(obj)lib$(ARCH).a SOBJS-y += memcmp.o @@ -34,12 +36,12 @@ SOBJS-y += memcpy.o SOBJS-y += memmove.o SOBJS-y += memset.o -COBJS-y += bf533_string.o COBJS-y += board.o COBJS-y += bootm.o COBJS-y += cache.o COBJS-y += muldi3.o COBJS-y += post.o +COBJS-y += string.o COBJS-y += tests.o SRCS := $(SOBJS-y:.o=.S) $(COBJS-y:.o=.c) diff --git a/lib_blackfin/bf533_string.c b/lib_blackfin/bf533_string.c deleted file mode 100644 index 9ceeeef80c..0000000000 --- a/lib_blackfin/bf533_string.c +++ /dev/null @@ -1,198 +0,0 @@ -/* - * U-boot - bf533_string.c Contains library routines. - * - * Copyright (c) 2005-2007 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., 51 Franklin St, Fifth Floor, Boston, - * MA 02110-1301 USA - */ - -#include <common.h> -#include <config.h> -#include <asm/blackfin.h> -#include <asm/io.h> -#include "cache.h" -#include <asm/mach-common/bits/dma.h> - -char *strcpy(char *dest, const char *src) -{ - char *xdest = dest; - char temp = 0; - - __asm__ __volatile__ - ("1:\t%2 = B [%1++] (Z);\n\t" - "B [%0++] = %2;\n\t" - "CC = %2;\n\t" - "if cc jump 1b (bp);\n":"=a"(dest), "=a"(src), "=d"(temp) - :"0"(dest), "1"(src), "2"(temp):"memory"); - - return xdest; -} - -char *strncpy(char *dest, const char *src, size_t n) -{ - char *xdest = dest; - char temp = 0; - - if (n == 0) - return xdest; - - __asm__ __volatile__ - ("1:\t%3 = B [%1++] (Z);\n\t" - "B [%0++] = %3;\n\t" - "CC = %3;\n\t" - "if ! cc jump 2f;\n\t" - "%2 += -1;\n\t" - "CC = %2 == 0;\n\t" - "if ! cc jump 1b (bp);\n" - "2:\n":"=a"(dest), "=a"(src), "=da"(n), "=d"(temp) - :"0"(dest), "1"(src), "2"(n), "3"(temp) - :"memory"); - - return xdest; -} - -int strcmp(const char *cs, const char *ct) -{ - char __res1, __res2; - - __asm__("1:\t%2 = B[%0++] (Z);\n\t" /* get *cs */ - "%3 = B[%1++] (Z);\n\t" /* get *ct */ - "CC = %2 == %3;\n\t" /* compare a byte */ - "if ! cc jump 2f;\n\t" /* not equal, break out */ - "CC = %2;\n\t" /* at end of cs? */ - "if cc jump 1b (bp);\n\t" /* no, keep going */ - "jump.s 3f;\n" /* strings are equal */ - "2:\t%2 = %2 - %3;\n" /* *cs - *ct */ - "3:\n": "=a"(cs), "=a"(ct), "=d"(__res1), "=d"(__res2) - : "0"(cs), "1"(ct)); - - return __res1; -} - -int strncmp(const char *cs, const char *ct, size_t count) -{ - char __res1, __res2; - - if (!count) - return 0; - - __asm__("1:\t%3 = B[%0++] (Z);\n\t" /* get *cs */ - "%4 = B[%1++] (Z);\n\t" /* get *ct */ - "CC = %3 == %4;\n\t" /* compare a byte */ - "if ! cc jump 3f;\n\t" /* not equal, break out */ - "CC = %3;\n\t" /* at end of cs? */ - "if ! cc jump 4f;\n\t" /* yes, all done */ - "%2 += -1;\n\t" /* no, adjust count */ - "CC = %2 == 0;\n\t" "if ! cc jump 1b;\n" /* more to do, keep going */ - "2:\t%3 = 0;\n\t" /* strings are equal */ - "jump.s 4f;\n" "3:\t%3 = %3 - %4;\n" /* *cs - *ct */ - "4:": "=a"(cs), "=a"(ct), "=da"(count), "=d"(__res1), - "=d"(__res2) - : "0"(cs), "1"(ct), "2"(count)); - - return __res1; -} - -#ifndef pMDMA_D0_IRQ_STATUS -# define pMDMA_D0_IRQ_STATUS pMDMA1_D0_IRQ_STATUS -# define pMDMA_D0_START_ADDR pMDMA1_D0_START_ADDR -# define pMDMA_D0_X_COUNT pMDMA1_D0_X_COUNT -# define pMDMA_D0_X_MODIFY pMDMA1_D0_X_MODIFY -# define pMDMA_D0_CONFIG pMDMA1_D0_CONFIG -# define pMDMA_S0_IRQ_STATUS pMDMA1_S0_IRQ_STATUS -# define pMDMA_S0_START_ADDR pMDMA1_S0_START_ADDR -# define pMDMA_S0_X_COUNT pMDMA1_S0_X_COUNT -# define pMDMA_S0_X_MODIFY pMDMA1_S0_X_MODIFY -# define pMDMA_S0_CONFIG pMDMA1_S0_CONFIG -#endif - -static void *dma_memcpy(void *dest, const void *src, size_t count) -{ - *pMDMA_D0_IRQ_STATUS = DMA_DONE | DMA_ERR; - - /* Copy sram functions from sdram to sram */ - /* Setup destination start address */ - *pMDMA_D0_START_ADDR = (volatile void **)dest; - /* Setup destination xcount */ - *pMDMA_D0_X_COUNT = count; - /* Setup destination xmodify */ - *pMDMA_D0_X_MODIFY = 1; - - /* Setup Source start address */ - *pMDMA_S0_START_ADDR = (volatile void **)src; - /* Setup Source xcount */ - *pMDMA_S0_X_COUNT = count; - /* Setup Source xmodify */ - *pMDMA_S0_X_MODIFY = 1; - - /* Enable source DMA */ - *pMDMA_S0_CONFIG = (DMAEN); - SSYNC(); - - *pMDMA_D0_CONFIG = (WNR | DMAEN); - - while (*pMDMA_D0_IRQ_STATUS & DMA_RUN) { - *pMDMA_D0_IRQ_STATUS |= (DMA_DONE | DMA_ERR); - } - *pMDMA_D0_IRQ_STATUS |= (DMA_DONE | DMA_ERR); - - dest += count; - src += count; - return dest; -} - -/* - * memcpy - Copy one area of memory to another - * @dest: Where to copy to - * @src: Where to copy from - * @count: The size of the area. - * - * You should not use this function to access IO space, use memcpy_toio() - * or memcpy_fromio() instead. - */ -extern void *memcpy_ASM(void *dest, const void *src, size_t count); -void *memcpy(void *dest, const void *src, size_t count) -{ - char *tmp = (char *) dest, *s = (char *) src; - - if (dcache_status()) { - blackfin_dcache_flush_range(src, src+count); - } - /* L1_INST_SRAM can only be accessed via dma */ - if ((tmp >= (char *)L1_INST_SRAM) && (tmp < (char *)L1_INST_SRAM_END)) { - /* L1 is the destination */ - dma_memcpy(dest,src,count); - } else if ((s >= (char *)L1_INST_SRAM) && (s < (char *)L1_INST_SRAM_END)) { - /* L1 is the source */ - dma_memcpy(dest,src,count); - - if (icache_status()) { - blackfin_icache_flush_range(dest, dest+count); - } - if (dcache_status()) { - blackfin_dcache_invalidate_range(dest, dest+count); - } - } else { - memcpy_ASM(dest,src,count); - } - return dest; -} diff --git a/lib_blackfin/blackfin_board.h b/lib_blackfin/blackfin_board.h deleted file mode 100644 index 1353421c33..0000000000 --- a/lib_blackfin/blackfin_board.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * U-boot - blackfin_board.h - * - * Copyright (c) 2005-2007 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., 51 Franklin St, Fifth Floor, Boston, - * MA 02110-1301 USA - */ - -#ifndef __BLACKFIN_BOARD_H__ -#define __BLACKFIN_BOARD_H__ - -#include <version.h> - -extern void timer_init(void); -extern void init_IRQ(void); -extern void rtc_init(void); - -extern ulong uboot_end_data; -extern ulong uboot_end; - -ulong monitor_flash_len; - - -#define VERSION_STRING_SIZE 150 /* including 40 bytes buffer to change any string */ -#define VERSION_STRING_FORMAT "%s (%s - %s)\n" -#define VERSION_STRING U_BOOT_VERSION, __DATE__, __TIME__ - -char version_string[VERSION_STRING_SIZE]; - -int *g_addr; -static ulong mem_malloc_start; -static ulong mem_malloc_end; -static ulong mem_malloc_brk; -extern char _sram_in_sdram_start[]; -extern char _sram_inst_size[]; -#ifdef DEBUG -static void display_global_data(void); -#endif - -/* definitions used to check the SMC card availability */ -#define SMC_BASE_ADDRESS CONFIG_SMC91111_BASE -#define UPPER_BYTE_MASK 0xFF00 -#define SMC_IDENT 0x3300 - -#endif diff --git a/lib_blackfin/board.c b/lib_blackfin/board.c index 2a5a2fce45..43d8be8e21 100644 --- a/lib_blackfin/board.c +++ b/lib_blackfin/board.c @@ -1,54 +1,50 @@ /* * U-boot - board.c First C file to be called contains init routines * - * Copyright (c) 2005-2007 Analog Devices Inc. + * 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., 51 Franklin St, Fifth Floor, Boston, - * MA 02110-1301 USA + * Licensed under the GPL-2 or later. */ #include <common.h> #include <command.h> -#include <malloc.h> #include <devices.h> -#include <version.h> -#include <net.h> #include <environment.h> #include <i2c.h> -#include "blackfin_board.h" +#include <malloc.h> +#include <net.h> +#include <version.h> + #include <asm/cplb.h> -#include "../drivers/net/smc91111.h" +#include <asm/mach-common/bits/mpu.h> -#if defined(CONFIG_BF537)&&defined(CONFIG_POST) +#ifdef CONFIG_CMD_NAND +#include <nand.h> /* cannot even include nand.h if it isnt configured */ +#endif + +#if defined(CONFIG_POST) #include <post.h> int post_flag; #endif DECLARE_GLOBAL_DATA_PTR; -#ifndef CFG_NO_FLASH -extern flash_info_t flash_info[]; +const char version_string[] = U_BOOT_VERSION " (" __DATE__ " - " __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 inline u_long get_vco(void) +/* Get the input voltage */ +static u_long get_vco(void) { u_long msel; u_long vco; @@ -63,7 +59,7 @@ static inline u_long get_vco(void) return vco; } -/*Get the Core clock*/ +/* Get the Core clock */ u_long get_cclk(void) { u_long csel, ssel; @@ -91,154 +87,152 @@ u_long get_sclk(void) return get_vco() / ssel; } +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 *)CFG_MALLOC_BASE; + mem_malloc_end = (void *)(CFG_MALLOC_BASE + CFG_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); + printf("\n\n%s\n\n", version_string); printf("CPU: ADSP " MK_STR(CONFIG_BFIN_CPU) " (Detected Rev: 0.%d)\n", bfin_revid()); - return (0); -} - -static void display_flash_config(ulong size) -{ - puts("FLASH: "); - print_size(size, "\n"); - return; + return 0; } static int init_baudrate(void) { - char 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) + ? simple_strtoul(baudrate, NULL, 10) : CONFIG_BAUDRATE; - return (0); + 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_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_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 +} -/* we cover everything with 4 meg pages, and need an extra for L1 */ -unsigned int icplb_table[page_descriptor_table_size][2]; -unsigned int dcplb_table[page_descriptor_table_size][2]; - +#define CPLB_PAGE_SIZE (4 * 1024 * 1024) +#define CPLB_PAGE_MASK (~(CPLB_PAGE_SIZE - 1)) void init_cplbtables(void) { - int i, j; - - j = 0; - icplb_table[j][0] = 0xFFA00000; - icplb_table[j][1] = L1_IMEMORY; - j++; - - for (i = 0; i < CONFIG_MEM_SIZE / 4; i++) { - icplb_table[j][0] = (i * 4 * 1024 * 1024); - if (i * 4 * 1024 * 1024 <= CFG_MONITOR_BASE - && (i + 1) * 4 * 1024 * 1024 >= CFG_MONITOR_BASE) { - icplb_table[j][1] = SDRAM_IKERNEL; - } else { - icplb_table[j][1] = SDRAM_IGENERIC; - } - j++; + 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; } -#if defined(CONFIG_BF561) - /* MAC space */ - icplb_table[j][0] = 0x2C000000; - icplb_table[j][1] = SDRAM_INON_CHBL; - j++; - /* Async Memory space */ - for (i = 0; i < 3; i++) { - icplb_table[j][0] = 0x20000000 + i * 4 * 1024 * 1024; - icplb_table[j][1] = SDRAM_INON_CHBL; - j++; - } -#else - icplb_table[j][0] = 0x20000000; - icplb_table[j][1] = SDRAM_INON_CHBL; -#endif - j = 0; - dcplb_table[j][0] = 0xFF800000; - dcplb_table[j][1] = L1_DMEMORY; - j++; - - for (i = 0; i < CONFIG_MEM_SIZE / 4; i++) { - dcplb_table[j][0] = (i * 4 * 1024 * 1024); - if (i * 4 * 1024 * 1024 <= CFG_MONITOR_BASE - && (i + 1) * 4 * 1024 * 1024 >= CFG_MONITOR_BASE) { - dcplb_table[j][1] = SDRAM_DKERNEL; - } else { - dcplb_table[j][1] = SDRAM_DGENERIC; - } - j++; + void dcplb_add(uint32_t addr, uint32_t data) + { + *(DCPLB_ADDR + i) = addr; + *(DCPLB_DATA + i) = data; } -#if defined(CONFIG_BF561) - /* MAC space */ - dcplb_table[j][0] = 0x2C000000; - dcplb_table[j][1] = SDRAM_EBIU; - j++; - - /* Flash space */ - for (i = 0; i < 3; i++) { - dcplb_table[j][0] = 0x20000000 + i * 4 * 1024 * 1024; - dcplb_table[j][1] = SDRAM_EBIU; - j++; + /* 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(CFG_MONITOR_BASE & CPLB_PAGE_MASK, SDRAM_IKERNEL); + dcplb_add(CFG_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 ((CFG_MONITOR_BASE & CPLB_PAGE_MASK) != ((CFG_MONITOR_BASE + CFG_MONITOR_LEN) & CPLB_PAGE_MASK)) { + icplb_add((CFG_MONITOR_BASE + CFG_MONITOR_LEN) & CPLB_PAGE_MASK, SDRAM_IKERNEL); + dcplb_add((CFG_MONITOR_BASE + CFG_MONITOR_LEN) & CPLB_PAGE_MASK, SDRAM_DKERNEL); + ++i; } -#else - dcplb_table[j][0] = 0x20000000; - dcplb_table[j][1] = SDRAM_EBIU; + + 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 < (CFG_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; + } } /* @@ -254,14 +248,37 @@ void init_cplbtables(void) * "continue" and != 0 means "fatal error, hang the system". */ +extern int exception_init(void); +extern int irq_init(void); +extern int rtc_init(void); +extern int timer_init(void); + void board_init_f(ulong bootflag) { ulong addr; bd_t *bd; - int i; +#ifdef CONFIG_BOARD_EARLY_INIT_F + serial_early_puts("Board early init flash\n"); + board_early_init_f(); +#endif + + 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 + + serial_early_puts("Init global data\n"); gd = (gd_t *) (CFG_GBL_DATA_ADDR); memset((void *)gd, 0, sizeof(gd_t)); @@ -274,41 +291,44 @@ void board_init_f(ulong bootflag) gd->bd = bd; 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(); -#ifdef CONFIG_ICACHE_ON - icache_enable(); -#endif -#ifdef CONFIG_DCACHE_ON - dcache_enable(); -#endif - display_banner(); /* say that we are here */ - - for (i = 0; i < page_descriptor_table_size; i++) { - debug - ("data (%02i)= 0x%08x : 0x%08x intr = 0x%08x : 0x%08x\n", - i, dcplb_table[i][0], dcplb_table[i][1], icplb_table[i][0], - icplb_table[i][1]); - } + serial_early_puts("End of early debugging\n"); + display_banner(); checkboard(); -#if defined(CONFIG_RTC_BF533) && defined(CONFIG_CMD_DATE) +#if defined(CONFIG_RTC_BFIN) && defined(CONFIG_CMD_DATE) rtc_init(); #endif timer_init(); + printf("Clock: VCO: %lu MHz, Core: %lu MHz, System: %lu MHz\n", get_vco() / 1000000, get_cclk() / 1000000, get_sclk() / 1000000); - printf("SDRAM: "); + + printf("RAM: "); print_size(initdram(0), "\n"); -#if defined(CONFIG_BF537)&&defined(CONFIG_POST) +#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); } @@ -324,25 +344,25 @@ static int init_func_i2c(void) 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 defined(CONFIG_BF537) && defined(CONFIG_POST) +#if defined(CONFIG_POST) post_output_backlog(); post_reloc(); #endif -#if (CONFIG_STAMP || CONFIG_BF537 || CONFIG_EZKIT561) && !defined(CFG_NO_FLASH) +#if !defined(CFG_NO_FLASH) /* There are some other pointer constants we must deal with */ /* configure available FLASH banks */ - size = flash_init(); - display_flash_config(size); + extern flash_info_t flash_info[]; + ulong size = flash_init(); + puts("Flash: "); + print_size(size, "\n"); flash_protect(FLAG_PROTECT_SET, CFG_FLASH_BASE, CFG_FLASH_BASE + 0x1ffff, &flash_info[0]); bd->bi_flashstart = CFG_FLASH_BASE; @@ -367,16 +387,34 @@ void board_init_r(gd_t * id, ulong dest_addr) /* relocate environment function pointers etc. */ env_relocate(); +#ifdef CONFIG_CMD_NET /* 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) + if (s == NULL) { +# ifndef CONFIG_ETHADDR +# if 0 + if (!board_get_enetaddr(bd->bi_enetaddr)) { + char nid[20]; + sprintf(nid, "%02X:%02X:%02X:%02X:%02X:%02X", + bd->bi_enetaddr[0], bd->bi_enetaddr[1], + bd->bi_enetaddr[2], bd->bi_enetaddr[3], + bd->bi_enetaddr[4], bd->bi_enetaddr[5]); + setenv("ethaddr", nid); + } +# endif +# endif + } else { + int i; + char *e; + for (i = 0; i < 6; ++i) { + bd->bi_enetaddr[i] = simple_strtoul(s, &e, 16); s = (*e) ? e + 1 : e; + } } /* IP Address */ bd->bi_ip_addr = getenv_IPaddr("ipaddr"); +#endif /* Initialize devices */ devices_init(); @@ -386,16 +424,14 @@ void board_init_r(gd_t * id, ulong dest_addr) console_init_r(); /* Initialize from environment */ - if ((s = getenv("loadaddr")) != NULL) { + if ((s = getenv("loadaddr")) != NULL) load_addr = simple_strtoul(s, NULL, 16); - } -#if defined(CONFIG_CMD_NET) - if ((s = getenv("bootfile")) != NULL) { +#ifdef CONFIG_CMD_NET + if ((s = getenv("bootfile")) != NULL) copy_filename(BootFile, s, sizeof(BootFile)); - } #endif -#if defined(CONFIG_CMD_NAND) +#ifdef CONFIG_CMD_NAND puts("NAND: "); nand_init(); /* go init the NAND */ #endif @@ -406,47 +442,36 @@ void board_init_r(gd_t * id, ulong dest_addr) #endif #ifdef CONFIG_CMD_NET - printf("Net: "); - eth_initialize(bd); -#endif - -#ifdef CONFIG_DRIVER_SMC91111 -#ifdef SHARED_RESOURCES - /* Switch to Ethernet */ - swap_to(ETHERNET); + printf("Net: "); + eth_initialize(gd->bd); + if (getenv("ethaddr")) + printf("MAC: %02X:%02X:%02X:%02X:%02X:%02X\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]); #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); - } -#ifdef SHARED_RESOURCES - swap_to(FLASH); -#endif -#endif #if defined(CONFIG_SOFT_I2C) || defined(CONFIG_HARD_I2C) init_func_i2c(); #endif -#ifdef DEBUG display_global_data(); -#endif -#if defined(CONFIG_BF537) && defined(CONFIG_POST) +#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 (;;) { + for (;;) main_loop(); - } } void hang(void) { 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;"); } diff --git a/lib_blackfin/bootm.c b/lib_blackfin/bootm.c index 1ea80f4e36..bea11ed6dd 100644 --- a/lib_blackfin/bootm.c +++ b/lib_blackfin/bootm.c @@ -1,52 +1,39 @@ /* - * U-boot - bf533_linux.c + * U-boot - bootm.c - misc boot helper functions * - * Copyright (c) 2005-2007 Analog Devices Inc. + * 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., 51 Franklin St, Fifth Floor, Boston, - * MA 02110-1301 USA + * Licensed under the GPL-2 or later. */ -/* Dummy functions, currently not in Use */ - #include <common.h> #include <command.h> #include <image.h> -#include <zlib.h> -#include <asm/byteorder.h> +#include <asm/blackfin.h> -#define LINUX_MAX_ENVS 256 -#define LINUX_MAX_ARGS 256 - -#define CMD_LINE_ADDR 0xFF900000 /* L1 scratchpad */ +extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); #ifdef SHARED_RESOURCES extern void swap_to(int device_id); #endif -extern void flush_instruction_cache(void); -extern void flush_data_cache(void); -static char *make_command_line(void); +static char *make_command_line(void) +{ + char *dest = (char *)CMD_LINE_ADDR; + char *bootargs = getenv("bootargs"); + + if (bootargs == NULL) + return NULL; + + strncpy(dest, bootargs, 0x1000); + dest[0xfff] = 0; + return dest; +} -void do_bootm_linux(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[], +void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], bootm_headers_t *images) { int (*appl) (char *cmdline); @@ -54,7 +41,7 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[], ulong ep = 0; if (!images->autostart) - return ; + return; #ifdef SHARED_RESOURCES swap_to(FLASH); @@ -80,33 +67,13 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[], printf("Starting Kernel at = %x\n", appl); cmdline = make_command_line(); - if (icache_status()) { - flush_instruction_cache(); - icache_disable(); - } - if (dcache_status()) { - flush_data_cache(); - dcache_disable(); - } + icache_disable(); + dcache_disable(); (*appl) (cmdline); /* does not return */ return; -error: + error: if (images->autostart) do_reset (cmdtp, flag, argc, argv); - return; -} - -char *make_command_line(void) -{ - char *dest = (char *)CMD_LINE_ADDR; - char *bootargs; - - if ((bootargs = getenv("bootargs")) == NULL) - return NULL; - - strncpy(dest, bootargs, 0x1000); - dest[0xfff] = 0; - return dest; } diff --git a/lib_blackfin/cache.c b/lib_blackfin/cache.c index 6fc4983772..c2f6e2848e 100644 --- a/lib_blackfin/cache.c +++ b/lib_blackfin/cache.c @@ -1,45 +1,26 @@ /* * U-boot - cache.c * - * Copyright (c) 2005-2007 Analog Devices Inc. + * 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., 51 Franklin St, Fifth Floor, Boston, - * MA 02110-1301 USA + * Licensed under the GPL-2 or later. */ -/* for now: just dummy functions to satisfy the linker */ -#include <config.h> #include <common.h> #include <asm/blackfin.h> -#include "cache.h" -void flush_cache(unsigned long dummy1, unsigned long dummy2) +void flush_cache(unsigned long addr, unsigned long size) { - if (dummy1 >= 0xE0000000) + /* no need to flush stuff in on chip memory (L1/L2/etc...) */ + if (addr >= 0xE0000000) return; if (icache_status()) - blackfin_icache_flush_range((void*)dummy1, (void*)(dummy1 + dummy2)); - if (dcache_status()) - blackfin_dcache_flush_range((void*)dummy1, (void*)(dummy1 + dummy2)); + blackfin_icache_flush_range((void *)addr, (void *)(addr + size)); - return; + if (dcache_status()) + blackfin_dcache_flush_range((void *)addr, (void *)(addr + size)); } diff --git a/lib_blackfin/cache.h b/lib_blackfin/cache.h deleted file mode 100644 index 3ea6809d31..0000000000 --- a/lib_blackfin/cache.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * U-boot - prototypes for cache handling functions. - * - * Copyright (c) 2005-2007 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, see the file COPYING, or write - * to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef _LIB_BLACKFIN_CACHE_H_ -#define _LIB_BLACKFIN_CACHE_H_ - -extern void blackfin_icache_flush_range(const void *, const void *); -extern void blackfin_dcache_flush_range(const void *, const void *); -extern void blackfin_dcache_invalidate_range(const void *, const void *); - -#endif diff --git a/lib_blackfin/string.c b/lib_blackfin/string.c new file mode 100644 index 0000000000..6887c93dec --- /dev/null +++ b/lib_blackfin/string.c @@ -0,0 +1,203 @@ +/* + * U-boot - string.c Contains library routines. + * + * Copyright (c) 2005-2007 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., 51 Franklin St, Fifth Floor, Boston, + * MA 02110-1301 USA + */ + +#include <common.h> +#include <config.h> +#include <asm/blackfin.h> +#include <asm/io.h> +#include <asm/mach-common/bits/dma.h> + +char *strcpy(char *dest, const char *src) +{ + char *xdest = dest; + char temp = 0; + + __asm__ __volatile__ ( + "1:\t%2 = B [%1++] (Z);\n\t" + "B [%0++] = %2;\n\t" + "CC = %2;\n\t" + "if cc jump 1b (bp);\n" + : "=a"(dest), "=a"(src), "=d"(temp) + : "0"(dest), "1"(src), "2"(temp) + : "memory"); + + return xdest; +} + +char *strncpy(char *dest, const char *src, size_t n) +{ + char *xdest = dest; + char temp = 0; + + if (n == 0) + return xdest; + + __asm__ __volatile__ ( + "1:\t%3 = B [%1++] (Z);\n\t" + "B [%0++] = %3;\n\t" + "CC = %3;\n\t" + "if ! cc jump 2f;\n\t" + "%2 += -1;\n\t" + "CC = %2 == 0;\n\t" + "if ! cc jump 1b (bp);\n" + "2:\n" + : "=a"(dest), "=a"(src), "=da"(n), "=d"(temp) + : "0"(dest), "1"(src), "2"(n), "3"(temp) + : "memory"); + + return xdest; +} + +int strcmp(const char *cs, const char *ct) +{ + char __res1, __res2; + + __asm__ ( + "1:\t%2 = B[%0++] (Z);\n\t" /* get *cs */ + "%3 = B[%1++] (Z);\n\t" /* get *ct */ + "CC = %2 == %3;\n\t" /* compare a byte */ + "if ! cc jump 2f;\n\t" /* not equal, break out */ + "CC = %2;\n\t" /* at end of cs? */ + "if cc jump 1b (bp);\n\t" /* no, keep going */ + "jump.s 3f;\n" /* strings are equal */ + "2:\t%2 = %2 - %3;\n" /* *cs - *ct */ + "3:\n" + : "=a"(cs), "=a"(ct), "=d"(__res1), "=d"(__res2) + : "0"(cs), "1"(ct)); + + return __res1; +} + +int strncmp(const char *cs, const char *ct, size_t count) +{ + char __res1, __res2; + + if (!count) + return 0; + + __asm__( + "1:\t%3 = B[%0++] (Z);\n\t" /* get *cs */ + "%4 = B[%1++] (Z);\n\t" /* get *ct */ + "CC = %3 == %4;\n\t" /* compare a byte */ + "if ! cc jump 3f;\n\t" /* not equal, break out */ + "CC = %3;\n\t" /* at end of cs? */ + "if ! cc jump 4f;\n\t" /* yes, all done */ + "%2 += -1;\n\t" /* no, adjust count */ + "CC = %2 == 0;\n\t" "if ! cc jump 1b;\n" /* more to do, keep going */ + "2:\t%3 = 0;\n\t" /* strings are equal */ + "jump.s 4f;\n" "3:\t%3 = %3 - %4;\n" /* *cs - *ct */ + "4:" + : "=a"(cs), "=a"(ct), "=da"(count), "=d"(__res1), "=d"(__res2) + : "0"(cs), "1"(ct), "2"(count)); + + return __res1; +} + +#ifdef bfin_write_MDMA1_D0_IRQ_STATUS +# define bfin_write_MDMA_D0_IRQ_STATUS bfin_write_MDMA1_D0_IRQ_STATUS +# define bfin_write_MDMA_D0_START_ADDR bfin_write_MDMA1_D0_START_ADDR +# define bfin_write_MDMA_D0_X_COUNT bfin_write_MDMA1_D0_X_COUNT +# define bfin_write_MDMA_D0_X_MODIFY bfin_write_MDMA1_D0_X_MODIFY +# define bfin_write_MDMA_D0_CONFIG bfin_write_MDMA1_D0_CONFIG +# define bfin_write_MDMA_S0_START_ADDR bfin_write_MDMA1_S0_START_ADDR +# define bfin_write_MDMA_S0_X_COUNT bfin_write_MDMA1_S0_X_COUNT +# define bfin_write_MDMA_S0_X_MODIFY bfin_write_MDMA1_S0_X_MODIFY +# define bfin_write_MDMA_S0_CONFIG bfin_write_MDMA1_S0_CONFIG +# define bfin_write_MDMA_D0_IRQ_STATUS bfin_write_MDMA1_D0_IRQ_STATUS +# define bfin_read_MDMA_D0_IRQ_STATUS bfin_read_MDMA1_D0_IRQ_STATUS +#endif +static void *dma_memcpy(void *dst, const void *src, size_t count) +{ + if (dcache_status()) + blackfin_dcache_flush_range(src, src + count); + + bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR); + + /* Copy sram functions from sdram to sram */ + /* Setup destination start address */ + bfin_write_MDMA_D0_START_ADDR(dst); + /* Setup destination xcount */ + bfin_write_MDMA_D0_X_COUNT(count); + /* Setup destination xmodify */ + bfin_write_MDMA_D0_X_MODIFY(1); + + /* Setup Source start address */ + bfin_write_MDMA_S0_START_ADDR(src); + /* Setup Source xcount */ + bfin_write_MDMA_S0_X_COUNT(count); + /* Setup Source xmodify */ + bfin_write_MDMA_S0_X_MODIFY(1); + + /* Enable source DMA */ + bfin_write_MDMA_S0_CONFIG(DMAEN); + SSYNC(); + + bfin_write_MDMA_D0_CONFIG(WNR | DMAEN); + + while (bfin_read_MDMA_D0_IRQ_STATUS() & DMA_RUN) + bfin_write_MDMA_D0_IRQ_STATUS(bfin_read_MDMA_D0_IRQ_STATUS() | DMA_DONE | DMA_ERR); + bfin_write_MDMA_D0_IRQ_STATUS(bfin_read_MDMA_D0_IRQ_STATUS() | DMA_DONE | DMA_ERR); + + if (icache_status()) + blackfin_icache_flush_range(dst, dst + count); + + if (dcache_status()) + blackfin_dcache_invalidate_range(dst, dst + count); + + return dst; +} + +/* + * memcpy - Copy one area of memory to another + * @dest: Where to copy to + * @src: Where to copy from + * @count: The size of the area. + * + * We need to have this wrapper in memcpy() as common code may call memcpy() + * to load up L1 regions. Consider loading an ELF which has sections with + * LMA's pointing to L1. The common code ELF loader will simply use memcpy() + * to move the ELF's sections into the right place. We need to catch that + * here and redirect to dma_memcpy(). + */ +extern void *memcpy_ASM(void *dst, const void *src, size_t count); +void *memcpy(void *dst, const void *src, size_t count) +{ + if (!count) + return dst; + + if (addr_bfin_on_chip_mem(dst)) { + /* L1 is the destination */ + return dma_memcpy(dst, src, count); + + } else if (addr_bfin_on_chip_mem(src)) { + /* L1 is the source */ + return dma_memcpy(dst, src, count); + + } else + /* No L1 is involved, so just call regular memcpy */ + return memcpy_ASM(dst, src, count); +} |