From 5779d8d985d95104ad74332f5fa3cb6c67645509 Mon Sep 17 00:00:00 2001 From: wdenk Date: Sat, 6 Dec 2003 23:55:10 +0000 Subject: * Patch by Nicolas Lacressonnière, 12 Nov 2003: update for for Atmel AT91RM9200DK development kit: - support for environment variables in DataFlash - Atmel DataFlash AT45DB1282 support * Patch by Jeff Carr, 11 Nov 2003: add support for new version of 8270 processors * Patches by George G. Davis, 05 Nov 2003: - only pass the ARM linux initrd tag to the kernel when an initrd is actually present - update omap1510inn configuration file --- common/Makefile | 2 +- common/cmd_flash.c | 22 ++++++++++- common/cmd_mem.c | 19 +++++++-- common/cmd_nvedit.c | 8 +++- common/env_dataflash.c | 104 +++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 147 insertions(+), 8 deletions(-) create mode 100644 common/env_dataflash.c (limited to 'common') diff --git a/common/Makefile b/common/Makefile index dae5942db5e..5595c23004c 100644 --- a/common/Makefile +++ b/common/Makefile @@ -42,7 +42,7 @@ COBJS = main.o ACEX1K.o altera.o bedbug.o \ cmd_reginfo.o cmd_scsi.o cmd_spi.o cmd_usb.o cmd_vfd.o \ command.o console.o devices.o dlmalloc.o docecc.o \ environment.o env_common.o \ - env_flash.o env_eeprom.o env_nvram.o env_nowhere.o exports.o \ + env_dataflash.o env_flash.o env_eeprom.o env_nvram.o env_nowhere.o exports.o \ flash.o fpga.o \ hush.o kgdb.o lists.o lynxkdi.o miiphybb.o miiphyutil.o \ s_record.o soft_i2c.o soft_spi.o spartan2.o \ diff --git a/common/cmd_flash.c b/common/cmd_flash.c index 430a33e2257..a51b5e998cd 100644 --- a/common/cmd_flash.c +++ b/common/cmd_flash.c @@ -307,7 +307,9 @@ int do_protect (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) ulong bank, addr_first, addr_last; int i, p, n, sect_first, sect_last; int rcode = 0; - +#ifdef CONFIG_HAS_DATAFLASH + int status; +#endif if (argc < 3) { printf ("Usage:\n%s\n", cmdtp->usage); return 1; @@ -322,6 +324,24 @@ int do_protect (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) return 1; } +#ifdef CONFIG_HAS_DATAFLASH + if ((strcmp(argv[2], "all") != 0) && (strcmp(argv[2], "bank") != 0)) { + addr_first = simple_strtoul(argv[2], NULL, 16); + addr_last = simple_strtoul(argv[3], NULL, 16); + + if (addr_dataflash(addr_first) && addr_dataflash(addr_last)) { + status = dataflash_real_protect(p,addr_first,addr_last); + if (status < 0){ + printf("Bad DataFlash sector specification\n"); + return 1; + } + printf("%sProtect %d DataFlash Sectors\n", + p ? "" : "Un-", status); + return 0; + } + } +#endif + if (strcmp(argv[2], "all") == 0) { for (bank=1; bank<=CFG_MAX_FLASH_BANKS; ++bank) { info = &flash_info[bank-1]; diff --git a/common/cmd_mem.c b/common/cmd_mem.c index 39186781406..35b3901d23b 100644 --- a/common/cmd_mem.c +++ b/common/cmd_mem.c @@ -136,13 +136,19 @@ int do_mem_md ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) uint *uip = (uint *)linebuf; ushort *usp = (ushort *)linebuf; u_char *ucp = (u_char *)linebuf; - +#ifdef CONFIG_HAS_DATAFLASH + int rc; +#endif printf("%08lx:", addr); linebytes = (nbytes>DISP_LINE_LEN)?DISP_LINE_LEN:nbytes; #ifdef CONFIG_HAS_DATAFLASH - if (read_dataflash(addr, (linebytes/size)*size, linebuf) != -1){ - + if ((rc = read_dataflash(addr, (linebytes/size)*size, linebuf)) == DATAFLASH_OK){ + /* if outside dataflash */ + /*if (rc != 1) { + dataflash_perror (rc); + return (1); + }*/ for (i=0; i #endif -#if !defined(CFG_ENV_IS_IN_NVRAM) && !defined(CFG_ENV_IS_IN_EEPROM) && !defined(CFG_ENV_IS_IN_FLASH) && !defined(CFG_ENV_IS_NOWHERE) -# error Define one of CFG_ENV_IS_IN_NVRAM, CFG_ENV_IS_IN_EEPROM, CFG_ENV_IS_IN_FLASH, CFG_ENV_IS_NOWHERE +#if !defined(CFG_ENV_IS_IN_NVRAM) && \ + !defined(CFG_ENV_IS_IN_EEPROM) && \ + !defined(CFG_ENV_IS_IN_FLASH) && \ + !defined(CFG_ENV_IS_IN_DATAFLASH) && \ + !defined(CFG_ENV_IS_NOWHERE) +# error Define one of CFG_ENV_IS_IN_{NVRAM|EEPROM|FLASH|DATAFLASH|NOWHERE} #endif #define XMK_STR(x) #x diff --git a/common/env_dataflash.c b/common/env_dataflash.c new file mode 100644 index 00000000000..8bfbbc943e1 --- /dev/null +++ b/common/env_dataflash.c @@ -0,0 +1,104 @@ +/* LowLevel function for DataFlash environment support + * Author : Gilles Gastaldi (Atmel) + * + * 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 + * + */ +#include + +#if defined(CFG_ENV_IS_IN_DATAFLASH) /* Environment is in DataFlash */ + +#include +#include +#include +#include +#include + +env_t *env_ptr = NULL; + +char * env_name_spec = "dataflash"; + +extern int read_dataflash (unsigned long addr, unsigned long size, char +*result); +extern int write_dataflash (unsigned long addr_dest, unsigned long addr_src, + unsigned long size); +extern int AT91F_DataflashInit (void); +extern uchar default_environment[]; +/* extern int default_environment_size; */ + + +uchar env_get_char_spec (int index) +{ + uchar c; + read_dataflash (CFG_ENV_ADDR+index+offsetof(env_t,data),1,&c); + return (c); +} + +void env_relocate_spec (void) +{ + read_dataflash (CFG_ENV_ADDR,CFG_ENV_SIZE,(uchar *)env_ptr); +} + +int saveenv(void) +{ +/* env must be copied to do not alter env structure in memory*/ +unsigned char temp[CFG_ENV_SIZE]; +int i; + memcpy(temp, env_ptr, CFG_ENV_SIZE); + return write_dataflash (CFG_ENV_ADDR, (unsigned long)temp, CFG_ENV_SIZE); +} + +/************************************************************************ + * Initialize Environment use + * + * We are still running from ROM, so data use is limited + * Use a (moderately small) buffer on the stack + */ +int env_init(void) +{ + DECLARE_GLOBAL_DATA_PTR; + + ulong crc, len, new; + unsigned off; + uchar buf[64]; + if (gd->env_valid == 0){ + AT91F_DataflashInit(); /* prepare for DATAFLASH read/write */ + + /* read old CRC */ + read_dataflash (CFG_ENV_ADDR+offsetof(env_t,crc),sizeof(ulong),&crc); + new = 0; + len = ENV_SIZE; + off = offsetof(env_t,data); + while (len > 0) { + int n = (len > sizeof(buf)) ? sizeof(buf) : len; + read_dataflash (CFG_ENV_ADDR+off,n , buf); + new = crc32 (new, buf, n); + len -= n; + off += n; + } + if (crc == new) { + gd->env_addr = offsetof(env_t,data); + gd->env_valid = 1; + } else { + gd->env_addr = (ulong)&default_environment[0]; + gd->env_valid = 0; + } + } + + return (0); +} + +#endif /* CFG_ENV_IS_IN_DATAFLASH */ -- cgit v1.2.3