1 #define pr_fmt(fmt) "mtd_test: " fmt
3 #include <linux/module.h>
4 #include <linux/sched.h>
5 #include <linux/printk.h>
9 int mtdtest_erase_eraseblock(struct mtd_info
*mtd
, unsigned int ebnum
)
13 loff_t addr
= (loff_t
)ebnum
* mtd
->erasesize
;
15 memset(&ei
, 0, sizeof(struct erase_info
));
18 ei
.len
= mtd
->erasesize
;
20 err
= mtd_erase(mtd
, &ei
);
22 pr_info("error %d while erasing EB %d\n", err
, ebnum
);
26 if (ei
.state
== MTD_ERASE_FAILED
) {
27 pr_info("some erase error occurred at EB %d\n", ebnum
);
33 static int is_block_bad(struct mtd_info
*mtd
, unsigned int ebnum
)
36 loff_t addr
= (loff_t
)ebnum
* mtd
->erasesize
;
38 ret
= mtd_block_isbad(mtd
, addr
);
40 pr_info("block %d is bad\n", ebnum
);
45 int mtdtest_scan_for_bad_eraseblocks(struct mtd_info
*mtd
, unsigned char *bbt
,
46 unsigned int eb
, int ebcnt
)
50 if (!mtd_can_have_bb(mtd
))
53 pr_info("scanning for bad eraseblocks\n");
54 for (i
= 0; i
< ebcnt
; ++i
) {
55 bbt
[i
] = is_block_bad(mtd
, eb
+ i
) ? 1 : 0;
60 pr_info("scanned %d eraseblocks, %d are bad\n", i
, bad
);
65 int mtdtest_erase_good_eraseblocks(struct mtd_info
*mtd
, unsigned char *bbt
,
66 unsigned int eb
, int ebcnt
)
71 for (i
= 0; i
< ebcnt
; ++i
) {
74 err
= mtdtest_erase_eraseblock(mtd
, eb
+ i
);
83 int mtdtest_read(struct mtd_info
*mtd
, loff_t addr
, size_t size
, void *buf
)
88 err
= mtd_read(mtd
, addr
, size
, &read
, buf
);
89 /* Ignore corrected ECC errors */
90 if (mtd_is_bitflip(err
))
92 if (!err
&& read
!= size
)
95 pr_err("error: read failed at %#llx\n", addr
);
100 int mtdtest_write(struct mtd_info
*mtd
, loff_t addr
, size_t size
,
106 err
= mtd_write(mtd
, addr
, size
, &written
, buf
);
107 if (!err
&& written
!= size
)
110 pr_err("error: write failed at %#llx\n", addr
);