Lines Matching full:mtd
3 * mtd.c
14 #include <mtd.h>
20 static uint mtd_len_to_pages(struct mtd_info *mtd, u64 len) in mtd_len_to_pages() argument
22 do_div(len, mtd->writesize); in mtd_len_to_pages()
27 static bool mtd_is_aligned_with_min_io_size(struct mtd_info *mtd, u64 size) in mtd_is_aligned_with_min_io_size() argument
29 return !do_div(size, mtd->writesize); in mtd_is_aligned_with_min_io_size()
32 static bool mtd_is_aligned_with_block_size(struct mtd_info *mtd, u64 size) in mtd_is_aligned_with_block_size() argument
34 return !do_div(size, mtd->erasesize); in mtd_is_aligned_with_block_size()
54 static void mtd_dump_device_buf(struct mtd_info *mtd, u64 start_off, in mtd_dump_device_buf() argument
57 bool has_pages = mtd->type == MTD_NANDFLASH || in mtd_dump_device_buf()
58 mtd->type == MTD_MLCNANDFLASH; in mtd_dump_device_buf()
59 int npages = mtd_len_to_pages(mtd, len); in mtd_dump_device_buf()
64 u64 data_off = page * mtd->writesize; in mtd_dump_device_buf()
67 mtd->writesize, start_off + data_off); in mtd_dump_device_buf()
69 mtd->writesize, start_off + data_off); in mtd_dump_device_buf()
72 u64 oob_off = page * mtd->oobsize; in mtd_dump_device_buf()
75 mtd->oobsize, start_off + data_off); in mtd_dump_device_buf()
77 mtd->oobsize, 0); in mtd_dump_device_buf()
87 static void mtd_show_parts(struct mtd_info *mtd, int level) in mtd_show_parts() argument
92 list_for_each_entry(part, &mtd->partitions, node) { in mtd_show_parts()
102 static void mtd_show_device(struct mtd_info *mtd) in mtd_show_device() argument
105 printf("* %s\n", mtd->name); in mtd_show_device()
107 if (mtd->dev) { in mtd_show_device()
108 printf(" - device: %s\n", mtd->dev->name); in mtd_show_device()
109 printf(" - parent: %s\n", mtd->dev->parent->name); in mtd_show_device()
110 printf(" - driver: %s\n", mtd->dev->driver->name); in mtd_show_device()
114 /* MTD device information */ in mtd_show_device()
116 switch (mtd->type) { in mtd_show_device()
144 printf(" - block size: 0x%x bytes\n", mtd->erasesize); in mtd_show_device()
145 printf(" - min I/O: 0x%x bytes\n", mtd->writesize); in mtd_show_device()
147 if (mtd->oobsize) { in mtd_show_device()
148 printf(" - OOB size: %u bytes\n", mtd->oobsize); in mtd_show_device()
149 printf(" - OOB available: %u bytes\n", mtd->oobavail); in mtd_show_device()
152 if (mtd->ecc_strength) { in mtd_show_device()
153 printf(" - ECC strength: %u bits\n", mtd->ecc_strength); in mtd_show_device()
154 printf(" - ECC step size: %u bytes\n", mtd->ecc_step_size); in mtd_show_device()
156 mtd->bitflip_threshold); in mtd_show_device()
160 mtd->offset, mtd->offset + mtd->size, mtd->name); in mtd_show_device()
162 /* MTD partitions, if any */ in mtd_show_device()
163 mtd_show_parts(mtd, 1); in mtd_show_device()
184 struct mtd_info *mtd; in do_mtd_list() local
190 printf("List of MTD devices:\n"); in do_mtd_list()
191 mtd_for_each_device(mtd) { in do_mtd_list()
192 if (!mtd_is_partition(mtd)) in do_mtd_list()
193 mtd_show_device(mtd); in do_mtd_list()
199 printf("No MTD device found\n"); in do_mtd_list()
206 static int mtd_special_write_oob(struct mtd_info *mtd, u64 off, in mtd_special_write_oob() argument
217 io_op->retlen = mtd->writesize; in mtd_special_write_oob()
218 io_op->oobretlen = woob ? mtd->oobsize : 0; in mtd_special_write_oob()
220 ret = mtd_write_oob(mtd, off, io_op); in mtd_special_write_oob()
228 struct mtd_info *mtd; in do_mtd() local
232 /* All MTD commands need at least two arguments */ in do_mtd()
239 /* List the MTD devices if that is what the user wants */ in do_mtd()
252 mtd = g_mtd; in do_mtd()
255 mtd = get_mtd_device_nm(mtd_name); in do_mtd()
256 if (IS_ERR_OR_NULL(mtd)) { in do_mtd()
257 printf("MTD device %s not found, ret %ld\n", in do_mtd()
258 mtd_name, PTR_ERR(mtd)); in do_mtd()
261 put_mtd_device(mtd); in do_mtd()
262 g_mtd = mtd; in do_mtd()
272 bool has_pages = mtd->type == MTD_NANDFLASH || in do_mtd()
273 mtd->type == MTD_MLCNANDFLASH; in do_mtd()
298 if (!mtd_is_aligned_with_min_io_size(mtd, start_off)) { in do_mtd()
300 mtd->writesize); in do_mtd()
304 default_len = dump ? mtd->writesize : mtd->size; in do_mtd()
307 if (!mtd_is_aligned_with_min_io_size(mtd, len)) { in do_mtd()
308 len = round_up(len, mtd->writesize); in do_mtd()
310 mtd->writesize, len); in do_mtd()
314 npages = mtd_len_to_pages(mtd, len); in do_mtd()
315 oob_len = woob ? npages * mtd->oobsize : 0; in do_mtd()
337 io_op.len = has_pages ? mtd->writesize : len; in do_mtd()
338 io_op.ooblen = woob ? mtd->oobsize : 0; in do_mtd()
344 while (mtd_block_isbad(mtd, off)) in do_mtd()
345 off += mtd->erasesize; in do_mtd()
350 if (mtd_is_aligned_with_block_size(mtd, off) && in do_mtd()
351 mtd_block_isbad(mtd, off)) { in do_mtd()
352 off += mtd->erasesize; in do_mtd()
357 ret = mtd_read_oob(mtd, off, &io_op); in do_mtd()
359 ret = mtd_special_write_oob(mtd, off, &io_op, in do_mtd()
376 mtd_dump_device_buf(mtd, start_off, buf, len, woob); in do_mtd()
385 read ? "Read" : "Write", mtd->name, ret); in do_mtd()
396 len = argc > 1 ? simple_strtoul(argv[1], NULL, 16) : mtd->size; in do_mtd()
398 if (!mtd_is_aligned_with_block_size(mtd, off)) { in do_mtd()
400 mtd->erasesize); in do_mtd()
404 if (!mtd_is_aligned_with_block_size(mtd, len)) { in do_mtd()
406 mtd->erasesize); in do_mtd()
411 off, off + len - 1, mtd_div_by_eb(len, mtd)); in do_mtd()
413 erase_op.mtd = mtd; in do_mtd()
419 ret = mtd_erase(mtd, &erase_op); in do_mtd()
430 erase_op.len -= mtd->erasesize; in do_mtd()
431 erase_op.addr = erase_op.fail_addr + mtd->erasesize; in do_mtd()
439 if (!mtd_can_have_bb(mtd)) { in do_mtd()
444 printf("MTD device %s bad blocks list:\n", mtd->name); in do_mtd()
445 for (off = 0; off < mtd->size; off += mtd->erasesize) in do_mtd()
446 if (mtd_block_isbad(mtd, off)) in do_mtd()
456 mtd, 10, 1, do_mtd,
457 "MTD utils",
459 "mtd list\n"
460 "mtd read[.raw][.oob] <name> <addr> [<off> [<size>]]\n"
461 "mtd dump[.raw][.oob] <name> [<off> [<size>]]\n"
462 "mtd write[.raw][.oob][.dontskipff] <name> <addr> [<off> [<size>]]\n"
463 "mtd erase[.dontskipbad] <name> [<off> [<size>]]\n"
466 "mtd bad <name>\n"