]>
Commit | Line | Data |
---|---|---|
d7e8ce10 KP |
1 | /* |
2 | * U-Boot command for OneNAND support | |
3 | * | |
c438ea17 | 4 | * Copyright (C) 2005-2008 Samsung Electronics |
d7e8ce10 KP |
5 | * Kyungmin Park <[email protected]> |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License version 2 as | |
9 | * published by the Free Software Foundation. | |
10 | */ | |
11 | ||
12 | #include <common.h> | |
13 | #include <command.h> | |
c438ea17 | 14 | #include <malloc.h> |
d7e8ce10 | 15 | |
7b15e2bb | 16 | #include <linux/compat.h> |
d7e8ce10 KP |
17 | #include <linux/mtd/mtd.h> |
18 | #include <linux/mtd/onenand.h> | |
19 | ||
20 | #include <asm/io.h> | |
21 | ||
c438ea17 SR |
22 | static struct mtd_info *mtd; |
23 | ||
24 | static loff_t next_ofs; | |
25 | static loff_t skip_ofs; | |
26 | ||
09c32807 HS |
27 | static int arg_off_size_onenand(int argc, char * const argv[], ulong *off, |
28 | size_t *size) | |
c438ea17 SR |
29 | { |
30 | if (argc >= 1) { | |
31 | if (!(str2long(argv[0], off))) { | |
32 | printf("'%s' is not a number\n", argv[0]); | |
33 | return -1; | |
34 | } | |
35 | } else { | |
36 | *off = 0; | |
37 | } | |
38 | ||
39 | if (argc >= 2) { | |
40 | if (!(str2long(argv[1], (ulong *)size))) { | |
41 | printf("'%s' is not a number\n", argv[1]); | |
42 | return -1; | |
43 | } | |
44 | } else { | |
45 | *size = mtd->size - *off; | |
46 | } | |
47 | ||
48 | if ((*off + *size) > mtd->size) { | |
8d2effea | 49 | printf("total chip size (0x%llx) exceeded!\n", mtd->size); |
c438ea17 SR |
50 | return -1; |
51 | } | |
52 | ||
53 | if (*size == mtd->size) | |
54 | puts("whole chip\n"); | |
55 | else | |
56 | printf("offset 0x%lx, size 0x%x\n", *off, *size); | |
57 | ||
58 | return 0; | |
59 | } | |
60 | ||
61 | static int onenand_block_read(loff_t from, size_t len, | |
62 | size_t *retlen, u_char *buf, int oob) | |
63 | { | |
64 | struct onenand_chip *this = mtd->priv; | |
65 | int blocks = (int) len >> this->erase_shift; | |
66 | int blocksize = (1 << this->erase_shift); | |
67 | loff_t ofs = from; | |
68 | struct mtd_oob_ops ops = { | |
69 | .retlen = 0, | |
70 | }; | |
71 | int ret; | |
72 | ||
73 | if (oob) | |
74 | ops.ooblen = blocksize; | |
75 | else | |
76 | ops.len = blocksize; | |
77 | ||
78 | while (blocks) { | |
dfe64e2c | 79 | ret = mtd_block_isbad(mtd, ofs); |
c438ea17 SR |
80 | if (ret) { |
81 | printk("Bad blocks %d at 0x%x\n", | |
82 | (u32)(ofs >> this->erase_shift), (u32)ofs); | |
83 | ofs += blocksize; | |
84 | continue; | |
85 | } | |
86 | ||
87 | if (oob) | |
88 | ops.oobbuf = buf; | |
89 | else | |
90 | ops.datbuf = buf; | |
91 | ||
92 | ops.retlen = 0; | |
dfe64e2c | 93 | ret = mtd_read_oob(mtd, ofs, &ops); |
c438ea17 SR |
94 | if (ret) { |
95 | printk("Read failed 0x%x, %d\n", (u32)ofs, ret); | |
96 | ofs += blocksize; | |
97 | continue; | |
98 | } | |
99 | ofs += blocksize; | |
100 | buf += blocksize; | |
101 | blocks--; | |
102 | *retlen += ops.retlen; | |
103 | } | |
104 | ||
105 | return 0; | |
106 | } | |
107 | ||
41c86240 LW |
108 | static int onenand_write_oneblock_withoob(loff_t to, const u_char * buf, |
109 | size_t *retlen) | |
110 | { | |
111 | struct mtd_oob_ops ops = { | |
112 | .len = mtd->writesize, | |
113 | .ooblen = mtd->oobsize, | |
dfe64e2c | 114 | .mode = MTD_OPS_AUTO_OOB, |
41c86240 LW |
115 | }; |
116 | int page, ret = 0; | |
117 | for (page = 0; page < (mtd->erasesize / mtd->writesize); page ++) { | |
118 | ops.datbuf = (u_char *)buf; | |
119 | buf += mtd->writesize; | |
120 | ops.oobbuf = (u_char *)buf; | |
121 | buf += mtd->oobsize; | |
dfe64e2c | 122 | ret = mtd_write_oob(mtd, to, &ops); |
41c86240 LW |
123 | if (ret) |
124 | break; | |
125 | to += mtd->writesize; | |
126 | } | |
127 | ||
128 | *retlen = (ret) ? 0 : mtd->erasesize; | |
129 | return ret; | |
130 | } | |
131 | ||
c438ea17 | 132 | static int onenand_block_write(loff_t to, size_t len, |
41c86240 | 133 | size_t *retlen, const u_char * buf, int withoob) |
c438ea17 SR |
134 | { |
135 | struct onenand_chip *this = mtd->priv; | |
136 | int blocks = len >> this->erase_shift; | |
137 | int blocksize = (1 << this->erase_shift); | |
138 | loff_t ofs; | |
139 | size_t _retlen = 0; | |
140 | int ret; | |
141 | ||
9c00d982 LM |
142 | if ((to & (mtd->writesize - 1)) != 0) { |
143 | printf("Attempt to write non block-aligned data\n"); | |
144 | *retlen = 0; | |
145 | return 1; | |
146 | } | |
147 | ||
c438ea17 SR |
148 | if (to == next_ofs) { |
149 | next_ofs = to + len; | |
150 | to += skip_ofs; | |
151 | } else { | |
152 | next_ofs = to + len; | |
153 | skip_ofs = 0; | |
154 | } | |
155 | ofs = to; | |
156 | ||
157 | while (blocks) { | |
dfe64e2c | 158 | ret = mtd_block_isbad(mtd, ofs); |
c438ea17 SR |
159 | if (ret) { |
160 | printk("Bad blocks %d at 0x%x\n", | |
161 | (u32)(ofs >> this->erase_shift), (u32)ofs); | |
162 | skip_ofs += blocksize; | |
163 | goto next; | |
164 | } | |
165 | ||
41c86240 | 166 | if (!withoob) |
dfe64e2c | 167 | ret = mtd_write(mtd, ofs, blocksize, &_retlen, buf); |
41c86240 LW |
168 | else |
169 | ret = onenand_write_oneblock_withoob(ofs, buf, &_retlen); | |
c438ea17 SR |
170 | if (ret) { |
171 | printk("Write failed 0x%x, %d", (u32)ofs, ret); | |
172 | skip_ofs += blocksize; | |
173 | goto next; | |
174 | } | |
175 | ||
176 | buf += blocksize; | |
177 | blocks--; | |
178 | *retlen += _retlen; | |
179 | next: | |
180 | ofs += blocksize; | |
181 | } | |
182 | ||
183 | return 0; | |
184 | } | |
185 | ||
186 | static int onenand_block_erase(u32 start, u32 size, int force) | |
187 | { | |
188 | struct onenand_chip *this = mtd->priv; | |
189 | struct erase_info instr = { | |
190 | .callback = NULL, | |
191 | }; | |
192 | loff_t ofs; | |
193 | int ret; | |
194 | int blocksize = 1 << this->erase_shift; | |
195 | ||
196 | for (ofs = start; ofs < (start + size); ofs += blocksize) { | |
dfe64e2c | 197 | ret = mtd_block_isbad(mtd, ofs); |
c438ea17 SR |
198 | if (ret && !force) { |
199 | printf("Skip erase bad block %d at 0x%x\n", | |
200 | (u32)(ofs >> this->erase_shift), (u32)ofs); | |
201 | continue; | |
202 | } | |
203 | ||
204 | instr.addr = ofs; | |
205 | instr.len = blocksize; | |
206 | instr.priv = force; | |
207 | instr.mtd = mtd; | |
dfe64e2c | 208 | ret = mtd_erase(mtd, &instr); |
c438ea17 SR |
209 | if (ret) { |
210 | printf("erase failed block %d at 0x%x\n", | |
211 | (u32)(ofs >> this->erase_shift), (u32)ofs); | |
212 | continue; | |
213 | } | |
214 | } | |
215 | ||
216 | return 0; | |
217 | } | |
218 | ||
219 | static int onenand_block_test(u32 start, u32 size) | |
220 | { | |
221 | struct onenand_chip *this = mtd->priv; | |
222 | struct erase_info instr = { | |
223 | .callback = NULL, | |
224 | .priv = 0, | |
225 | }; | |
226 | ||
227 | int blocks; | |
228 | loff_t ofs; | |
229 | int blocksize = 1 << this->erase_shift; | |
230 | int start_block, end_block; | |
231 | size_t retlen; | |
232 | u_char *buf; | |
233 | u_char *verify_buf; | |
234 | int ret; | |
235 | ||
236 | buf = malloc(blocksize); | |
237 | if (!buf) { | |
238 | printf("Not enough malloc space available!\n"); | |
239 | return -1; | |
240 | } | |
241 | ||
242 | verify_buf = malloc(blocksize); | |
243 | if (!verify_buf) { | |
244 | printf("Not enough malloc space available!\n"); | |
245 | return -1; | |
246 | } | |
247 | ||
248 | start_block = start >> this->erase_shift; | |
249 | end_block = (start + size) >> this->erase_shift; | |
250 | ||
251 | /* Protect boot-loader from badblock testing */ | |
252 | if (start_block < 2) | |
253 | start_block = 2; | |
254 | ||
255 | if (end_block > (mtd->size >> this->erase_shift)) | |
256 | end_block = mtd->size >> this->erase_shift; | |
257 | ||
258 | blocks = start_block; | |
259 | ofs = start; | |
260 | while (blocks < end_block) { | |
261 | printf("\rTesting block %d at 0x%x", (u32)(ofs >> this->erase_shift), (u32)ofs); | |
262 | ||
dfe64e2c | 263 | ret = mtd_block_isbad(mtd, ofs); |
c438ea17 SR |
264 | if (ret) { |
265 | printf("Skip erase bad block %d at 0x%x\n", | |
266 | (u32)(ofs >> this->erase_shift), (u32)ofs); | |
267 | goto next; | |
268 | } | |
269 | ||
270 | instr.addr = ofs; | |
271 | instr.len = blocksize; | |
dfe64e2c | 272 | ret = mtd_erase(mtd, &instr); |
c438ea17 SR |
273 | if (ret) { |
274 | printk("Erase failed 0x%x, %d\n", (u32)ofs, ret); | |
275 | goto next; | |
276 | } | |
277 | ||
dfe64e2c | 278 | ret = mtd_write(mtd, ofs, blocksize, &retlen, buf); |
c438ea17 SR |
279 | if (ret) { |
280 | printk("Write failed 0x%x, %d\n", (u32)ofs, ret); | |
281 | goto next; | |
282 | } | |
283 | ||
dfe64e2c | 284 | ret = mtd_read(mtd, ofs, blocksize, &retlen, verify_buf); |
c438ea17 SR |
285 | if (ret) { |
286 | printk("Read failed 0x%x, %d\n", (u32)ofs, ret); | |
287 | goto next; | |
288 | } | |
289 | ||
290 | if (memcmp(buf, verify_buf, blocksize)) | |
291 | printk("\nRead/Write test failed at 0x%x\n", (u32)ofs); | |
292 | ||
293 | next: | |
294 | ofs += blocksize; | |
295 | blocks++; | |
296 | } | |
297 | printf("...Done\n"); | |
298 | ||
299 | free(buf); | |
300 | free(verify_buf); | |
301 | ||
302 | return 0; | |
303 | } | |
304 | ||
305 | static int onenand_dump(struct mtd_info *mtd, ulong off, int only_oob) | |
306 | { | |
307 | int i; | |
308 | u_char *datbuf, *oobbuf, *p; | |
309 | struct mtd_oob_ops ops; | |
310 | loff_t addr; | |
311 | ||
312 | datbuf = malloc(mtd->writesize + mtd->oobsize); | |
313 | oobbuf = malloc(mtd->oobsize); | |
314 | if (!datbuf || !oobbuf) { | |
315 | puts("No memory for page buffer\n"); | |
316 | return 1; | |
317 | } | |
318 | off &= ~(mtd->writesize - 1); | |
319 | addr = (loff_t) off; | |
320 | memset(&ops, 0, sizeof(ops)); | |
321 | ops.datbuf = datbuf; | |
a430b137 | 322 | ops.oobbuf = oobbuf; |
c438ea17 SR |
323 | ops.len = mtd->writesize; |
324 | ops.ooblen = mtd->oobsize; | |
325 | ops.retlen = 0; | |
dfe64e2c | 326 | i = mtd_read_oob(mtd, addr, &ops); |
c438ea17 SR |
327 | if (i < 0) { |
328 | printf("Error (%d) reading page %08lx\n", i, off); | |
329 | free(datbuf); | |
330 | free(oobbuf); | |
331 | return 1; | |
332 | } | |
333 | printf("Page %08lx dump:\n", off); | |
334 | i = mtd->writesize >> 4; | |
335 | p = datbuf; | |
336 | ||
337 | while (i--) { | |
338 | if (!only_oob) | |
339 | printf("\t%02x %02x %02x %02x %02x %02x %02x %02x" | |
340 | " %02x %02x %02x %02x %02x %02x %02x %02x\n", | |
341 | p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], | |
342 | p[8], p[9], p[10], p[11], p[12], p[13], p[14], | |
343 | p[15]); | |
344 | p += 16; | |
345 | } | |
346 | puts("OOB:\n"); | |
347 | i = mtd->oobsize >> 3; | |
a430b137 LW |
348 | p = oobbuf; |
349 | ||
c438ea17 SR |
350 | while (i--) { |
351 | printf("\t%02x %02x %02x %02x %02x %02x %02x %02x\n", | |
352 | p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]); | |
353 | p += 8; | |
354 | } | |
355 | free(datbuf); | |
356 | free(oobbuf); | |
357 | ||
358 | return 0; | |
359 | } | |
d7e8ce10 | 360 | |
54841ab5 | 361 | static int do_onenand_info(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) |
d7e8ce10 | 362 | { |
8cd85282 FM |
363 | printf("%s\n", mtd->name); |
364 | return 0; | |
365 | } | |
366 | ||
54841ab5 | 367 | static int do_onenand_bad(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) |
8cd85282 FM |
368 | { |
369 | ulong ofs; | |
370 | ||
371 | mtd = &onenand_mtd; | |
372 | /* Currently only one OneNAND device is supported */ | |
373 | printf("\nDevice %d bad blocks:\n", 0); | |
374 | for (ofs = 0; ofs < mtd->size; ofs += mtd->erasesize) { | |
dfe64e2c | 375 | if (mtd_block_isbad(mtd, ofs)) |
8cd85282 FM |
376 | printf(" %08x\n", (u32)ofs); |
377 | } | |
378 | ||
379 | return 0; | |
380 | } | |
381 | ||
54841ab5 | 382 | static int do_onenand_read(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) |
8cd85282 FM |
383 | { |
384 | char *s; | |
385 | int oob = 0; | |
c438ea17 | 386 | ulong addr, ofs; |
8cd85282 | 387 | size_t len; |
8360b66b | 388 | int ret = 0; |
8cd85282 | 389 | size_t retlen = 0; |
c438ea17 | 390 | |
8cd85282 | 391 | if (argc < 3) |
4c12eeb8 | 392 | return CMD_RET_USAGE; |
c438ea17 | 393 | |
8cd85282 FM |
394 | s = strchr(argv[0], '.'); |
395 | if ((s != NULL) && (!strcmp(s, ".oob"))) | |
396 | oob = 1; | |
d7e8ce10 | 397 | |
8cd85282 | 398 | addr = (ulong)simple_strtoul(argv[1], NULL, 16); |
d7e8ce10 | 399 | |
8cd85282 | 400 | printf("\nOneNAND read: "); |
09c32807 | 401 | if (arg_off_size_onenand(argc - 2, argv + 2, &ofs, &len) != 0) |
8cd85282 | 402 | return 1; |
c438ea17 | 403 | |
8cd85282 | 404 | ret = onenand_block_read(ofs, len, &retlen, (u8 *)addr, oob); |
c438ea17 | 405 | |
8cd85282 | 406 | printf(" %d bytes read: %s\n", retlen, ret ? "ERROR" : "OK"); |
d7e8ce10 | 407 | |
8cd85282 FM |
408 | return ret == 0 ? 0 : 1; |
409 | } | |
a9da2b41 | 410 | |
54841ab5 | 411 | static int do_onenand_write(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) |
8cd85282 FM |
412 | { |
413 | ulong addr, ofs; | |
414 | size_t len; | |
41c86240 | 415 | int ret = 0, withoob = 0; |
8cd85282 | 416 | size_t retlen = 0; |
d7e8ce10 | 417 | |
8cd85282 | 418 | if (argc < 3) |
4c12eeb8 | 419 | return CMD_RET_USAGE; |
d7e8ce10 | 420 | |
41c86240 LW |
421 | if (strncmp(argv[0] + 6, "yaffs", 5) == 0) |
422 | withoob = 1; | |
423 | ||
8cd85282 FM |
424 | addr = (ulong)simple_strtoul(argv[1], NULL, 16); |
425 | ||
426 | printf("\nOneNAND write: "); | |
09c32807 | 427 | if (arg_off_size_onenand(argc - 2, argv + 2, &ofs, &len) != 0) |
8cd85282 | 428 | return 1; |
d7e8ce10 | 429 | |
41c86240 | 430 | ret = onenand_block_write(ofs, len, &retlen, (u8 *)addr, withoob); |
d7e8ce10 | 431 | |
8cd85282 | 432 | printf(" %d bytes written: %s\n", retlen, ret ? "ERROR" : "OK"); |
c438ea17 | 433 | |
8cd85282 FM |
434 | return ret == 0 ? 0 : 1; |
435 | } | |
436 | ||
54841ab5 | 437 | static int do_onenand_erase(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) |
8cd85282 FM |
438 | { |
439 | ulong ofs; | |
440 | int ret = 0; | |
441 | size_t len; | |
442 | int force; | |
443 | ||
444 | /* | |
445 | * Syntax is: | |
446 | * 0 1 2 3 4 | |
447 | * onenand erase [force] [off size] | |
448 | */ | |
449 | argc--; | |
450 | argv++; | |
451 | if (argc) | |
452 | { | |
453 | if (!strcmp("force", argv[0])) | |
454 | { | |
455 | force = 1; | |
456 | argc--; | |
457 | argv++; | |
d7e8ce10 | 458 | } |
8cd85282 FM |
459 | } |
460 | printf("\nOneNAND erase: "); | |
d7e8ce10 | 461 | |
8cd85282 | 462 | /* skip first two or three arguments, look for offset and size */ |
09c32807 | 463 | if (arg_off_size_onenand(argc, argv, &ofs, &len) != 0) |
8cd85282 | 464 | return 1; |
bfd7f386 | 465 | |
8cd85282 | 466 | ret = onenand_block_erase(ofs, len, force); |
bfd7f386 | 467 | |
8cd85282 | 468 | printf("%s\n", ret ? "ERROR" : "OK"); |
d7e8ce10 | 469 | |
8cd85282 FM |
470 | return ret == 0 ? 0 : 1; |
471 | } | |
d7e8ce10 | 472 | |
54841ab5 | 473 | static int do_onenand_test(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) |
8cd85282 FM |
474 | { |
475 | ulong ofs; | |
476 | int ret = 0; | |
477 | size_t len; | |
d7e8ce10 | 478 | |
8cd85282 FM |
479 | /* |
480 | * Syntax is: | |
481 | * 0 1 2 3 4 | |
482 | * onenand test [force] [off size] | |
483 | */ | |
d7e8ce10 | 484 | |
8cd85282 | 485 | printf("\nOneNAND test: "); |
d7e8ce10 | 486 | |
8cd85282 | 487 | /* skip first two or three arguments, look for offset and size */ |
09c32807 | 488 | if (arg_off_size_onenand(argc - 1, argv + 1, &ofs, &len) != 0) |
8cd85282 | 489 | return 1; |
d7e8ce10 | 490 | |
8cd85282 | 491 | ret = onenand_block_test(ofs, len); |
d7e8ce10 | 492 | |
8cd85282 | 493 | printf("%s\n", ret ? "ERROR" : "OK"); |
d7e8ce10 | 494 | |
8cd85282 FM |
495 | return ret == 0 ? 0 : 1; |
496 | } | |
bfd7f386 | 497 | |
54841ab5 | 498 | static int do_onenand_dump(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) |
8cd85282 FM |
499 | { |
500 | ulong ofs; | |
501 | int ret = 0; | |
502 | char *s; | |
d7e8ce10 | 503 | |
8cd85282 | 504 | if (argc < 2) |
4c12eeb8 | 505 | return CMD_RET_USAGE; |
8cd85282 FM |
506 | |
507 | s = strchr(argv[0], '.'); | |
508 | ofs = (int)simple_strtoul(argv[1], NULL, 16); | |
509 | ||
510 | if (s != NULL && strcmp(s, ".oob") == 0) | |
511 | ret = onenand_dump(mtd, ofs, 1); | |
512 | else | |
513 | ret = onenand_dump(mtd, ofs, 0); | |
d7e8ce10 | 514 | |
8cd85282 FM |
515 | return ret == 0 ? 1 : 0; |
516 | } | |
517 | ||
54841ab5 | 518 | static int do_onenand_markbad(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) |
8cd85282 FM |
519 | { |
520 | int ret = 0; | |
521 | ulong addr; | |
522 | ||
523 | argc -= 2; | |
524 | argv += 2; | |
525 | ||
526 | if (argc <= 0) | |
4c12eeb8 | 527 | return CMD_RET_USAGE; |
d7e8ce10 | 528 | |
8cd85282 FM |
529 | while (argc > 0) { |
530 | addr = simple_strtoul(*argv, NULL, 16); | |
531 | ||
dfe64e2c | 532 | if (mtd_block_markbad(mtd, addr)) { |
8cd85282 FM |
533 | printf("block 0x%08lx NOT marked " |
534 | "as bad! ERROR %d\n", | |
535 | addr, ret); | |
536 | ret = 1; | |
537 | } else { | |
538 | printf("block 0x%08lx successfully " | |
539 | "marked as bad\n", | |
540 | addr); | |
541 | } | |
542 | --argc; | |
543 | ++argv; | |
544 | } | |
545 | return ret; | |
546 | } | |
547 | ||
548 | static cmd_tbl_t cmd_onenand_sub[] = { | |
549 | U_BOOT_CMD_MKENT(info, 1, 0, do_onenand_info, "", ""), | |
550 | U_BOOT_CMD_MKENT(bad, 1, 0, do_onenand_bad, "", ""), | |
551 | U_BOOT_CMD_MKENT(read, 4, 0, do_onenand_read, "", ""), | |
552 | U_BOOT_CMD_MKENT(write, 4, 0, do_onenand_write, "", ""), | |
41c86240 | 553 | U_BOOT_CMD_MKENT(write.yaffs, 4, 0, do_onenand_write, "", ""), |
8cd85282 FM |
554 | U_BOOT_CMD_MKENT(erase, 3, 0, do_onenand_erase, "", ""), |
555 | U_BOOT_CMD_MKENT(test, 3, 0, do_onenand_test, "", ""), | |
556 | U_BOOT_CMD_MKENT(dump, 2, 0, do_onenand_dump, "", ""), | |
557 | U_BOOT_CMD_MKENT(markbad, CONFIG_SYS_MAXARGS, 0, do_onenand_markbad, "", ""), | |
558 | }; | |
559 | ||
2e5167cc | 560 | #ifdef CONFIG_NEEDS_MANUAL_RELOC |
cdb1d4f9 EBS |
561 | void onenand_reloc(void) { |
562 | fixup_cmdtable(cmd_onenand_sub, ARRAY_SIZE(cmd_onenand_sub)); | |
563 | } | |
564 | #endif | |
565 | ||
54841ab5 | 566 | static int do_onenand(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) |
8cd85282 FM |
567 | { |
568 | cmd_tbl_t *c; | |
569 | ||
57ff9f24 | 570 | if (argc < 2) |
4c12eeb8 | 571 | return CMD_RET_USAGE; |
57ff9f24 | 572 | |
8cd85282 FM |
573 | mtd = &onenand_mtd; |
574 | ||
575 | /* Strip off leading 'onenand' command argument */ | |
576 | argc--; | |
577 | argv++; | |
c438ea17 | 578 | |
8cd85282 FM |
579 | c = find_cmd_tbl(argv[0], &cmd_onenand_sub[0], ARRAY_SIZE(cmd_onenand_sub)); |
580 | ||
47e26b1b WD |
581 | if (c) |
582 | return c->cmd(cmdtp, flag, argc, argv); | |
583 | else | |
4c12eeb8 | 584 | return CMD_RET_USAGE; |
d7e8ce10 KP |
585 | } |
586 | ||
587 | U_BOOT_CMD( | |
8360b66b | 588 | onenand, CONFIG_SYS_MAXARGS, 1, do_onenand, |
2fb2604d | 589 | "OneNAND sub-system", |
c438ea17 SR |
590 | "info - show available OneNAND devices\n" |
591 | "onenand bad - show bad blocks\n" | |
592 | "onenand read[.oob] addr off size\n" | |
41c86240 | 593 | "onenand write[.yaffs] addr off size\n" |
c438ea17 SR |
594 | " read/write 'size' bytes starting at offset 'off'\n" |
595 | " to/from memory address 'addr', skipping bad blocks.\n" | |
596 | "onenand erase [force] [off size] - erase 'size' bytes from\n" | |
597 | "onenand test [off size] - test 'size' bytes from\n" | |
598 | " offset 'off' (entire device if not specified)\n" | |
599 | "onenand dump[.oob] off - dump page\n" | |
a89c33db | 600 | "onenand markbad off [...] - mark bad block(s) at offset (UNSAFE)" |
d7e8ce10 | 601 | ); |