X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs%2F.git;a=blobdiff_plain;f=yaffs_fileem.c;h=3ee50eb739ab6a39f32bff4259b985a0ec331c14;hp=b850581d9b1e3da6ddee81f6fb87bf522a240786;hb=ce5e10874d3f7ef75757bb48bbf7181d63f2ef2c;hpb=daffb0c61b90abbfc5fd8c335c5b79b0feeff2ab diff --git a/yaffs_fileem.c b/yaffs_fileem.c index b850581..3ee50eb 100644 --- a/yaffs_fileem.c +++ b/yaffs_fileem.c @@ -26,7 +26,9 @@ #include #include -#define FILE_SIZE_IN_MEG 32 +#define FILE_SIZE_IN_MEG 2 + +// #define YAFFS_ERROR_TESTING #define BLOCK_SIZE (32 * 528) #define BLOCKS_PER_MEG ((1024*1024)/(32 * 512)) @@ -43,6 +45,7 @@ static int markedBadBlocks[] = { 1, 4, -1}; static int IsAMarkedBadBlock(int blk) { +#if YAFFS_ERROR_TESTING int *m = markedBadBlocks; while(*m >= 0) @@ -50,12 +53,14 @@ static int IsAMarkedBadBlock(int blk) if(*m == blk) return 1; m++; } +#endif return 0; } static __u8 yaffs_WriteFailCorruption(int chunkInNAND) { +#if YAFFS_ERROR_TESTING // Whole blocks that fail switch(chunkInNAND/YAFFS_CHUNKS_PER_BLOCK) @@ -82,28 +87,32 @@ static __u8 yaffs_WriteFailCorruption(int chunkInNAND) } - +#endif return 0; } static void yaffs_ModifyWriteData(int chunkInNAND,__u8 *data) { +#if YAFFS_ERROR_TESTING if(data) { *data ^= yaffs_WriteFailCorruption(chunkInNAND); } +#endif } static __u8 yaffs_ReadFailCorruption(int chunkInNAND) { switch(chunkInNAND) { +#if YAFFS_ERROR_TESTING case 500: return 3;// ding two bits case 700: case 750: return 1;// ding one bit +#endif default: return 0; } @@ -111,10 +120,12 @@ static __u8 yaffs_ReadFailCorruption(int chunkInNAND) static void yaffs_ModifyReadData(int chunkInNAND,__u8 *data) { +#if YAFFS_ERROR_TESTING if(data) { *data ^= yaffs_ReadFailCorruption(chunkInNAND); } +#endif } @@ -126,13 +137,18 @@ static void CheckInit(yaffs_Device *dev) static int initialised = 0; int length; + int nWritten; if(!initialised) { memset(ffChunk,0xFF,528); +//#ifdef YAFFS_DUMP +// h = open("yaffs-em-file" , O_RDONLY); +//#else h = open("yaffs-em-file" , O_RDWR | O_CREAT, S_IREAD | S_IWRITE); +//#endif if(h < 0) { perror("Fatal error opening yaffs emulation file"); @@ -141,27 +157,26 @@ static void CheckInit(yaffs_Device *dev) initialised = 1; length = lseek(h,0,SEEK_END); - if(length != FILE_SIZE_IN_BYTES) + nWritten = 528; + while(length < FILE_SIZE_IN_BYTES && nWritten == 528) { - // Create file contents - int i; - - printf("Creating emulation file...\n"); - for(i = 0; i < FILE_SIZE_IN_BLOCKS; i++) - { - yaffs_FEEraseBlockInNAND(dev,i); - - if(IsAMarkedBadBlock(i)) - { - yaffs_Spare spare; - memset(&spare,0xff,sizeof(spare)); - spare.blockStatus = 1; - - yaffs_FEWriteChunkToNAND(dev, i * 32,NULL,&spare); - } - } + write(h,ffChunk,528); + length = lseek(h,0,SEEK_END); } - eraseDisplayEnabled = 1; + if(nWritten != 528) + { + perror("Fatal error expanding yaffs emulation file"); + exit(1); + + } + + close(h); + +#ifdef YAFFS_DUMP + h = open("yaffs-em-file" , O_RDONLY); +#else + h = open("yaffs-em-file" , O_RDWR | O_CREAT, S_IREAD | S_IWRITE); +#endif } }