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.3 2005-07-20 18:57:05 charles Exp $";
20 #ifdef CONFIG_YAFFS_MTD_ENABLED
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);
53 #ifndef CONFIG_YAFFS_USE_OLD_MTD
57 retval = mtd->write_ecc(mtd,addr,dev->nBytesPerChunk,&dummy,data,(__u8 *)&pt,NULL);
59 retval = mtd->write_ecc(mtd,addr,dev->nBytesPerChunk,&dummy,data,(__u8 *)&pt,NULL);
65 retval = mtd->write(mtd,addr,dev->nBytesPerChunk,&dummy,data);
67 retval = mtd->write_oob(mtd,addr,mtd->oobsize,&dummy,(__u8 *)&pt);
69 #ifndef CONFIG_YAFFS_USE_OLD_MTD
79 int nandmtd2_ReadChunkWithTagsFromNAND(yaffs_Device *dev,int chunkInNAND, __u8 *data, yaffs_ExtendedTags *tags)
81 struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice);
86 loff_t addr = ((loff_t)chunkInNAND) * dev->nBytesPerChunk;
90 T(YAFFS_TRACE_MTD,(TSTR("nandmtd2_ReadChunkWithTagsToNAND chunk %d data %p tags %p" TENDSTR),chunkInNAND,data,tags));
92 #ifndef CONFIG_YAFFS_USE_OLD_MTD
97 retval = mtd->read_ecc(mtd,addr,dev->nBytesPerChunk,&dummy,data,dev->spareBuffer,NULL);
101 retval = mtd->read_ecc(mtd,addr,dev->nBytesPerChunk,&dummy,data,dev->spareBuffer,NULL);
108 retval = mtd->read(mtd,addr,dev->nBytesPerChunk,&dummy,data);
110 retval = mtd->read_oob(mtd,addr,mtd->oobsize,&dummy,dev->spareBuffer);
111 #ifndef CONFIG_YAFFS_USE_OLD_MTD
115 memcpy(&pt,dev->spareBuffer,sizeof(pt));
118 yaffs_UnpackTags2(tags,&pt);
126 int nandmtd2_MarkNANDBlockBad(struct yaffs_DeviceStruct *dev, int blockNo)
128 struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice);
130 T(YAFFS_TRACE_MTD,(TSTR("nandmtd2_MarkNANDBlockBad %d" TENDSTR),blockNo));
133 retval = mtd->block_markbad(mtd,blockNo * dev->nChunksPerBlock * dev->nBytesPerChunk);
142 int nandmtd2_QueryNANDBlock(struct yaffs_DeviceStruct *dev, int blockNo, yaffs_BlockState *state, int *sequenceNumber)
144 struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice);
147 T(YAFFS_TRACE_MTD,(TSTR("nandmtd2_QueryNANDBlock %d" TENDSTR),blockNo));
148 retval = mtd->block_isbad(mtd,blockNo* dev->nChunksPerBlock * dev->nBytesPerChunk);
152 T(YAFFS_TRACE_MTD,(TSTR("block is bad" TENDSTR)));
154 *state = YAFFS_BLOCK_STATE_DEAD;
159 yaffs_ExtendedTags t;
160 nandmtd2_ReadChunkWithTagsFromNAND(dev,blockNo * dev->nChunksPerBlock,NULL, &t);
164 *sequenceNumber = t.sequenceNumber;
165 *state = YAFFS_BLOCK_STATE_NEEDS_SCANNING;
170 *state = YAFFS_BLOCK_STATE_EMPTY;
173 T(YAFFS_TRACE_MTD,(TSTR("block is bad seq %d state %d" TENDSTR), *sequenceNumber,*state));