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 const char *yaffs_mtdif_c_version =
17 "$Id: yaffs_mtdif.c,v 1.13 2005-11-07 07:13:33 charles Exp $";
22 #include "yaffs_mtdif.h"
24 #include "linux/mtd/mtd.h"
25 #include "linux/types.h"
26 #include "linux/time.h"
27 #include "linux/mtd/nand.h"
29 static struct nand_oobinfo yaffs_oobinfo = {
32 .eccpos = {8, 9, 10, 13, 14, 15}
35 static struct nand_oobinfo yaffs_noeccinfo = {
39 int nandmtd_WriteChunkToNAND(yaffs_Device * dev, int chunkInNAND,
40 const __u8 * data, const yaffs_Spare * spare)
42 struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice);
46 loff_t addr = ((loff_t) chunkInNAND) * dev->nBytesPerChunk;
48 __u8 *spareAsBytes = (__u8 *) spare;
53 mtd->write_ecc(mtd, addr, dev->nBytesPerChunk,
54 &dummy, data, spareAsBytes,
58 mtd->write_ecc(mtd, addr, dev->nBytesPerChunk,
59 &dummy, data, spareAsBytes,
64 mtd->write(mtd, addr, dev->nBytesPerChunk, &dummy,
68 mtd->write_oob(mtd, addr, YAFFS_BYTES_PER_SPARE,
69 &dummy, spareAsBytes);
78 int nandmtd_ReadChunkFromNAND(yaffs_Device * dev, int chunkInNAND, __u8 * data,
81 struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice);
85 loff_t addr = ((loff_t) chunkInNAND) * dev->nBytesPerChunk;
87 __u8 *spareAsBytes = (__u8 *) spare;
90 if (dev->useNANDECC) {
91 /* Careful, this call adds 2 ints */
92 /* to the end of the spare data. Calling function */
93 /* should allocate enough memory for spare, */
94 /* i.e. [YAFFS_BYTES_PER_SPARE+2*sizeof(int)]. */
96 mtd->read_ecc(mtd, addr, dev->nBytesPerChunk,
97 &dummy, data, spareAsBytes,
101 mtd->read_ecc(mtd, addr, dev->nBytesPerChunk,
102 &dummy, data, spareAsBytes,
108 mtd->read(mtd, addr, dev->nBytesPerChunk, &dummy,
112 mtd->read_oob(mtd, addr, YAFFS_BYTES_PER_SPARE,
113 &dummy, spareAsBytes);
122 int nandmtd_EraseBlockInNAND(yaffs_Device * dev, int blockNumber)
124 struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice);
126 ((loff_t) blockNumber) * dev->nBytesPerChunk
127 * dev->nChunksPerBlock;
128 struct erase_info ei;
133 ei.len = dev->nBytesPerChunk * dev->nChunksPerBlock;
137 ei.priv = (u_long) dev;
139 /* Todo finish off the ei if required */
141 sema_init(&dev->sem, 0);
143 retval = mtd->erase(mtd, &ei);
151 int nandmtd_InitialiseNAND(yaffs_Device * dev)