*** empty log message ***
authorcharles <charles>
Fri, 31 May 2002 08:59:42 +0000 (08:59 +0000)
committercharles <charles>
Fri, 31 May 2002 08:59:42 +0000 (08:59 +0000)
Documentation/yaffs_on_mtd.html
snMakefile
yaffs_fileem.c
yaffs_fs.c
yaffs_guts.c
yaffs_guts.h
yaffsdev
yaffsdev.c
yaffsdev.proj

index b994fba698f79ed4d1dac972fdb6a5ad51826621..bba25e739469b643ea5c4b24b23b25339a094a8e 100644 (file)
@@ -6,11 +6,11 @@
        <META NAME="GENERATOR" CONTENT="StarOffice/5.2 (Linux)">
        <META NAME="CREATED" CONTENT="20020517;23103700">
        <META NAME="CHANGEDBY" CONTENT=" ">
-       <META NAME="CHANGED" CONTENT="20020518;7200400">
+       <META NAME="CHANGED" CONTENT="20020531;19314400">
 </HEAD>
 <BODY>
 <H2 ALIGN=CENTER>Running up YAFFS using the MTD interface</H2>
-<P>Here are  the steps required to get YAFFS going with the
+<P>Here are the steps required to get YAFFS going with the
 NANDemulation MTD that I have written.</P>
 <P><FONT COLOR="#800000"><FONT SIZE=4 STYLE="font-size: 16pt"><I><U><B>Warning:
 This is experimental stuff that plugs into the kernel. It has only
@@ -21,10 +21,10 @@ you're working from the 2.4.18 kernel code base.</P>
 <H3>Preparing the kernel</H3>
 <P>First off, you need to patch the mtdcore services.</P>
 <OL>
-       <LI><P>Replace the devices/mtd/mtdpart.c file with the one enclosed.
-       This patches the problem where special NAND functions are not being
-       copied through the partition handler. The changes are marked with a
-       comment containing my initials <B><FONT FACE="Courier, monospace">cdhm</FONT></B>.</P>
+       <LI><P>Replace the mtd files with the latest from the mtd cvs. This
+       fixes problems where special NAND functions are not being copied
+       through the partition handler. 
+       </P>
        <LI><P>Build the kernel including the following configurations to
        support mtd.</P>
 </OL>
@@ -39,14 +39,13 @@ used only to find the device for mounting</P>
 <P STYLE="margin-left: 2cm">CONFIG_MTD_DEBUG=y</P>
 <OL>
        <P>CONFIG_MTD_DEBUG_VERBOSE=3</P>
-       <H3 ALIGN=LEFT></H3>
 </OL>
 <H3 ALIGN=LEFT>Setting up yaffs</H3>
 <OL>
        <LI><P>Run the mtd utility MAKEDEV to make the /dev/mtdxxx entries.</P>
        <LI><P>Load up the NANDemul MTD by typing<BR><FONT FACE="Courier, monospace">#/sbin/insmod
        mtdemul/nandemul.o</FONT><BR>You should now be able to see the
-       device in the mtd list by typing  <BR>#<FONT FACE="Courier, monospace">cat
+       device in the mtd list by typing <BR>#<FONT FACE="Courier, monospace">cat
        /proc/mtd</FONT><BR>If all is well, the device will now be
        accessible as <FONT FACE="Courier, monospace">/dev/mtd0</FONT> and
        <FONT FACE="Courier, monospace">/dev/mtdblock0</FONT> (or whatever).</P>
@@ -69,8 +68,18 @@ real NAND device.</FONT></P>
 NANDemul tests out the mtd interface so in theory it should work on
 real NAND too.</FONT></P>
 <P><FONT FACE="Times, serif">Note though that since YAFFS applies the
-ECC, it does not expect the NAND device to be applying ECC.  You
-probably want to configure the NAND driver with ECC disabled.</FONT></P>
+ECC and verify, it does not expect the NAND device to be applying ECC
+or verification. </FONT>
+</P>
+<P><FONT FACE="Times, serif">You probably need to configure the NAND
+with the following disabled:</FONT></P>
+<P><FONT FACE="Times, serif">CONFIG_MTD_NAND_ECC</FONT></P>
+<P><FONT FACE="Times, serif">CONFIG_MTD_NAND_VERIFY_WRITE</FONT></P>
+<P><FONT FACE="Times, serif">Nick Banes has had YAFFS working on real
+NAND, with a few issues. </FONT>
+</P>
+<P><BR><BR>
+</P>
 <P><BR><BR>
 </P>
 </BODY>
