diff options
Diffstat (limited to 'drivers/mtd/tests')
-rw-r--r-- | drivers/mtd/tests/Makefile | 1 | ||||
-rw-r--r-- | drivers/mtd/tests/mtd_nandecctest.c | 87 | ||||
-rw-r--r-- | drivers/mtd/tests/mtd_oobtest.c | 18 | ||||
-rw-r--r-- | drivers/mtd/tests/mtd_pagetest.c | 1 |
4 files changed, 93 insertions, 14 deletions
diff --git a/drivers/mtd/tests/Makefile b/drivers/mtd/tests/Makefile index c1d501335006..b44dcab940d8 100644 --- a/drivers/mtd/tests/Makefile +++ b/drivers/mtd/tests/Makefile | |||
@@ -5,3 +5,4 @@ obj-$(CONFIG_MTD_TESTS) += mtd_speedtest.o | |||
5 | obj-$(CONFIG_MTD_TESTS) += mtd_stresstest.o | 5 | obj-$(CONFIG_MTD_TESTS) += mtd_stresstest.o |
6 | obj-$(CONFIG_MTD_TESTS) += mtd_subpagetest.o | 6 | obj-$(CONFIG_MTD_TESTS) += mtd_subpagetest.o |
7 | obj-$(CONFIG_MTD_TESTS) += mtd_torturetest.o | 7 | obj-$(CONFIG_MTD_TESTS) += mtd_torturetest.o |
8 | obj-$(CONFIG_MTD_TESTS) += mtd_nandecctest.o | ||
diff --git a/drivers/mtd/tests/mtd_nandecctest.c b/drivers/mtd/tests/mtd_nandecctest.c new file mode 100644 index 000000000000..c1f31051784c --- /dev/null +++ b/drivers/mtd/tests/mtd_nandecctest.c | |||
@@ -0,0 +1,87 @@ | |||
1 | #include <linux/kernel.h> | ||
2 | #include <linux/module.h> | ||
3 | #include <linux/list.h> | ||
4 | #include <linux/slab.h> | ||
5 | #include <linux/random.h> | ||
6 | #include <linux/string.h> | ||
7 | #include <linux/bitops.h> | ||
8 | #include <linux/jiffies.h> | ||
9 | #include <linux/mtd/nand_ecc.h> | ||
10 | |||
11 | #if defined(CONFIG_MTD_NAND) || defined(CONFIG_MTD_NAND_MODULE) | ||
12 | |||
13 | static void inject_single_bit_error(void *data, size_t size) | ||
14 | { | ||
15 | unsigned long offset = random32() % (size * BITS_PER_BYTE); | ||
16 | |||
17 | __change_bit(offset, data); | ||
18 | } | ||
19 | |||
20 | static unsigned char data[512]; | ||
21 | static unsigned char error_data[512]; | ||
22 | |||
23 | static int nand_ecc_test(const size_t size) | ||
24 | { | ||
25 | unsigned char code[3]; | ||
26 | unsigned char error_code[3]; | ||
27 | char testname[30]; | ||
28 | |||
29 | BUG_ON(sizeof(data) < size); | ||
30 | |||
31 | sprintf(testname, "nand-ecc-%zu", size); | ||
32 | |||
33 | get_random_bytes(data, size); | ||
34 | |||
35 | memcpy(error_data, data, size); | ||
36 | inject_single_bit_error(error_data, size); | ||
37 | |||
38 | __nand_calculate_ecc(data, size, code); | ||
39 | __nand_calculate_ecc(error_data, size, error_code); | ||
40 | __nand_correct_data(error_data, code, error_code, size); | ||
41 | |||
42 | if (!memcmp(data, error_data, size)) { | ||
43 | printk(KERN_INFO "mtd_nandecctest: ok - %s\n", testname); | ||
44 | return 0; | ||
45 | } | ||
46 | |||
47 | printk(KERN_ERR "mtd_nandecctest: not ok - %s\n", testname); | ||
48 | |||
49 | printk(KERN_DEBUG "hexdump of data:\n"); | ||
50 | print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 16, 4, | ||
51 | data, size, false); | ||
52 | printk(KERN_DEBUG "hexdump of error data:\n"); | ||
53 | print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 16, 4, | ||
54 | error_data, size, false); | ||
55 | |||
56 | return -1; | ||
57 | } | ||
58 | |||
59 | #else | ||
60 | |||
61 | static int nand_ecc_test(const size_t size) | ||
62 | { | ||
63 | return 0; | ||
64 | } | ||
65 | |||
66 | #endif | ||
67 | |||
68 | static int __init ecc_test_init(void) | ||
69 | { | ||
70 | srandom32(jiffies); | ||
71 | |||
72 | nand_ecc_test(256); | ||
73 | nand_ecc_test(512); | ||
74 | |||
75 | return 0; | ||
76 | } | ||
77 | |||
78 | static void __exit ecc_test_exit(void) | ||
79 | { | ||
80 | } | ||
81 | |||
82 | module_init(ecc_test_init); | ||
83 | module_exit(ecc_test_exit); | ||
84 | |||
85 | MODULE_DESCRIPTION("NAND ECC function test module"); | ||
86 | MODULE_AUTHOR("Akinobu Mita"); | ||
87 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/mtd/tests/mtd_oobtest.c b/drivers/mtd/tests/mtd_oobtest.c index 5553cd4eab20..5813920e79a5 100644 --- a/drivers/mtd/tests/mtd_oobtest.c +++ b/drivers/mtd/tests/mtd_oobtest.c | |||
@@ -343,7 +343,6 @@ static int scan_for_bad_eraseblocks(void) | |||
343 | printk(PRINT_PREF "error: cannot allocate memory\n"); | 343 | printk(PRINT_PREF "error: cannot allocate memory\n"); |
344 | return -ENOMEM; | 344 | return -ENOMEM; |
345 | } | 345 | } |
346 | memset(bbt, 0 , ebcnt); | ||
347 | 346 | ||
348 | printk(PRINT_PREF "scanning for bad eraseblocks\n"); | 347 | printk(PRINT_PREF "scanning for bad eraseblocks\n"); |
349 | for (i = 0; i < ebcnt; ++i) { | 348 | for (i = 0; i < ebcnt; ++i) { |
@@ -392,7 +391,6 @@ static int __init mtd_oobtest_init(void) | |||
392 | mtd->writesize, ebcnt, pgcnt, mtd->oobsize); | 391 | mtd->writesize, ebcnt, pgcnt, mtd->oobsize); |
393 | 392 | ||
394 | err = -ENOMEM; | 393 | err = -ENOMEM; |
395 | mtd->erasesize = mtd->erasesize; | ||
396 | readbuf = kmalloc(mtd->erasesize, GFP_KERNEL); | 394 | readbuf = kmalloc(mtd->erasesize, GFP_KERNEL); |
397 | if (!readbuf) { | 395 | if (!readbuf) { |
398 | printk(PRINT_PREF "error: cannot allocate memory\n"); | 396 | printk(PRINT_PREF "error: cannot allocate memory\n"); |
@@ -476,18 +474,10 @@ static int __init mtd_oobtest_init(void) | |||
476 | use_len_max = mtd->ecclayout->oobavail; | 474 | use_len_max = mtd->ecclayout->oobavail; |
477 | vary_offset = 1; | 475 | vary_offset = 1; |
478 | simple_srand(5); | 476 | simple_srand(5); |
479 | printk(PRINT_PREF "writing OOBs of whole device\n"); | 477 | |
480 | for (i = 0; i < ebcnt; ++i) { | 478 | err = write_whole_device(); |
481 | if (bbt[i]) | 479 | if (err) |
482 | continue; | 480 | goto out; |
483 | err = write_eraseblock(i); | ||
484 | if (err) | ||
485 | goto out; | ||
486 | if (i % 256 == 0) | ||
487 | printk(PRINT_PREF "written up to eraseblock %u\n", i); | ||
488 | cond_resched(); | ||
489 | } | ||
490 | printk(PRINT_PREF "written %u eraseblocks\n", i); | ||
491 | 481 | ||
492 | /* Check all eraseblocks */ | 482 | /* Check all eraseblocks */ |
493 | use_offset = 0; | 483 | use_offset = 0; |
diff --git a/drivers/mtd/tests/mtd_pagetest.c b/drivers/mtd/tests/mtd_pagetest.c index 103cac480fee..ce17cbe918c5 100644 --- a/drivers/mtd/tests/mtd_pagetest.c +++ b/drivers/mtd/tests/mtd_pagetest.c | |||
@@ -523,6 +523,7 @@ static int __init mtd_pagetest_init(void) | |||
523 | do_div(tmp, mtd->erasesize); | 523 | do_div(tmp, mtd->erasesize); |
524 | ebcnt = tmp; | 524 | ebcnt = tmp; |
525 | pgcnt = mtd->erasesize / mtd->writesize; | 525 | pgcnt = mtd->erasesize / mtd->writesize; |
526 | pgsize = mtd->writesize; | ||
526 | 527 | ||
527 | printk(PRINT_PREF "MTD device size %llu, eraseblock size %u, " | 528 | printk(PRINT_PREF "MTD device size %llu, eraseblock size %u, " |
528 | "page size %u, count of eraseblocks %u, pages per " | 529 | "page size %u, count of eraseblocks %u, pages per " |