summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/yaffs2/files/mkyaffs2image.patch
diff options
context:
space:
mode:
authorSaul Wold <sgw@linux.intel.com>2011-05-13 17:43:12 -0700
committerRichard Purdie <richard.purdie@linuxfoundation.org>2011-05-18 14:32:43 +0100
commit7aabd71d0a84c689f747eab95a4e8370ff35889f (patch)
tree92d8755f82486ce9527b92437106982b3d691062 /meta/recipes-devtools/yaffs2/files/mkyaffs2image.patch
parent8fdd65f9977e5dc46bba208b9085a0b14ed7098b (diff)
downloadpoky-7aabd71d0a84c689f747eab95a4e8370ff35889f.tar.gz
yaffs2: Remove yaffs2 from oe-core
Move to meta-extras Also remove yaffs2 from image_types.bbclass (From OE-Core rev: 6a97657ae834945ae26e5933d29bd94d0f7fea67) Signed-off-by: Saul Wold <sgw@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/recipes-devtools/yaffs2/files/mkyaffs2image.patch')
-rw-r--r--meta/recipes-devtools/yaffs2/files/mkyaffs2image.patch351
1 files changed, 0 insertions, 351 deletions
diff --git a/meta/recipes-devtools/yaffs2/files/mkyaffs2image.patch b/meta/recipes-devtools/yaffs2/files/mkyaffs2image.patch
deleted file mode 100644
index e78b350377..0000000000
--- a/meta/recipes-devtools/yaffs2/files/mkyaffs2image.patch
+++ /dev/null
@@ -1,351 +0,0 @@
1Upstream-Status: Backport
2
3 *
4 * mkyaffs2image hacks by NCB
5 *
6 * Changes by Sergey Kubushin flagged KSI
7 *
8 */
9
10/* KSI:
11 * All this nightmare should be rewritten from ground up. Why save return
12 * values if nobody checks them? The read/write function returns only one
13 * error, -1. Positive return value does NOT mean read/write operation has
14 * been completed successfully. If somebody opens files, he MUST close them
15 * when they are not longer needed. Only those brave enough can write 64
16 * bytes from a yaffs_PackedTags2 structure. The list is too long, there is
17 * enough bugs here to write a couple of thick books on how NOT to write
18 * programs...
19 *
20 * And BTW, what was one supposed to do with that file that this horror
21 * occasionally managed to generate?
22 */
23Index: yaffs2/utils/mkyaffs2image.c
24===================================================================
25--- yaffs2.orig/utils/mkyaffs2image.c 2010-01-11 13:43:18.000000000 -0800
26+++ yaffs2/utils/mkyaffs2image.c 2011-05-04 14:50:42.045984700 -0700
27@@ -29,10 +29,10 @@
28 #include <dirent.h>
29 #include <string.h>
30 #include <unistd.h>
31+#include <mtd/mtd-user.h>
32 #include "yaffs_ecc.h"
33 #include "yaffs_guts.h"
34
35-#include "yaffs_tagsvalidity.h"
36 #include "yaffs_packedtags2.h"
37
38 unsigned yaffs_traceMask=0;
39@@ -41,9 +41,47 @@
40
41 #define chunkSize 2048
42 #define spareSize 64
43+#define PT2_BYTES 25
44+
45
46 const char * mkyaffsimage_c_version = "$Id: mkyaffs2image.c,v 1.5 2010-01-11 21:43:18 charles Exp $";
47
48+static int layout_no;
49+
50+static struct nand_oobinfo oob_layout[] = {
51+ /* KSI:
52+ * Dummy "raw" layout - no ECC, all the bytes are free. Does NOT
53+ * really work, only used for compatibility with CVS YAFFS2 that
54+ * never ever worked with any stock MTD.
55+ */
56+ {
57+ .useecc = MTD_NANDECC_AUTOPLACE,
58+ .eccbytes = 0,
59+ .eccpos = {},
60+ .oobfree = { {0, 64} }
61+ },
62+ /* KSI:
63+ * Regular MTD AUTOPLACED ECC for large page NAND devices, the
64+ * only one existing in stock MTD so far. It corresponds to layout# 1
65+ * in command line arguments. Any other layouts could be added to
66+ * the list when they made their way in kernel's MTD. The structure
67+ * is simply copied from kernel's drivers/mtd/nand/nand_base.c as-is.
68+ */
69+ {
70+ .useecc = MTD_NANDECC_AUTOPLACE,
71+ .eccbytes = 24,
72+ .eccpos = {
73+ 40, 41, 42, 43, 44, 45, 46, 47,
74+ 48, 49, 50, 51, 52, 53, 54, 55,
75+ 56, 57, 58, 59, 60, 61, 62, 63},
76+ .oobfree = { {2, 38} }
77+ },
78+ /* End-of-list marker */
79+ {
80+ .useecc = -1,
81+ }
82+};
83+
84
85 typedef struct
86 {
87@@ -57,7 +95,7 @@
88 static int n_obj = 0;
89 static int obj_id = YAFFS_NOBJECT_BUCKETS + 1;
90
91-static int nObjects, nDirectories, nPages;
92+static int nObjects = 0, nDirectories = 0, nPages = 0;
93
94 static int outFile;
95
96@@ -121,6 +159,11 @@
97 return -1;
98 }
99
100+/* KSI:
101+ * No big endian for now. This is left for a later time. The existing code
102+ * is FUBAR.
103+ */
104+#if 0
105 /* This little function converts a little endian tag to a big endian tag.
106 * NOTE: The tag is not usable after this other than calculating the CRC
107 * with.
108@@ -153,11 +196,56 @@
109 tags->asBytes[7] = temp.asBytes[7];
110 #endif
111 }
112+#endif
113+
114+void nandmtd2_pt2buf(unsigned char *buf, yaffs_PackedTags2 *pt)
115+{
116+ int i, j = 0, k, n;
117+ unsigned char pt2_byte_buf[PT2_BYTES];
118+
119+ *((unsigned int *) &pt2_byte_buf[0]) = pt->t.sequenceNumber;
120+ *((unsigned int *) &pt2_byte_buf[4]) = pt->t.objectId;
121+ *((unsigned int *) &pt2_byte_buf[8]) = pt->t.chunkId;
122+ *((unsigned int *) &pt2_byte_buf[12]) = pt->t.byteCount;
123+ pt2_byte_buf[16] = pt->ecc.colParity;
124+ pt2_byte_buf[17] = pt->ecc.lineParity & 0xff;
125+ pt2_byte_buf[18] = (pt->ecc.lineParity >> 8) & 0xff;
126+ pt2_byte_buf[19] = (pt->ecc.lineParity >> 16) & 0xff;
127+ pt2_byte_buf[20] = (pt->ecc.lineParity >> 24) & 0xff;
128+ pt2_byte_buf[21] = pt->ecc.lineParityPrime & 0xff;
129+ pt2_byte_buf[22] = (pt->ecc.lineParityPrime >> 8) & 0xff;
130+ pt2_byte_buf[23] = (pt->ecc.lineParityPrime >> 16) & 0xff;
131+ pt2_byte_buf[24] = (pt->ecc.lineParityPrime >> 24) & 0xff;
132+
133+ k = oob_layout[layout_no].oobfree[j][0];
134+ n = oob_layout[layout_no].oobfree[j][1];
135+
136+ if (n == 0) {
137+ fprintf(stderr, "No OOB space for tags");
138+ exit(-1);
139+ }
140+
141+ for (i = 0; i < PT2_BYTES; i++) {
142+ if (n == 0) {
143+ j++;
144+ k = oob_layout[layout_no].oobfree[j][0];
145+ n = oob_layout[layout_no].oobfree[j][1];
146+ if (n == 0) {
147+ fprintf(stderr, "No OOB space for tags");
148+ exit(-1);
149+ }
150+ }
151+ buf[k++] = pt2_byte_buf[i];
152+ n--;
153+ }
154+}
155
156 static int write_chunk(__u8 *data, __u32 objId, __u32 chunkId, __u32 nBytes)
157 {
158 yaffs_ExtendedTags t;
159 yaffs_PackedTags2 pt;
160+ unsigned char spare_buf[spareSize];
161+
162
163 error = write(outFile,data,chunkSize);
164 if(error < 0) return error;
165@@ -175,18 +263,28 @@
166 // added NCB **CHECK**
167 t.chunkUsed = 1;
168
169+/* KSI: Broken anyway -- e.g. &t is pointer to a wrong type... */
170+#if 0
171 if (convert_endian)
172 {
173 little_to_big_endian(&t);
174 }
175+#endif
176
177 nPages++;
178
179 yaffs_PackTags2(&pt,&t,1);
180-
181-// return write(outFile,&pt,sizeof(yaffs_PackedTags2));
182- return write(outFile,&pt,spareSize);
183-
184+
185+ memset(spare_buf, 0xff, sizeof(spare_buf));
186+
187+ if (layout_no == 0) {
188+ memcpy(spare_buf, &pt, sizeof(yaffs_PackedTags2));
189+ } else {
190+ nandmtd2_pt2buf(spare_buf, &pt);
191+ }
192+
193+ return write(outFile,spare_buf,spareSize);
194+
195 }
196
197 #define SWAP32(x) ((((x) & 0x000000FF) << 24) | \
198@@ -197,6 +295,8 @@
199 #define SWAP16(x) ((((x) & 0x00FF) << 8) | \
200 (((x) & 0xFF00) >> 8))
201
202+/* KSI: Removed for now. TBD later when the proper util (from scratch) is written */
203+#if 0
204 // This one is easier, since the types are more standard. No funky shifts here.
205 static void object_header_little_to_big_endian(yaffs_ObjectHeader* oh)
206 {
207@@ -254,6 +354,7 @@
208 oh->roomToGrow[11] = SWAP32(oh->roomToGrow[11]);
209 #endif
210 }
211+#endif
212
213 static int write_object_header(int objId, yaffs_ObjectType t, struct stat *s, int parent, const char *name, int equivalentObj, const char * alias)
214 {
215@@ -298,10 +399,13 @@
216 strncpy(oh->alias,alias,YAFFS_MAX_ALIAS_LENGTH);
217 }
218
219+/* KSI: FUBAR. Left for a leter time. */
220+#if 0
221 if (convert_endian)
222 {
223 object_header_little_to_big_endian(oh);
224 }
225+#endif
226
227 return write_chunk(bytes,objId,0,0xffff);
228
229@@ -317,7 +421,7 @@
230 nDirectories++;
231
232 dir = opendir(path);
233-
234+
235 if(dir)
236 {
237 while((entry = readdir(dir)) != NULL)
238@@ -401,12 +505,12 @@
239 error = nBytes;
240
241 printf("%d data chunks written\n",chunk);
242+ close(h);
243 }
244 else
245 {
246 perror("Error opening file");
247 }
248- close(h);
249
250 }
251
252@@ -446,58 +550,82 @@
253 }
254 }
255 }
256+ /* KSI:
257+ * Who is supposed to close those open directories in this
258+ * recursive function, lord Byron? Stock "ulimit -n" is 1024
259+ * and e.g. stock Fedora /etc directory has more that 1024
260+ * directories...
261+ */
262+ closedir(dir);
263 }
264
265 return 0;
266
267 }
268
269+void usage(void)
270+{
271+ printf("usage: mkyaffs2image layout# dir image_file [convert]\n");
272+ printf(" layout# NAND OOB layout # (0 - raw, 1 - nand_oob_64)\n");
273+ printf(" dir the directory tree to be converted\n");
274+ printf(" image_file the output file to hold the image\n");
275+ printf(" 'convert' make a big-endian img on a little-endian machine. BROKEN !\n");
276+ exit(1);
277+}
278
279 int main(int argc, char *argv[])
280 {
281 struct stat stats;
282+ int i;
283
284 printf("mkyaffs2image: image building tool for YAFFS2 built "__DATE__"\n");
285
286- if(argc < 3)
287+ if ((argc < 4) || (sscanf(argv[1], "%u", &layout_no) != 1))
288 {
289- printf("usage: mkyaffs2image dir image_file [convert]\n");
290- printf(" dir the directory tree to be converted\n");
291- printf(" image_file the output file to hold the image\n");
292- printf(" 'convert' produce a big-endian image from a little-endian machine\n");
293- exit(1);
294+ usage();
295 }
296
297- if ((argc == 4) && (!strncmp(argv[3], "convert", strlen("convert"))))
298- {
299- convert_endian = 1;
300- }
301+ i = 0;
302+
303+ while (oob_layout[i].useecc != -1)
304+ i++;
305+
306+ if (layout_no >= i)
307+ usage();
308+
309+ if ((argc == 5) && (!strncmp(argv[4], "convert", strlen("convert"))))
310+ {
311+ /* KSI: Broken as of now. TBD. Fail. */
312+ usage();
313+ convert_endian = 1;
314+ }
315
316- if(stat(argv[1],&stats) < 0)
317+ if(stat(argv[2],&stats) < 0)
318 {
319- printf("Could not stat %s\n",argv[1]);
320+ printf("Could not stat %s\n",argv[2]);
321 exit(1);
322 }
323
324 if(!S_ISDIR(stats.st_mode))
325 {
326- printf(" %s is not a directory\n",argv[1]);
327+ printf(" %s is not a directory\n",argv[2]);
328 exit(1);
329 }
330
331- outFile = open(argv[2],O_CREAT | O_TRUNC | O_WRONLY, S_IREAD | S_IWRITE);
332+ outFile = open(argv[3],O_CREAT | O_TRUNC | O_WRONLY, S_IREAD | S_IWRITE);
333
334
335 if(outFile < 0)
336 {
337- printf("Could not open output file %s\n",argv[2]);
338+ printf("Could not open output file %s\n",argv[3]);
339 exit(1);
340 }
341
342- printf("Processing directory %s into image file %s\n",argv[1],argv[2]);
343+ printf("Processing directory %s into image file %s\n",argv[2],argv[3]);
344 error = write_object_header(1, YAFFS_OBJECT_TYPE_DIRECTORY, &stats, 1,"", -1, NULL);
345+
346 if(error)
347- error = process_directory(YAFFS_OBJECTID_ROOT,argv[1]);
348+ error = process_directory(YAFFS_OBJECTID_ROOT,argv[2]);
349
350 close(outFile);
351