aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/mtd/tests/oobtest.c92
1 files changed, 12 insertions, 80 deletions
diff --git a/drivers/mtd/tests/oobtest.c b/drivers/mtd/tests/oobtest.c
index ab81e9a5947e..ff35c465bfee 100644
--- a/drivers/mtd/tests/oobtest.c
+++ b/drivers/mtd/tests/oobtest.c
@@ -31,6 +31,8 @@
31#include <linux/sched.h> 31#include <linux/sched.h>
32#include <linux/random.h> 32#include <linux/random.h>
33 33
34#include "mtd_test.h"
35
34static int dev = -EINVAL; 36static int dev = -EINVAL;
35module_param(dev, int, S_IRUGO); 37module_param(dev, int, S_IRUGO);
36MODULE_PARM_DESC(dev, "MTD device number to use"); 38MODULE_PARM_DESC(dev, "MTD device number to use");
@@ -49,49 +51,6 @@ static int use_len_max;
49static int vary_offset; 51static int vary_offset;
50static struct rnd_state rnd_state; 52static struct rnd_state rnd_state;
51 53
52static int erase_eraseblock(int ebnum)
53{
54 int err;
55 struct erase_info ei;
56 loff_t addr = ebnum * mtd->erasesize;
57
58 memset(&ei, 0, sizeof(struct erase_info));
59 ei.mtd = mtd;
60 ei.addr = addr;
61 ei.len = mtd->erasesize;
62
63 err = mtd_erase(mtd, &ei);
64 if (err) {
65 pr_err("error %d while erasing EB %d\n", err, ebnum);
66 return err;
67 }
68
69 if (ei.state == MTD_ERASE_FAILED) {
70 pr_err("some erase error occurred at EB %d\n", ebnum);
71 return -EIO;
72 }
73
74 return 0;
75}
76
77static int erase_whole_device(void)
78{
79 int err;
80 unsigned int i;
81
82 pr_info("erasing whole device\n");
83 for (i = 0; i < ebcnt; ++i) {
84 if (bbt[i])
85 continue;
86 err = erase_eraseblock(i);
87 if (err)
88 return err;
89 cond_resched();
90 }
91 pr_info("erased %u eraseblocks\n", i);
92 return 0;
93}
94
95static void do_vary_offset(void) 54static void do_vary_offset(void)
96{ 55{
97 use_len -= 1; 56 use_len -= 1;
@@ -304,36 +263,6 @@ static int verify_all_eraseblocks(void)
304 return 0; 263 return 0;
305} 264}
306 265
307static int is_block_bad(int ebnum)
308{
309 int ret;
310 loff_t addr = ebnum * mtd->erasesize;
311
312 ret = mtd_block_isbad(mtd, addr);
313 if (ret)
314 pr_info("block %d is bad\n", ebnum);
315 return ret;
316}
317
318static int scan_for_bad_eraseblocks(void)
319{
320 int i, bad = 0;
321
322 bbt = kmalloc(ebcnt, GFP_KERNEL);
323 if (!bbt)
324 return -ENOMEM;
325
326 pr_info("scanning for bad eraseblocks\n");
327 for (i = 0; i < ebcnt; ++i) {
328 bbt[i] = is_block_bad(i) ? 1 : 0;
329 if (bbt[i])
330 bad += 1;
331 cond_resched();
332 }
333 pr_info("scanned %d eraseblocks, %d are bad\n", i, bad);
334 return 0;
335}
336
337static int __init mtd_oobtest_init(void) 266static int __init mtd_oobtest_init(void)
338{ 267{
339 int err = 0; 268 int err = 0;
@@ -383,8 +312,11 @@ static int __init mtd_oobtest_init(void)
383 writebuf = kmalloc(mtd->erasesize, GFP_KERNEL); 312 writebuf = kmalloc(mtd->erasesize, GFP_KERNEL);
384 if (!writebuf) 313 if (!writebuf)
385 goto out; 314 goto out;
315 bbt = kzalloc(ebcnt, GFP_KERNEL);
316 if (!bbt)
317 goto out;
386 318
387 err = scan_for_bad_eraseblocks(); 319 err = mtdtest_scan_for_bad_eraseblocks(mtd, bbt, 0, ebcnt);
388 if (err) 320 if (err)
389 goto out; 321 goto out;
390 322
@@ -396,7 +328,7 @@ static int __init mtd_oobtest_init(void)
396 /* First test: write all OOB, read it back and verify */ 328 /* First test: write all OOB, read it back and verify */
397 pr_info("test 1 of 5\n"); 329 pr_info("test 1 of 5\n");
398 330
399 err = erase_whole_device(); 331 err = mtdtest_erase_good_eraseblocks(mtd, bbt, 0, ebcnt);
400 if (err) 332 if (err)
401 goto out; 333 goto out;
402 334
@@ -416,7 +348,7 @@ static int __init mtd_oobtest_init(void)
416 */ 348 */
417 pr_info("test 2 of 5\n"); 349 pr_info("test 2 of 5\n");
418 350
419 err = erase_whole_device(); 351 err = mtdtest_erase_good_eraseblocks(mtd, bbt, 0, ebcnt);
420 if (err) 352 if (err)
421 goto out; 353 goto out;
422 354
@@ -446,7 +378,7 @@ static int __init mtd_oobtest_init(void)
446 */ 378 */
447 pr_info("test 3 of 5\n"); 379 pr_info("test 3 of 5\n");
448 380
449 err = erase_whole_device(); 381 err = mtdtest_erase_good_eraseblocks(mtd, bbt, 0, ebcnt);
450 if (err) 382 if (err)
451 goto out; 383 goto out;
452 384
@@ -479,7 +411,7 @@ static int __init mtd_oobtest_init(void)
479 /* Fourth test: try to write off end of device */ 411 /* Fourth test: try to write off end of device */
480 pr_info("test 4 of 5\n"); 412 pr_info("test 4 of 5\n");
481 413
482 err = erase_whole_device(); 414 err = mtdtest_erase_good_eraseblocks(mtd, bbt, 0, ebcnt);
483 if (err) 415 if (err)
484 goto out; 416 goto out;
485 417
@@ -571,7 +503,7 @@ static int __init mtd_oobtest_init(void)
571 errcnt += 1; 503 errcnt += 1;
572 } 504 }
573 505
574 err = erase_eraseblock(ebcnt - 1); 506 err = mtdtest_erase_eraseblock(mtd, ebcnt - 1);
575 if (err) 507 if (err)
576 goto out; 508 goto out;
577 509
@@ -620,7 +552,7 @@ static int __init mtd_oobtest_init(void)
620 pr_info("test 5 of 5\n"); 552 pr_info("test 5 of 5\n");
621 553
622 /* Erase all eraseblocks */ 554 /* Erase all eraseblocks */
623 err = erase_whole_device(); 555 err = mtdtest_erase_good_eraseblocks(mtd, bbt, 0, ebcnt);
624 if (err) 556 if (err)
625 goto out; 557 goto out;
626 558