Lines Matching refs:mtd

24 	struct mtd_info *mtd;  in get_mtd_by_name()  local
28 mtd = get_mtd_device_nm(name); in get_mtd_by_name()
29 if (IS_ERR_OR_NULL(mtd)) in get_mtd_by_name()
31 PTR_ERR(mtd)); in get_mtd_by_name()
33 return mtd; in get_mtd_by_name()
36 static uint mtd_len_to_pages(struct mtd_info *mtd, u64 len) in mtd_len_to_pages() argument
38 do_div(len, mtd->writesize); in mtd_len_to_pages()
43 static bool mtd_is_aligned_with_min_io_size(struct mtd_info *mtd, u64 size) in mtd_is_aligned_with_min_io_size() argument
45 return !do_div(size, mtd->writesize); in mtd_is_aligned_with_min_io_size()
48 static bool mtd_is_aligned_with_block_size(struct mtd_info *mtd, u64 size) in mtd_is_aligned_with_block_size() argument
50 return !do_div(size, mtd->erasesize); in mtd_is_aligned_with_block_size()
70 static void mtd_dump_device_buf(struct mtd_info *mtd, u64 start_off, in mtd_dump_device_buf() argument
73 bool has_pages = mtd->type == MTD_NANDFLASH || in mtd_dump_device_buf()
74 mtd->type == MTD_MLCNANDFLASH; in mtd_dump_device_buf()
75 int npages = mtd_len_to_pages(mtd, len); in mtd_dump_device_buf()
80 u64 data_off = page * mtd->writesize; in mtd_dump_device_buf()
83 mtd->writesize, start_off + data_off); in mtd_dump_device_buf()
85 mtd->writesize, start_off + data_off); in mtd_dump_device_buf()
88 u64 oob_off = page * mtd->oobsize; in mtd_dump_device_buf()
91 mtd->oobsize, start_off + data_off); in mtd_dump_device_buf()
93 mtd->oobsize, 0); in mtd_dump_device_buf()
103 static void mtd_show_parts(struct mtd_info *mtd, int level) in mtd_show_parts() argument
108 list_for_each_entry(part, &mtd->partitions, node) { in mtd_show_parts()
118 static void mtd_show_device(struct mtd_info *mtd) in mtd_show_device() argument
121 printf("* %s\n", mtd->name); in mtd_show_device()
123 if (mtd->dev) { in mtd_show_device()
124 printf(" - device: %s\n", mtd->dev->name); in mtd_show_device()
125 printf(" - parent: %s\n", mtd->dev->parent->name); in mtd_show_device()
126 printf(" - driver: %s\n", mtd->dev->driver->name); in mtd_show_device()
132 switch (mtd->type) { in mtd_show_device()
160 printf(" - block size: 0x%x bytes\n", mtd->erasesize); in mtd_show_device()
161 printf(" - min I/O: 0x%x bytes\n", mtd->writesize); in mtd_show_device()
163 if (mtd->oobsize) { in mtd_show_device()
164 printf(" - OOB size: %u bytes\n", mtd->oobsize); in mtd_show_device()
165 printf(" - OOB available: %u bytes\n", mtd->oobavail); in mtd_show_device()
168 if (mtd->ecc_strength) { in mtd_show_device()
169 printf(" - ECC strength: %u bits\n", mtd->ecc_strength); in mtd_show_device()
170 printf(" - ECC step size: %u bytes\n", mtd->ecc_step_size); in mtd_show_device()
172 mtd->bitflip_threshold); in mtd_show_device()
176 mtd->offset, mtd->offset + mtd->size, mtd->name); in mtd_show_device()
179 mtd_show_parts(mtd, 1); in mtd_show_device()
201 struct mtd_info *mtd; in do_mtd_list() local
208 mtd_for_each_device(mtd) { in do_mtd_list()
209 if (!mtd_is_partition(mtd)) in do_mtd_list()
210 mtd_show_device(mtd); in do_mtd_list()
223 static int mtd_special_write_oob(struct mtd_info *mtd, u64 off, in mtd_special_write_oob() argument
234 io_op->retlen = mtd->writesize; in mtd_special_write_oob()
235 io_op->oobretlen = woob ? mtd->oobsize : 0; in mtd_special_write_oob()
237 ret = mtd_write_oob(mtd, off, io_op); in mtd_special_write_oob()
251 struct mtd_info *mtd; in do_mtd_io() local
259 mtd = get_mtd_by_name(argv[1]); in do_mtd_io()
260 if (IS_ERR_OR_NULL(mtd)) in do_mtd_io()
263 if (mtd->type == MTD_NANDFLASH || mtd->type == MTD_MLCNANDFLASH) in do_mtd_io()
287 if (!mtd_is_aligned_with_min_io_size(mtd, start_off)) { in do_mtd_io()
289 mtd->writesize); in do_mtd_io()
294 default_len = dump ? mtd->writesize : mtd->size; in do_mtd_io()
296 if (!mtd_is_aligned_with_min_io_size(mtd, len)) { in do_mtd_io()
297 len = round_up(len, mtd->writesize); in do_mtd_io()
299 mtd->writesize, len); in do_mtd_io()
303 npages = mtd_len_to_pages(mtd, len); in do_mtd_io()
304 oob_len = woob ? npages * mtd->oobsize : 0; in do_mtd_io()
327 io_op.len = has_pages ? mtd->writesize : len; in do_mtd_io()
328 io_op.ooblen = woob ? mtd->oobsize : 0; in do_mtd_io()
334 while (mtd_block_isbad(mtd, off)) in do_mtd_io()
335 off += mtd->erasesize; in do_mtd_io()
340 if (mtd_is_aligned_with_block_size(mtd, off) && in do_mtd_io()
341 mtd_block_isbad(mtd, off)) { in do_mtd_io()
342 off += mtd->erasesize; in do_mtd_io()
347 ret = mtd_read_oob(mtd, off, &io_op); in do_mtd_io()
349 ret = mtd_special_write_oob(mtd, off, &io_op, in do_mtd_io()
365 mtd_dump_device_buf(mtd, start_off, buf, len, woob); in do_mtd_io()
374 read ? "Read" : "Write", mtd->name, ret); in do_mtd_io()
381 put_mtd_device(mtd); in do_mtd_io()
390 struct mtd_info *mtd; in do_mtd_erase() local
398 mtd = get_mtd_by_name(argv[1]); in do_mtd_erase()
399 if (IS_ERR_OR_NULL(mtd)) in do_mtd_erase()
408 len = argc > 1 ? simple_strtoul(argv[1], NULL, 16) : mtd->size; in do_mtd_erase()
410 if (!mtd_is_aligned_with_block_size(mtd, off)) { in do_mtd_erase()
412 mtd->erasesize); in do_mtd_erase()
417 if (!mtd_is_aligned_with_block_size(mtd, len)) { in do_mtd_erase()
419 mtd->erasesize); in do_mtd_erase()
425 off, off + len - 1, mtd_div_by_eb(len, mtd)); in do_mtd_erase()
427 erase_op.mtd = mtd; in do_mtd_erase()
429 erase_op.len = mtd->erasesize; in do_mtd_erase()
433 ret = mtd_erase(mtd, &erase_op); in do_mtd_erase()
443 len -= mtd->erasesize; in do_mtd_erase()
444 erase_op.addr += mtd->erasesize; in do_mtd_erase()
453 put_mtd_device(mtd); in do_mtd_erase()
461 struct mtd_info *mtd; in do_mtd_bad() local
467 mtd = get_mtd_by_name(argv[1]); in do_mtd_bad()
468 if (IS_ERR_OR_NULL(mtd)) in do_mtd_bad()
471 if (!mtd_can_have_bb(mtd)) { in do_mtd_bad()
476 printf("MTD device %s bad blocks list:\n", mtd->name); in do_mtd_bad()
477 for (off = 0; off < mtd->size; off += mtd->erasesize) { in do_mtd_bad()
478 if (mtd_block_isbad(mtd, off)) in do_mtd_bad()
483 put_mtd_device(mtd); in do_mtd_bad()
493 struct mtd_info *mtd; in mtd_name_complete() local
505 mtd_for_each_device(mtd) { in mtd_name_complete()
507 (len > strlen(mtd->name) || in mtd_name_complete()
508 strncmp(argv[0], mtd->name, len))) in mtd_name_complete()
516 cmdv[n_found++] = mtd->name; in mtd_name_complete()
550 U_BOOT_CMD_WITH_SUBCMDS(mtd, "MTD utils", mtd_help_text,