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