summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/yaffs2/files/yaffs2-unioob.patch
blob: c894528ca141a9261790137f5c47e6209bc62a50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
diff -urN yaffs2.orig/yaffs_mtdif2.c yaffs2/yaffs_mtdif2.c
--- yaffs2.orig/yaffs_mtdif2.c	2005-12-07 14:00:38.000000000 -0800
+++ yaffs2/yaffs_mtdif2.c	2006-02-10 17:13:58.000000000 -0800
@@ -29,6 +29,130 @@
 
 #include "yaffs_packedtags2.h"
 
+#define PT2_BYTES		25
+
+void nandmtd2_pt2buf(yaffs_Device *dev, yaffs_PackedTags2 *pt, int is_raw)
+{
+	struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice);
+	int	i, j = 0, k, n;
+	__u8	pt2_byte_buf[PT2_BYTES];
+	
+	/* Pack buffer with 0xff */
+	for (i = 0; i < mtd->oobsize; i++)
+		dev->spareBuffer[i] = 0xff;
+		
+	if (!is_raw) {
+		*((unsigned int *) &dev->spareBuffer[0]) = pt->t.sequenceNumber;
+		*((unsigned int *) &dev->spareBuffer[4]) = pt->t.objectId;
+		*((unsigned int *) &dev->spareBuffer[8]) = pt->t.chunkId;
+		*((unsigned int *) &dev->spareBuffer[12]) = pt->t.byteCount;
+		dev->spareBuffer[16] = pt->ecc.colParity;
+		dev->spareBuffer[17] = pt->ecc.lineParity & 0xff;
+		dev->spareBuffer[18] = (pt->ecc.lineParity >> 8) & 0xff;
+		dev->spareBuffer[19] = (pt->ecc.lineParity >> 16) & 0xff;
+		dev->spareBuffer[20] = (pt->ecc.lineParity >> 24) & 0xff;
+		dev->spareBuffer[21] = pt->ecc.lineParityPrime & 0xff;
+		dev->spareBuffer[22] = (pt->ecc.lineParityPrime >> 8) & 0xff;
+		dev->spareBuffer[23] = (pt->ecc.lineParityPrime >> 16) & 0xff;
+		dev->spareBuffer[24] = (pt->ecc.lineParityPrime >> 24) & 0xff;
+	} else {
+		*((unsigned int *) &pt2_byte_buf[0]) = pt->t.sequenceNumber;
+		*((unsigned int *) &pt2_byte_buf[4]) = pt->t.objectId;
+		*((unsigned int *) &pt2_byte_buf[8]) = pt->t.chunkId;
+		*((unsigned int *) &pt2_byte_buf[12]) = pt->t.byteCount;
+		pt2_byte_buf[16] = pt->ecc.colParity;
+		pt2_byte_buf[17] = pt->ecc.lineParity & 0xff;
+		pt2_byte_buf[18] = (pt->ecc.lineParity >> 8) & 0xff;
+		pt2_byte_buf[19] = (pt->ecc.lineParity >> 16) & 0xff;
+		pt2_byte_buf[20] = (pt->ecc.lineParity >> 24) & 0xff;
+		pt2_byte_buf[21] = pt->ecc.lineParityPrime & 0xff;
+		pt2_byte_buf[22] = (pt->ecc.lineParityPrime >> 8) & 0xff;
+		pt2_byte_buf[23] = (pt->ecc.lineParityPrime >> 16) & 0xff;
+		pt2_byte_buf[24] = (pt->ecc.lineParityPrime >> 24) & 0xff;
+
+		k = mtd->oobinfo.oobfree[j][0];
+		n = mtd->oobinfo.oobfree[j][1];
+		
+		if (n == 0) {
+			T(YAFFS_TRACE_ERROR, (TSTR("No OOB space for tags" TENDSTR)));
+			YBUG();
+		}
+                                
+		for (i = 0; i < PT2_BYTES; i++) {
+			if (n == 0) {
+				j++;
+				k = mtd->oobinfo.oobfree[j][0];
+				n = mtd->oobinfo.oobfree[j][1];
+				if (n == 0) {
+					T(YAFFS_TRACE_ERROR, (TSTR("No OOB space for tags" TENDSTR)));
+					YBUG();
+				}
+			}
+			dev->spareBuffer[k++] = pt2_byte_buf[i];
+			n--;
+		}
+	}
+}
+
+void nandmtd2_buf2pt(yaffs_Device *dev, yaffs_PackedTags2 *pt, int is_raw)
+{
+	struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice);
+	int	i, j = 0, k, n;
+	__u8	pt2_byte_buf[PT2_BYTES];
+	
+
+	if (!is_raw) {
+		pt->t.sequenceNumber = *((unsigned int *) &dev->spareBuffer[0]);
+		pt->t.objectId = *((unsigned int *) &dev->spareBuffer[4]);
+		pt->t.chunkId = *((unsigned int *) &dev->spareBuffer[8]);
+		pt->t.byteCount = *((unsigned int *) &dev->spareBuffer[12]);
+		pt->ecc.colParity = dev->spareBuffer[16];
+		pt->ecc.lineParity = (dev->spareBuffer[17] & 0x000000ff) |
+	 		((dev->spareBuffer[18] << 8) & 0x0000ff00) |
+	 		((dev->spareBuffer[19] << 16) & 0x00ff0000) |
+	 		((dev->spareBuffer[20] << 24) & 0xff000000);
+		pt->ecc.lineParityPrime = (dev->spareBuffer[21] & 0x000000ff) |
+	 		((dev->spareBuffer[22] << 8) & 0x0000ff00) |
+	 		((dev->spareBuffer[23] << 16) & 0x00ff0000) |
+	 		((dev->spareBuffer[24] << 24) & 0xff000000);
+	} else {
+		k = mtd->oobinfo.oobfree[j][0];
+		n = mtd->oobinfo.oobfree[j][1];
+		
+		if (n == 0) {
+			T(YAFFS_TRACE_ERROR, (TSTR("No space in OOB for tags" TENDSTR)));
+			YBUG();
+		}
+                                
+		for (i = 0; i < PT2_BYTES; i++) {
+			if (n == 0) {
+				j++;
+				k = mtd->oobinfo.oobfree[j][0];
+				n = mtd->oobinfo.oobfree[j][1];
+				if (n == 0) {
+					T(YAFFS_TRACE_ERROR, (TSTR("No space in OOB for tags" TENDSTR)));
+					YBUG();
+				}
+			}
+			pt2_byte_buf[i] = dev->spareBuffer[k++];
+			n--;
+		}
+		pt->t.sequenceNumber = *((unsigned int *) &pt2_byte_buf[0]);
+		pt->t.objectId = *((unsigned int *) &pt2_byte_buf[4]);
+		pt->t.chunkId = *((unsigned int *) &pt2_byte_buf[8]);
+		pt->t.byteCount = *((unsigned int *) &pt2_byte_buf[12]);
+		pt->ecc.colParity = pt2_byte_buf[16];
+		pt->ecc.lineParity = (pt2_byte_buf[17] & 0x000000ff) |
+	 		((pt2_byte_buf[18] << 8) & 0x0000ff00) |
+	 		((pt2_byte_buf[19] << 16) & 0x00ff0000) |
+	 		((pt2_byte_buf[20] << 24) & 0xff000000);
+		pt->ecc.lineParityPrime = (pt2_byte_buf[21] & 0x000000ff) |
+	 		((pt2_byte_buf[22] << 8) & 0x0000ff00) |
+	 		((pt2_byte_buf[23] << 16) & 0x00ff0000) |
+	 		((pt2_byte_buf[24] << 24) & 0xff000000);
+	}
+}
+
 int nandmtd2_WriteChunkWithTagsToNAND(yaffs_Device * dev, int chunkInNAND,
 				      const __u8 * data,
 				      const yaffs_ExtendedTags * tags)