index 4557fa5768860161399cc4d6e2988e05070d404f..d7f5966a3e543810268fcad265a8961d02697785 100644 (file)
@@ -1,13 +1,13 @@
 #########################################################
 # Makefile auto generated by Cygnus Source Navigator.
-# Target: yaffsdev_RAM Date: May 03 2002 Time: 07:11:35 PM
+# Target: yaffsdev_disk Date: May 29 2002 Time: 08:12:41 PM
 #
 
 
 .SUFFIXES: .cc .class .java .cxx .C .cpp .o .c .l .y
 
 
-VPATH = /opt/aleph1/yaffs/.
+VPATH = /opt/yaffs/.
 
 
 YACC = bison
@@ -18,7 +18,7 @@ CPP = g++
 YACC_FLAGS =      
 LEX_FLAGS =      
 JAVA_FLAGS =      
-CC_FLAGS =  -g  -Wall  
+CC_FLAGS =  -g  -Wall  -DYAFFS_PARANOID -DYAFFS_FILEEM
 CPP_FLAGS =      
 YACC_INCLUDES = 
 LEX_INCLUDES = 
@@ -30,16 +30,16 @@ LEX_DEFINES =
 JAVA_DEFINES = 
 CC_DEFINES = 
 CPP_DEFINES = 
-yaffsdev_RAM_LIBS = 
+yaffsdev_disk_LIBS = 
 LINKER = gcc
 LINKER_FLAGS = 
 LINKER_ENTRY = 
-yaffsdev_RAM_OBJECTS = yaffs_guts.o yaffs_ramem.o yaffsdev.o
+yaffsdev_disk_OBJECTS = nand_ecc.o yaffs_fileem.o yaffs_guts.o yaffsdev.o
 
 all: yaffsdev
 
-yaffsdev: $(yaffsdev_RAM_OBJECTS)
-       $(LINKER) -o yaffsdev $(LINKER_ENTRY) $(LINKER_FLAGS) $(yaffsdev_RAM_OBJECTS) $(yaffsdev_RAM_LIBS)
+yaffsdev: $(yaffsdev_disk_OBJECTS)
+       $(LINKER) -o yaffsdev $(LINKER_ENTRY) $(LINKER_FLAGS) $(yaffsdev_disk_OBJECTS) $(yaffsdev_disk_LIBS)
 
 .y.c:
        $(YACC) $< $(YACC_FLAGS) $(YACC_DEFINES) $(YACC_INCLUDES)
@@ -69,9 +69,10 @@ yaffsdev: $(yaffsdev_RAM_OBJECTS)
        $(CPP) -c $< $(CPP_FLAGS) $(CPP_DEFINES) $(CPP_INCLUDES)
 
 
-yaffs_guts.o: /opt/aleph1/yaffs/yaffs_guts.h /opt/aleph1/yaffs/yaffsinterface.h /opt/aleph1/yaffs/yportenv.h
-yaffs_ramem.o: yaffs_nandemul.h /opt/aleph1/yaffs/devextras.h /opt/aleph1/yaffs/yaffs_guts.h /opt/aleph1/yaffs/yaffsinterface.h /opt/aleph1/yaffs/yportenv.h
-yaffsdev.o: yaffs_nandemul.h /usr/include/stdio.h /usr/include/stdlib.h /usr/include/string.h /opt/aleph1/yaffs/yaffs_guts.h /opt/aleph1/yaffs/yaffsinterface.h
+nand_ecc.o: /opt/yaffs/yportenv.h
+yaffs_fileem.o: /opt/2.4.18/linux/include/linux/stat.h /opt/2.4.18/linux/include/linux/types.h /usr/include/fcntl.h /usr/include/stdio.h /usr/include/stdlib.h /usr/include/string.h /usr/include/unistd.h /opt/yaffs/yaffs_fileem.h /opt/yaffs/yaffs_guts.h /opt/yaffs/yaffsinterface.h
+yaffs_guts.o: /opt/yaffs/yaffs_guts.h /opt/yaffs/yaffsinterface.h /opt/yaffs/yportenv.h
+yaffsdev.o: yaffs_nandemul.h /usr/include/stdio.h /usr/include/stdlib.h /usr/include/string.h /opt/yaffs/yaffs_fileem.h /opt/yaffs/yaffs_guts.h /opt/yaffs/yaffsinterface.h
 
 clean:
        rm -f *.o
index a137fb47fd14f79c498add26f9b6693fd0c72002..a03461017bd5c76de5858c572135e1511ed7db99 100644 (file)
@@ -14,7 +14,7 @@
  */
  //yaffs_fileem.c
 
