2 * YAFFS: Yet another FFS. A NAND-flash specific file system.
3 * yaffs_mtdif.c NAND mtd wrapper functions.
5 * Copyright (C) 2002 Aleph One Ltd.
6 * for Toby Churchill Ltd and Brightstar Engineering
8 * Created by Charles Manning <charles@aleph1.co.uk>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
16 // mtd interface for YAFFS2
18 const char *yaffs_mtdif2_c_version = "$Id: yaffs_mtdif2.c,v 1.6 2005-08-01 20:52:35 luc Exp $";
22 #ifdef CONFIG_YAFFS_YAFFS1
24 #include "yaffs_mtdif2.h"
26 #include "linux/mtd/mtd.h"
27 #include "linux/types.h"
28 #include "linux/time.h"
30 #include "yaffs_packedtags2.h"
35 int nandmtd2_WriteChunkWithTagsToNAND(yaffs_Device *dev,int chunkInNAND,const __u8 *data, const yaffs_ExtendedTags *tags)
37 struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice);
42 loff_t addr = ((loff_t)chunkInNAND) * dev->nBytesPerChunk;
46 T(YAFFS_TRACE_MTD,(TSTR("nandmtd2_WriteChunkWithTagsToNAND chunk %d data %p tags %p" TENDSTR),chunkInNAND,data,tags));
50 yaffs_PackTags2(&pt,tags);
56 retval = mtd->write_ecc(mtd,addr,dev->nBytesPerChunk,&dummy,data,(__u8 *)&pt,NULL);
58 retval = mtd->write_ecc(mtd,addr,dev->nBytesPerChunk,&dummy,data,(__u8 *)&pt,NULL);
63 retval = mtd->write(mtd,addr,dev->nBytesPerChunk,&dummy,data);
65 retval = mtd->write_oob(mtd,addr,mtd->oobsize,&dummy,(__u8 *)&pt);
75 int nandmtd2_ReadChunkWithTagsFromNAND(yaffs_Device *dev,int chunkInNAND, __u8 *data, yaffs_ExtendedTags *tags)
77 struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice);
82 loff_t addr = ((loff_t)chunkInNAND) * dev->nBytesPerChunk;
86 T(YAFFS_TRACE_MTD,(TSTR("nandmtd2_ReadChunkWithTagsToNAND chunk %d data %p tags %p" TENDSTR),chunkInNAND,data,tags));
92 retval = mtd->read_ecc(mtd,addr,dev->nBytesPerChunk,&dummy,data,dev->spareBuffer,NULL);
96 retval = mtd->read_ecc(mtd,addr,dev->nBytesPerChunk,&dummy,data,dev->spareBuffer,NULL);
102 retval = mtd->read(mtd,addr,dev->nBytesPerChunk,&dummy,data);
104 retval = mtd->read_oob(mtd,addr,mtd->oobsize,&dummy,dev->spareBuffer);
107 memcpy(&pt,dev->spareBuffer,sizeof(pt));
110 yaffs_UnpackTags2(tags,&pt);
118 int nandmtd2_MarkNANDBlockBad(struct yaffs_DeviceStruct *dev, int blockNo)
120 struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice);
122 T(YAFFS_TRACE_MTD,(TSTR("nandmtd2_MarkNANDBlockBad %d" TENDSTR),blockNo));
125 retval = mtd->block_markbad(mtd,blockNo * dev->nChunksPerBlock * dev->nBytesPerChunk);
134 int nandmtd2_QueryNANDBlock(struct yaffs_DeviceStruct *dev, int blockNo, yaffs_BlockState *state, int *sequenceNumber)
136 struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice);
139 T(YAFFS_TRACE_MTD,(TSTR("nandmtd2_QueryNANDBlock %d" TENDSTR),blockNo));
140 retval = mtd->block_isbad(mtd,blockNo* dev->nChunksPerBlock * dev->nBytesPerChunk);
144 T(YAFFS_TRACE_MTD,(TSTR("block is bad" TENDSTR)));
146 *state = YAFFS_BLOCK_STATE_DEAD;
151 yaffs_ExtendedTags t;
152 nandmtd2_ReadChunkWithTagsFromNAND(dev,blockNo * dev->nChunksPerBlock,NULL, &t);
156 *sequenceNumber = t.sequenceNumber;
157 *state = YAFFS_BLOCK_STATE_NEEDS_SCANNING;
162 *state = YAFFS_BLOCK_STATE_EMPTY;
165 T(YAFFS_TRACE_MTD,(TSTR("block is bad seq %d state %d" TENDSTR), *sequenceNumber,*state));