add a workaround preventing libtool from hardcoding library path in shared libs
[openwrt.git] / target / linux / generic-2.6 / files / fs / yaffs2 / yaffs_mtdif2.c
1 /*
2 * YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
3 *
4 * Copyright (C) 2002-2007 Aleph One Ltd.
5 * for Toby Churchill Ltd and Brightstar Engineering
6 *
7 * Created by Charles Manning <charles@aleph1.co.uk>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13
14 /* mtd interface for YAFFS2 */
15
16 const char *yaffs_mtdif2_c_version =
17
18 #include "yportenv.h"
19
20
21 #include "yaffs_mtdif2.h"
22
23 #include "linux/mtd/mtd.h"
24 #include "linux/types.h"
25 #include "linux/time.h"
26
27 #include "yaffs_packedtags2.h"
28
29 int nandmtd2_WriteChunkWithTagsToNAND(yaffs_Device * dev, int chunkInNAND,
30 const __u8 * data,
31 const yaffs_ExtendedTags * tags)
32 {
33 struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice);
34 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17))
35 struct mtd_oob_ops ops;
36 #else
37 size_t dummy;
38 #endif
39 int retval = 0;
40
41 loff_t addr = ((loff_t) chunkInNAND) * dev->nDataBytesPerChunk;
42
43 yaffs_PackedTags2 pt;
44
45 T(YAFFS_TRACE_MTD,
46 (TSTR
47 ("nandmtd2_WriteChunkWithTagsToNAND chunk %d data %p tags %p"
48 TENDSTR), chunkInNAND, data, tags));
49
50 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17))
51 if (tags)
52 yaffs_PackTags2(&pt, tags);
53 else
54 BUG(); /* both tags and data should always be present */
55
56 if (data) {
57 ops.mode = MTD_OOB_AUTO;
58 ops.ooblen = sizeof(pt);
59 ops.len = dev->nDataBytesPerChunk;
60 ops.ooboffs = 0;
61 ops.datbuf = (__u8 *)data;
62 ops.oobbuf = (void *)&pt;
63 retval = mtd->write_oob(mtd, addr, &ops);
64 } else
65 BUG(); /* both tags and data should always be present */
66 #else
67 if (tags) {
68 yaffs_PackTags2(&pt, tags);
69 }
70
71 if (data && tags) {
72 if (dev->useNANDECC)
73 retval =
74 mtd->write_ecc(mtd, addr, dev->nDataBytesPerChunk,
75 &dummy, data, (__u8 *) & pt, NULL);
76 else
77 retval =
78 mtd->write_ecc(mtd, addr, dev->nDataBytesPerChunk,
79 &dummy, data, (__u8 *) & pt, NULL);
80 } else {
81 if (data)
82 retval =
83 mtd->write(mtd, addr, dev->nDataBytesPerChunk, &dummy,
84 data);
85 if (tags)
86 retval =
87 mtd->write_oob(mtd, addr, mtd->oobsize, &dummy,
88 (__u8 *) & pt);
89
90 }
91 #endif
92
93 if (retval == 0)
94 return YAFFS_OK;
95 else
96 return YAFFS_FAIL;
97 }
98
99 int nandmtd2_ReadChunkWithTagsFromNAND(yaffs_Device * dev, int chunkInNAND,
100 __u8 * data, yaffs_ExtendedTags * tags)
101 {
102 struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice);
103 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17))
104 struct mtd_oob_ops ops;
105 #endif
106 size_t dummy;
107 int retval = 0;
108
109 loff_t addr = ((loff_t) chunkInNAND) * dev->nDataBytesPerChunk;
110
111 yaffs_PackedTags2 pt;
112
113 T(YAFFS_TRACE_MTD,
114 (TSTR
115 ("nandmtd2_ReadChunkWithTagsFromNAND chunk %d data %p tags %p"
116 TENDSTR), chunkInNAND, data, tags));
117
118 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17))
119 if (data && !tags)
120 retval = mtd->read(mtd, addr, dev->nDataBytesPerChunk,
121 &dummy, data);
122 else if (tags) {
123 ops.mode = MTD_OOB_AUTO;
124 ops.ooblen = sizeof(pt);
125 ops.len = data ? dev->nDataBytesPerChunk : sizeof(pt);
126 ops.ooboffs = 0;
127 ops.datbuf = data;
128 ops.oobbuf = dev->spareBuffer;
129 retval = mtd->read_oob(mtd, addr, &ops);
130 }
131 #else
132 if (data && tags) {
133 if (dev->useNANDECC) {
134 retval =
135 mtd->read_ecc(mtd, addr, dev->nDataBytesPerChunk,
136 &dummy, data, dev->spareBuffer,
137 NULL);
138 } else {
139 retval =
140 mtd->read_ecc(mtd, addr, dev->nDataBytesPerChunk,
141 &dummy, data, dev->spareBuffer,
142 NULL);
143 }
144 } else {
145 if (data)
146 retval =
147 mtd->read(mtd, addr, dev->nDataBytesPerChunk, &dummy,
148 data);
149 if (tags)
150 retval =
151 mtd->read_oob(mtd, addr, mtd->oobsize, &dummy,
152 dev->spareBuffer);
153 }
154 #endif
155
156 memcpy(&pt, dev->spareBuffer, sizeof(pt));
157
158 if (tags)
159 yaffs_UnpackTags2(tags, &pt);
160
161 if(tags && retval == -EBADMSG && tags->eccResult == YAFFS_ECC_RESULT_NO_ERROR)
162 tags->eccResult = YAFFS_ECC_RESULT_UNFIXED;
163
164 if (retval == 0)
165 return YAFFS_OK;
166 else
167 return YAFFS_FAIL;
168 }
169
170 int nandmtd2_MarkNANDBlockBad(struct yaffs_DeviceStruct *dev, int blockNo)
171 {
172 struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice);
173 int retval;
174 T(YAFFS_TRACE_MTD,
175 (TSTR("nandmtd2_MarkNANDBlockBad %d" TENDSTR), blockNo));
176
177 retval =
178 mtd->block_markbad(mtd,
179 blockNo * dev->nChunksPerBlock *
180 dev->nDataBytesPerChunk);
181
182 if (retval == 0)
183 return YAFFS_OK;
184 else
185 return YAFFS_FAIL;
186
187 }
188
189 int nandmtd2_QueryNANDBlock(struct yaffs_DeviceStruct *dev, int blockNo,
190 yaffs_BlockState * state, int *sequenceNumber)
191 {
192 struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice);
193 int retval;
194
195 T(YAFFS_TRACE_MTD,
196 (TSTR("nandmtd2_QueryNANDBlock %d" TENDSTR), blockNo));
197 retval =
198 mtd->block_isbad(mtd,
199 blockNo * dev->nChunksPerBlock *
200 dev->nDataBytesPerChunk);
201
202 if (retval) {
203 T(YAFFS_TRACE_MTD, (TSTR("block is bad" TENDSTR)));
204
205 *state = YAFFS_BLOCK_STATE_DEAD;
206 *sequenceNumber = 0;
207 } else {
208 yaffs_ExtendedTags t;
209 nandmtd2_ReadChunkWithTagsFromNAND(dev,
210 blockNo *
211 dev->nChunksPerBlock, NULL,
212 &t);
213
214 if (t.chunkUsed) {
215 *sequenceNumber = t.sequenceNumber;
216 *state = YAFFS_BLOCK_STATE_NEEDS_SCANNING;
217 } else {
218 *sequenceNumber = 0;
219 *state = YAFFS_BLOCK_STATE_EMPTY;
220 }
221 }
222 T(YAFFS_TRACE_MTD,
223 (TSTR("block is bad seq %d state %d" TENDSTR), *sequenceNumber,
224 *state));
225
226 if (retval == 0)
227 return YAFFS_OK;
228 else
229 return YAFFS_FAIL;
230 }
231
This page took 0.048488 seconds and 5 git commands to generate.