blob: aecc6ce5a9e1c131a38d657325356ab590de845c [file] [log] [blame]
Artem Bityutskiybf608622008-12-08 13:37:48 +02001/*
2 * Copyright (C) 2006-2007 Nokia Corporation
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 2 as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program; see the file COPYING. If not, write to the Free Software
15 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 *
17 * Test sub-page read and write on MTD device.
18 * Author: Adrian Hunter <ext-adrian.hunter@nokia.com>
19 *
20 */
21
Vikram Narayanancd66a2d2012-10-10 23:11:06 +053022#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
23
Artem Bityutskiybf608622008-12-08 13:37:48 +020024#include <linux/init.h>
25#include <linux/module.h>
26#include <linux/moduleparam.h>
27#include <linux/err.h>
28#include <linux/mtd/mtd.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090029#include <linux/slab.h>
Artem Bityutskiybf608622008-12-08 13:37:48 +020030#include <linux/sched.h>
Akinobu Mitaa312b782013-02-27 17:05:39 -080031#include <linux/random.h>
Artem Bityutskiybf608622008-12-08 13:37:48 +020032
Akinobu Mita725cd712013-08-03 18:52:14 +090033#include "mtd_test.h"
34
Wolfram Sang74060602011-10-30 00:11:53 +020035static int dev = -EINVAL;
Artem Bityutskiybf608622008-12-08 13:37:48 +020036module_param(dev, int, S_IRUGO);
37MODULE_PARM_DESC(dev, "MTD device number to use");
38
39static struct mtd_info *mtd;
40static unsigned char *writebuf;
41static unsigned char *readbuf;
42static unsigned char *bbt;
43
44static int subpgsize;
45static int bufsize;
46static int ebcnt;
47static int pgcnt;
48static int errcnt;
Akinobu Mitaa312b782013-02-27 17:05:39 -080049static struct rnd_state rnd_state;
Artem Bityutskiybf608622008-12-08 13:37:48 +020050
51static inline void clear_data(unsigned char *buf, size_t len)
52{
53 memset(buf, 0, len);
54}
55
Artem Bityutskiybf608622008-12-08 13:37:48 +020056static int write_eraseblock(int ebnum)
57{
Artem Bityutskiy30fa9842011-12-29 15:16:28 +020058 size_t written;
Artem Bityutskiybf608622008-12-08 13:37:48 +020059 int err = 0;
Brian Norris1001ff7a2014-07-21 19:07:12 -070060 loff_t addr = (loff_t)ebnum * mtd->erasesize;
Artem Bityutskiybf608622008-12-08 13:37:48 +020061
Akinobu Mitaa312b782013-02-27 17:05:39 -080062 prandom_bytes_state(&rnd_state, writebuf, subpgsize);
Artem Bityutskiyeda95cb2011-12-23 17:35:41 +020063 err = mtd_write(mtd, addr, subpgsize, &written, writebuf);
Artem Bityutskiybf608622008-12-08 13:37:48 +020064 if (unlikely(err || written != subpgsize)) {
Vikram Narayanancd66a2d2012-10-10 23:11:06 +053065 pr_err("error: write failed at %#llx\n",
Artem Bityutskiybf608622008-12-08 13:37:48 +020066 (long long)addr);
67 if (written != subpgsize) {
Vikram Narayanancd66a2d2012-10-10 23:11:06 +053068 pr_err(" write size: %#x\n", subpgsize);
69 pr_err(" written: %#zx\n", written);
Artem Bityutskiybf608622008-12-08 13:37:48 +020070 }
71 return err ? err : -1;
72 }
73
74 addr += subpgsize;
75
Akinobu Mitaa312b782013-02-27 17:05:39 -080076 prandom_bytes_state(&rnd_state, writebuf, subpgsize);
Artem Bityutskiyeda95cb2011-12-23 17:35:41 +020077 err = mtd_write(mtd, addr, subpgsize, &written, writebuf);
Artem Bityutskiybf608622008-12-08 13:37:48 +020078 if (unlikely(err || written != subpgsize)) {
Vikram Narayanancd66a2d2012-10-10 23:11:06 +053079 pr_err("error: write failed at %#llx\n",
Artem Bityutskiybf608622008-12-08 13:37:48 +020080 (long long)addr);
81 if (written != subpgsize) {
Vikram Narayanancd66a2d2012-10-10 23:11:06 +053082 pr_err(" write size: %#x\n", subpgsize);
83 pr_err(" written: %#zx\n", written);
Artem Bityutskiybf608622008-12-08 13:37:48 +020084 }
85 return err ? err : -1;
86 }
87
88 return err;
89}
90
91static int write_eraseblock2(int ebnum)
92{
Artem Bityutskiy30fa9842011-12-29 15:16:28 +020093 size_t written;
Artem Bityutskiybf608622008-12-08 13:37:48 +020094 int err = 0, k;
Brian Norris1001ff7a2014-07-21 19:07:12 -070095 loff_t addr = (loff_t)ebnum * mtd->erasesize;
Artem Bityutskiybf608622008-12-08 13:37:48 +020096
97 for (k = 1; k < 33; ++k) {
Brian Norrisb9da8ba2015-02-28 02:02:26 -080098 if (addr + (subpgsize * k) > (loff_t)(ebnum + 1) * mtd->erasesize)
Artem Bityutskiybf608622008-12-08 13:37:48 +020099 break;
Akinobu Mitaa312b782013-02-27 17:05:39 -0800100 prandom_bytes_state(&rnd_state, writebuf, subpgsize * k);
Artem Bityutskiyeda95cb2011-12-23 17:35:41 +0200101 err = mtd_write(mtd, addr, subpgsize * k, &written, writebuf);
Artem Bityutskiybf608622008-12-08 13:37:48 +0200102 if (unlikely(err || written != subpgsize * k)) {
Vikram Narayanancd66a2d2012-10-10 23:11:06 +0530103 pr_err("error: write failed at %#llx\n",
Artem Bityutskiybf608622008-12-08 13:37:48 +0200104 (long long)addr);
105 if (written != subpgsize) {
Vikram Narayanancd66a2d2012-10-10 23:11:06 +0530106 pr_err(" write size: %#x\n",
Artem Bityutskiybf608622008-12-08 13:37:48 +0200107 subpgsize * k);
Vikram Narayanancd66a2d2012-10-10 23:11:06 +0530108 pr_err(" written: %#08zx\n",
Artem Bityutskiybf608622008-12-08 13:37:48 +0200109 written);
110 }
111 return err ? err : -1;
112 }
113 addr += subpgsize * k;
114 }
115
116 return err;
117}
118
119static void print_subpage(unsigned char *p)
120{
121 int i, j;
122
123 for (i = 0; i < subpgsize; ) {
124 for (j = 0; i < subpgsize && j < 32; ++i, ++j)
125 printk("%02x", *p++);
126 printk("\n");
127 }
128}
129
130static int verify_eraseblock(int ebnum)
131{
Artem Bityutskiy30fa9842011-12-29 15:16:28 +0200132 size_t read;
Artem Bityutskiybf608622008-12-08 13:37:48 +0200133 int err = 0;
Brian Norris1001ff7a2014-07-21 19:07:12 -0700134 loff_t addr = (loff_t)ebnum * mtd->erasesize;
Artem Bityutskiybf608622008-12-08 13:37:48 +0200135
Akinobu Mitaa312b782013-02-27 17:05:39 -0800136 prandom_bytes_state(&rnd_state, writebuf, subpgsize);
Artem Bityutskiybf608622008-12-08 13:37:48 +0200137 clear_data(readbuf, subpgsize);
Artem Bityutskiy329ad392011-12-23 17:30:16 +0200138 err = mtd_read(mtd, addr, subpgsize, &read, readbuf);
Artem Bityutskiybf608622008-12-08 13:37:48 +0200139 if (unlikely(err || read != subpgsize)) {
Brian Norrisd57f40542011-09-20 18:34:25 -0700140 if (mtd_is_bitflip(err) && read == subpgsize) {
Vikram Narayanancd66a2d2012-10-10 23:11:06 +0530141 pr_info("ECC correction at %#llx\n",
Artem Bityutskiybf608622008-12-08 13:37:48 +0200142 (long long)addr);
143 err = 0;
144 } else {
Vikram Narayanancd66a2d2012-10-10 23:11:06 +0530145 pr_err("error: read failed at %#llx\n",
Artem Bityutskiybf608622008-12-08 13:37:48 +0200146 (long long)addr);
147 return err ? err : -1;
148 }
149 }
150 if (unlikely(memcmp(readbuf, writebuf, subpgsize))) {
Vikram Narayanancd66a2d2012-10-10 23:11:06 +0530151 pr_err("error: verify failed at %#llx\n",
Artem Bityutskiybf608622008-12-08 13:37:48 +0200152 (long long)addr);
Vikram Narayanancd66a2d2012-10-10 23:11:06 +0530153 pr_info("------------- written----------------\n");
Artem Bityutskiybf608622008-12-08 13:37:48 +0200154 print_subpage(writebuf);
Vikram Narayanancd66a2d2012-10-10 23:11:06 +0530155 pr_info("------------- read ------------------\n");
Artem Bityutskiybf608622008-12-08 13:37:48 +0200156 print_subpage(readbuf);
Vikram Narayanancd66a2d2012-10-10 23:11:06 +0530157 pr_info("-------------------------------------\n");
Artem Bityutskiybf608622008-12-08 13:37:48 +0200158 errcnt += 1;
159 }
160
161 addr += subpgsize;
162
Akinobu Mitaa312b782013-02-27 17:05:39 -0800163 prandom_bytes_state(&rnd_state, writebuf, subpgsize);
Artem Bityutskiybf608622008-12-08 13:37:48 +0200164 clear_data(readbuf, subpgsize);
Artem Bityutskiy329ad392011-12-23 17:30:16 +0200165 err = mtd_read(mtd, addr, subpgsize, &read, readbuf);
Artem Bityutskiybf608622008-12-08 13:37:48 +0200166 if (unlikely(err || read != subpgsize)) {
Brian Norrisd57f40542011-09-20 18:34:25 -0700167 if (mtd_is_bitflip(err) && read == subpgsize) {
Vikram Narayanancd66a2d2012-10-10 23:11:06 +0530168 pr_info("ECC correction at %#llx\n",
Artem Bityutskiybf608622008-12-08 13:37:48 +0200169 (long long)addr);
170 err = 0;
171 } else {
Vikram Narayanancd66a2d2012-10-10 23:11:06 +0530172 pr_err("error: read failed at %#llx\n",
Artem Bityutskiybf608622008-12-08 13:37:48 +0200173 (long long)addr);
174 return err ? err : -1;
175 }
176 }
177 if (unlikely(memcmp(readbuf, writebuf, subpgsize))) {
Vikram Narayanancd66a2d2012-10-10 23:11:06 +0530178 pr_info("error: verify failed at %#llx\n",
Artem Bityutskiybf608622008-12-08 13:37:48 +0200179 (long long)addr);
Vikram Narayanancd66a2d2012-10-10 23:11:06 +0530180 pr_info("------------- written----------------\n");
Artem Bityutskiybf608622008-12-08 13:37:48 +0200181 print_subpage(writebuf);
Vikram Narayanancd66a2d2012-10-10 23:11:06 +0530182 pr_info("------------- read ------------------\n");
Artem Bityutskiybf608622008-12-08 13:37:48 +0200183 print_subpage(readbuf);
Vikram Narayanancd66a2d2012-10-10 23:11:06 +0530184 pr_info("-------------------------------------\n");
Artem Bityutskiybf608622008-12-08 13:37:48 +0200185 errcnt += 1;
186 }
187
188 return err;
189}
190
191static int verify_eraseblock2(int ebnum)
192{
Artem Bityutskiy30fa9842011-12-29 15:16:28 +0200193 size_t read;
Artem Bityutskiybf608622008-12-08 13:37:48 +0200194 int err = 0, k;
Brian Norris1001ff7a2014-07-21 19:07:12 -0700195 loff_t addr = (loff_t)ebnum * mtd->erasesize;
Artem Bityutskiybf608622008-12-08 13:37:48 +0200196
197 for (k = 1; k < 33; ++k) {
Brian Norrisb9da8ba2015-02-28 02:02:26 -0800198 if (addr + (subpgsize * k) > (loff_t)(ebnum + 1) * mtd->erasesize)
Artem Bityutskiybf608622008-12-08 13:37:48 +0200199 break;
Akinobu Mitaa312b782013-02-27 17:05:39 -0800200 prandom_bytes_state(&rnd_state, writebuf, subpgsize * k);
Artem Bityutskiybf608622008-12-08 13:37:48 +0200201 clear_data(readbuf, subpgsize * k);
Artem Bityutskiy329ad392011-12-23 17:30:16 +0200202 err = mtd_read(mtd, addr, subpgsize * k, &read, readbuf);
Artem Bityutskiybf608622008-12-08 13:37:48 +0200203 if (unlikely(err || read != subpgsize * k)) {
Brian Norrisd57f40542011-09-20 18:34:25 -0700204 if (mtd_is_bitflip(err) && read == subpgsize * k) {
Vikram Narayanancd66a2d2012-10-10 23:11:06 +0530205 pr_info("ECC correction at %#llx\n",
Artem Bityutskiybf608622008-12-08 13:37:48 +0200206 (long long)addr);
207 err = 0;
208 } else {
Vikram Narayanancd66a2d2012-10-10 23:11:06 +0530209 pr_err("error: read failed at "
Artem Bityutskiybf608622008-12-08 13:37:48 +0200210 "%#llx\n", (long long)addr);
211 return err ? err : -1;
212 }
213 }
214 if (unlikely(memcmp(readbuf, writebuf, subpgsize * k))) {
Vikram Narayanancd66a2d2012-10-10 23:11:06 +0530215 pr_err("error: verify failed at %#llx\n",
Artem Bityutskiybf608622008-12-08 13:37:48 +0200216 (long long)addr);
217 errcnt += 1;
218 }
219 addr += subpgsize * k;
220 }
221
222 return err;
223}
224
225static int verify_eraseblock_ff(int ebnum)
226{
227 uint32_t j;
Artem Bityutskiy30fa9842011-12-29 15:16:28 +0200228 size_t read;
Artem Bityutskiybf608622008-12-08 13:37:48 +0200229 int err = 0;
Brian Norris1001ff7a2014-07-21 19:07:12 -0700230 loff_t addr = (loff_t)ebnum * mtd->erasesize;
Artem Bityutskiybf608622008-12-08 13:37:48 +0200231
232 memset(writebuf, 0xff, subpgsize);
233 for (j = 0; j < mtd->erasesize / subpgsize; ++j) {
234 clear_data(readbuf, subpgsize);
Artem Bityutskiy329ad392011-12-23 17:30:16 +0200235 err = mtd_read(mtd, addr, subpgsize, &read, readbuf);
Artem Bityutskiybf608622008-12-08 13:37:48 +0200236 if (unlikely(err || read != subpgsize)) {
Brian Norrisd57f40542011-09-20 18:34:25 -0700237 if (mtd_is_bitflip(err) && read == subpgsize) {
Vikram Narayanancd66a2d2012-10-10 23:11:06 +0530238 pr_info("ECC correction at %#llx\n",
Artem Bityutskiybf608622008-12-08 13:37:48 +0200239 (long long)addr);
240 err = 0;
241 } else {
Vikram Narayanancd66a2d2012-10-10 23:11:06 +0530242 pr_err("error: read failed at "
Artem Bityutskiybf608622008-12-08 13:37:48 +0200243 "%#llx\n", (long long)addr);
244 return err ? err : -1;
245 }
246 }
247 if (unlikely(memcmp(readbuf, writebuf, subpgsize))) {
Vikram Narayanancd66a2d2012-10-10 23:11:06 +0530248 pr_err("error: verify 0xff failed at "
Artem Bityutskiybf608622008-12-08 13:37:48 +0200249 "%#llx\n", (long long)addr);
250 errcnt += 1;
251 }
252 addr += subpgsize;
253 }
254
255 return err;
256}
257
258static int verify_all_eraseblocks_ff(void)
259{
260 int err;
261 unsigned int i;
262
Vikram Narayanancd66a2d2012-10-10 23:11:06 +0530263 pr_info("verifying all eraseblocks for 0xff\n");
Artem Bityutskiybf608622008-12-08 13:37:48 +0200264 for (i = 0; i < ebcnt; ++i) {
265 if (bbt[i])
266 continue;
267 err = verify_eraseblock_ff(i);
268 if (err)
269 return err;
270 if (i % 256 == 0)
Vikram Narayanancd66a2d2012-10-10 23:11:06 +0530271 pr_info("verified up to eraseblock %u\n", i);
Richard Weinberger2a6a28e72015-03-29 21:52:06 +0200272
273 err = mtdtest_relax();
274 if (err)
275 return err;
Artem Bityutskiybf608622008-12-08 13:37:48 +0200276 }
Vikram Narayanancd66a2d2012-10-10 23:11:06 +0530277 pr_info("verified %u eraseblocks\n", i);
Artem Bityutskiybf608622008-12-08 13:37:48 +0200278 return 0;
279}
280
Artem Bityutskiybf608622008-12-08 13:37:48 +0200281static int __init mtd_subpagetest_init(void)
282{
283 int err = 0;
284 uint32_t i;
285 uint64_t tmp;
286
287 printk(KERN_INFO "\n");
288 printk(KERN_INFO "=================================================\n");
Wolfram Sang74060602011-10-30 00:11:53 +0200289
290 if (dev < 0) {
Masanari Iida064a76942012-11-09 23:20:58 +0900291 pr_info("Please specify a valid mtd-device via module parameter\n");
Vikram Narayanancd66a2d2012-10-10 23:11:06 +0530292 pr_crit("CAREFUL: This test wipes all data on the specified MTD device!\n");
Wolfram Sang74060602011-10-30 00:11:53 +0200293 return -EINVAL;
294 }
295
Vikram Narayanancd66a2d2012-10-10 23:11:06 +0530296 pr_info("MTD device: %d\n", dev);
Artem Bityutskiybf608622008-12-08 13:37:48 +0200297
298 mtd = get_mtd_device(NULL, dev);
299 if (IS_ERR(mtd)) {
300 err = PTR_ERR(mtd);
Vikram Narayanancd66a2d2012-10-10 23:11:06 +0530301 pr_err("error: cannot get MTD device\n");
Artem Bityutskiybf608622008-12-08 13:37:48 +0200302 return err;
303 }
304
Huang Shijie818b9732013-09-25 14:58:17 +0800305 if (!mtd_type_is_nand(mtd)) {
Vikram Narayanancd66a2d2012-10-10 23:11:06 +0530306 pr_info("this test requires NAND flash\n");
Artem Bityutskiybf608622008-12-08 13:37:48 +0200307 goto out;
308 }
309
310 subpgsize = mtd->writesize >> mtd->subpage_sft;
Roman Tereshonkov7b7e9052011-02-03 13:45:56 +0200311 tmp = mtd->size;
312 do_div(tmp, mtd->erasesize);
313 ebcnt = tmp;
314 pgcnt = mtd->erasesize / mtd->writesize;
315
Vikram Narayanancd66a2d2012-10-10 23:11:06 +0530316 pr_info("MTD device size %llu, eraseblock size %u, "
Artem Bityutskiybf608622008-12-08 13:37:48 +0200317 "page size %u, subpage size %u, count of eraseblocks %u, "
318 "pages per eraseblock %u, OOB size %u\n",
319 (unsigned long long)mtd->size, mtd->erasesize,
320 mtd->writesize, subpgsize, ebcnt, pgcnt, mtd->oobsize);
321
322 err = -ENOMEM;
323 bufsize = subpgsize * 32;
324 writebuf = kmalloc(bufsize, GFP_KERNEL);
Brian Norris33777e62013-05-02 14:18:51 -0700325 if (!writebuf)
Artem Bityutskiybf608622008-12-08 13:37:48 +0200326 goto out;
Artem Bityutskiybf608622008-12-08 13:37:48 +0200327 readbuf = kmalloc(bufsize, GFP_KERNEL);
Brian Norris33777e62013-05-02 14:18:51 -0700328 if (!readbuf)
Artem Bityutskiybf608622008-12-08 13:37:48 +0200329 goto out;
Akinobu Mita725cd712013-08-03 18:52:14 +0900330 bbt = kzalloc(ebcnt, GFP_KERNEL);
331 if (!bbt)
332 goto out;
Artem Bityutskiybf608622008-12-08 13:37:48 +0200333
Akinobu Mita725cd712013-08-03 18:52:14 +0900334 err = mtdtest_scan_for_bad_eraseblocks(mtd, bbt, 0, ebcnt);
Artem Bityutskiybf608622008-12-08 13:37:48 +0200335 if (err)
336 goto out;
337
Akinobu Mita725cd712013-08-03 18:52:14 +0900338 err = mtdtest_erase_good_eraseblocks(mtd, bbt, 0, ebcnt);
Artem Bityutskiybf608622008-12-08 13:37:48 +0200339 if (err)
340 goto out;
341
Vikram Narayanancd66a2d2012-10-10 23:11:06 +0530342 pr_info("writing whole device\n");
Akinobu Mitaa312b782013-02-27 17:05:39 -0800343 prandom_seed_state(&rnd_state, 1);
Artem Bityutskiybf608622008-12-08 13:37:48 +0200344 for (i = 0; i < ebcnt; ++i) {
345 if (bbt[i])
346 continue;
347 err = write_eraseblock(i);
348 if (unlikely(err))
349 goto out;
350 if (i % 256 == 0)
Vikram Narayanancd66a2d2012-10-10 23:11:06 +0530351 pr_info("written up to eraseblock %u\n", i);
Richard Weinberger2a6a28e72015-03-29 21:52:06 +0200352
353 err = mtdtest_relax();
354 if (err)
355 goto out;
Artem Bityutskiybf608622008-12-08 13:37:48 +0200356 }
Vikram Narayanancd66a2d2012-10-10 23:11:06 +0530357 pr_info("written %u eraseblocks\n", i);
Artem Bityutskiybf608622008-12-08 13:37:48 +0200358
Akinobu Mitaa312b782013-02-27 17:05:39 -0800359 prandom_seed_state(&rnd_state, 1);
Vikram Narayanancd66a2d2012-10-10 23:11:06 +0530360 pr_info("verifying all eraseblocks\n");
Artem Bityutskiybf608622008-12-08 13:37:48 +0200361 for (i = 0; i < ebcnt; ++i) {
362 if (bbt[i])
363 continue;
364 err = verify_eraseblock(i);
365 if (unlikely(err))
366 goto out;
367 if (i % 256 == 0)
Vikram Narayanancd66a2d2012-10-10 23:11:06 +0530368 pr_info("verified up to eraseblock %u\n", i);
Richard Weinberger2a6a28e72015-03-29 21:52:06 +0200369
370 err = mtdtest_relax();
371 if (err)
372 goto out;
Artem Bityutskiybf608622008-12-08 13:37:48 +0200373 }
Vikram Narayanancd66a2d2012-10-10 23:11:06 +0530374 pr_info("verified %u eraseblocks\n", i);
Artem Bityutskiybf608622008-12-08 13:37:48 +0200375
Akinobu Mita725cd712013-08-03 18:52:14 +0900376 err = mtdtest_erase_good_eraseblocks(mtd, bbt, 0, ebcnt);
Artem Bityutskiybf608622008-12-08 13:37:48 +0200377 if (err)
378 goto out;
379
380 err = verify_all_eraseblocks_ff();
381 if (err)
382 goto out;
383
384 /* Write all eraseblocks */
Akinobu Mitaa312b782013-02-27 17:05:39 -0800385 prandom_seed_state(&rnd_state, 3);
Vikram Narayanancd66a2d2012-10-10 23:11:06 +0530386 pr_info("writing whole device\n");
Artem Bityutskiybf608622008-12-08 13:37:48 +0200387 for (i = 0; i < ebcnt; ++i) {
388 if (bbt[i])
389 continue;
390 err = write_eraseblock2(i);
391 if (unlikely(err))
392 goto out;
393 if (i % 256 == 0)
Vikram Narayanancd66a2d2012-10-10 23:11:06 +0530394 pr_info("written up to eraseblock %u\n", i);
Richard Weinberger2a6a28e72015-03-29 21:52:06 +0200395
396 err = mtdtest_relax();
397 if (err)
398 goto out;
Artem Bityutskiybf608622008-12-08 13:37:48 +0200399 }
Vikram Narayanancd66a2d2012-10-10 23:11:06 +0530400 pr_info("written %u eraseblocks\n", i);
Artem Bityutskiybf608622008-12-08 13:37:48 +0200401
402 /* Check all eraseblocks */
Akinobu Mitaa312b782013-02-27 17:05:39 -0800403 prandom_seed_state(&rnd_state, 3);
Vikram Narayanancd66a2d2012-10-10 23:11:06 +0530404 pr_info("verifying all eraseblocks\n");
Artem Bityutskiybf608622008-12-08 13:37:48 +0200405 for (i = 0; i < ebcnt; ++i) {
406 if (bbt[i])
407 continue;
408 err = verify_eraseblock2(i);
409 if (unlikely(err))
410 goto out;
411 if (i % 256 == 0)
Vikram Narayanancd66a2d2012-10-10 23:11:06 +0530412 pr_info("verified up to eraseblock %u\n", i);
Richard Weinberger2a6a28e72015-03-29 21:52:06 +0200413
414 err = mtdtest_relax();
415 if (err)
416 goto out;
Artem Bityutskiybf608622008-12-08 13:37:48 +0200417 }
Vikram Narayanancd66a2d2012-10-10 23:11:06 +0530418 pr_info("verified %u eraseblocks\n", i);
Artem Bityutskiybf608622008-12-08 13:37:48 +0200419
Akinobu Mita725cd712013-08-03 18:52:14 +0900420 err = mtdtest_erase_good_eraseblocks(mtd, bbt, 0, ebcnt);
Artem Bityutskiybf608622008-12-08 13:37:48 +0200421 if (err)
422 goto out;
423
424 err = verify_all_eraseblocks_ff();
425 if (err)
426 goto out;
427
Vikram Narayanancd66a2d2012-10-10 23:11:06 +0530428 pr_info("finished with %d errors\n", errcnt);
Artem Bityutskiybf608622008-12-08 13:37:48 +0200429
430out:
431 kfree(bbt);
432 kfree(readbuf);
433 kfree(writebuf);
434 put_mtd_device(mtd);
435 if (err)
Vikram Narayanancd66a2d2012-10-10 23:11:06 +0530436 pr_info("error %d occurred\n", err);
Artem Bityutskiybf608622008-12-08 13:37:48 +0200437 printk(KERN_INFO "=================================================\n");
438 return err;
439}
440module_init(mtd_subpagetest_init);
441
442static void __exit mtd_subpagetest_exit(void)
443{
444 return;
445}
446module_exit(mtd_subpagetest_exit);
447
448MODULE_DESCRIPTION("Subpage test module");
449MODULE_AUTHOR("Adrian Hunter");
450MODULE_LICENSE("GPL");