aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/tests/pagetest.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mtd/tests/pagetest.c')
-rw-r--r--drivers/mtd/tests/pagetest.c205
1 files changed, 58 insertions, 147 deletions
diff --git a/drivers/mtd/tests/pagetest.c b/drivers/mtd/tests/pagetest.c
index acd991f4bf94..83189765eb05 100644
--- a/drivers/mtd/tests/pagetest.c
+++ b/drivers/mtd/tests/pagetest.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");
@@ -48,42 +50,15 @@ static int pgcnt;
48static int errcnt; 50static int errcnt;
49static struct rnd_state rnd_state; 51static struct rnd_state rnd_state;
50 52
51static int erase_eraseblock(int ebnum)
52{
53 int err;
54 struct erase_info ei;
55 loff_t addr = ebnum * mtd->erasesize;
56
57 memset(&ei, 0, sizeof(struct erase_info));
58 ei.mtd = mtd;
59 ei.addr = addr;
60 ei.len = mtd->erasesize;
61
62 err = mtd_erase(mtd, &ei);
63 if (err) {
64 pr_err("error %d while erasing EB %d\n", err, ebnum);
65 return err;
66 }
67
68 if (ei.state == MTD_ERASE_FAILED) {
69 pr_err("some erase error occurred at EB %d\n",
70 ebnum);
71 return -EIO;
72 }
73
74 return 0;
75}
76
77static int write_eraseblock(int ebnum) 53static int write_eraseblock(int ebnum)
78{ 54{
79 int err = 0; 55 int err;
80 size_t written;
81 loff_t addr = ebnum * mtd->erasesize; 56 loff_t addr = ebnum * mtd->erasesize;
82 57
83 prandom_bytes_state(&rnd_state, writebuf, mtd->erasesize); 58 prandom_bytes_state(&rnd_state, writebuf, mtd->erasesize);
84 cond_resched(); 59 cond_resched();
85 err = mtd_write(mtd, addr, mtd->erasesize, &written, writebuf); 60 err = mtdtest_write(mtd, addr, mtd->erasesize, writebuf);
86 if (err || written != mtd->erasesize) 61 if (err)
87 pr_err("error: write failed at %#llx\n", 62 pr_err("error: write failed at %#llx\n",
88 (long long)addr); 63 (long long)addr);
89 64
@@ -93,7 +68,6 @@ static int write_eraseblock(int ebnum)
93static int verify_eraseblock(int ebnum) 68static int verify_eraseblock(int ebnum)
94{ 69{
95 uint32_t j; 70 uint32_t j;
96 size_t read;
97 int err = 0, i; 71 int err = 0, i;
98 loff_t addr0, addrn; 72 loff_t addr0, addrn;
99 loff_t addr = ebnum * mtd->erasesize; 73 loff_t addr = ebnum * mtd->erasesize;
@@ -109,27 +83,21 @@ static int verify_eraseblock(int ebnum)
109 prandom_bytes_state(&rnd_state, writebuf, mtd->erasesize); 83 prandom_bytes_state(&rnd_state, writebuf, mtd->erasesize);
110 for (j = 0; j < pgcnt - 1; ++j, addr += pgsize) { 84 for (j = 0; j < pgcnt - 1; ++j, addr += pgsize) {
111 /* Do a read to set the internal dataRAMs to different data */ 85 /* Do a read to set the internal dataRAMs to different data */
112 err = mtd_read(mtd, addr0, bufsize, &read, twopages); 86 err = mtdtest_read(mtd, addr0, bufsize, twopages);
113 if (mtd_is_bitflip(err)) 87 if (err) {
114 err = 0;
115 if (err || read != bufsize) {
116 pr_err("error: read failed at %#llx\n", 88 pr_err("error: read failed at %#llx\n",
117 (long long)addr0); 89 (long long)addr0);
118 return err; 90 return err;
119 } 91 }
120 err = mtd_read(mtd, addrn - bufsize, bufsize, &read, twopages); 92 err = mtdtest_read(mtd, addrn - bufsize, bufsize, twopages);
121 if (mtd_is_bitflip(err)) 93 if (err) {
122 err = 0;
123 if (err || read != bufsize) {
124 pr_err("error: read failed at %#llx\n", 94 pr_err("error: read failed at %#llx\n",
125 (long long)(addrn - bufsize)); 95 (long long)(addrn - bufsize));
126 return err; 96 return err;
127 } 97 }
128 memset(twopages, 0, bufsize); 98 memset(twopages, 0, bufsize);
129 err = mtd_read(mtd, addr, bufsize, &read, twopages); 99 err = mtdtest_read(mtd, addr, bufsize, twopages);
130 if (mtd_is_bitflip(err)) 100 if (err) {
131 err = 0;
132 if (err || read != bufsize) {
133 pr_err("error: read failed at %#llx\n", 101 pr_err("error: read failed at %#llx\n",
134 (long long)addr); 102 (long long)addr);
135 break; 103 break;
@@ -145,27 +113,21 @@ static int verify_eraseblock(int ebnum)
145 struct rnd_state old_state = rnd_state; 113 struct rnd_state old_state = rnd_state;
146 114
147 /* Do a read to set the internal dataRAMs to different data */ 115 /* Do a read to set the internal dataRAMs to different data */
148 err = mtd_read(mtd, addr0, bufsize, &read, twopages); 116 err = mtdtest_read(mtd, addr0, bufsize, twopages);
149 if (mtd_is_bitflip(err)) 117 if (err) {
150 err = 0;
151 if (err || read != bufsize) {
152 pr_err("error: read failed at %#llx\n", 118 pr_err("error: read failed at %#llx\n",
153 (long long)addr0); 119 (long long)addr0);
154 return err; 120 return err;
155 } 121 }
156 err = mtd_read(mtd, addrn - bufsize, bufsize, &read, twopages); 122 err = mtdtest_read(mtd, addrn - bufsize, bufsize, twopages);
157 if (mtd_is_bitflip(err)) 123 if (err) {
158 err = 0;
159 if (err || read != bufsize) {
160 pr_err("error: read failed at %#llx\n", 124 pr_err("error: read failed at %#llx\n",
161 (long long)(addrn - bufsize)); 125 (long long)(addrn - bufsize));
162 return err; 126 return err;
163 } 127 }
164 memset(twopages, 0, bufsize); 128 memset(twopages, 0, bufsize);
165 err = mtd_read(mtd, addr, bufsize, &read, twopages); 129 err = mtdtest_read(mtd, addr, bufsize, twopages);
166 if (mtd_is_bitflip(err)) 130 if (err) {
167 err = 0;
168 if (err || read != bufsize) {
169 pr_err("error: read failed at %#llx\n", 131 pr_err("error: read failed at %#llx\n",
170 (long long)addr); 132 (long long)addr);
171 return err; 133 return err;
@@ -184,7 +146,6 @@ static int verify_eraseblock(int ebnum)
184 146
185static int crosstest(void) 147static int crosstest(void)
186{ 148{
187 size_t read;
188 int err = 0, i; 149 int err = 0, i;
189 loff_t addr, addr0, addrn; 150 loff_t addr, addr0, addrn;
190 unsigned char *pp1, *pp2, *pp3, *pp4; 151 unsigned char *pp1, *pp2, *pp3, *pp4;
@@ -208,10 +169,8 @@ static int crosstest(void)
208 169
209 /* Read 2nd-to-last page to pp1 */ 170 /* Read 2nd-to-last page to pp1 */
210 addr = addrn - pgsize - pgsize; 171 addr = addrn - pgsize - pgsize;
211 err = mtd_read(mtd, addr, pgsize, &read, pp1); 172 err = mtdtest_read(mtd, addr, pgsize, pp1);
212 if (mtd_is_bitflip(err)) 173 if (err) {
213 err = 0;
214 if (err || read != pgsize) {
215 pr_err("error: read failed at %#llx\n", 174 pr_err("error: read failed at %#llx\n",
216 (long long)addr); 175 (long long)addr);
217 kfree(pp1); 176 kfree(pp1);
@@ -220,10 +179,8 @@ static int crosstest(void)
220 179
221 /* Read 3rd-to-last page to pp1 */ 180 /* Read 3rd-to-last page to pp1 */
222 addr = addrn - pgsize - pgsize - pgsize; 181 addr = addrn - pgsize - pgsize - pgsize;
223 err = mtd_read(mtd, addr, pgsize, &read, pp1); 182 err = mtdtest_read(mtd, addr, pgsize, pp1);
224 if (mtd_is_bitflip(err)) 183 if (err) {
225 err = 0;
226 if (err || read != pgsize) {
227 pr_err("error: read failed at %#llx\n", 184 pr_err("error: read failed at %#llx\n",
228 (long long)addr); 185 (long long)addr);
229 kfree(pp1); 186 kfree(pp1);
@@ -233,10 +190,8 @@ static int crosstest(void)
233 /* Read first page to pp2 */ 190 /* Read first page to pp2 */
234 addr = addr0; 191 addr = addr0;
235 pr_info("reading page at %#llx\n", (long long)addr); 192 pr_info("reading page at %#llx\n", (long long)addr);
236 err = mtd_read(mtd, addr, pgsize, &read, pp2); 193 err = mtdtest_read(mtd, addr, pgsize, pp2);
237 if (mtd_is_bitflip(err)) 194 if (err) {
238 err = 0;
239 if (err || read != pgsize) {
240 pr_err("error: read failed at %#llx\n", 195 pr_err("error: read failed at %#llx\n",
241 (long long)addr); 196 (long long)addr);
242 kfree(pp1); 197 kfree(pp1);
@@ -246,10 +201,8 @@ static int crosstest(void)
246 /* Read last page to pp3 */ 201 /* Read last page to pp3 */
247 addr = addrn - pgsize; 202 addr = addrn - pgsize;
248 pr_info("reading page at %#llx\n", (long long)addr); 203 pr_info("reading page at %#llx\n", (long long)addr);
249 err = mtd_read(mtd, addr, pgsize, &read, pp3); 204 err = mtdtest_read(mtd, addr, pgsize, pp3);
250 if (mtd_is_bitflip(err)) 205 if (err) {
251 err = 0;
252 if (err || read != pgsize) {
253 pr_err("error: read failed at %#llx\n", 206 pr_err("error: read failed at %#llx\n",
254 (long long)addr); 207 (long long)addr);
255 kfree(pp1); 208 kfree(pp1);
@@ -259,10 +212,8 @@ static int crosstest(void)
259 /* Read first page again to pp4 */ 212 /* Read first page again to pp4 */
260 addr = addr0; 213 addr = addr0;
261 pr_info("reading page at %#llx\n", (long long)addr); 214 pr_info("reading page at %#llx\n", (long long)addr);
262 err = mtd_read(mtd, addr, pgsize, &read, pp4); 215 err = mtdtest_read(mtd, addr, pgsize, pp4);
263 if (mtd_is_bitflip(err)) 216 if (err) {
264 err = 0;
265 if (err || read != pgsize) {
266 pr_err("error: read failed at %#llx\n", 217 pr_err("error: read failed at %#llx\n",
267 (long long)addr); 218 (long long)addr);
268 kfree(pp1); 219 kfree(pp1);
@@ -283,7 +234,6 @@ static int crosstest(void)
283 234
284static int erasecrosstest(void) 235static int erasecrosstest(void)
285{ 236{
286 size_t read, written;
287 int err = 0, i, ebnum, ebnum2; 237 int err = 0, i, ebnum, ebnum2;
288 loff_t addr0; 238 loff_t addr0;
289 char *readbuf = twopages; 239 char *readbuf = twopages;
@@ -302,29 +252,27 @@ static int erasecrosstest(void)
302 ebnum2 -= 1; 252 ebnum2 -= 1;
303 253
304 pr_info("erasing block %d\n", ebnum); 254 pr_info("erasing block %d\n", ebnum);
305 err = erase_eraseblock(ebnum); 255 err = mtdtest_erase_eraseblock(mtd, ebnum);
306 if (err) 256 if (err)
307 return err; 257 return err;
308 258
309 pr_info("writing 1st page of block %d\n", ebnum); 259 pr_info("writing 1st page of block %d\n", ebnum);
310 prandom_bytes_state(&rnd_state, writebuf, pgsize); 260 prandom_bytes_state(&rnd_state, writebuf, pgsize);
311 strcpy(writebuf, "There is no data like this!"); 261 strcpy(writebuf, "There is no data like this!");
312 err = mtd_write(mtd, addr0, pgsize, &written, writebuf); 262 err = mtdtest_write(mtd, addr0, pgsize, writebuf);
313 if (err || written != pgsize) { 263 if (err) {
314 pr_info("error: write failed at %#llx\n", 264 pr_info("error: write failed at %#llx\n",
315 (long long)addr0); 265 (long long)addr0);
316 return err ? err : -1; 266 return err;
317 } 267 }
318 268
319 pr_info("reading 1st page of block %d\n", ebnum); 269 pr_info("reading 1st page of block %d\n", ebnum);
320 memset(readbuf, 0, pgsize); 270 memset(readbuf, 0, pgsize);
321 err = mtd_read(mtd, addr0, pgsize, &read, readbuf); 271 err = mtdtest_read(mtd, addr0, pgsize, readbuf);
322 if (mtd_is_bitflip(err)) 272 if (err) {
323 err = 0;
324 if (err || read != pgsize) {
325 pr_err("error: read failed at %#llx\n", 273 pr_err("error: read failed at %#llx\n",
326 (long long)addr0); 274 (long long)addr0);
327 return err ? err : -1; 275 return err;
328 } 276 }
329 277
330 pr_info("verifying 1st page of block %d\n", ebnum); 278 pr_info("verifying 1st page of block %d\n", ebnum);
@@ -335,34 +283,32 @@ static int erasecrosstest(void)
335 } 283 }
336 284
337 pr_info("erasing block %d\n", ebnum); 285 pr_info("erasing block %d\n", ebnum);
338 err = erase_eraseblock(ebnum); 286 err = mtdtest_erase_eraseblock(mtd, ebnum);
339 if (err) 287 if (err)
340 return err; 288 return err;
341 289
342 pr_info("writing 1st page of block %d\n", ebnum); 290 pr_info("writing 1st page of block %d\n", ebnum);
343 prandom_bytes_state(&rnd_state, writebuf, pgsize); 291 prandom_bytes_state(&rnd_state, writebuf, pgsize);
344 strcpy(writebuf, "There is no data like this!"); 292 strcpy(writebuf, "There is no data like this!");
345 err = mtd_write(mtd, addr0, pgsize, &written, writebuf); 293 err = mtdtest_write(mtd, addr0, pgsize, writebuf);
346 if (err || written != pgsize) { 294 if (err) {
347 pr_err("error: write failed at %#llx\n", 295 pr_err("error: write failed at %#llx\n",
348 (long long)addr0); 296 (long long)addr0);
349 return err ? err : -1; 297 return err;
350 } 298 }
351 299
352 pr_info("erasing block %d\n", ebnum2); 300 pr_info("erasing block %d\n", ebnum2);
353 err = erase_eraseblock(ebnum2); 301 err = mtdtest_erase_eraseblock(mtd, ebnum2);
354 if (err) 302 if (err)
355 return err; 303 return err;
356 304
357 pr_info("reading 1st page of block %d\n", ebnum); 305 pr_info("reading 1st page of block %d\n", ebnum);
358 memset(readbuf, 0, pgsize); 306 memset(readbuf, 0, pgsize);
359 err = mtd_read(mtd, addr0, pgsize, &read, readbuf); 307 err = mtdtest_read(mtd, addr0, pgsize, readbuf);
360 if (mtd_is_bitflip(err)) 308 if (err) {
361 err = 0;
362 if (err || read != pgsize) {
363 pr_err("error: read failed at %#llx\n", 309 pr_err("error: read failed at %#llx\n",
364 (long long)addr0); 310 (long long)addr0);
365 return err ? err : -1; 311 return err;
366 } 312 }
367 313
368 pr_info("verifying 1st page of block %d\n", ebnum); 314 pr_info("verifying 1st page of block %d\n", ebnum);
@@ -379,7 +325,6 @@ static int erasecrosstest(void)
379 325
380static int erasetest(void) 326static int erasetest(void)
381{ 327{
382 size_t read, written;
383 int err = 0, i, ebnum, ok = 1; 328 int err = 0, i, ebnum, ok = 1;
384 loff_t addr0; 329 loff_t addr0;
385 330
@@ -393,32 +338,30 @@ static int erasetest(void)
393 } 338 }
394 339
395 pr_info("erasing block %d\n", ebnum); 340 pr_info("erasing block %d\n", ebnum);
396 err = erase_eraseblock(ebnum); 341 err = mtdtest_erase_eraseblock(mtd, ebnum);
397 if (err) 342 if (err)
398 return err; 343 return err;
399 344
400 pr_info("writing 1st page of block %d\n", ebnum); 345 pr_info("writing 1st page of block %d\n", ebnum);
401 prandom_bytes_state(&rnd_state, writebuf, pgsize); 346 prandom_bytes_state(&rnd_state, writebuf, pgsize);
402 err = mtd_write(mtd, addr0, pgsize, &written, writebuf); 347 err = mtdtest_write(mtd, addr0, pgsize, writebuf);
403 if (err || written != pgsize) { 348 if (err) {
404 pr_err("error: write failed at %#llx\n", 349 pr_err("error: write failed at %#llx\n",
405 (long long)addr0); 350 (long long)addr0);
406 return err ? err : -1; 351 return err;
407 } 352 }
408 353
409 pr_info("erasing block %d\n", ebnum); 354 pr_info("erasing block %d\n", ebnum);
410 err = erase_eraseblock(ebnum); 355 err = mtdtest_erase_eraseblock(mtd, ebnum);
411 if (err) 356 if (err)
412 return err; 357 return err;
413 358
414 pr_info("reading 1st page of block %d\n", ebnum); 359 pr_info("reading 1st page of block %d\n", ebnum);
415 err = mtd_read(mtd, addr0, pgsize, &read, twopages); 360 err = mtdtest_read(mtd, addr0, pgsize, twopages);
416 if (mtd_is_bitflip(err)) 361 if (err) {
417 err = 0;
418 if (err || read != pgsize) {
419 pr_err("error: read failed at %#llx\n", 362 pr_err("error: read failed at %#llx\n",
420 (long long)addr0); 363 (long long)addr0);
421 return err ? err : -1; 364 return err;
422 } 365 }
423 366
424 pr_info("verifying 1st page of block %d is all 0xff\n", 367 pr_info("verifying 1st page of block %d is all 0xff\n",
@@ -438,36 +381,6 @@ static int erasetest(void)
438 return err; 381 return err;
439} 382}
440 383
441static int is_block_bad(int ebnum)
442{
443 loff_t addr = ebnum * mtd->erasesize;
444 int ret;
445
446 ret = mtd_block_isbad(mtd, addr);
447 if (ret)
448 pr_info("block %d is bad\n", ebnum);
449 return ret;
450}
451
452static int scan_for_bad_eraseblocks(void)
453{
454 int i, bad = 0;
455
456 bbt = kzalloc(ebcnt, GFP_KERNEL);
457 if (!bbt)
458 return -ENOMEM;
459
460 pr_info("scanning for bad eraseblocks\n");
461 for (i = 0; i < ebcnt; ++i) {
462 bbt[i] = is_block_bad(i) ? 1 : 0;
463 if (bbt[i])
464 bad += 1;
465 cond_resched();
466 }
467 pr_info("scanned %d eraseblocks, %d are bad\n", i, bad);
468 return 0;
469}
470
471static int __init mtd_pagetest_init(void) 384static int __init mtd_pagetest_init(void)
472{ 385{
473 int err = 0; 386 int err = 0;
@@ -521,21 +434,19 @@ static int __init mtd_pagetest_init(void)
521 if (!boundary) 434 if (!boundary)
522 goto out; 435 goto out;
523 436
524 err = scan_for_bad_eraseblocks(); 437 bbt = kzalloc(ebcnt, GFP_KERNEL);
438 if (!bbt)
439 goto out;
440 err = mtdtest_scan_for_bad_eraseblocks(mtd, bbt, 0, ebcnt);
525 if (err) 441 if (err)
526 goto out; 442 goto out;
527 443
528 /* Erase all eraseblocks */ 444 /* Erase all eraseblocks */
529 pr_info("erasing whole device\n"); 445 pr_info("erasing whole device\n");
530 for (i = 0; i < ebcnt; ++i) { 446 err = mtdtest_erase_good_eraseblocks(mtd, bbt, 0, ebcnt);
531 if (bbt[i]) 447 if (err)
532 continue; 448 goto out;
533 err = erase_eraseblock(i); 449 pr_info("erased %u eraseblocks\n", ebcnt);
534 if (err)
535 goto out;
536 cond_resched();
537 }
538 pr_info("erased %u eraseblocks\n", i);
539 450
540 /* Write all eraseblocks */ 451 /* Write all eraseblocks */
541 prandom_seed_state(&rnd_state, 1); 452 prandom_seed_state(&rnd_state, 1);