[Yaffs] overwrite problem in yaffs2?

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Sohn Chung-MCG31424
Date:  
To: yaffs
Subject: [Yaffs] overwrite problem in yaffs2?

Hello,

I am using the latest yaffs2 release + Sergey's patch on Large page
NAND.

I got some data corruption on the yaffs2 filesystem when an application
program overwrite data into the file. So I configured the yaffs2 code to
check every page before
it wrote on NAND flash. I also added code to stop the system if yaffs2
tried to write
on Nand flash that wasn't erased in yaffs_WriteNewChunkWithTagsToNAND.

I wrote a quick overwrite test program to test this problem.
While running the test, this message was showed up.

Chunk 87680 not erased
**>> yaffs chunk 87680 was not erased

It is easy to reproduce the problem if the size of file is larger than
60MB.
I can reproduce the problem with this scenario.

1) flash_eraseall /dev/mtd/7 /* 64MB NAND partition */
2) mount -t yaffs2 /dev/mtdblock/7 /tmp/yaffs -o sync,noatime
3) dd if=/dev/zero of=/tmp/yaffs/foo bs=1024k count=60

  /* Problem showed up with around 9th run */
4) for i in 1 2 3 4 5 6 7 8 9 10
   do
     my_test /tmp/yaffs/foo 1048576
   done


   where /tmp/yaffs/foo is the file to overwrite
         1048576 is the write size. 


I turned on yaffs_traceMask to 0xffffffff from the step 3.
The log file showed that some chunks were not erased.

nandmtd2_ReadChunkWithTagsToNAND chunk 174114 data 00000000 tags
c19ddc68
sed 1 obj 262 chunk26655 byte 2048 del 0 ser 0 seq 6914
Chunk 180352 not erased
>>Block 2818 erasure supposedly OK, but chunk 0 not erased

nandmtd2_ReadChunkWithTagsToNAND chunk 180289 data c2fe7000 tags
c19ddb10
packed tags obj 262 chunk 26656 byte 2048 seq 6914
ext.tags eccres 0 blkbad 0 chused 1 obj 262 chunk26656 byte 2048 del 0
ser 0 seq 6
914
Chunk 180353 not erased
>>Block 2818 erasure supposedly OK, but chunk 1 not erased

nandmtd2_ReadChunkWithTagsToNAND chunk 180290 data c2fe7000 tags
c19ddb10
packed tags obj 262 chunk 26657 byte 2048 seq 6914
ext.tags eccres 0 blkbad 0 chused 1 obj 262 chunk26657 byte 2048 del 0
ser 0 seq 6
914


===================================
This is my_test:

#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <errno.h>

int main(int argc, char **argv)
{
    int outputlen, num_of_pages, i, writecnt;
    int total_writecnt=0;
    int offset, write_pagesize;
    int file_id = -1;
    unsigned char *writebuf;


    if (argc != 3) {
        printf("usage: %s [filename] [writesize]\n", argv[0]);
        exit(1);
    }


    file_id = open(argv[1], O_RDWR);
    if (file_id == -1) {
        printf("open %s failed\n", argv[1]);
        exit(1);
    }


    write_pagesize = strtol(argv[2], NULL, 0);


    writebuf = malloc(write_pagesize);
    if (writebuf == NULL) {
           printf("cannot get memory\n");
    exit(1);
    }


    /* Find out the size of input file. */
    outputlen = lseek(file_id, 0, SEEK_END);
    lseek(file_id, 0, SEEK_SET);


    /* Figure out the number of pages from the file. */
    if (outputlen % write_pagesize)
        num_of_pages = (outputlen / write_pagesize) + 1;
    else
        num_of_pages = (outputlen / write_pagesize);


   memset(writebuf, 'a', write_pagesize);
   for (i=0; i < num_of_pages; i++)
    {
        offset = i * write_pagesize;


        lseek(file_id, offset, SEEK_SET);
        if ((writecnt = write(file_id, writebuf, write_pagesize)) !=
write_pagesize){


              if (writecnt < 0) {
                     printf("write_file: File I/O error on input file");
             exit(1);
               }


                printf("write_file: partial write: %d, total
writecnt=%d\n",
                         writecnt, total_writecnt+writecnt);
         }
         total_writecnt += writecnt;
    }


    printf("Total write count: %d\n", total_writecnt);


    free(writebuf);
    close(file_id);
    exit(0);
}
===========================


Any idea what caused this problem?

Thanks,
Chung