X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs2.git;a=blobdiff_plain;f=direct%2Ftest-framework%2Fyramsim.c;h=6466d3b9a2ce9e1c1088927d27515b856d95c259;hp=10c9c072740eb9eb83135f853858dad1136e65bc;hb=d13e6146b4ccadd7aab2033b6cf9f4551d6abd71;hpb=54721f22512e7c859c4c4a4ae7e5374ecf7fb570 diff --git a/direct/test-framework/yramsim.c b/direct/test-framework/yramsim.c index 10c9c07..6466d3b 100644 --- a/direct/test-framework/yramsim.c +++ b/direct/test-framework/yramsim.c @@ -15,11 +15,12 @@ * NAND Simulator for testing YAFFS */ -#include #include "yramsim.h" -#include "yaffs_nandif.h" +#include "yaffs_guts.h" +#include + #define DATA_SIZE 2048 @@ -43,10 +44,7 @@ SimData *simDevs[N_RAM_SIM_DEVS]; static SimData *DevToSim(struct yaffs_dev *dev) { - struct ynandif_Geometry *geom = - (struct ynandif_Geometry *)(dev->driver_context); - SimData * sim = (SimData*)(geom->privateData); - return sim; + return (SimData*)(dev->driver_context); } @@ -91,10 +89,10 @@ static int yramsim_deinitialise(struct yaffs_dev *dev) return 1; } -static int yramsim_rd_chunk (struct yaffs_dev *dev, unsigned pageId, - unsigned char *data, unsigned dataLength, - unsigned char *spare, unsigned spareLength, - int *eccStatus) +static int yramsim_rd_chunk (struct yaffs_dev *dev, int pageId, + u8 *data, int dataLength, + u8 *spare, int spareLength, + enum yaffs_ecc_result *ecc_result) { SimData *sim = DevToSim(dev); Block **blockList = sim->blockList; @@ -107,9 +105,8 @@ static int yramsim_rd_chunk (struct yaffs_dev *dev, unsigned pageId, pageOffset >= PAGES_PER_BLOCK || dataLength >DATA_SIZE || spareLength > SPARE_SIZE || - !eccStatus || !blockList[blockId]->blockOk){ - return 0; + return YAFFS_FAIL; } d = blockList[blockId]->page[pageOffset]; @@ -121,14 +118,15 @@ static int yramsim_rd_chunk (struct yaffs_dev *dev, unsigned pageId, if(spare) memcpy(spare,s,spareLength); - *eccStatus = 0; // 0 = no error, -1 = unfixable error, 1 = fixable + if (ecc_result) + *ecc_result = YAFFS_ECC_RESULT_NO_ERROR; - return 1; + return YAFFS_OK; } -static int yramsim_wr_chunk (struct yaffs_dev *dev,unsigned pageId, - const unsigned char *data, unsigned dataLength, - const unsigned char *spare, unsigned spareLength) +static int yramsim_wr_chunk (struct yaffs_dev *dev, int pageId, + const u8 *data, int dataLength, + const u8 *spare, int spareLength) { SimData *sim = DevToSim(dev); Block **blockList = sim->blockList; @@ -142,7 +140,7 @@ static int yramsim_wr_chunk (struct yaffs_dev *dev,unsigned pageId, dataLength >DATA_SIZE || spareLength > SPARE_SIZE || !blockList[blockId]->blockOk){ - return 0; + return YAFFS_FAIL; } d = blockList[blockId]->page[pageOffset]; @@ -154,11 +152,11 @@ static int yramsim_wr_chunk (struct yaffs_dev *dev,unsigned pageId, if(spare) memcpy(s,spare,spareLength); - return 1; + return YAFFS_OK; } -static int yramsim_erase(struct yaffs_dev *dev,unsigned blockId) +static int yramsim_erase(struct yaffs_dev *dev, int blockId) { SimData *sim = DevToSim(dev); @@ -166,28 +164,28 @@ static int yramsim_erase(struct yaffs_dev *dev,unsigned blockId) return yramsim_erase_internal(sim,blockId,0); } -static int yramsim_check_block_ok(struct yaffs_dev *dev,unsigned blockId) +static int yramsim_check_block_bad(struct yaffs_dev *dev, int blockId) { SimData *sim = DevToSim(dev); Block **blockList = sim->blockList; if(blockId >= sim->nBlocks){ - return 0; + return YAFFS_FAIL; } - return blockList[blockId]->blockOk ? 1 : 0; + return blockList[blockId]->blockOk ? YAFFS_OK : YAFFS_FAIL; } -static int yramsim_mark_block_bad(struct yaffs_dev *dev,unsigned blockId) +static int yramsim_mark_block_bad(struct yaffs_dev *dev, int blockId) { SimData *sim = DevToSim(dev); Block **blockList = sim->blockList; if(blockId >= sim->nBlocks){ - return 0; + return YAFFS_FAIL; } blockList[blockId]->blockOk = 0; - return 1; + return YAFFS_OK; } @@ -257,40 +255,49 @@ struct yaffs_dev *yramsim_CreateRamSim(const YCHAR *name, u32 start_block, u32 end_block) { SimData *sim; - struct ynandif_Geometry *g; + struct yaffs_dev *dev; + struct yaffs_param *p; + struct yaffs_driver *d; sim = yramsim_alloc_sim_data(devId, nBlocks); - g = malloc(sizeof(*g)); + dev = malloc(sizeof(*dev)); - if(!sim || !g){ - if(g) - free(g); + if(!sim || !dev){ + free(sim); + free(dev); return NULL; } + + memset(dev, 0, sizeof(*dev)); if(start_block >= sim->nBlocks) start_block = 0; if(end_block == 0 || end_block >= sim->nBlocks) end_block = sim->nBlocks - 1; - memset(g,0,sizeof(*g)); - g->start_block = start_block; - g->end_block = end_block; - g->dataSize = DATA_SIZE; - g->spareSize= SPARE_SIZE; - g->pagesPerBlock = PAGES_PER_BLOCK; - g->hasECC = 1; - g->inband_tags = 0; - g->useYaffs2 = 1; - g->initialise = yramsim_initialise; - g->deinitialise = yramsim_deinitialise; - g->readChunk = yramsim_rd_chunk, - g->writeChunk = yramsim_wr_chunk, - g->eraseBlock = yramsim_erase, - g->checkBlockOk = yramsim_check_block_ok, - g->markBlockBad = yramsim_mark_block_bad, - g->privateData = (void *)sim; - - return yaffs_add_dev_from_geometry(name,g); + p = &dev->param; + p->name = strdup(name); + p->start_block = start_block; + p->end_block = end_block; + p->total_bytes_per_chunk = DATA_SIZE; + p->spare_bytes_per_chunk= SPARE_SIZE; + p->chunks_per_block = PAGES_PER_BLOCK; + p->n_reserved_blocks = 2; + p->use_nand_ecc = 1; + p->inband_tags = 0; + p->is_yaffs2 = 1; + + d= &dev->drv; + d->drv_initialise_fn = yramsim_initialise; + d->drv_deinitialise_fn = yramsim_deinitialise; + d->drv_read_chunk_fn = yramsim_rd_chunk; + d->drv_write_chunk_fn = yramsim_wr_chunk; + d->drv_erase_fn = yramsim_erase; + d->drv_check_bad_fn = yramsim_check_block_bad; + d->drv_mark_bad_fn = yramsim_mark_block_bad; + + dev->driver_context= (void *)sim; + + return dev; }