From: Charles Manning Date: Wed, 20 Jun 2012 04:15:11 +0000 (+1200) Subject: yaffs: Refactor drivers WIP - stress tests passing X-Git-Tag: aleph1-release~73^2~7 X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs2.git;a=commitdiff_plain;h=5587d9d89d5fb9c31fd723e85949f85da70ef3a9 yaffs: Refactor drivers WIP - stress tests passing Both yaffs1 and yaffs2 modes seem to be doing the right thing under stress testing. Signed-off-by: Charles Manning --- diff --git a/direct/basic-test/Makefile b/direct/basic-test/Makefile index 026c0b8..b4fb52a 100644 --- a/direct/basic-test/Makefile +++ b/direct/basic-test/Makefile @@ -37,7 +37,8 @@ CFLAGS+= -DCONFIG_YAFFS_USE_PTHREADS -lpthread COMMONTESTOBJS = yaffscfg2k.o yaffs_osglue.o yaffs_hweight.o \ yaffs_ecc.o yaffs_fileem.o yaffs_fileem2k.o yaffsfs.o yaffs_guts.o \ yaffs_packedtags1.o yaffs_ramdisk.o yaffs_ramem2k.o \ - yaffs_tagscompat.o yaffs_packedtags2.o yaffs_nand.o \ + yaffs_tagscompat.o yaffs_tagsmarshall.o \ + yaffs_packedtags2.o yaffs_nand.o \ yaffs_checkptrw.o yaffs_qsort.o\ yaffs_nameval.o yaffs_attribs.o \ yaffs_norif1.o ynorsim.o \ @@ -54,6 +55,7 @@ COMMONTESTOBJS = yaffscfg2k.o yaffs_osglue.o yaffs_hweight.o \ YAFFSDIRECTSYMLINKS = \ yaffs_ecc.c yaffs_ecc.h yaffs_guts.c yaffs_guts.h \ yaffs_tagscompat.c yaffs_tagscompat.h \ + yaffs_tagsmarshall.c yaffs_tagsmarshall.h \ yaffs_packedtags1.c yaffs_packedtags1.h yaffs_packedtags2.c yaffs_packedtags2.h \ yaffs_nand.c yaffs_nand.h yaffs_getblockinfo.h \ yaffs_checkptrw.h yaffs_checkptrw.c \ diff --git a/direct/basic-test/yaffs_fileem2k.c b/direct/basic-test/yaffs_fileem2k.c index 836d1f7..6604f04 100644 --- a/direct/basic-test/yaffs_fileem2k.c +++ b/direct/basic-test/yaffs_fileem2k.c @@ -16,9 +16,6 @@ * This is only intended as test code to test persistence etc. */ -const char *yaffs_flashif2_c_version = "$Id: yaffs_fileem2k.c,v 1.24 2010-02-18 01:18:04 charles Exp $"; - - #include "yportenv.h" #include "yaffs_trace.h" @@ -31,13 +28,11 @@ const char *yaffs_flashif2_c_version = "$Id: yaffs_fileem2k.c,v 1.24 2010-02-18 #include #include #include -#include - - +#include #define REPORT_ERROR 0 -typedef struct +typedef struct { u8 data[PAGE_SIZE]; // Data + spare } yflash_Page; @@ -45,7 +40,7 @@ typedef struct typedef struct { yflash_Page page[PAGES_PER_BLOCK]; // The pages in the block - + } yflash_Block; @@ -75,8 +70,8 @@ static void yflash2_MaybePowerFail(unsigned int nand_chunk, int failPoint) { nops_so_far++; - - + + remaining_ops--; if(simulate_power_failure && remaining_ops < 1){ @@ -105,12 +100,12 @@ static int GetBlockFileHandle(int n) { int h; int requiredSize; - + char name[40]; NToName(name,n); int fSize; int i; - + h = open(name, O_RDWR | O_CREAT, S_IREAD | S_IWRITE); if(h >= 0){ fSize = lseek(h,0,SEEK_END); @@ -119,10 +114,10 @@ static int GetBlockFileHandle(int n) for(i = 0; i < BLOCKS_PER_HANDLE; i++) if(write(h,dummyBuffer,BLOCK_SIZE) != BLOCK_SIZE) return -1; - + } } - + return h; } @@ -134,30 +129,30 @@ static int CheckInit(void) int blk; - - if(initialised) + + if(initialised) { return YAFFS_OK; } initialised = 1; - + srand(random_seed); remaining_ops = (rand() % 1000) * 5; memset(dummyBuffer,0xff,sizeof(dummyBuffer)); - - + + filedisk.nBlocks = SIZE_IN_MB * BLOCKS_PER_MB; for(i = 0; i < MAX_HANDLES; i++) filedisk.handle[i] = -1; - + for(i = 0,blk = 0; blk < filedisk.nBlocks; blk+=BLOCKS_PER_HANDLE,i++) filedisk.handle[i] = GetBlockFileHandle(i); - - + + return 1; } @@ -165,209 +160,10 @@ static int CheckInit(void) int yflash2_GetNumberOfBlocks(void) { CheckInit(); - + return filedisk.nBlocks; } -int yflash2_WriteChunkWithTagsToNAND(struct yaffs_dev *dev,int nand_chunk,const u8 *data, const struct yaffs_ext_tags *tags) -{ - int written; - int pos; - int h; - int i; - int nRead; - int error; - - yaffs_trace(YAFFS_TRACE_MTD, "write chunk %d data %p tags %p",nand_chunk, data, tags); - - CheckInit(); - - - if(dev->param.inband_tags){ - - struct yaffs_packed_tags2_tags_only * pt2tp; - pt2tp = (struct yaffs_packed_tags2_tags_only *)&data[dev->data_bytes_per_chunk]; - yaffs_pack_tags2_tags_only(pt2tp,tags); - - pos = (nand_chunk % (PAGES_PER_BLOCK * BLOCKS_PER_HANDLE)) * PAGE_SIZE; - h = filedisk.handle[(nand_chunk / (PAGES_PER_BLOCK * BLOCKS_PER_HANDLE))]; - - lseek(h,pos,SEEK_SET); - written = write(h,data,dev->param.total_bytes_per_chunk); - - - if(yaffs_test_partial_write){ - close(h); - exit(1); - } - - if(written != dev->param.total_bytes_per_chunk) return YAFFS_FAIL; - - - } - - else { - /* First do a write of a partial page */ - int n_partials; - int bpos; - - if(data) - { - pos = (nand_chunk % (PAGES_PER_BLOCK * BLOCKS_PER_HANDLE)) * PAGE_SIZE; - h = filedisk.handle[(nand_chunk / (PAGES_PER_BLOCK * BLOCKS_PER_HANDLE))]; - - - memcpy(localBuffer,data, dev->data_bytes_per_chunk); - - n_partials = rand()%20; - - for(i = 0; i < n_partials; i++){ - bpos = rand() % dev->data_bytes_per_chunk; - - localBuffer[bpos] |= (1 << (rand() & 7)); - } - - if(REPORT_ERROR && memcmp(localBuffer,data,dev->data_bytes_per_chunk)) - printf("nand simulator: data does not match\n"); - - lseek(h,pos,SEEK_SET); - written = write(h,localBuffer,dev->data_bytes_per_chunk); - - if(yaffs_test_partial_write){ - close(h); - exit(1); - } - - - if(written != dev->data_bytes_per_chunk) return YAFFS_FAIL; - } - // yflash2_MaybePowerFail(nand_chunk,1); - - if(tags) - { - pos = (nand_chunk % (PAGES_PER_BLOCK * BLOCKS_PER_HANDLE)) * PAGE_SIZE + PAGE_DATA_SIZE ; - h = filedisk.handle[(nand_chunk / (PAGES_PER_BLOCK * BLOCKS_PER_HANDLE))]; - - lseek(h,pos,SEEK_SET); - - if( 0 && dev->param.is_yaffs2) - { - - written = write(h,tags,sizeof(struct yaffs_ext_tags)); - if(written != sizeof(struct yaffs_ext_tags)) return YAFFS_FAIL; - } - else - { - struct yaffs_packed_tags2 pt; - yaffs_pack_tags2(&pt,tags, !dev->param.no_tags_ecc); - u8 * ptab = (u8 *)&pt; - - nRead = read(h,localBuffer,sizeof(pt)); - for(i = error = 0; REPORT_ERROR && i < sizeof(pt) && !error; i++){ - if(localBuffer[i] != 0xFF){ - printf("nand simulation: chunk %d oob byte %d was %0x2\n", - nand_chunk,i,localBuffer[i]); - error = 1; - } - } - - for(i = 0; i < sizeof(pt); i++) - localBuffer[i] &= ptab[i]; - - n_partials = rand()% sizeof(pt); - - for(i = 0; i < n_partials; i++){ - bpos = rand() % sizeof(pt); - - localBuffer[bpos] |= (1 << (rand() & 7)); - } - - if(REPORT_ERROR && memcmp(localBuffer,&pt,sizeof(pt))) - printf("nand sim: tags corruption\n"); - - lseek(h,pos,SEEK_SET); - - written = write(h,localBuffer,sizeof(pt)); - if(written != sizeof(pt)) return YAFFS_FAIL; - } - } - - //yflash2_MaybePowerFail(nand_chunk,2); - - /* Next do the whole write */ - if(data) - { - pos = (nand_chunk % (PAGES_PER_BLOCK * BLOCKS_PER_HANDLE)) * PAGE_SIZE; - h = filedisk.handle[(nand_chunk / (PAGES_PER_BLOCK * BLOCKS_PER_HANDLE))]; - - - memset(localBuffer,0xFF, PAGE_SIZE); - for(i = 0; i < dev->data_bytes_per_chunk; i++){ - localBuffer[i] &= data[i]; - } - - if(REPORT_ERROR && memcmp(localBuffer,data,dev->data_bytes_per_chunk)) - printf("nand simulator: data does not match\n"); - - lseek(h,pos,SEEK_SET); - written = write(h,localBuffer,dev->data_bytes_per_chunk); - - if(yaffs_test_partial_write){ - close(h); - exit(1); - } - - - if(written != dev->data_bytes_per_chunk) return YAFFS_FAIL; - } - - if(tags) - { - pos = (nand_chunk % (PAGES_PER_BLOCK * BLOCKS_PER_HANDLE)) * PAGE_SIZE + PAGE_DATA_SIZE ; - h = filedisk.handle[(nand_chunk / (PAGES_PER_BLOCK * BLOCKS_PER_HANDLE))]; - - lseek(h,pos,SEEK_SET); - - if( 0 && dev->param.is_yaffs2) - { - - written = write(h,tags,sizeof(struct yaffs_ext_tags)); - if(written != sizeof(struct yaffs_ext_tags)) return YAFFS_FAIL; - } - else - { - struct yaffs_packed_tags2 pt; - yaffs_pack_tags2(&pt,tags,!dev->param.no_tags_ecc); - u8 * ptab = (u8 *)&pt; - - nRead = read(h,localBuffer,sizeof(pt)); - for(i = error = 0; REPORT_ERROR && i < sizeof(pt) && !error; i++){ - if(localBuffer[i] != 0xFF){ - printf("nand simulation: chunk %d oob byte %d was %0x2\n", - nand_chunk,i,localBuffer[i]); - error = 1; - } - } - - for(i = 0; i < sizeof(pt); i++) - localBuffer[i] &= ptab[i]; - - if(REPORT_ERROR && memcmp(localBuffer,&pt,sizeof(pt))) - printf("nand sim: tags corruption\n"); - - lseek(h,pos,SEEK_SET); - - written = write(h,localBuffer,sizeof(pt)); - if(written != sizeof(pt)) return YAFFS_FAIL; - } - } - - yflash2_MaybePowerFail(nand_chunk,3); - - } - return YAFFS_OK; - -} int yaffs_check_all_ff(const u8 *ptr, int n) { @@ -381,222 +177,164 @@ int yaffs_check_all_ff(const u8 *ptr, int n) } -static int fail300 = 1; -static int fail320 = 1; - -static int failRead10 = 2; - -int yflash2_ReadChunkWithTagsFromNAND(struct yaffs_dev *dev,int nand_chunk, u8 *data, struct yaffs_ext_tags *tags) +static int yflash2_WriteChunk(struct yaffs_dev *dev, int nand_chunk, + const u8 *data, int data_len, + const u8 *oob, int oob_len) { - int nread; + int retval = YAFFS_OK; int pos; int h; - int localData = 0; - int retval = YAFFS_OK; - int nRead; - - yaffs_trace(YAFFS_TRACE_MTD,"read chunk %d data %p tags %p",nand_chunk, data, tags); - - CheckInit(); - - - - - if(dev->param.inband_tags){ - /* Got to suck the tags out of the data area */ - if(!data) { - localData=1; - data = yaffs_get_temp_buffer(dev); - } + int nwritten; - - struct yaffs_packed_tags2_tags_only * pt2tp; - pt2tp = (struct yaffs_packed_tags2_tags_only *)&data[dev->data_bytes_per_chunk]; + (void) dev; - + if (data && data_len) { pos = (nand_chunk % (PAGES_PER_BLOCK * BLOCKS_PER_HANDLE)) * PAGE_SIZE; h = filedisk.handle[(nand_chunk / (PAGES_PER_BLOCK * BLOCKS_PER_HANDLE))]; - lseek(h,pos,SEEK_SET); - - nRead = read(h, data,dev->param.total_bytes_per_chunk); - - yaffs_unpack_tags2_tags_only(tags,pt2tp); - - if(nread != dev->param.total_bytes_per_chunk) + nwritten = write(h,data,data_len); + if(nwritten != data_len) retval = YAFFS_FAIL; - - if(localData) - yaffs_release_temp_buffer(dev, data); - - - } - - else { - - if(data) - { - pos = (nand_chunk % (PAGES_PER_BLOCK * BLOCKS_PER_HANDLE)) * PAGE_SIZE; - h = filedisk.handle[(nand_chunk / (PAGES_PER_BLOCK * BLOCKS_PER_HANDLE))]; - lseek(h,pos,SEEK_SET); - nread = read(h,data,dev->data_bytes_per_chunk); - - - if(nread != dev->data_bytes_per_chunk) - retval = YAFFS_FAIL; - } - - if(tags) - { - pos = (nand_chunk % (PAGES_PER_BLOCK * BLOCKS_PER_HANDLE)) * PAGE_SIZE + PAGE_DATA_SIZE; - h = filedisk.handle[(nand_chunk / (PAGES_PER_BLOCK * BLOCKS_PER_HANDLE))]; - lseek(h,pos,SEEK_SET); - - if(0 && dev->param.is_yaffs2) - { - nread= read(h,tags,sizeof(struct yaffs_ext_tags)); - if(nread != sizeof(struct yaffs_ext_tags)) - retval = YAFFS_FAIL; - if(yaffs_check_all_ff((u8 *)tags, sizeof(struct yaffs_ext_tags))) - memset(tags, 0, sizeof(struct yaffs_ext_tags)); - else - tags->chunk_used = 1; - } - else - { - struct yaffs_packed_tags2 pt; - nread= read(h,&pt,sizeof(pt)); - yaffs_unpack_tags2(tags,&pt, !dev->param.no_tags_ecc); -#ifdef SIMULATE_FAILURES - if((nand_chunk >> 6) == 100) { - if(fail300 && tags->ecc_result == YAFFS_ECC_RESULT_NO_ERROR){ - tags->ecc_result = YAFFS_ECC_RESULT_FIXED; - fail300 = 0; - } - } - - if((nand_chunk >> 6) == 110) { - if(fail320 && tags->ecc_result == YAFFS_ECC_RESULT_NO_ERROR){ - tags->ecc_result = YAFFS_ECC_RESULT_FIXED; - fail320 = 0; - } - } -#endif - if(failRead10>0 && nand_chunk == 10){ - failRead10--; - nread = 0; - } - - if(nread != sizeof(pt)) - retval = YAFFS_FAIL; - } - } + if (oob && oob_len) { + pos = (nand_chunk % (PAGES_PER_BLOCK * BLOCKS_PER_HANDLE)) * PAGE_SIZE + PAGE_DATA_SIZE; + h = filedisk.handle[(nand_chunk / (PAGES_PER_BLOCK * BLOCKS_PER_HANDLE))]; + lseek(h,pos,SEEK_SET); + nwritten = write(h,oob,oob_len); + if(nwritten != oob_len) + retval = YAFFS_FAIL; } - + yflash2_MaybePowerFail(nand_chunk,3); - return retval; - + return retval; } - -int yflash2_MarkNANDBlockBad(struct yaffs_dev *dev, int block_no) +static int yflash2_ReadChunk(struct yaffs_dev *dev, int nand_chunk, + u8 *data, int data_len, + u8 *oob, int oob_len, + enum yaffs_ecc_result *ecc_result) { - int written; + int retval = YAFFS_OK; + int pos; int h; - - struct yaffs_packed_tags2 pt; + int nread; - CheckInit(); - - memset(&pt,0,sizeof(pt)); - h = filedisk.handle[(block_no / ( BLOCKS_PER_HANDLE))]; - lseek(h,((block_no % BLOCKS_PER_HANDLE) * dev->param.chunks_per_block) * PAGE_SIZE + PAGE_DATA_SIZE,SEEK_SET); - written = write(h,&pt,sizeof(pt)); - - if(written != sizeof(pt)) return YAFFS_FAIL; - - - return YAFFS_OK; - + (void) dev; + + if (data && data_len) { + pos = (nand_chunk % (PAGES_PER_BLOCK * BLOCKS_PER_HANDLE)) * PAGE_SIZE; + h = filedisk.handle[(nand_chunk / (PAGES_PER_BLOCK * BLOCKS_PER_HANDLE))]; + lseek(h,pos,SEEK_SET); + nread = read(h,data,data_len); + if(nread != data_len) + retval = YAFFS_FAIL; + } + + if (oob && oob_len) { + pos = (nand_chunk % (PAGES_PER_BLOCK * BLOCKS_PER_HANDLE)) * PAGE_SIZE + PAGE_DATA_SIZE; + h = filedisk.handle[(nand_chunk / (PAGES_PER_BLOCK * BLOCKS_PER_HANDLE))]; + lseek(h,pos,SEEK_SET); + nread = read(h,oob,oob_len); + if(nread != oob_len) + retval = YAFFS_FAIL; + } + + if (ecc_result) + *ecc_result = YAFFS_ECC_RESULT_NO_ERROR; + + return retval; } -int yflash2_EraseBlockInNAND(struct yaffs_dev *dev, int blockNumber) +static int yflash2_EraseBlock(struct yaffs_dev *dev, int block_no) { - int i; int h; - + CheckInit(); - - //printf("erase block %d\n",blockNumber); - - if(blockNumber == 320) - fail320 = 1; - - if(blockNumber < 0 || blockNumber >= filedisk.nBlocks) + + if(block_no < 0 || block_no >= filedisk.nBlocks) { - yaffs_trace(YAFFS_TRACE_ALWAYS,"Attempt to erase non-existant block %d",blockNumber); + yaffs_trace(YAFFS_TRACE_ALWAYS,"Attempt to erase non-existant block %d",block_no); return YAFFS_FAIL; } else { - + u8 pg[PAGE_SIZE]; int syz = PAGE_SIZE; int pos; - + memset(pg,0xff,syz); - - h = filedisk.handle[(blockNumber / ( BLOCKS_PER_HANDLE))]; - lseek(h,((blockNumber % BLOCKS_PER_HANDLE) * dev->param.chunks_per_block) * PAGE_SIZE,SEEK_SET); + + h = filedisk.handle[(block_no / ( BLOCKS_PER_HANDLE))]; + lseek(h,((block_no % BLOCKS_PER_HANDLE) * dev->param.chunks_per_block) * PAGE_SIZE,SEEK_SET); for(i = 0; i < dev->param.chunks_per_block; i++) { write(h,pg,PAGE_SIZE); } pos = lseek(h, 0,SEEK_CUR); - + return YAFFS_OK; } - } -int yflash2_InitialiseNAND(struct yaffs_dev *dev) +static int yflash2_MarkBad(struct yaffs_dev *dev, int block_no) { + int written; + int h; + + struct yaffs_packed_tags2 pt; + CheckInit(); - + + memset(&pt,0,sizeof(pt)); + h = filedisk.handle[(block_no / ( BLOCKS_PER_HANDLE))]; + lseek(h,((block_no % BLOCKS_PER_HANDLE) * dev->param.chunks_per_block) * PAGE_SIZE + PAGE_DATA_SIZE,SEEK_SET); + written = write(h,&pt,sizeof(pt)); + + if(written != sizeof(pt)) + return YAFFS_FAIL; + return YAFFS_OK; -} +} +static int yflash2_CheckBad(struct yaffs_dev *dev, int block_no) +{ + (void) dev; + (void) block_no; + return YAFFS_OK; +} -int yflash2_QueryNANDBlock(struct yaffs_dev *dev, int block_no, enum yaffs_block_state *state, u32 *seq_number) +static int yflash2_Initialise(struct yaffs_dev *dev) { - struct yaffs_ext_tags tags; - int chunkNo; - - *seq_number = 0; - - chunkNo = block_no * dev->param.chunks_per_block; - - yflash2_ReadChunkWithTagsFromNAND(dev,chunkNo,NULL,&tags); - if(tags.block_bad) - { - *state = YAFFS_BLOCK_STATE_DEAD; - } - else if(!tags.chunk_used) - { - *state = YAFFS_BLOCK_STATE_EMPTY; - } - else if(tags.chunk_used) - { - *state = YAFFS_BLOCK_STATE_NEEDS_SCAN; - *seq_number = tags.seq_number; - } + (void) dev; + + CheckInit(); + return YAFFS_OK; } +void yflash2_install_drv(struct yaffs_dev *dev) +{ + struct yaffs_param *param = &dev->param; + + param->drv_write_chunk_fn = yflash2_WriteChunk; + param->drv_read_chunk_fn = yflash2_ReadChunk; + param->drv_erase_fn = yflash2_EraseBlock; + param->drv_mark_bad_fn = yflash2_MarkBad; + param->drv_check_bad_fn = yflash2_CheckBad; + param->drv_initialise_fn = yflash2_Initialise; + + + param->total_bytes_per_chunk = 2048; + param->chunks_per_block = 64; + param->start_block = 0; + param->end_block = yflash2_GetNumberOfBlocks()-1; + param->is_yaffs2 = 1; + param->use_nand_ecc=1; +} diff --git a/direct/basic-test/yaffs_fileem2k.h b/direct/basic-test/yaffs_fileem2k.h index e2e8dc3..e447987 100644 --- a/direct/basic-test/yaffs_fileem2k.h +++ b/direct/basic-test/yaffs_fileem2k.h @@ -1,5 +1,5 @@ /* - * YAFFS: Yet another Flash File System . A NAND-flash specific file system. + * YAFFS: Yet another Flash File System . A NAND-flash specific file system. * * Copyright (C) 2002-2011 Aleph One Ltd. * for Toby Churchill Ltd and Brightstar Engineering @@ -44,8 +44,10 @@ #endif +struct yaffs_dev; + +void yflash2_install_drv(struct yaffs_dev *dev); -int yflash2_GetNumberOfBlocks(void); #endif diff --git a/direct/basic-test/yaffs_norif1.c b/direct/basic-test/yaffs_norif1.c index 98008b5..20511e4 100644 --- a/direct/basic-test/yaffs_norif1.c +++ b/direct/basic-test/yaffs_norif1.c @@ -17,22 +17,22 @@ /* First set up for M18 with 1k chunks and 16-byte spares. * - * NB We're using the oddball M18 modes of operation here + * NB We're using the oddball M18 modes of operation here * The chip is 64MB based at 0x0000, but YAFFS only going to use the top half * ie. YAFFS will be from 32MB to 64MB. * - * The M18 has two ways of writing data. Every Programming Region (1kbytes) + * The M18 has two ways of writing data. Every Programming Region (1kbytes) * can be programmed in two modes: * * Object Mode 1024 bytes of write once data. - * * Control Mode: 512bytes of bit-writeable data. + * * Control Mode: 512bytes of bit-writeable data. * This is arranged as 32 * (16 bytes of bit-writable followed by 16 bytes of "dont touch") - * + * * The block size is 256kB, making 128 blocks in the 32MB YAFFS area. * Each block comprises: * Offset 0k: 248 x 1k data pages * Offset 248k: 248 x 32-byte spare areas implemented as 16 bytes of spare followed by 16 bytes untouched) * Offset 248k + (248 * 32): Format marker - * + * */ const char *yaffs_norif1_c_version = "$Id: yaffs_norif1.c,v 1.6 2010-02-18 01:18:04 charles Exp $"; @@ -70,8 +70,8 @@ const char *yaffs_norif1_c_version = "$Id: yaffs_norif1.c,v 1.6 2010-02-18 01:18 #include "ynorsim.h" #define ynorif1_FlashInit() ynorsim_initialise() #define ynorif1_FlashDeinit() ynorsim_shutdown() -#define ynorif1_FlashWrite32(addr,buf,nwords) ynorsim_wr32(addr,buf,nwords) -#define ynorif1_FlashRead32(addr,buf,nwords) ynorsim_rd32(addr,buf,nwords) +#define ynorif1_FlashWrite32(addr,buf,nwords) ynorsim_wr32(addr,buf,nwords) +#define ynorif1_FlashRead32(addr,buf,nwords) ynorsim_rd32(addr,buf,nwords) #define ynorif1_FlashEraseBlock(addr) ynorsim_erase(addr) #define DEVICE_BASE ynorsim_get_base() #else @@ -80,56 +80,57 @@ const char *yaffs_norif1_c_version = "$Id: yaffs_norif1.c,v 1.6 2010-02-18 01:18 #include "../blob/yflashrw.h" #define ynorif1_FlashInit() do{} while(0) #define ynorif1_FlashDeinit() do {} while(0) -#define ynorif1_FlashWrite32(addr,buf,nwords) Y_FlashWrite(addr,buf,nwords) -#define ynorif1_FlashRead32(addr,buf,nwords) Y_FlashRead(addr,buf,nwords) +#define ynorif1_FlashWrite32(addr,buf,nwords) Y_FlashWrite(addr,buf,nwords) +#define ynorif1_FlashRead32(addr,buf,nwords) Y_FlashRead(addr,buf,nwords) #define ynorif1_FlashEraseBlock(addr) Y_FlashErase(addr,BLOCK_SIZE_IN_BYTES) #define DEVICE_BASE (32 * 1024 * 1024) #endif -u32 *Block2Addr(struct yaffs_dev *dev, int blockNumber) +static u32 *Block2Addr(struct yaffs_dev *dev, int blockNumber) { u32 addr; dev=dev; - + addr = (u32) DEVICE_BASE; addr += blockNumber * BLOCK_SIZE_IN_BYTES; - + return (u32 *) addr; } -u32 *Block2FormatAddr(struct yaffs_dev *dev,int blockNumber) +static u32 *Block2FormatAddr(struct yaffs_dev *dev,int blockNumber) { u32 addr; addr = (u32) Block2Addr(dev,blockNumber); addr += FORMAT_OFFSET; - + return (u32 *)addr; } -u32 *Chunk2DataAddr(struct yaffs_dev *dev,int chunk_id) + +static u32 *Chunk2DataAddr(struct yaffs_dev *dev,int chunk_id) { unsigned block; unsigned chunkInBlock; u32 addr; - + block = chunk_id/dev->param.chunks_per_block; chunkInBlock = chunk_id % dev->param.chunks_per_block; - + addr = (u32) Block2Addr(dev,block); addr += chunkInBlock * DATA_BYTES_PER_CHUNK; - + return (u32 *)addr; } -u32 *Chunk2SpareAddr(struct yaffs_dev *dev,int chunk_id) +static u32 *Chunk2SpareAddr(struct yaffs_dev *dev,int chunk_id) { unsigned block; unsigned chunkInBlock; u32 addr; - + block = chunk_id/dev->param.chunks_per_block; chunkInBlock = chunk_id % dev->param.chunks_per_block; - + addr = (u32) Block2Addr(dev,block); addr += SPARE_AREA_OFFSET; addr += chunkInBlock * (SPARE_BYTES_PER_CHUNK + M18_SKIP); @@ -137,7 +138,7 @@ u32 *Chunk2SpareAddr(struct yaffs_dev *dev,int chunk_id) } -void ynorif1_AndBytes(u8*target, const u8 *src, int nbytes) +static void ynorif1_AndBytes(u8*target, const u8 *src, int nbytes) { while(nbytes > 0){ *target &= *src; @@ -146,24 +147,31 @@ void ynorif1_AndBytes(u8*target, const u8 *src, int nbytes) nbytes--; } } - -int ynorif1_WriteChunkToNAND(struct yaffs_dev *dev,int nand_chunk,const u8 *data, const struct yaffs_spare *spare) + int (*drv_write_chunk_fn) (struct yaffs_dev *dev, int nand_chunk, + const u8 *data, int data_len, + const u8 *oob, int oob_len); +static int ynorif1_WriteChunkToNAND(struct yaffs_dev *dev,int nand_chunk, + const u8 *data, int data_len, + const u8 *oob, int oob_len) { u32 *dataAddr = Chunk2DataAddr(dev,nand_chunk); u32 *spareAddr = Chunk2SpareAddr(dev,nand_chunk); - + + struct yaffs_spare *spare = (struct yaffs_spare *)oob; struct yaffs_spare tmpSpare; - + + (void) oob_len; + /* We should only be getting called for one of 3 reasons: * Writing a chunk: data and spare will not be NULL * Writing a deletion marker: data will be NULL, spare not NULL * Writing a bad block marker: data will be NULL, spare not NULL */ - + if(sizeof(struct yaffs_spare) != 16) BUG(); - - if(data && spare) + + if(data && oob) { if(spare->page_status != 0xff) BUG(); @@ -172,53 +180,57 @@ int ynorif1_WriteChunkToNAND(struct yaffs_dev *dev,int nand_chunk,const u8 *data tmpSpare.page_status = YNOR_PREMARKER; ynorif1_FlashWrite32(spareAddr,(u32 *)&tmpSpare,sizeof(struct yaffs_spare)/4); - /* Write the data */ - ynorif1_FlashWrite32(dataAddr,(u32 *)data,dev->param.total_bytes_per_chunk / 4); - - + /* Write the data */ + ynorif1_FlashWrite32(dataAddr,(u32 *)data, data_len/ 4); + + memcpy(&tmpSpare,spare,sizeof(struct yaffs_spare)); - + /* Write the real tags, but override the premarker*/ tmpSpare.page_status = YNOR_PREMARKER; ynorif1_FlashWrite32(spareAddr,(u32 *)&tmpSpare,sizeof(struct yaffs_spare)/4); - + /* Write a post-marker */ tmpSpare.page_status = YNOR_POSTMARKER; - ynorif1_FlashWrite32(spareAddr,(u32 *)&tmpSpare,sizeof(tmpSpare)/4); + ynorif1_FlashWrite32(spareAddr,(u32 *)&tmpSpare,sizeof(tmpSpare)/4); } else if(spare){ /* This has to be a read-modify-write operation to handle NOR-ness */ ynorif1_FlashRead32(spareAddr,(u32 *)&tmpSpare,16/ 4); - + ynorif1_AndBytes((u8 *)&tmpSpare,(u8 *)spare,sizeof(struct yaffs_spare)); - + ynorif1_FlashWrite32(spareAddr,(u32 *)&tmpSpare,16/ 4); } else { BUG(); } - - return YAFFS_OK; + + return YAFFS_OK; } -int ynorif1_ReadChunkFromNAND(struct yaffs_dev *dev,int nand_chunk, u8 *data, struct yaffs_spare *spare) +static int ynorif1_ReadChunkFromNAND(struct yaffs_dev *dev,int nand_chunk, + u8 *data, int data_len, + u8 *oob, int oob_len, + enum yaffs_ecc_result *ecc_result) { + struct yaffs_spare *spare = (struct yaffs_spare *)oob; u32 *dataAddr = Chunk2DataAddr(dev,nand_chunk); u32 *spareAddr = Chunk2SpareAddr(dev,nand_chunk); - + if(data) { ynorif1_FlashRead32(dataAddr,(u32 *)data,dev->param.total_bytes_per_chunk / 4); } - - if(spare) + + if(oob) { - ynorif1_FlashRead32(spareAddr,(u32 *)spare,16/ 4); - + ynorif1_FlashRead32(spareAddr,(u32 *)spare, oob_len/ 4); + /* If the page status is YNOR_POSTMARKER then it was written properly * so change that to 0xFF so that the rest of yaffs is happy. */ @@ -228,21 +240,24 @@ int ynorif1_ReadChunkFromNAND(struct yaffs_dev *dev,int nand_chunk, u8 *data, st (spare->page_status | YNOR_PREMARKER) != 0xff) spare->page_status = YNOR_PREMARKER; } - - return YAFFS_OK; + if(ecc_result) + *ecc_result = YAFFS_ECC_RESULT_NO_ERROR; + + return YAFFS_OK; } + static int ynorif1_FormatBlock(struct yaffs_dev *dev, int blockNumber) { u32 *blockAddr = Block2Addr(dev,blockNumber); u32 *formatAddr = Block2FormatAddr(dev,blockNumber); u32 formatValue = FORMAT_VALUE; - + ynorif1_FlashEraseBlock(blockAddr); ynorif1_FlashWrite32(formatAddr,&formatValue,1); - + return YAFFS_OK; } @@ -250,9 +265,9 @@ static int ynorif1_UnformatBlock(struct yaffs_dev *dev, int blockNumber) { u32 *formatAddr = Block2FormatAddr(dev,blockNumber); u32 formatValue = 0; - + ynorif1_FlashWrite32(formatAddr,&formatValue,1); - + return YAFFS_OK; } @@ -260,14 +275,14 @@ static int ynorif1_IsBlockFormatted(struct yaffs_dev *dev, int blockNumber) { u32 *formatAddr = Block2FormatAddr(dev,blockNumber); u32 formatValue; - - + + ynorif1_FlashRead32(formatAddr,&formatValue,1); - + return (formatValue == FORMAT_VALUE); } -int ynorif1_EraseBlockInNAND(struct yaffs_dev *dev, int blockNumber) +static int ynorif1_EraseBlockInNAND(struct yaffs_dev *dev, int blockNumber) { if(blockNumber < 0 || blockNumber >= BLOCKS_IN_DEVICE) @@ -283,13 +298,13 @@ int ynorif1_EraseBlockInNAND(struct yaffs_dev *dev, int blockNumber) ynorif1_FormatBlock(dev,blockNumber); return YAFFS_OK; } - + } -int ynorif1_InitialiseNAND(struct yaffs_dev *dev) +static int ynorif1_InitialiseNAND(struct yaffs_dev *dev) { int i; - + ynorif1_FlashInit(); /* Go through the blocks formatting them if they are not formatted */ for(i = dev->param.start_block; i <= dev->param.end_block; i++){ @@ -300,12 +315,28 @@ int ynorif1_InitialiseNAND(struct yaffs_dev *dev) return YAFFS_OK; } -int ynorif1_Deinitialise_flash_fn(struct yaffs_dev *dev) +static int ynorif1_Deinitialise_flash_fn(struct yaffs_dev *dev) { - dev=dev; + dev=dev; ynorif1_FlashDeinit(); return YAFFS_OK; } +void ynorif1_install_drv(struct yaffs_dev *dev) +{ + struct yaffs_param *param = &dev->param; + + param->total_bytes_per_chunk = 1024; + param->chunks_per_block =248; + param->n_reserved_blocks = 2; + param->start_block = 0; // Can use block 0 + param->end_block = 31; // Last block + param->use_nand_ecc = 0; // use YAFFS's ECC + param->drv_write_chunk_fn = ynorif1_WriteChunkToNAND; + param->drv_read_chunk_fn = ynorif1_ReadChunkFromNAND; + param->drv_erase_fn = ynorif1_EraseBlockInNAND; + param->drv_initialise_fn = ynorif1_InitialiseNAND; + param->drv_deinitialise_fn = ynorif1_Deinitialise_flash_fn; +} diff --git a/direct/basic-test/yaffs_norif1.h b/direct/basic-test/yaffs_norif1.h index 72952b4..d245b6d 100644 --- a/direct/basic-test/yaffs_norif1.h +++ b/direct/basic-test/yaffs_norif1.h @@ -1,5 +1,5 @@ /* - * YAFFS: Yet another Flash File System . A NAND-flash specific file system. + * YAFFS: Yet another Flash File System . A NAND-flash specific file system. * * Copyright (C) 2002-2011 Aleph One Ltd. * for Toby Churchill Ltd and Brightstar Engineering @@ -17,13 +17,8 @@ #ifndef __YAFFS_NOR_IF1_H__ #define __YAFFS_NOR_IF1_H__ -#include "yaffs_guts.h" - -int ynorif1_WriteChunkToNAND(struct yaffs_dev *dev,int nand_chunk,const u8 *data, const struct yaffs_spare *spare); -int ynorif1_ReadChunkFromNAND(struct yaffs_dev *dev,int nand_chunk, u8 *data, struct yaffs_spare *spare); -int ynorif1_EraseBlockInNAND(struct yaffs_dev *dev, int blockNumber); -int ynorif1_InitialiseNAND(struct yaffs_dev *dev); -int ynorif1_Deinitialise_flash_fn(struct yaffs_dev *dev); +struct yaffs_dev; +void ynorif1_install_drv(struct yaffs_dev *dev); #endif diff --git a/direct/basic-test/yaffscfg2k.c b/direct/basic-test/yaffscfg2k.c index bbaacb9..4849889 100644 --- a/direct/basic-test/yaffscfg2k.c +++ b/direct/basic-test/yaffscfg2k.c @@ -61,7 +61,7 @@ int yaffs_start_up(void) static int start_up_called = 0; if(start_up_called) - return; + return 0; start_up_called = 1; // Stuff to configure YAFFS @@ -69,41 +69,15 @@ int yaffs_start_up(void) yaffsfs_OSInitialisation(); // Set up devices - // /ram1 ram, yaffs1 - memset(&ram1Dev,0,sizeof(ram1Dev)); - ram1Dev.param.name = "ram1"; - ram1Dev.param.total_bytes_per_chunk = 512; - ram1Dev.param.chunks_per_block = 32; - ram1Dev.param.n_reserved_blocks = 2; // Set this smaller for RAM - ram1Dev.param.start_block = 0; // Can use block 0 - ram1Dev.param.end_block = 127; // Last block in 2MB. - //ram1Dev.param.use_nand_ecc = 1; - ram1Dev.param.n_caches = 0; // Disable caching on this device. - ram1Dev.driver_context = (void *) 0; // Used to identify the device in fstat. - ram1Dev.param.write_chunk_tags_fn = yramdisk_wr_chunk; - ram1Dev.param.read_chunk_tags_fn = yramdisk_rd_chunk; - ram1Dev.param.erase_fn = yramdisk_erase; - ram1Dev.param.initialise_flash_fn = yramdisk_initialise; - - yaffs_add_device(&ram1Dev); // /M18-1 yaffs1 on M18 nor sim memset(&m18_1Dev,0,sizeof(m18_1Dev)); + ynorif1_install_drv(&m18_1Dev); m18_1Dev.param.name = "M18-1"; - m18_1Dev.param.total_bytes_per_chunk = 1024; - m18_1Dev.param.chunks_per_block =248; - m18_1Dev.param.n_reserved_blocks = 2; - m18_1Dev.param.start_block = 0; // Can use block 0 - m18_1Dev.param.end_block = 31; // Last block - m18_1Dev.param.use_nand_ecc = 0; // use YAFFS's ECC m18_1Dev.param.n_caches = 10; // Use caches m18_1Dev.param.disable_soft_del = 1; m18_1Dev.driver_context = (void *) 1; // Used to identify the device in fstat. - m18_1Dev.param.write_chunk_fn = ynorif1_WriteChunkToNAND; - m18_1Dev.param.read_chunk_fn = ynorif1_ReadChunkFromNAND; - m18_1Dev.param.erase_fn = ynorif1_EraseBlockInNAND; - m18_1Dev.param.initialise_flash_fn = ynorif1_InitialiseNAND; - m18_1Dev.param.deinitialise_flash_fn = ynorif1_Deinitialise_flash_fn; + // m18_1Dev.param.disable_soft_del = 1; @@ -113,31 +87,19 @@ int yaffs_start_up(void) // 2kpage/64chunk per block // memset(&flashDev,0,sizeof(flashDev)); + yflash2_install_drv(&flashDev); flashDev.param.name = "yaffs2"; - flashDev.param.total_bytes_per_chunk = 2048; - flashDev.param.chunks_per_block = 64; + flashDev.param.n_reserved_blocks = 5; - flashDev.param.inband_tags = 0; - flashDev.param.start_block = 0; - flashDev.param.end_block = yflash2_GetNumberOfBlocks()-1; - flashDev.param.is_yaffs2 = 1; - flashDev.param.use_nand_ecc=1; flashDev.param.wide_tnodes_disabled=0; flashDev.param.refresh_period = 1000; flashDev.param.n_caches = 10; // Use caches flashDev.driver_context = (void *) 2; // Used to identify the device in fstat. - flashDev.param.write_chunk_tags_fn = yflash2_WriteChunkWithTagsToNAND; - flashDev.param.read_chunk_tags_fn = yflash2_ReadChunkWithTagsFromNAND; - flashDev.param.erase_fn = yflash2_EraseBlockInNAND; - flashDev.param.initialise_flash_fn = yflash2_InitialiseNAND; - flashDev.param.bad_block_fn = yflash2_MarkNANDBlockBad; - flashDev.param.query_block_fn = yflash2_QueryNANDBlock; + flashDev.param.enable_xattr = 1; yaffs_add_device(&flashDev); -// todo yaffs_initialise(yaffsfs_config); - return 0; } diff --git a/direct/handle_common.sh b/direct/handle_common.sh index 0e339f1..be9d122 100755 --- a/direct/handle_common.sh +++ b/direct/handle_common.sh @@ -3,6 +3,7 @@ YAFFS_COMMON_SOURCES="\ yaffs_ecc.c yaffs_ecc.h yaffs_guts.c yaffs_guts.h \ yaffs_tagscompat.c yaffs_tagscompat.h \ + yaffs_tagsmarshall.c yaffs_tagsmarshall.h \ yaffs_packedtags1.c yaffs_packedtags1.h \ yaffs_packedtags2.c yaffs_packedtags2.h \ yaffs_nand.c yaffs_nand.h yaffs_getblockinfo.h \ diff --git a/direct/tests/Makefile b/direct/tests/Makefile index 4f6e3c3..b2b16a7 100644 --- a/direct/tests/Makefile +++ b/direct/tests/Makefile @@ -33,7 +33,8 @@ CFLAGS += -Wextra -Wpointer-arith COMMONTESTOBJS = yaffscfg2k.o yaffs_osglue.o yaffs_hweight.o\ yaffs_ecc.o yaffs_fileem.o yaffs_fileem2k.o yaffsfs.o yaffs_guts.o \ yaffs_packedtags1.o yaffs_ramdisk.o yaffs_ramem2k.o \ - yaffs_tagscompat.o yaffs_packedtags2.o yaffs_nand.o \ + yaffs_tagscompat.o yaffs_tagsmarshall.o \ + yaffs_packedtags2.o yaffs_nand.o \ yaffs_checkptrw.o yaffs_qsort.o\ yaffs_nameval.o yaffs_attribs.o \ yaffs_norif1.o ynorsim.o nor_stress.o yaffs_fsx.o \ @@ -61,6 +62,7 @@ YAFFSDIRECTSYMLINKS = \ yaffs_hweight.c yaffs_hweight.h \ yaffs_ecc.c yaffs_ecc.h yaffs_guts.c yaffs_guts.h \ yaffs_tagscompat.c yaffs_tagscompat.h \ + yaffs_tagsmarshall.c yaffs_tagsmarshall.h \ yaffs_packedtags1.c yaffs_packedtags1.h \ yaffs_packedtags2.c yaffs_packedtags2.h \ yaffs_nand.c yaffs_nand.h yaffs_getblockinfo.h \ diff --git a/direct/yaffsfs.c b/direct/yaffsfs.c index 2917a5d..def672d 100644 --- a/direct/yaffsfs.c +++ b/direct/yaffsfs.c @@ -501,6 +501,9 @@ static struct yaffs_dev *yaffsfs_FindDevice(const YCHAR *path, thisMatchLength = 0; matching = 1; + if(!p) + continue; + while (matching && *p && *leftOver) { /* Skip over any /s */ while (yaffsfs_IsPathDivider(*p)) diff --git a/yaffs_checkptrw.c b/yaffs_checkptrw.c index b1c4bee..d64c436 100644 --- a/yaffs_checkptrw.c +++ b/yaffs_checkptrw.c @@ -98,7 +98,7 @@ static int yaffs_checkpt_erase(struct yaffs_dev *dev) dev->n_free_chunks += dev->param.chunks_per_block; } else { - dev->param.drv_bad_block_fn(dev, offset_i); + dev->param.drv_mark_bad_fn(dev, offset_i); bi->block_state = YAFFS_BLOCK_STATE_DEAD; } } diff --git a/yaffs_guts.c b/yaffs_guts.c index 0c33102..66e8c5e 100644 --- a/yaffs_guts.c +++ b/yaffs_guts.c @@ -4540,8 +4540,7 @@ static int yaffs_check_dev_fns(struct yaffs_dev *dev) if (!param->drv_initialise_fn || !param->drv_read_chunk_fn || !param->drv_write_chunk_fn || - !param->drv_erase_fn || - !param->drv_initialise_fn) + !param->drv_erase_fn) return 0; /* Install the default tags marshalling functions if needed. */ diff --git a/yaffs_tagscompat.c b/yaffs_tagscompat.c index 78781e6..3d72be4 100644 --- a/yaffs_tagscompat.c +++ b/yaffs_tagscompat.c @@ -22,11 +22,6 @@ static void yaffs_handle_rd_data_error(struct yaffs_dev *dev, int nand_chunk); /********** Tags ECC calculations *********/ -static void yaffs_calc_ecc(const u8 *data, struct yaffs_spare *spare) -{ - yaffs_ecc_calc(data, spare->ecc1); - yaffs_ecc_calc(&data[256], spare->ecc2); -} void yaffs_calc_tags_ecc(struct yaffs_tags *tags) { @@ -127,22 +122,11 @@ static int yaffs_wr_nand(struct yaffs_dev *dev, int nand_chunk, const u8 *data, struct yaffs_spare *spare) { - int data_size; - int spare_size; - u8 spare_buffer[100]; - - if (nand_chunk < dev->param.start_block * dev->param.chunks_per_block) { - yaffs_trace(YAFFS_TRACE_ERROR, - "**>> yaffs chunk %d is not valid", - nand_chunk); - return YAFFS_FAIL; - } - - /* Format up the spare */ + int data_size = dev->data_bytes_per_chunk; return dev->param.drv_write_chunk_fn(dev, nand_chunk, data, data_size, - spare_buffer, spare_size); + (u8 *) spare, sizeof(*spare)); } static int yaffs_rd_chunk_nand(struct yaffs_dev *dev, @@ -156,116 +140,75 @@ static int yaffs_rd_chunk_nand(struct yaffs_dev *dev, struct yaffs_spare local_spare; int data_size; int spare_size; + int ecc_result1, ecc_result2; + u8 calc_ecc[3]; if (!spare) { /* If we don't have a real spare, then we use a local one. */ /* Need this for the calculation of the ecc */ spare = &local_spare; } + data_size = dev->data_bytes_per_chunk; + spare_size = sizeof(struct yaffs_spare); + + if (dev->param.use_nand_ecc) + return dev->param.drv_read_chunk_fn(dev, nand_chunk, + data, data_size, + (u8 *) spare, spare_size, + ecc_result); + + + /* Handle the ECC at this level. */ - if (!dev->param.use_nand_ecc) { - ret_val = - dev->param.drv_read_chunk_fn(dev, nand_chunk, + ret_val = dev->param.drv_read_chunk_fn(dev, nand_chunk, data, data_size, (u8 *)spare, spare_size, - ecc_result); - if (data && correct_errors) { - /* Do ECC correction */ - /* Todo handle any errors */ - int ecc_result1, ecc_result2; - u8 calc_ecc[3]; - - yaffs_ecc_calc(data, calc_ecc); - ecc_result1 = - yaffs_ecc_correct(data, spare->ecc1, calc_ecc); - yaffs_ecc_calc(&data[256], calc_ecc); - ecc_result2 = - yaffs_ecc_correct(&data[256], spare->ecc2, - calc_ecc); - - if (ecc_result1 > 0) { - yaffs_trace(YAFFS_TRACE_ERROR, - "**>>yaffs ecc error fix performed on chunk %d:0", - nand_chunk); - dev->n_ecc_fixed++; - } else if (ecc_result1 < 0) { - yaffs_trace(YAFFS_TRACE_ERROR, - "**>>yaffs ecc error unfixed on chunk %d:0", - nand_chunk); - dev->n_ecc_unfixed++; - } - - if (ecc_result2 > 0) { - yaffs_trace(YAFFS_TRACE_ERROR, - "**>>yaffs ecc error fix performed on chunk %d:1", - nand_chunk); - dev->n_ecc_fixed++; - } else if (ecc_result2 < 0) { - yaffs_trace(YAFFS_TRACE_ERROR, - "**>>yaffs ecc error unfixed on chunk %d:1", - nand_chunk); - dev->n_ecc_unfixed++; - } - - if (ecc_result1 || ecc_result2) { - /* We had a data problem on this page */ - yaffs_handle_rd_data_error(dev, nand_chunk); - } - - if (ecc_result1 < 0 || ecc_result2 < 0) - *ecc_result = YAFFS_ECC_RESULT_UNFIXED; - else if (ecc_result1 > 0 || ecc_result2 > 0) - *ecc_result = YAFFS_ECC_RESULT_FIXED; - else - *ecc_result = YAFFS_ECC_RESULT_NO_ERROR; - } - } else { - /* Must allocate enough memory for spare+2*sizeof(int) */ - /* for ecc results from device. */ - struct yaffs_nand_spare nspare; + NULL); + if (!data || !correct_errors) + return ret_val; - memset(&nspare, 0, sizeof(nspare)); + /* Do ECC correction if needed. */ + yaffs_ecc_calc(data, calc_ecc); + ecc_result1 = yaffs_ecc_correct(data, spare->ecc1, calc_ecc); + yaffs_ecc_calc(&data[256], calc_ecc); + ecc_result2 = yaffs_ecc_correct(&data[256], spare->ecc2, calc_ecc); - ret_val = dev->param.drv_read_chunk_fn(dev, nand_chunk, - data, data_size, - (u8 *) &nspare, sizeof(nspare), - NULL); - memcpy(spare, &nspare, sizeof(struct yaffs_spare)); - if (data && correct_errors) { - if (nspare.eccres1 > 0) { - yaffs_trace(YAFFS_TRACE_ERROR, - "**>>mtd ecc error fix performed on chunk %d:0", - nand_chunk); - } else if (nspare.eccres1 < 0) { - yaffs_trace(YAFFS_TRACE_ERROR, - "**>>mtd ecc error unfixed on chunk %d:0", - nand_chunk); - } - - if (nspare.eccres2 > 0) { - yaffs_trace(YAFFS_TRACE_ERROR, - "**>>mtd ecc error fix performed on chunk %d:1", - nand_chunk); - } else if (nspare.eccres2 < 0) { - yaffs_trace(YAFFS_TRACE_ERROR, - "**>>mtd ecc error unfixed on chunk %d:1", - nand_chunk); - } - - if (nspare.eccres1 || nspare.eccres2) { - /* We had a data problem on this page */ - yaffs_handle_rd_data_error(dev, nand_chunk); - } - - if (nspare.eccres1 < 0 || nspare.eccres2 < 0) - *ecc_result = YAFFS_ECC_RESULT_UNFIXED; - else if (nspare.eccres1 > 0 || nspare.eccres2 > 0) - *ecc_result = YAFFS_ECC_RESULT_FIXED; - else - *ecc_result = YAFFS_ECC_RESULT_NO_ERROR; + if (ecc_result1 > 0) { + yaffs_trace(YAFFS_TRACE_ERROR, + "**>>yaffs ecc error fix performed on chunk %d:0", + nand_chunk); + dev->n_ecc_fixed++; + } else if (ecc_result1 < 0) { + yaffs_trace(YAFFS_TRACE_ERROR, + "**>>yaffs ecc error unfixed on chunk %d:0", + nand_chunk); + dev->n_ecc_unfixed++; + } - } + if (ecc_result2 > 0) { + yaffs_trace(YAFFS_TRACE_ERROR, + "**>>yaffs ecc error fix performed on chunk %d:1", + nand_chunk); + dev->n_ecc_fixed++; + } else if (ecc_result2 < 0) { + yaffs_trace(YAFFS_TRACE_ERROR, + "**>>yaffs ecc error unfixed on chunk %d:1", + nand_chunk); + dev->n_ecc_unfixed++; + } + + if (ecc_result1 || ecc_result2) { + /* We had a data problem on this page */ + yaffs_handle_rd_data_error(dev, nand_chunk); } + + if (ecc_result1 < 0 || ecc_result2 < 0) + *ecc_result = YAFFS_ECC_RESULT_UNFIXED; + else if (ecc_result1 > 0 || ecc_result2 > 0) + *ecc_result = YAFFS_ECC_RESULT_FIXED; + else + *ecc_result = YAFFS_ECC_RESULT_NO_ERROR; + return ret_val; } @@ -315,8 +258,10 @@ static int yaffs_tags_compat_wr(struct yaffs_dev *dev, tags.serial_number = ext_tags->serial_number; - if (!dev->param.use_nand_ecc && data) - yaffs_calc_ecc(data, &spare); + if (!dev->param.use_nand_ecc && data) { + yaffs_ecc_calc(data, spare.ecc1); + yaffs_ecc_calc(&data[256], spare.ecc2); + } yaffs_load_tags_to_spare(&spare, &tags); } @@ -405,10 +350,10 @@ static int yaffs_tags_compat_query_block(struct yaffs_dev *dev, *seq_number = 0; - yaffs_rd_chunk_nand(dev, block_no * dev->param.chunks_per_block, NULL, - &spare0, &dummy, 1); yaffs_rd_chunk_nand(dev, block_no * dev->param.chunks_per_block + 1, - NULL, &spare1, &dummy, 1); + NULL, &spare0, &dummy, 0); + yaffs_rd_chunk_nand(dev, block_no * dev->param.chunks_per_block + 1, + NULL, &spare1, &dummy, 0); if (hweight8(spare0.block_status & spare1.block_status) < 7) *state = YAFFS_BLOCK_STATE_DEAD; @@ -428,7 +373,7 @@ void yaffs_tags_compat_install(struct yaffs_dev *dev) dev->param.write_chunk_tags_fn = yaffs_tags_compat_wr; if(!dev->param.read_chunk_tags_fn) dev->param.read_chunk_tags_fn = yaffs_tags_compat_rd; - if(!dev->param.read_chunk_tags_fn) + if(!dev->param.query_block_fn) dev->param.query_block_fn = yaffs_tags_compat_query_block; if(!dev->param.mark_bad_fn) dev->param.mark_bad_fn = yaffs_tags_compat_mark_bad;