[Yaffs] Fix for mkyaffs2image utility

Top Page
Attachments:
Message as email
+ (text/plain)
+ mkyaffs2image_fix.patch (text/x-patch)
Delete this message
Reply to this message
Author: Vu Tran
Date:  
To: yaffs
Subject: [Yaffs] Fix for mkyaffs2image utility
Hi,

This patch intends to address the issue of no file appears in a mounted
NAND partition which is written with yaffs2 image created by the
mkyaffs2image utility using nandwrite command. The patch applies only to
the mkyaffs2image.c file. The main problem was that mkyaffs2image was
writing YAFFS2 OOB data into the OOB area that the MTD driver uses for
ECC. Therefore we need to leave room inside the OOB yaffs2 image space
for data ECC. This is achieved by introducing a new optional parameter
called oob_ecc_size to specify the size of data ECC (e.g. for 2k
page/64bytes OOB, this data ECC is 14 bytes). The patch will copy the
OOB Tags into the OOB space starting at position oob_ecc_size. Please
also note that the default behavior of mkyaffs2image is not changed and
the nandwrite command to work with this patch is: nandwrite -a -o
MTD_DEVICE INPUTFILE.


Best Regards,
Vu Tran

Index: utils/mkyaffs2image.c
===================================================================
--- utils.orig/mkyaffs2image.c    2007-09-11 13:30:38.000000000 -0400
+++ utils/mkyaffs2image.c    2007-09-11 16:13:26.000000000 -0400
@@ -65,6 +65,9 @@


static int convert_endian = 0;

+#define OOB_TAGS_POSITION_DEFAULT 0;
+static int oob_tags_pos = OOB_TAGS_POSITION_DEFAULT;
+
 static int obj_compare(const void *a, const void * b)
 {
   objItem *oa, *ob;
@@ -158,6 +161,7 @@
 {
     yaffs_ExtendedTags t;
     yaffs_PackedTags2 pt;
+    char oobData[spareSize];


     error = write(outFile,data,chunkSize);
     if(error < 0) return error;
@@ -183,9 +187,18 @@
     nPages++;


     yaffs_PackTags2(&pt,&t);
-    
-//    return write(outFile,&pt,sizeof(yaffs_PackedTags2));
-    return write(outFile,&pt,spareSize);
+
+    // * Need to write to the oob tags to the right position within the oob space
+    if((oob_tags_pos < 0) || (oob_tags_pos > (spareSize-sizeof(yaffs_PackedTags2))))
+    {
+        oob_tags_pos = OOB_TAGS_POSITION_DEFAULT;
+    }
+    memset(oobData,0xFF,spareSize);
+    memcpy(&(oobData[oob_tags_pos]),&pt,sizeof(yaffs_PackedTags2));
+    return write(outFile,oobData,spareSize);
+
+    //return write(outFile,&pt,sizeof(yaffs_PackedTags2));
+    //return write(outFile,&pt,spareSize);

    
}

@@ -461,17 +474,33 @@
    
     if(argc < 3)
     {
-        printf("usage: mkyaffs2image dir image_file [convert]\n");
-        printf("           dir        the directory tree to be converted\n");
-        printf("           image_file the output file to hold the image\n");
-        printf("           'convert'  produce a big-endian image from a little-endian machine\n");
+        printf("usage: mkyaffs2image dir image_file [oob_ecc_size] [convert]\n");
+        printf("           dir             the directory tree to be converted\n");
+        printf("           image_file      the output file to hold the image\n");
+        printf("           [oob_ecc_size]  the number of oob bytes reserved for ecc data (default is 0)\n");
+        printf("           ['convert']     produce a big-endian image from a little-endian machine\n");
         exit(1);
     }


-    if ((argc == 4) && (!strncmp(argv[3], "convert", strlen("convert"))))
-    {
-        convert_endian = 1;
-    }
+    if(argc == 4)
+    {
+        if(!strncmp(argv[3], "convert", strlen("convert")))
+        {
+            convert_endian = 1;
+        }
+        else
+        {
+            oob_tags_pos = atoi(argv[3]);
+        }
+    }
+    else if(argc == 5)
+    {
+        oob_tags_pos = atoi(argv[3]);
+        if(!strncmp(argv[4], "convert", strlen("convert")))
+        {
+            convert_endian = 1;
+        }
+    }


     if(stat(argv[1],&stats) < 0)
     {