-#include "yaffs_nandif.h"
+#include "yaffs_fileem.h"
 #include "yaffs_guts.h"
 #include "yaffsinterface.h"
 
@@ -39,7 +39,7 @@ static __u8 ffChunk[528];
 
 
 
-static void  CheckInit(void)
+static void  CheckInit(yaffs_Device *dev)
 {
        static int initialised = 0;
 
@@ -67,19 +67,19 @@ static void  CheckInit(void)
                        printf("Creating emulation file...\n");
                        for(i = 0; i < FILE_SIZE_IN_BLOCKS; i++)
                        {
-                               yaffs_EraseBlockInNAND(i);
+                               yaffs_FEEraseBlockInNAND(dev,i);
                        }
                }
        }
 }
 
-int yaffs_WriteChunkToNAND(int chunkInNAND,__u8 *data, yaffs_Spare *spare)
+int yaffs_FEWriteChunkToNAND(yaffs_Device *dev,int chunkInNAND,const __u8 *data, yaffs_Spare *spare)
 {
        int pos;
        
        pos = chunkInNAND * 528;
        
-       CheckInit();
+       CheckInit(dev);
        
        
        if(data)
@@ -100,14 +100,14 @@ int yaffs_WriteChunkToNAND(int chunkInNAND,__u8 *data, yaffs_Spare *spare)
 }
 
 
-int yaffs_ReadChunkFromNAND(int chunkInNAND, __u8 *data, yaffs_Spare *spare)
+int yaffs_FEReadChunkFromNAND(yaffs_Device *dev,int chunkInNAND, __u8 *data, yaffs_Spare *spare)
 {
        int pos;
 
        pos = chunkInNAND * 528;
        
        
-       CheckInit();
+       CheckInit(dev);
        
        if(data)
        {
@@ -127,11 +127,11 @@ int yaffs_ReadChunkFromNAND(int chunkInNAND, __u8 *data, yaffs_Spare *spare)
 }
 
 
-int yaffs_EraseBlockInNAND(int blockInNAND)
+int yaffs_FEEraseBlockInNAND(yaffs_Device *dev,int blockInNAND)
 {
        int i;
        
-       CheckInit();
+       CheckInit(dev);
        
        printf("Erasing block %d\n",blockInNAND);
        
@@ -143,3 +143,7 @@ int yaffs_EraseBlockInNAND(int blockInNAND)
        return YAFFS_OK;
 }
 
+int yaffs_FEInitialiseNAND(yaffs_Device *dev)
+{
+       return YAFFS_OK;
+}
index de71211a985bd43d4c61ce7abaeeae511326bfa3..c3f57d7723bc2757030bdd3ef993fc47e9fd37b7 100644 (file)
@@ -60,6 +60,8 @@
 
 
 
+static void yaffs_put_super(struct super_block *sb);
+
 static ssize_t yaffs_file_read(struct file *f, char *buf, size_t n, loff_t *pos);
 static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n, loff_t *pos);
 
@@ -128,6 +130,7 @@ static struct super_operations yaffs_super_ops = {
        statfs:                 yaffs_statfs,
        read_inode:             yaffs_read_inode,
        put_inode:              yaffs_put_inode,
+       put_super:              yaffs_put_super,
 //     read_inode:
 //     remount_fs:
 //     clear_inode:
@@ -177,6 +180,9 @@ static struct dentry * yaffs_lookup(struct inode *dir, struct dentry *dentry)
 static void yaffs_put_inode(struct inode *inode)
 {
        T(("yaffs_put_inode: ino %d, count %d\n",(int)inode->i_ino, atomic_read(&inode->i_count)));
+       
+       yaffs_FlushFile(yaffs_InodeToObject(inode));
+       
 }
 
 #ifdef YAFFS_ADDRESS_OPS
@@ -626,6 +632,34 @@ static void yaffs_read_inode (struct inode *inode)
 }
 
 
