aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/tests
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mtd/tests')
-rw-r--r--drivers/mtd/tests/Makefile1
-rw-r--r--drivers/mtd/tests/mtd_nandecctest.c86
-rw-r--r--drivers/mtd/tests/mtd_oobtest.c19
-rw-r--r--drivers/mtd/tests/mtd_pagetest.c2
-rw-r--r--drivers/mtd/tests/mtd_readtest.c7
-rw-r--r--drivers/mtd/tests/mtd_speedtest.c8
-rw-r--r--drivers/mtd/tests/mtd_stresstest.c7
-rw-r--r--drivers/mtd/tests/mtd_subpagetest.c1
-rw-r--r--drivers/mtd/tests/mtd_torturetest.c1
9 files changed, 115 insertions, 17 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
5obj-$(CONFIG_MTD_TESTS) += mtd_stresstest.o 5obj-$(CONFIG_MTD_TESTS) += mtd_stresstest.o
6obj-$(CONFIG_MTD_TESTS) += mtd_subpagetest.o 6obj-$(CONFIG_MTD_TESTS) += mtd_subpagetest.o
7obj-$(CONFIG_MTD_TESTS) += mtd_torturetest.o 7obj-$(CONFIG_MTD_TESTS) += mtd_torturetest.o
8obj-$(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..70d6d7d0d656
--- /dev/null
+++ b/drivers/mtd/tests/mtd_nandecctest.c
@@ -0,0 +1,86 @@
1#include <linux/kernel.h>
2#include <linux/module.h>
3#include <linux/list.h>
4#include <linux/random.h>
5#include <linux/string.h>
6#include <linux/bitops.h>
7#include <linux/jiffies.h>
8#include <linux/mtd/nand_ecc.h>
9
10#if defined(CONFIG_MTD_NAND) || defined(CONFIG_MTD_NAND_MODULE)
11
12static void inject_single_bit_error(void *data, size_t size)
13{
14 unsigned long offset = random32() % (size * BITS_PER_BYTE);
15
16 __change_bit(offset, data);
17}
18
19static unsigned char data[512];
20static unsigned char error_data[512];
21
22static int nand_ecc_test(const size_t size)
23{
24 unsigned char code[3];
25 unsigned char error_code[3];
26 char testname[30];
27
28 BUG_ON(sizeof(data) < size);
29
30 sprintf(testname, "nand-ecc-%zu", size);
31
32 get_random_bytes(data, size);
33
34 memcpy(error_data, data, size);
35 inject_single_bit_error(error_data, size);
36
37 __nand_calculate_ecc(data, size, code);
38 __nand_calculate_ecc(error_data, size, error_code);
39 __nand_correct_data(error_data, code, error_code, size);
40
41 if (!memcmp(data, error_data, size)) {
42 printk(KERN_INFO "mtd_nandecctest: ok - %s\n", testname);
43 return 0;
44 }
45
46 printk(KERN_ERR "mtd_nandecctest: not ok - %s\n", testname);
47
48 printk(KERN_DEBUG "hexdump of data:\n");
49 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 16, 4,
50 data, size, false);
51 printk(KERN_DEBUG "hexdump of error data:\n");
52 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 16, 4,
53 error_data, size, false);
54
55 return -1;
56}
57
58#else
59
60static int nand_ecc_test(const size_t size)
61{
62 return 0;
63}
64
65#endif
66
67static int __init ecc_test_init(void)
68{
69 srandom32(jiffies);
70
71 nand_ecc_test(256);
72 nand_ecc_test(512);
73
74 return 0;
75}
76
77static void __exit ecc_test_exit(void)
78{
79}
80
81module_init(ecc_test_init);
82module_exit(ecc_test_exit);
83
84MODULE_DESCRIPTION("NAND ECC function test module");
85MODULE_AUTHOR("Akinobu Mita");
86MODULE_LICENSE("GPL");
diff --git a/drivers/mtd/tests/mtd_oobtest.c b/drivers/mtd/tests/mtd_oobtest.c
index 5553cd4eab20..dec92ae6111a 100644
--- a/drivers/mtd/tests/mtd_oobtest.c
+++ b/drivers/mtd/tests/mtd_oobtest.c
@@ -25,6 +25,7 @@
25#include <linux/moduleparam.h> 25#include <linux/moduleparam.h>
26#include <linux/err.h> 26#include <linux/err.h>
27#include <linux/mtd/mtd.h> 27#include <linux/mtd/mtd.h>
28#include <linux/slab.h>
28#include <linux/sched.h> 29#include <linux/sched.h>
29 30
30#define PRINT_PREF KERN_INFO "mtd_oobtest: " 31#define PRINT_PREF KERN_INFO "mtd_oobtest: "
@@ -343,7 +344,6 @@ static int scan_for_bad_eraseblocks(void)
343 printk(PRINT_PREF "error: cannot allocate memory\n"); 344 printk(PRINT_PREF "error: cannot allocate memory\n");
344 return -ENOMEM; 345 return -ENOMEM;
345 } 346 }
346 memset(bbt, 0 , ebcnt);
347 347
348 printk(PRINT_PREF "scanning for bad eraseblocks\n"); 348 printk(PRINT_PREF "scanning for bad eraseblocks\n");
349 for (i = 0; i < ebcnt; ++i) { 349 for (i = 0; i < ebcnt; ++i) {
@@ -392,7 +392,6 @@ static int __init mtd_oobtest_init(void)
392 mtd->writesize, ebcnt, pgcnt, mtd->oobsize); 392 mtd->writesize, ebcnt, pgcnt, mtd->oobsize);
393 393
394 err = -ENOMEM; 394 err = -ENOMEM;
395 mtd->erasesize = mtd->erasesize;
396 readbuf = kmalloc(mtd->erasesize, GFP_KERNEL); 395 readbuf = kmalloc(mtd->erasesize, GFP_KERNEL);
397 if (!readbuf) { 396 if (!readbuf) {
398 printk(PRINT_PREF "error: cannot allocate memory\n"); 397 printk(PRINT_PREF "error: cannot allocate memory\n");
@@ -476,18 +475,10 @@ static int __init mtd_oobtest_init(void)
476 use_len_max = mtd->ecclayout->oobavail; 475 use_len_max = mtd->ecclayout->oobavail;
477 vary_offset = 1; 476 vary_offset = 1;
478 simple_srand(5); 477 simple_srand(5);
479 printk(PRINT_PREF "writing OOBs of whole device\n"); 478
480 for (i = 0; i < ebcnt; ++i) { 479 err = write_whole_device();
481 if (bbt[i]) 480 if (err)
482 continue; 481 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 482
492 /* Check all eraseblocks */ 483 /* Check all eraseblocks */
493 use_offset = 0; 484 use_offset = 0;
diff --git a/drivers/mtd/tests/mtd_pagetest.c b/drivers/mtd/tests/mtd_pagetest.c
index 103cac480fee..921a85df9196 100644
--- a/drivers/mtd/tests/mtd_pagetest.c
+++ b/drivers/mtd/tests/mtd_pagetest.c
@@ -25,6 +25,7 @@
25#include <linux/moduleparam.h> 25#include <linux/moduleparam.h>
26#include <linux/err.h> 26#include <linux/err.h>
27#include <linux/mtd/mtd.h> 27#include <linux/mtd/mtd.h>
28#include <linux/slab.h>
28#include <linux/sched.h> 29#include <linux/sched.h>
29 30
30#define PRINT_PREF KERN_INFO "mtd_pagetest: " 31#define PRINT_PREF KERN_INFO "mtd_pagetest: "
@@ -523,6 +524,7 @@ static int __init mtd_pagetest_init(void)
523 do_div(tmp, mtd->erasesize); 524 do_div(tmp, mtd->erasesize);
524 ebcnt = tmp; 525 ebcnt = tmp;
525 pgcnt = mtd->erasesize / mtd->writesize; 526 pgcnt = mtd->erasesize / mtd->writesize;
527 pgsize = mtd->writesize;
526 528
527 printk(PRINT_PREF "MTD device size %llu, eraseblock size %u, " 529 printk(PRINT_PREF "MTD device size %llu, eraseblock size %u, "
528 "page size %u, count of eraseblocks %u, pages per " 530 "page size %u, count of eraseblocks %u, pages per "
diff --git a/drivers/mtd/tests/mtd_readtest.c b/drivers/mtd/tests/mtd_readtest.c
index 79fc4530987b..7107fccbc7de 100644
--- a/drivers/mtd/tests/mtd_readtest.c
+++ b/drivers/mtd/tests/mtd_readtest.c
@@ -24,6 +24,7 @@
24#include <linux/moduleparam.h> 24#include <linux/moduleparam.h>
25#include <linux/err.h> 25#include <linux/err.h>
26#include <linux/mtd/mtd.h> 26#include <linux/mtd/mtd.h>
27#include <linux/slab.h>
27#include <linux/sched.h> 28#include <linux/sched.h>
28 29
29#define PRINT_PREF KERN_INFO "mtd_readtest: " 30#define PRINT_PREF KERN_INFO "mtd_readtest: "
@@ -147,6 +148,10 @@ static int scan_for_bad_eraseblocks(void)
147 } 148 }
148 memset(bbt, 0 , ebcnt); 149 memset(bbt, 0 , ebcnt);
149 150
151 /* NOR flash does not implement block_isbad */
152 if (mtd->block_isbad == NULL)
153 return 0;
154
150 printk(PRINT_PREF "scanning for bad eraseblocks\n"); 155 printk(PRINT_PREF "scanning for bad eraseblocks\n");
151 for (i = 0; i < ebcnt; ++i) { 156 for (i = 0; i < ebcnt; ++i) {
152 bbt[i] = is_block_bad(i) ? 1 : 0; 157 bbt[i] = is_block_bad(i) ? 1 : 0;
@@ -184,7 +189,7 @@ static int __init mtd_readtest_init(void)
184 tmp = mtd->size; 189 tmp = mtd->size;
185 do_div(tmp, mtd->erasesize); 190 do_div(tmp, mtd->erasesize);
186 ebcnt = tmp; 191 ebcnt = tmp;
187 pgcnt = mtd->erasesize / mtd->writesize; 192 pgcnt = mtd->erasesize / pgsize;
188 193
189 printk(PRINT_PREF "MTD device size %llu, eraseblock size %u, " 194 printk(PRINT_PREF "MTD device size %llu, eraseblock size %u, "
190 "page size %u, count of eraseblocks %u, pages per " 195 "page size %u, count of eraseblocks %u, pages per "
diff --git a/drivers/mtd/tests/mtd_speedtest.c b/drivers/mtd/tests/mtd_speedtest.c
index 141363a7e805..56ca62bb96bf 100644
--- a/drivers/mtd/tests/mtd_speedtest.c
+++ b/drivers/mtd/tests/mtd_speedtest.c
@@ -24,6 +24,7 @@
24#include <linux/moduleparam.h> 24#include <linux/moduleparam.h>
25#include <linux/err.h> 25#include <linux/err.h>
26#include <linux/mtd/mtd.h> 26#include <linux/mtd/mtd.h>
27#include <linux/slab.h>
27#include <linux/sched.h> 28#include <linux/sched.h>
28 29
29#define PRINT_PREF KERN_INFO "mtd_speedtest: " 30#define PRINT_PREF KERN_INFO "mtd_speedtest: "
@@ -301,6 +302,10 @@ static int scan_for_bad_eraseblocks(void)
301 } 302 }
302 memset(bbt, 0 , ebcnt); 303 memset(bbt, 0 , ebcnt);
303 304
305 /* NOR flash does not implement block_isbad */
306 if (mtd->block_isbad == NULL)
307 goto out;
308
304 printk(PRINT_PREF "scanning for bad eraseblocks\n"); 309 printk(PRINT_PREF "scanning for bad eraseblocks\n");
305 for (i = 0; i < ebcnt; ++i) { 310 for (i = 0; i < ebcnt; ++i) {
306 bbt[i] = is_block_bad(i) ? 1 : 0; 311 bbt[i] = is_block_bad(i) ? 1 : 0;
@@ -309,6 +314,7 @@ static int scan_for_bad_eraseblocks(void)
309 cond_resched(); 314 cond_resched();
310 } 315 }
311 printk(PRINT_PREF "scanned %d eraseblocks, %d are bad\n", i, bad); 316 printk(PRINT_PREF "scanned %d eraseblocks, %d are bad\n", i, bad);
317out:
312 goodebcnt = ebcnt - bad; 318 goodebcnt = ebcnt - bad;
313 return 0; 319 return 0;
314} 320}
@@ -340,7 +346,7 @@ static int __init mtd_speedtest_init(void)
340 tmp = mtd->size; 346 tmp = mtd->size;
341 do_div(tmp, mtd->erasesize); 347 do_div(tmp, mtd->erasesize);
342 ebcnt = tmp; 348 ebcnt = tmp;
343 pgcnt = mtd->erasesize / mtd->writesize; 349 pgcnt = mtd->erasesize / pgsize;
344 350
345 printk(PRINT_PREF "MTD device size %llu, eraseblock size %u, " 351 printk(PRINT_PREF "MTD device size %llu, eraseblock size %u, "
346 "page size %u, count of eraseblocks %u, pages per " 352 "page size %u, count of eraseblocks %u, pages per "
diff --git a/drivers/mtd/tests/mtd_stresstest.c b/drivers/mtd/tests/mtd_stresstest.c
index 63920476b57a..3854afec56d0 100644
--- a/drivers/mtd/tests/mtd_stresstest.c
+++ b/drivers/mtd/tests/mtd_stresstest.c
@@ -24,6 +24,7 @@
24#include <linux/moduleparam.h> 24#include <linux/moduleparam.h>
25#include <linux/err.h> 25#include <linux/err.h>
26#include <linux/mtd/mtd.h> 26#include <linux/mtd/mtd.h>
27#include <linux/slab.h>
27#include <linux/sched.h> 28#include <linux/sched.h>
28#include <linux/vmalloc.h> 29#include <linux/vmalloc.h>
29 30
@@ -227,6 +228,10 @@ static int scan_for_bad_eraseblocks(void)
227 } 228 }
228 memset(bbt, 0 , ebcnt); 229 memset(bbt, 0 , ebcnt);
229 230
231 /* NOR flash does not implement block_isbad */
232 if (mtd->block_isbad == NULL)
233 return 0;
234
230 printk(PRINT_PREF "scanning for bad eraseblocks\n"); 235 printk(PRINT_PREF "scanning for bad eraseblocks\n");
231 for (i = 0; i < ebcnt; ++i) { 236 for (i = 0; i < ebcnt; ++i) {
232 bbt[i] = is_block_bad(i) ? 1 : 0; 237 bbt[i] = is_block_bad(i) ? 1 : 0;
@@ -265,7 +270,7 @@ static int __init mtd_stresstest_init(void)
265 tmp = mtd->size; 270 tmp = mtd->size;
266 do_div(tmp, mtd->erasesize); 271 do_div(tmp, mtd->erasesize);
267 ebcnt = tmp; 272 ebcnt = tmp;
268 pgcnt = mtd->erasesize / mtd->writesize; 273 pgcnt = mtd->erasesize / pgsize;
269 274
270 printk(PRINT_PREF "MTD device size %llu, eraseblock size %u, " 275 printk(PRINT_PREF "MTD device size %llu, eraseblock size %u, "
271 "page size %u, count of eraseblocks %u, pages per " 276 "page size %u, count of eraseblocks %u, pages per "
diff --git a/drivers/mtd/tests/mtd_subpagetest.c b/drivers/mtd/tests/mtd_subpagetest.c
index 5b889724268e..700237a3d120 100644
--- a/drivers/mtd/tests/mtd_subpagetest.c
+++ b/drivers/mtd/tests/mtd_subpagetest.c
@@ -24,6 +24,7 @@
24#include <linux/moduleparam.h> 24#include <linux/moduleparam.h>
25#include <linux/err.h> 25#include <linux/err.h>
26#include <linux/mtd/mtd.h> 26#include <linux/mtd/mtd.h>
27#include <linux/slab.h>
27#include <linux/sched.h> 28#include <linux/sched.h>
28 29
29#define PRINT_PREF KERN_INFO "mtd_subpagetest: " 30#define PRINT_PREF KERN_INFO "mtd_subpagetest: "
diff --git a/drivers/mtd/tests/mtd_torturetest.c b/drivers/mtd/tests/mtd_torturetest.c
index 631a0ab3a33c..5c6c3d248901 100644
--- a/drivers/mtd/tests/mtd_torturetest.c
+++ b/drivers/mtd/tests/mtd_torturetest.c
@@ -28,6 +28,7 @@
28#include <linux/moduleparam.h> 28#include <linux/moduleparam.h>
29#include <linux/err.h> 29#include <linux/err.h>
30#include <linux/mtd/mtd.h> 30#include <linux/mtd/mtd.h>
31#include <linux/slab.h>
31#include <linux/sched.h> 32#include <linux/sched.h>
32 33
33#define PRINT_PREF KERN_INFO "mtd_torturetest: " 34#define PRINT_PREF KERN_INFO "mtd_torturetest: "