*** empty log message ***
authorcharles <charles>
Tue, 11 Mar 2003 05:16:53 +0000 (05:16 +0000)
committercharles <charles>
Tue, 11 Mar 2003 05:16:53 +0000 (05:16 +0000)
Makefile
direct/yaffsfs.c
utils/Makefile
utils/mkyaffs.c
yaffs_fs.c
yaffs_guts.c
yaffs_mtdif.c

index 21d4b59182697ed19258788e0826dd918a6dbc04..8a1b6fe26e0f3a65d1294d03ed2fb6b2b06acb1a 100644 (file)
--- 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
 
 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
index ff7f459f4d31f61cb554deba4ae2cf685a71a03b..f4dfdcb6055a305890b4a201a78dbbcb2668fb57 100644 (file)
@@ -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)
index f4f94c05f59a7965ec5a772d0cf954d6c8290447..265bb04b41eadeead33b6c89b91a106db71d779f 100644 (file)
@@ -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
index 8b7350d6bc1430dbeb19046af8d906146eda9352..a0107bad89e917f8f98c6adc6aac6036d8447096 100644 (file)
@@ -34,7 +34,7 @@
 #include <linux/config.h>
 #include <linux/mtd/mtd.h>
 
-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 <mtdname> [image name]\n", argv[0]);
+       if(argc < (optcnt + 2)) {
+               printf("usage: %s -e <mtdname> <image name>\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 <meminfo.erasesize; offset+=512)
                                {
                                        if(read(img,imgpage,528) == 528){
-                                               lseek(fd,addr+offset,SEEK_SET);
-                                               write(fd,imgpage,512);
+                                               if (usemtdecc) {
+                                                       imgpage[512+8] = 0xff;
+                                                       imgpage[512+9] = 0xff;
+                                                       imgpage[512+10] = 0xff;
+                                                       imgpage[512+13] = 0xff;
+                                                       imgpage[512+14] = 0xff;
+                                                       imgpage[512+15] = 0xff;
+                                               }
                                                oob.start = addr+offset;
                                                oob.length=16;
                                                oob.ptr=&imgpage[512];
                                                ioctl(fd,MEMWRITEOOB,&oob);
+
+                                               lseek(fd,addr+offset,SEEK_SET);
+                                               write(fd,imgpage,512);
                                        }
                                }
                        }
index 6096bbed045adb1aecf4ac8b7115132da535de46..ff7221baf2e9147dba00082e56c02abd46441f4c 100644 (file)
@@ -27,7 +27,7 @@
  */
 
 
-const char *yaffs_fs_c_version = "$Id: yaffs_fs.c,v 1.24 2003-01-31 03:30:33 charles Exp $";
+const char *yaffs_fs_c_version = "$Id: yaffs_fs.c,v 1.25 2003-03-11 05:16:53 charles Exp $";
 extern const char *yaffs_guts_c_version;
 
 
@@ -1130,7 +1130,7 @@ static struct super_block *yaffs_internal_read_super(int useRam, struct super_bl
        T(YAFFS_TRACE_OS,("yaffs_read_super: %s block size %d\n", useRam ? "RAM" : "MTD",(int)(sb->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
 
 
index 9d9dc3e8e88cd25260ee3a2dc67af72b41aac13c..dfef9def4c17a10e89afb2e304f93993baf5d068 100644 (file)
@@ -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)
        {
index 7ada87a8c37216373b01654d85d9a6e3482f6039..a7b6aaedc3379d8a26271a02ccac91da91a52c24 100644 (file)
@@ -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