/*
* 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
+ * Copyright (C) 2002-2018 Aleph One Ltd.
*
* Created by Charles Manning <charles@aleph1.co.uk>
*
* NAND Simulator for testing YAFFS
*/
-#include <string.h>
#include "yramsim.h"
-#include "yaffs_nandif.h"
+#include "yaffs_guts.h"
+#include <string.h>
+
#define DATA_SIZE 2048
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);
}
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;
pageOffset >= PAGES_PER_BLOCK ||
dataLength >DATA_SIZE ||
spareLength > SPARE_SIZE ||
- !eccStatus ||
!blockList[blockId]->blockOk){
- return 0;
+ return YAFFS_FAIL;
}
d = blockList[blockId]->page[pageOffset];
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;
dataLength >DATA_SIZE ||
spareLength > SPARE_SIZE ||
!blockList[blockId]->blockOk){
- return 0;
+ return YAFFS_FAIL;
}
d = blockList[blockId]->page[pageOffset];
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);
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;
}
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;
}