@@ -51,24 +175,22 @@
 	}
 
 	if (data && tags) {
-		if (dev->useNANDECC)
-			retval =
-			    mtd->write_ecc(mtd, addr, dev->nBytesPerChunk,
-					   &dummy, data, (__u8 *) & pt, NULL);
-		else
+			nandmtd2_pt2buf(dev, &pt, 0);
 			retval =
 			    mtd->write_ecc(mtd, addr, dev->nBytesPerChunk,
-					   &dummy, data, (__u8 *) & pt, NULL);
+					   &dummy, data, dev->spareBuffer,
+					   NULL);
 	} else {
 		if (data)
 			retval =
 			    mtd->write(mtd, addr, dev->nBytesPerChunk, &dummy,
 				       data);
-		if (tags)
+		if (tags) {
+			nandmtd2_pt2buf(dev, &pt, 1);
 			retval =
 			    mtd->write_oob(mtd, addr, mtd->oobsize, &dummy,
-					   (__u8 *) & pt);
-
+			    dev->spareBuffer);
+		}
 	}
 
 	if (retval == 0)
@@ -94,30 +216,24 @@
 	    TENDSTR), chunkInNAND, data, tags));
 
 	if (data && tags) {
-		if (dev->useNANDECC) {
 			retval =
 			    mtd->read_ecc(mtd, addr, dev->nBytesPerChunk,
 					  &dummy, data, dev->spareBuffer,
 					  NULL);
-		} else {
-			retval =
-			    mtd->read_ecc(mtd, addr, dev->nBytesPerChunk,
-					  &dummy, data, dev->spareBuffer,
-					  NULL);
-		}
+			nandmtd2_buf2pt(dev, &pt, 0);
 	} else {
 		if (data)
 			retval =
 			    mtd->read(mtd, addr, dev->nBytesPerChunk, &dummy,
 				      data);
-		if (tags)
+		if (tags) {
 			retval =
 			    mtd->read_oob(mtd, addr, mtd->oobsize, &dummy,
 					  dev->spareBuffer);
+			nandmtd2_buf2pt(dev, &pt, 1);
+		}
 	}
 
-	memcpy(&pt, dev->spareBuffer, sizeof(pt));
-
 	if (tags)
 		yaffs_UnpackTags2(tags, &pt);
 
@@ -178,10 +294,11 @@
 			*sequenceNumber = 0;
 			*state = YAFFS_BLOCK_STATE_EMPTY;
 		}
+
+		T(YAFFS_TRACE_MTD,
+		  (TSTR("block is OK seq %d state %d" TENDSTR), *sequenceNumber,
+		   *state));
 	}
-	T(YAFFS_TRACE_MTD,
-	  (TSTR("block is bad seq %d state %d" TENDSTR), *sequenceNumber,
-	   *state));
 
 	if (retval == 0)
 		return YAFFS_OK;