[Yaffs] Fixes for working with MTD

Chris Williams chris at jem.co.jp
Wed Jul 27 09:36:22 BST 2005


Hello,

I wrote earlier trying to figure out why I was losing data with YAFFS2, 
thinking I had the settings wrong. Instead it appears that there are a 
couple bugs in the code that interfaces to MTD (assuming that I 
understand everything correctly of course ;) .)

Anyhow, the two issues I was experiencing were that data would be lost 
because all blocks written to would become bad blocks if I reset the 
system (i.e. updated the bad block table), and after solving that, my 
data would be minorly corrupted. Number one was caused by the code in 
nandmtd2_WriteChunkWithTagsToNAND() and 
nandmtd2_ReadChunkWithTagsToNAND() which write and read the tags struct 
from position 0 in the OOB--thus overwriting the bad block marker. The 
second issue (data corruption) was being caused by these same two 
functions which when writing out the tag, write it out as oobsize, so it 
overwrites the MTD ECC with random data that's past the end of the tag 
in memory.

In nandmtd2_WriteChunkWithTagsToNAND()
-    if(tags)
-        retval = mtd->write_oob(mtd,addr, mtd->oobsize,&dummy,(__u8 *)&pt);
+    if(tags)
+        retval = mtd->write_oob(mtd,addr + 2, sizeof(pt),&dummy,(__u8 
*)&pt);   /* skip two bytes so we don't have to worry about the bad 
block marker */

In nandmtd2_ReadChunkWithTagsToNAND()
-    if(tags)
-        retval = 
mtd->read_oob(mtd,addr,mtd->oobsize,&dummy,dev->spareBuffer);
+    if(tags)
+        retval = mtd->read_oob(mtd,addr + 
2,sizeof(pt),&dummy,dev->spareBuffer);   /* tag data begins two bytes 
into the OOB */

Also, I noticed that the tag ecc is, according to the reference 
material, only supposed to be three bytes, however the structure is 
defined as:

typedef struct
{
    unsigned char colParity;
    unsigned lineParity;           //int
    unsigned lineParityPrime;   //int
} yaffs_ECCOther;

So it is actually being written out as 9 bytes in the OOB, I believe.

-Chris



More information about the yaffs mailing list