23 #include <linux/module.h>
27 #include <linux/slab.h>
28 #include <linux/sched.h>
30 #include <linux/random.h>
32 #define PRINT_PREF KERN_INFO "mtd_stresstest: "
38 static int count = 10000;
43 static unsigned char *writebuf;
44 static unsigned char *readbuf;
45 static unsigned char *bbt;
53 static int rand_eb(
void)
66 static int rand_offs(
void)
75 static int rand_len(
int offs)
84 static int erase_eraseblock(
int ebnum)
110 static int is_block_bad(
int ebnum)
125 int offs = rand_offs();
126 int len = rand_len(offs),
err;
136 err =
mtd_read(mtd, addr, len, &read, readbuf);
137 if (mtd_is_bitflip(err))
157 err = erase_eraseblock(eb);
160 offs = offsets[
eb] = 0;
162 len = rand_len(offs);
163 len = ((len + pgsize - 1) / pgsize) * pgsize;
168 err = erase_eraseblock(eb + 1);
175 err =
mtd_write(mtd, addr, len, &written, writebuf);
176 if (
unlikely(err || written != len)) {
192 static int do_operation(
void)
200 static int scan_for_bad_eraseblocks(
void)
210 if (!mtd_can_have_bb(mtd))
214 for (i = 0; i < ebcnt; ++
i) {
215 bbt[
i] = is_block_bad(i) ? 1 : 0;
224 static int __init mtd_stresstest_init(
void)
231 printk(
KERN_INFO "=================================================\n");
234 printk(
PRINT_PREF "Please specify a valid mtd-device via module paramter\n");
235 printk(
KERN_CRIT "CAREFUL: This test wipes all data on the specified MTD device!\n");
261 "page size %u, count of eraseblocks %u, pages per "
262 "eraseblock %u, OOB size %u\n",
264 pgsize, ebcnt, pgcnt, mtd->
oobsize);
279 if (!readbuf || !writebuf || !offsets) {
283 for (i = 0; i < ebcnt; i++)
288 err = scan_for_bad_eraseblocks();
294 for (op = 0; op <
count; op++) {
295 if ((op & 1023) == 0)
297 err = do_operation();
313 printk(
KERN_INFO "=================================================\n");
318 static void __exit mtd_stresstest_exit(
void)