From f5b76bfb34c6b0b5e42a4247dc2df3014a70a425 Mon Sep 17 00:00:00 2001 From: charles Date: Tue, 11 Mar 2003 05:16:53 +0000 Subject: [PATCH] *** empty log message *** --- Makefile | 12 ++++++++--- direct/yaffsfs.c | 5 +++-- utils/Makefile | 12 +++++++---- utils/mkyaffs.c | 55 ++++++++++++++++++++++++++++++++++++++++-------- yaffs_fs.c | 4 ++-- yaffs_guts.c | 23 ++++++++++---------- yaffs_mtdif.c | 25 +++++++++++++++------- 7 files changed, 96 insertions(+), 40 deletions(-) diff --git a/Makefile b/Makefile index 21d4b59..8a1b6fe 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. # -# $Id: Makefile,v 1.9 2002-12-13 00:13:06 charles Exp $ +# $Id: Makefile,v 1.10 2003-03-11 05:16:53 charles Exp $ # ## Change or override KERNELDIR to your kernel @@ -20,6 +20,12 @@ KERNELDIR = /usr/src/kernel-headers-2.4.18 +## Change if you are using a cross-compiler +MAKETOOLS = + +CC=$(MAKETOOLS)gcc +LD=$(MAKETOOLS)ld + # Configurations... # Comment out the stuff you don't want. # @@ -104,10 +110,10 @@ OBJS = yaffs_fs.o yaffs_guts.o yaffs_ramem.o yaffs_mtdif.o nand_ecc.o all: yaffs.o $(OBJS): %.o: %.c Makefile - gcc -c $(CFLAGS) $< -o $@ + $(CC) -c $(CFLAGS) $< -o $@ yaffs.o: $(OBJS) - ld -r $(OBJS) -o $@ + $(LD) -r $(OBJS) -o $@ clean: rm -f $(OBJS) core diff --git a/direct/yaffsfs.c b/direct/yaffsfs.c index ff7f459..f4dfdcb 100644 --- a/direct/yaffsfs.c +++ b/direct/yaffsfs.c @@ -25,7 +25,7 @@ #endif -const char *yaffsfs_c_version="$Id: yaffsfs.c,v 1.4 2003-02-24 23:49:29 charles Exp $"; +const char *yaffsfs_c_version="$Id: yaffsfs.c,v 1.5 2003-03-11 05:16:53 charles Exp $"; // configurationList is the list of devices that are supported static yaffsfs_DeviceConfiguration *yaffsfs_configurationList; @@ -439,7 +439,8 @@ int yaffs_open(const char *path, int oflag, int mode) } else { - } yaffsfs_SetError(-ENOTDIR); + yaffsfs_SetError(-ENOTDIR); + } } if(obj && !openDenied) diff --git a/utils/Makefile b/utils/Makefile index f4f94c0..265bb04 100644 --- a/utils/Makefile +++ b/utils/Makefile @@ -20,6 +20,10 @@ CFLAGS = -I$(KERNELDIR)/include -I.. -O2 -Wall -DCONFIG_YAFFS_UTIL CFLAGS+= -Wshadow -Wpointer-arith -Wwrite-strings -Wstrict-prototypes -Wmissing-declarations CFLAGS+= -Wmissing-prototypes -Wredundant-decls -Wnested-externs -Winline +## Change if you are using a cross-compiler +MAKETOOLS = + +CC=$(MAKETOOLS)gcc MKYAFFSOBJS = mkyaffs.o @@ -29,16 +33,16 @@ MKYAFFSIMAGEOBJS = mkyaffsimage.o nand_ecc.o all: mkyaffs mkyaffsimage $(MKYAFFSIMAGEOBJS): %.o: %.c - gcc -c $(CFLAGS) $< -o $@ + $(CC) -c $(CFLAGS) $< -o $@ mkyaffsimage: $(MKYAFFSIMAGEOBJS) - gcc -o $@ $(MKYAFFSIMAGEOBJS) + $(CC) -o $@ $(MKYAFFSIMAGEOBJS) $(MKYAFFSOBJS): %.o: %.c - gcc -c $(CFLAGS) $< -o $@ + $(CC) -c $(CFLAGS) $< -o $@ mkyaffs: $(MKYAFFSOBJS) - gcc -o $@ $(MKYAFFSOBJS) + $(CC) -o $@ $(MKYAFFSOBJS) nand_ecc.c: ln -s ../nand_ecc.c nand_ecc.c diff --git a/utils/mkyaffs.c b/utils/mkyaffs.c index 8b7350d..a0107ba 100644 --- a/utils/mkyaffs.c +++ b/utils/mkyaffs.c @@ -34,7 +34,7 @@ #include #include -const char *mkyaffs_c_version = "$Id: mkyaffs.c,v 1.5 2002-12-13 00:13:06 charles Exp $"; +const char *mkyaffs_c_version = "$Id: mkyaffs.c,v 1.6 2003-03-11 05:16:53 charles Exp $"; // countBits is a quick way of counting the number of bits in a byte. // ie. countBits[n] holds the number of 1 bits in a byte with the value n. @@ -66,6 +66,19 @@ static const char countBits[256] = unsigned char oobbuf[16]; unsigned char imgpage[528]; +/* + * OOB layout + */ + +struct nand_oobinfo yaffs_oobinfo = { + useecc: 1, + eccpos: {8, 9, 10, 13, 14, 15} +}; + +struct nand_oobinfo yaffs_noeccinfo = { + useecc: 0, +}; + /* * Main program @@ -76,19 +89,26 @@ int main(int argc, char **argv) unsigned long offset; int fd; int img=-1; + int optcnt = 1; + int usemtdecc = 0; int imglen = 0; struct mtd_oob_buf oob = {0, 16, (unsigned char *) &oobbuf}; mtd_info_t meminfo; erase_info_t erase; + struct nand_oobinfo oobsel; + if (strcmp (argv[optcnt], "-e") == 0) { + optcnt++; + usemtdecc = 1; + } + /* Make sure a device was specified */ - if(argc < 2) { - printf("usage: %s [image name]\n", argv[0]); + if(argc < (optcnt + 2)) { + printf("usage: %s -e \n", argv[0]); exit(1); } - - if(argc > 2 && - (img = open(argv[2],O_RDONLY)) == -1) { + + if((img = open(argv[optcnt + 1],O_RDONLY)) == -1) { perror("opening image file"); exit(1); } @@ -104,7 +124,7 @@ int main(int argc, char **argv) lseek(img,0,SEEK_SET); /* Open the device */ - if((fd = open(argv[1], O_RDWR)) == -1) { + if((fd = open(argv[optcnt], O_RDWR)) == -1) { perror("opening flash"); exit(1); } @@ -116,6 +136,14 @@ int main(int argc, char **argv) exit(1); } + // set the appropriate oob layout selector + oobsel = usemtdecc ? yaffs_oobinfo : yaffs_noeccinfo; + if (ioctl (fd, MEMSETOOBSEL, &oobsel) != 0) { + perror ("MEMSETOOBSEL"); + close (fd); + exit (1); + } + /* Make sure device page sizes are valid */ if( !(meminfo.oobsize == 16 && meminfo.oobblock == 512)) { @@ -171,12 +199,21 @@ int main(int argc, char **argv) for(offset = 0; offset s_blocksize))); #ifdef CONFIG_YAFFS_DISABLE_WRITE_VERIFY - T(YAFFS_TRACE_OS,("yaffs: Write verification disabled. All guarantees null and void\n"); + T(YAFFS_TRACE_OS,("yaffs: Write verification disabled. All guarantees null and void\n")); #endif diff --git a/yaffs_guts.c b/yaffs_guts.c index 9d9dc3e..dfef9de 100644 --- a/yaffs_guts.c +++ b/yaffs_guts.c @@ -14,7 +14,7 @@ */ //yaffs_guts.c -const char *yaffs_guts_c_version="$Id: yaffs_guts.c,v 1.21 2003-02-03 18:33:28 charles Exp $"; +const char *yaffs_guts_c_version="$Id: yaffs_guts.c,v 1.22 2003-03-11 05:16:53 charles Exp $"; #include "yportenv.h" @@ -216,10 +216,6 @@ int yaffs_ReadChunkFromNAND(struct yaffs_DeviceStruct *dev, int retVal; yaffs_Spare localSpare; - __u8 calcEcc[3]; - int eccResult1,eccResult2; - struct yaffs_NANDSpare nspare; - dev->nPageReads++; @@ -240,6 +236,9 @@ int yaffs_ReadChunkFromNAND(struct yaffs_DeviceStruct *dev, { // Do ECC correction //Todo handle any errors + int eccResult1,eccResult2; + __u8 calcEcc[3]; + nand_calculate_ecc(data,calcEcc); eccResult1 = nand_correct_data (data,spare->ecc1, calcEcc); nand_calculate_ecc(&data[256],calcEcc); @@ -276,6 +275,8 @@ int yaffs_ReadChunkFromNAND(struct yaffs_DeviceStruct *dev, } else { + // Must allocate enough memory for spare+2*sizeof(int) for ecc results from device. + struct yaffs_NANDSpare nspare; retVal = dev->readChunkFromNAND(dev,chunkInNAND,data,(yaffs_Spare*)&nspare); memcpy (spare, &nspare, sizeof(yaffs_Spare)); if(data && doErrorCorrection) @@ -298,7 +299,7 @@ int yaffs_ReadChunkFromNAND(struct yaffs_DeviceStruct *dev, T(YAFFS_TRACE_ERROR,(TSTR("**>>ecc error unfixed on chunk %d:1" TENDSTR),chunkInNAND)); } - if(nspare.eccres2 || nspare.eccres2) + if(nspare.eccres1 || nspare.eccres2) { // Hoosterman, we had a data problem on this page yaffs_HandleReadDataError(dev,chunkInNAND); @@ -316,12 +317,10 @@ static int yaffs_CheckChunkErased(struct yaffs_DeviceStruct *dev,int chunkInNAND static int init = 0; static __u8 cmpbuf[YAFFS_BYTES_PER_CHUNK]; static __u8 data[YAFFS_BYTES_PER_CHUNK]; - static __u8 spare[16]; - - - dev->readChunkFromNAND(dev,chunkInNAND,data,(yaffs_Spare *)spare); - - + // Might as well always allocate the larger size for dev->useNANDECC == true; + static __u8 spare[sizeof(struct yaffs_NANDSpare)]; + + dev->readChunkFromNAND(dev,chunkInNAND,data,(yaffs_Spare *)spare); if(!init) { diff --git a/yaffs_mtdif.c b/yaffs_mtdif.c index 7ada87a..a7b6aae 100644 --- a/yaffs_mtdif.c +++ b/yaffs_mtdif.c @@ -13,7 +13,7 @@ * */ -const char *yaffs_mtdif_c_version = "$Id: yaffs_mtdif.c,v 1.7 2003-01-17 04:19:08 charles Exp $"; +const char *yaffs_mtdif_c_version = "$Id: yaffs_mtdif.c,v 1.8 2003-03-11 05:16:53 charles Exp $"; #ifdef CONFIG_YAFFS_MTD_ENABLED @@ -29,6 +29,16 @@ const char *yaffs_mtdif_c_version = "$Id: yaffs_mtdif.c,v 1.7 2003-01-17 04:19:0 #include "linux/mtd/nand.h" #endif +struct nand_oobinfo yaffs_oobinfo = { + useecc: 1, + eccpos: {8, 9, 10, 13, 14, 15} +}; + +struct nand_oobinfo yaffs_noeccinfo = { + useecc: 0, +}; + + int nandmtd_WriteChunkToNAND(yaffs_Device *dev,int chunkInNAND,const __u8 *data, yaffs_Spare *spare) { struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice); @@ -43,9 +53,9 @@ int nandmtd_WriteChunkToNAND(yaffs_Device *dev,int chunkInNAND,const __u8 *data, if(data && spare) { if(dev->useNANDECC) - mtd->write_ecc(mtd,addr,dev->nBytesPerChunk,&dummy,data,spareAsBytes,NAND_YAFFS_OOB); + mtd->write_ecc(mtd,addr,dev->nBytesPerChunk,&dummy,data,spareAsBytes,&yaffs_oobinfo); else - mtd->write_ecc(mtd,addr,dev->nBytesPerChunk,&dummy,data,spareAsBytes,NAND_NONE_OOB); + mtd->write_ecc(mtd,addr,dev->nBytesPerChunk,&dummy,data,spareAsBytes,&yaffs_noeccinfo); } else { @@ -78,14 +88,13 @@ int nandmtd_ReadChunkFromNAND(yaffs_Device *dev,int chunkInNAND, __u8 *data, yaf if(data && spare) { if(dev->useNANDECC) - { - u8 tmpSpare[ YAFFS_BYTES_PER_SPARE + (2*sizeof(int)) ]; - retval = mtd->read_ecc(mtd,addr,dev->nBytesPerChunk,&dummy,data,tmpSpare,NAND_YAFFS_OOB); - memcpy(spareAsBytes, tmpSpare, YAFFS_BYTES_PER_SPARE); + { // Careful, this call adds 2 ints to the end of the spare data. Calling function should + // allocate enough memory for spare, i.e. [YAFFS_BYTES_PER_SPARE+2*sizeof(int)]. + retval = mtd->read_ecc(mtd,addr,dev->nBytesPerChunk,&dummy,data,spareAsBytes,&yaffs_oobinfo); } else { - retval = mtd->read_ecc(mtd,addr,dev->nBytesPerChunk,&dummy,data,spareAsBytes,NAND_NONE_OOB); + retval = mtd->read_ecc(mtd,addr,dev->nBytesPerChunk,&dummy,data,spareAsBytes,&yaffs_noeccinfo); } } else -- 2.30.2