+static void yaffs_put_super(struct super_block *sb)
+{
+       yaffs_Device *dev = yaffs_SuperToDevice(sb);
+       
+       if(dev->putSuperFunc)
+       {
+                dev->putSuperFunc(sb);
+       }
+}
+
+
+#ifdef YAFFS_MTD_ENABLED
+
+static void  yaffs_MTDPutSuper(struct super_block *sb)
+{
+       
+       struct mtd_info *mtd = yaffs_SuperToDevice(sb)->genericDevice;
+       
+       if(mtd->sync)
+       {
+               mtd->sync(mtd);
+       }
+       
+       put_mtd_device(mtd);
+}
+
+#endif
+
 static struct super_block *yaffs_internal_read_super(int useRam, struct super_block * sb, void * data, int silent)
 {
        struct inode * inode;
@@ -653,7 +687,7 @@ static struct super_block *yaffs_internal_read_super(int useRam, struct super_bl
        if(useRam)
        {
 
-#if YAFFS_RAM_ENABLED
+#ifdef YAFFS_RAM_ENABLED
                // Set the yaffs_Device up for ram emulation
 
                sb->u.generic_sbp =     dev = kmalloc(sizeof(yaffs_Device),GFP_KERNEL);
@@ -675,6 +709,7 @@ static struct super_block *yaffs_internal_read_super(int useRam, struct super_bl
                dev->readChunkFromNAND = nandemul_ReadChunkFromNAND;
                dev->eraseBlockInNAND = nandemul_EraseBlockInNAND;
                dev->initialiseNAND = nandemul_InitialiseNAND;
+               
 #endif
 
        }
@@ -755,6 +790,7 @@ static struct super_block *yaffs_internal_read_super(int useRam, struct super_bl
                dev->eraseBlockInNAND = nandmtd_EraseBlockInNAND;
                dev->initialiseNAND = nandmtd_InitialiseNAND;
                
+               dev->putSuperFunc = yaffs_MTDPutSuper;
 #endif
        }
 
index 66014bb3f449d95b5a94aec02ff026c17c622c0c..88b02a3659cf7b51da032b6d0bf31ba7d2991dcc 100644 (file)
@@ -82,8 +82,8 @@ loff_t yaffs_GetFileSize(yaffs_Object *obj);
 
 static int yaffs_AllocateChunk(yaffs_Device *dev,int useReserve);
 
-#if YAFFS_PARANOID
-static int yaffs_CheckFileSanity(yaffs_Object *in)
+#ifdef YAFFS_PARANOID
+static int yaffs_CheckFileSanity(yaffs_Object *in);
 #else
 #define yaffs_CheckFileSanity(in)
 #endif
@@ -136,6 +136,39 @@ int yaffs_ReadChunkFromNAND(struct yaffs_DeviceStruct *dev,int chunkInNAND, __u8
        return retVal;
 }
 
+#ifdef YAFFS_PARANOID
+
+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];
+       
+       int retVal;
+       
+       retVal  = YAFFS_OK;
+       
+       dev->readChunkFromNAND(dev,chunkInNAND,data,(yaffs_Spare *)spare);
+       
+       
+       
+       if(!init)
+       {
+               memset(cmpbuf,0xff,YAFFS_BYTES_PER_CHUNK);
+               init = 1;
+       }
+       
+       if(memcmp(cmpbuf,data,YAFFS_BYTES_PER_CHUNK)) retVal = YAFFS_FAIL;
+       if(memcmp(cmpbuf,spare,16)) retVal = YAFFS_FAIL;
+       
+       return retVal;
+       
+}
+
+#endif
+
+
 int yaffs_EraseBlockInNAND(struct yaffs_DeviceStruct *dev,int blockInNAND)
 {
        return dev->eraseBlockInNAND(dev,blockInNAND);
@@ -1429,7 +1462,7 @@ static int yaffs_AllocateChunk(yaffs_Device *dev,int useReserve)
                }
 
 #ifdef YAFFS_PARANOID
-               if(yaffs_CheckChunkErased(retVal) == YAFFS_FAIL)
+               if(yaffs_CheckChunkErased(dev,retVal) == YAFFS_FAIL)
                {
                        T(("..................Trying to allocate non-erased page %d\n",retVal));
                }
@@ -1677,7 +1710,7 @@ int yaffs_FindChunkInFile(yaffs_Object *in,int chunkInInode,yaffs_Tags *tags)
                theChunk = tn->level0[chunkInInode & YAFFS_TNODES_LEVEL0_MASK] << dev->chunkGroupBits;
 
                // Now we need to do the shifting etc and search for it
-               for(i = 0,found = 0; i < dev->chunkGroupSize && !found; i++)
+               for(i = 0,found = 0; theChunk && i < dev->chunkGroupSize && !found; i++)
                {
                        yaffs_ReadChunkTagsFromNAND(dev,theChunk,tags);
                        if(tags->chunkId == chunkInInode &&
@@ -1719,7 +1752,7 @@ int yaffs_FindAndDeleteChunkInFile(yaffs_Object *in,int chunkInInode,yaffs_Tags
                theChunk = tn->level0[chunkInInode & YAFFS_TNODES_LEVEL0_MASK] << dev->chunkGroupBits;
     
                // Now we need to do the shifting etc and search for it
-               for(i = 0,found = 0; i < dev->chunkGroupSize && !found; i++)
+               for(i = 0,found = 0; theChunk && i < dev->chunkGroupSize && !found; i++)
                {
                        yaffs_ReadChunkTagsFromNAND(dev,theChunk,tags);
                        if(tags->chunkId == chunkInInode &&
@@ -1780,20 +1813,20 @@ static int yaffs_CheckFileSanity(yaffs_Object *in)
        
        for(chunk = 1; chunk <= nChunks; chunk++)
        {
-               tn = yaffs_FindLevel0Tnode(&in->variant.fileVariant, chunk);
+               tn = yaffs_FindLevel0Tnode(in->myDev,&in->variant.fileVariant, chunk);
     
                if(tn)
                {
     
-                       theChunk = tn->level0[chunk & YAFFS_TNODES_LEVEL0_MASK] << dev->chunkGroupBits;
+                       theChunk = tn->level0[chunk & YAFFS_TNODES_LEVEL0_MASK] << in->myDev->chunkGroupBits;
     
 
-                               yaffs_ReadChunkTagsFromNAND(theChunk,tags);
+                               yaffs_ReadChunkTagsFromNAND(in->myDev,theChunk,tags);
                                if(tags->chunkId == chunk &&
                                tags->objectId == in->objectId)
                                {
                                        // found it;
-                                       
+                               
                                }
                                else
                                {
@@ -2370,6 +2403,7 @@ int yaffs_FlushFile(yaffs_Object *in)
        int retVal;
        if(in->dirty)
        {
+               T(("flushing object header\n"));
                retVal = yaffs_UpdateObjectHeader(in,NULL);
        }
        else
index e6f74ddbc72daa600a13cc19951eaa5f8e65fdaa..7b059aacd6be6d03d8685147e05bb704c16c1d99 100644 (file)
@@ -334,9 +334,11 @@ struct yaffs_DeviceStruct
        int (*readChunkFromNAND)(struct yaffs_DeviceStruct *dev,int chunkInNAND, __u8 *data, yaffs_Spare *spare);
        int (*eraseBlockInNAND)(struct yaffs_DeviceStruct *dev,int blockInNAND);        
        int (*initialiseNAND)(struct yaffs_DeviceStruct *dev);
-       
 
-       
+#ifdef __KERNEL__
+       void (*putSuperFunc)(struct super_block *sb);
+#endif
+
        // Runtime parameters.
        yaffs_BlockInfo *blockInfo;
        int   nErasedBlocks;
index 6e51051b859dcc7fdd205bf6b372f0915281d490..70d4cc2136bc2f54eedded57b3a4a67290d7ee49 100755 (executable)
Binary files a/yaffsdev and b/yaffsdev differ
index 64368f449852501b44ca423e0312e1fb50eb367e..e38a98330a5f04b2f4139ea86a3a431dd71e8be1 100644 (file)
  */
  
 #include "yaffsinterface.h"
+#if YAFFS_FILEEM       
+#include "yaffs_fileem.h"
+#else
 #include "yaffs_nandemul.h" 
+#endif
+
 #include "yaffs_guts.h"
 #include <stdlib.h>
 
@@ -287,12 +292,23 @@ int main(int argc,char *argv[])
        device.nBlocks = (2 * 1024 * 1024) / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK);
        device.startBlock = 1;  // Don't use block 0
        device.endBlock = device.nBlocks - 1;
-       
+
+#if YAFFS_FILEEM       
+       device.writeChunkToNAND = yaffs_FEWriteChunkToNAND;
+       device.readChunkFromNAND = yaffs_FEReadChunkFromNAND;
+       device.eraseBlockInNAND = yaffs_FEEraseBlockInNAND;
+       device.initialiseNAND = yaffs_FEInitialiseNAND;
+
+       printf("Testing on file emulation\n");
+#else
        device.writeChunkToNAND = nandemul_WriteChunkToNAND;
        device.readChunkFromNAND = nandemul_ReadChunkFromNAND;
        device.eraseBlockInNAND = nandemul_EraseBlockInNAND;
        device.initialiseNAND = nandemul_InitialiseNAND;
        
+       printf("Testing on RAM emulation\n");
+#endif
+
        yaffs_GutsInitialise(&device);
        
        // yaffs_GutsTest();
index b6f80f5aa93e77e197762d84bdab35ebc16ac520..fc2bac33a6995411fcd1a8d65cf58e8f071abf2c 100644 (file)
Binary files a/yaffsdev.proj and b/yaffsdev.proj differ