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 =
19 "$Id: yaffs_mtdif2.c,v 1.7 2005-08-11 01:07:43 marty Exp $";
23 #ifdef CONFIG_YAFFS_YAFFS1
25 #include "yaffs_mtdif2.h"
27 #include "linux/mtd/mtd.h"
28 #include "linux/types.h"
29 #include "linux/time.h"
31 #include "yaffs_packedtags2.h"
33 int nandmtd2_WriteChunkWithTagsToNAND(yaffs_Device * dev, int chunkInNAND,
35 const yaffs_ExtendedTags * tags)
37 struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice);
41 loff_t addr = ((loff_t) chunkInNAND) * dev->nBytesPerChunk;
47 ("nandmtd2_WriteChunkWithTagsToNAND chunk %d data %p tags %p"
48 TENDSTR), chunkInNAND, data, tags));
51 yaffs_PackTags2(&pt, tags);
57 mtd->write_ecc(mtd, addr, dev->nBytesPerChunk,
58 &dummy, data, (__u8 *) & pt, NULL);
61 mtd->write_ecc(mtd, addr, dev->nBytesPerChunk,
62 &dummy, data, (__u8 *) & pt, NULL);
66 mtd->write(mtd, addr, dev->nBytesPerChunk, &dummy,
70 mtd->write_oob(mtd, addr, mtd->oobsize, &dummy,
81 int nandmtd2_ReadChunkWithTagsFromNAND(yaffs_Device * dev, int chunkInNAND,
82 __u8 * data, yaffs_ExtendedTags * tags)
84 struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice);
88 loff_t addr = ((loff_t) chunkInNAND) * dev->nBytesPerChunk;
94 ("nandmtd2_ReadChunkWithTagsToNAND chunk %d data %p tags %p"
95 TENDSTR), chunkInNAND, data, tags));
98 if (dev->useNANDECC) {
100 mtd->read_ecc(mtd, addr, dev->nBytesPerChunk,
101 &dummy, data, dev->spareBuffer,
105 mtd->read_ecc(mtd, addr, dev->nBytesPerChunk,
106 &dummy, data, dev->spareBuffer,
112 mtd->read(mtd, addr, dev->nBytesPerChunk, &dummy,
116 mtd->read_oob(mtd, addr, mtd->oobsize, &dummy,
120 memcpy(&pt, dev->spareBuffer, sizeof(pt));
123 yaffs_UnpackTags2(tags, &pt);
131 int nandmtd2_MarkNANDBlockBad(struct yaffs_DeviceStruct *dev, int blockNo)
133 struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice);
136 (TSTR("nandmtd2_MarkNANDBlockBad %d" TENDSTR), blockNo));
139 mtd->block_markbad(mtd,
140 blockNo * dev->nChunksPerBlock *
141 dev->nBytesPerChunk);
150 int nandmtd2_QueryNANDBlock(struct yaffs_DeviceStruct *dev, int blockNo,
151 yaffs_BlockState * state, int *sequenceNumber)
153 struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice);
157 (TSTR("nandmtd2_QueryNANDBlock %d" TENDSTR), blockNo));
159 mtd->block_isbad(mtd,
160 blockNo * dev->nChunksPerBlock *
161 dev->nBytesPerChunk);
164 T(YAFFS_TRACE_MTD, (TSTR("block is bad" TENDSTR)));
166 *state = YAFFS_BLOCK_STATE_DEAD;
169 yaffs_ExtendedTags t;
170 nandmtd2_ReadChunkWithTagsFromNAND(dev,
172 dev->nChunksPerBlock, NULL,
176 *sequenceNumber = t.sequenceNumber;
177 *state = YAFFS_BLOCK_STATE_NEEDS_SCANNING;
180 *state = YAFFS_BLOCK_STATE_EMPTY;
184 (TSTR("block is bad seq %d state %d" TENDSTR), *sequenceNumber,