Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006-2008 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 page read and write on MTD device. |
| 18 | * |
| 19 | * Author: Adrian Hunter <ext-adrian.hunter@nokia.com> |
| 20 | */ |
| 21 | |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 22 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 23 | |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 24 | #include <asm/div64.h> |
| 25 | #include <linux/init.h> |
| 26 | #include <linux/module.h> |
| 27 | #include <linux/moduleparam.h> |
| 28 | #include <linux/err.h> |
| 29 | #include <linux/mtd/mtd.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 30 | #include <linux/slab.h> |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 31 | #include <linux/sched.h> |
| 32 | |
Wolfram Sang | 7406060 | 2011-10-30 00:11:53 +0200 | [diff] [blame] | 33 | static int dev = -EINVAL; |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 34 | module_param(dev, int, S_IRUGO); |
| 35 | MODULE_PARM_DESC(dev, "MTD device number to use"); |
| 36 | |
| 37 | static struct mtd_info *mtd; |
| 38 | static unsigned char *twopages; |
| 39 | static unsigned char *writebuf; |
| 40 | static unsigned char *boundary; |
| 41 | static unsigned char *bbt; |
| 42 | |
| 43 | static int pgsize; |
| 44 | static int bufsize; |
| 45 | static int ebcnt; |
| 46 | static int pgcnt; |
| 47 | static int errcnt; |
| 48 | static unsigned long next = 1; |
| 49 | |
| 50 | static inline unsigned int simple_rand(void) |
| 51 | { |
| 52 | next = next * 1103515245 + 12345; |
| 53 | return (unsigned int)((next / 65536) % 32768); |
| 54 | } |
| 55 | |
| 56 | static inline void simple_srand(unsigned long seed) |
| 57 | { |
| 58 | next = seed; |
| 59 | } |
| 60 | |
| 61 | static void set_random_data(unsigned char *buf, size_t len) |
| 62 | { |
| 63 | size_t i; |
| 64 | |
| 65 | for (i = 0; i < len; ++i) |
| 66 | buf[i] = simple_rand(); |
| 67 | } |
| 68 | |
| 69 | static int erase_eraseblock(int ebnum) |
| 70 | { |
| 71 | int err; |
| 72 | struct erase_info ei; |
| 73 | loff_t addr = ebnum * mtd->erasesize; |
| 74 | |
| 75 | memset(&ei, 0, sizeof(struct erase_info)); |
| 76 | ei.mtd = mtd; |
| 77 | ei.addr = addr; |
| 78 | ei.len = mtd->erasesize; |
| 79 | |
Artem Bityutskiy | 7e1f0dc | 2011-12-23 15:25:39 +0200 | [diff] [blame] | 80 | err = mtd_erase(mtd, &ei); |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 81 | if (err) { |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 82 | pr_err("error %d while erasing EB %d\n", err, ebnum); |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 83 | return err; |
| 84 | } |
| 85 | |
| 86 | if (ei.state == MTD_ERASE_FAILED) { |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 87 | pr_err("some erase error occurred at EB %d\n", |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 88 | ebnum); |
| 89 | return -EIO; |
| 90 | } |
| 91 | |
| 92 | return 0; |
| 93 | } |
| 94 | |
| 95 | static int write_eraseblock(int ebnum) |
| 96 | { |
| 97 | int err = 0; |
Artem Bityutskiy | 30fa984 | 2011-12-29 15:16:28 +0200 | [diff] [blame] | 98 | size_t written; |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 99 | loff_t addr = ebnum * mtd->erasesize; |
| 100 | |
| 101 | set_random_data(writebuf, mtd->erasesize); |
| 102 | cond_resched(); |
Artem Bityutskiy | eda95cb | 2011-12-23 17:35:41 +0200 | [diff] [blame] | 103 | err = mtd_write(mtd, addr, mtd->erasesize, &written, writebuf); |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 104 | if (err || written != mtd->erasesize) |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 105 | pr_err("error: write failed at %#llx\n", |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 106 | (long long)addr); |
| 107 | |
| 108 | return err; |
| 109 | } |
| 110 | |
| 111 | static int verify_eraseblock(int ebnum) |
| 112 | { |
| 113 | uint32_t j; |
Artem Bityutskiy | 30fa984 | 2011-12-29 15:16:28 +0200 | [diff] [blame] | 114 | size_t read; |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 115 | int err = 0, i; |
| 116 | loff_t addr0, addrn; |
| 117 | loff_t addr = ebnum * mtd->erasesize; |
| 118 | |
| 119 | addr0 = 0; |
Roel Kluin | c6f7e7b | 2009-07-31 16:21:01 +0200 | [diff] [blame] | 120 | for (i = 0; i < ebcnt && bbt[i]; ++i) |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 121 | addr0 += mtd->erasesize; |
| 122 | |
| 123 | addrn = mtd->size; |
Roel Kluin | c6f7e7b | 2009-07-31 16:21:01 +0200 | [diff] [blame] | 124 | for (i = 0; i < ebcnt && bbt[ebcnt - i - 1]; ++i) |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 125 | addrn -= mtd->erasesize; |
| 126 | |
| 127 | set_random_data(writebuf, mtd->erasesize); |
| 128 | for (j = 0; j < pgcnt - 1; ++j, addr += pgsize) { |
| 129 | /* Do a read to set the internal dataRAMs to different data */ |
Artem Bityutskiy | 329ad39 | 2011-12-23 17:30:16 +0200 | [diff] [blame] | 130 | err = mtd_read(mtd, addr0, bufsize, &read, twopages); |
Brian Norris | d57f4054 | 2011-09-20 18:34:25 -0700 | [diff] [blame] | 131 | if (mtd_is_bitflip(err)) |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 132 | err = 0; |
| 133 | if (err || read != bufsize) { |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 134 | pr_err("error: read failed at %#llx\n", |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 135 | (long long)addr0); |
| 136 | return err; |
| 137 | } |
Artem Bityutskiy | 329ad39 | 2011-12-23 17:30:16 +0200 | [diff] [blame] | 138 | err = mtd_read(mtd, addrn - bufsize, bufsize, &read, twopages); |
Brian Norris | d57f4054 | 2011-09-20 18:34:25 -0700 | [diff] [blame] | 139 | if (mtd_is_bitflip(err)) |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 140 | err = 0; |
| 141 | if (err || read != bufsize) { |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 142 | pr_err("error: read failed at %#llx\n", |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 143 | (long long)(addrn - bufsize)); |
| 144 | return err; |
| 145 | } |
| 146 | memset(twopages, 0, bufsize); |
Artem Bityutskiy | 329ad39 | 2011-12-23 17:30:16 +0200 | [diff] [blame] | 147 | err = mtd_read(mtd, addr, bufsize, &read, twopages); |
Brian Norris | d57f4054 | 2011-09-20 18:34:25 -0700 | [diff] [blame] | 148 | if (mtd_is_bitflip(err)) |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 149 | err = 0; |
| 150 | if (err || read != bufsize) { |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 151 | pr_err("error: read failed at %#llx\n", |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 152 | (long long)addr); |
| 153 | break; |
| 154 | } |
| 155 | if (memcmp(twopages, writebuf + (j * pgsize), bufsize)) { |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 156 | pr_err("error: verify failed at %#llx\n", |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 157 | (long long)addr); |
| 158 | errcnt += 1; |
| 159 | } |
| 160 | } |
| 161 | /* Check boundary between eraseblocks */ |
| 162 | if (addr <= addrn - pgsize - pgsize && !bbt[ebnum + 1]) { |
| 163 | unsigned long oldnext = next; |
| 164 | /* Do a read to set the internal dataRAMs to different data */ |
Artem Bityutskiy | 329ad39 | 2011-12-23 17:30:16 +0200 | [diff] [blame] | 165 | err = mtd_read(mtd, addr0, bufsize, &read, twopages); |
Brian Norris | d57f4054 | 2011-09-20 18:34:25 -0700 | [diff] [blame] | 166 | if (mtd_is_bitflip(err)) |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 167 | err = 0; |
| 168 | if (err || read != bufsize) { |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 169 | pr_err("error: read failed at %#llx\n", |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 170 | (long long)addr0); |
| 171 | return err; |
| 172 | } |
Artem Bityutskiy | 329ad39 | 2011-12-23 17:30:16 +0200 | [diff] [blame] | 173 | err = mtd_read(mtd, addrn - bufsize, bufsize, &read, twopages); |
Brian Norris | d57f4054 | 2011-09-20 18:34:25 -0700 | [diff] [blame] | 174 | if (mtd_is_bitflip(err)) |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 175 | err = 0; |
| 176 | if (err || read != bufsize) { |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 177 | pr_err("error: read failed at %#llx\n", |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 178 | (long long)(addrn - bufsize)); |
| 179 | return err; |
| 180 | } |
| 181 | memset(twopages, 0, bufsize); |
Artem Bityutskiy | 329ad39 | 2011-12-23 17:30:16 +0200 | [diff] [blame] | 182 | err = mtd_read(mtd, addr, bufsize, &read, twopages); |
Brian Norris | d57f4054 | 2011-09-20 18:34:25 -0700 | [diff] [blame] | 183 | if (mtd_is_bitflip(err)) |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 184 | err = 0; |
| 185 | if (err || read != bufsize) { |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 186 | pr_err("error: read failed at %#llx\n", |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 187 | (long long)addr); |
| 188 | return err; |
| 189 | } |
| 190 | memcpy(boundary, writebuf + mtd->erasesize - pgsize, pgsize); |
| 191 | set_random_data(boundary + pgsize, pgsize); |
| 192 | if (memcmp(twopages, boundary, bufsize)) { |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 193 | pr_err("error: verify failed at %#llx\n", |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 194 | (long long)addr); |
| 195 | errcnt += 1; |
| 196 | } |
| 197 | next = oldnext; |
| 198 | } |
| 199 | return err; |
| 200 | } |
| 201 | |
| 202 | static int crosstest(void) |
| 203 | { |
Artem Bityutskiy | 30fa984 | 2011-12-29 15:16:28 +0200 | [diff] [blame] | 204 | size_t read; |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 205 | int err = 0, i; |
| 206 | loff_t addr, addr0, addrn; |
| 207 | unsigned char *pp1, *pp2, *pp3, *pp4; |
| 208 | |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 209 | pr_info("crosstest\n"); |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 210 | pp1 = kmalloc(pgsize * 4, GFP_KERNEL); |
| 211 | if (!pp1) { |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 212 | pr_err("error: cannot allocate memory\n"); |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 213 | return -ENOMEM; |
| 214 | } |
| 215 | pp2 = pp1 + pgsize; |
| 216 | pp3 = pp2 + pgsize; |
| 217 | pp4 = pp3 + pgsize; |
| 218 | memset(pp1, 0, pgsize * 4); |
| 219 | |
| 220 | addr0 = 0; |
Roel Kluin | c6f7e7b | 2009-07-31 16:21:01 +0200 | [diff] [blame] | 221 | for (i = 0; i < ebcnt && bbt[i]; ++i) |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 222 | addr0 += mtd->erasesize; |
| 223 | |
| 224 | addrn = mtd->size; |
Roel Kluin | c6f7e7b | 2009-07-31 16:21:01 +0200 | [diff] [blame] | 225 | for (i = 0; i < ebcnt && bbt[ebcnt - i - 1]; ++i) |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 226 | addrn -= mtd->erasesize; |
| 227 | |
| 228 | /* Read 2nd-to-last page to pp1 */ |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 229 | addr = addrn - pgsize - pgsize; |
Artem Bityutskiy | 329ad39 | 2011-12-23 17:30:16 +0200 | [diff] [blame] | 230 | err = mtd_read(mtd, addr, pgsize, &read, pp1); |
Brian Norris | d57f4054 | 2011-09-20 18:34:25 -0700 | [diff] [blame] | 231 | if (mtd_is_bitflip(err)) |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 232 | err = 0; |
| 233 | if (err || read != pgsize) { |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 234 | pr_err("error: read failed at %#llx\n", |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 235 | (long long)addr); |
| 236 | kfree(pp1); |
| 237 | return err; |
| 238 | } |
| 239 | |
| 240 | /* Read 3rd-to-last page to pp1 */ |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 241 | addr = addrn - pgsize - pgsize - pgsize; |
Artem Bityutskiy | 329ad39 | 2011-12-23 17:30:16 +0200 | [diff] [blame] | 242 | err = mtd_read(mtd, addr, pgsize, &read, pp1); |
Brian Norris | d57f4054 | 2011-09-20 18:34:25 -0700 | [diff] [blame] | 243 | if (mtd_is_bitflip(err)) |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 244 | err = 0; |
| 245 | if (err || read != pgsize) { |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 246 | pr_err("error: read failed at %#llx\n", |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 247 | (long long)addr); |
| 248 | kfree(pp1); |
| 249 | return err; |
| 250 | } |
| 251 | |
| 252 | /* Read first page to pp2 */ |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 253 | addr = addr0; |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 254 | pr_info("reading page at %#llx\n", (long long)addr); |
Artem Bityutskiy | 329ad39 | 2011-12-23 17:30:16 +0200 | [diff] [blame] | 255 | err = mtd_read(mtd, addr, pgsize, &read, pp2); |
Brian Norris | d57f4054 | 2011-09-20 18:34:25 -0700 | [diff] [blame] | 256 | if (mtd_is_bitflip(err)) |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 257 | err = 0; |
| 258 | if (err || read != pgsize) { |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 259 | pr_err("error: read failed at %#llx\n", |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 260 | (long long)addr); |
| 261 | kfree(pp1); |
| 262 | return err; |
| 263 | } |
| 264 | |
| 265 | /* Read last page to pp3 */ |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 266 | addr = addrn - pgsize; |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 267 | pr_info("reading page at %#llx\n", (long long)addr); |
Artem Bityutskiy | 329ad39 | 2011-12-23 17:30:16 +0200 | [diff] [blame] | 268 | err = mtd_read(mtd, addr, pgsize, &read, pp3); |
Brian Norris | d57f4054 | 2011-09-20 18:34:25 -0700 | [diff] [blame] | 269 | if (mtd_is_bitflip(err)) |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 270 | err = 0; |
| 271 | if (err || read != pgsize) { |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 272 | pr_err("error: read failed at %#llx\n", |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 273 | (long long)addr); |
| 274 | kfree(pp1); |
| 275 | return err; |
| 276 | } |
| 277 | |
| 278 | /* Read first page again to pp4 */ |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 279 | addr = addr0; |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 280 | pr_info("reading page at %#llx\n", (long long)addr); |
Artem Bityutskiy | 329ad39 | 2011-12-23 17:30:16 +0200 | [diff] [blame] | 281 | err = mtd_read(mtd, addr, pgsize, &read, pp4); |
Brian Norris | d57f4054 | 2011-09-20 18:34:25 -0700 | [diff] [blame] | 282 | if (mtd_is_bitflip(err)) |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 283 | err = 0; |
| 284 | if (err || read != pgsize) { |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 285 | pr_err("error: read failed at %#llx\n", |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 286 | (long long)addr); |
| 287 | kfree(pp1); |
| 288 | return err; |
| 289 | } |
| 290 | |
| 291 | /* pp2 and pp4 should be the same */ |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 292 | pr_info("verifying pages read at %#llx match\n", |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 293 | (long long)addr0); |
| 294 | if (memcmp(pp2, pp4, pgsize)) { |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 295 | pr_err("verify failed!\n"); |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 296 | errcnt += 1; |
| 297 | } else if (!err) |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 298 | pr_info("crosstest ok\n"); |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 299 | kfree(pp1); |
| 300 | return err; |
| 301 | } |
| 302 | |
| 303 | static int erasecrosstest(void) |
| 304 | { |
Artem Bityutskiy | 30fa984 | 2011-12-29 15:16:28 +0200 | [diff] [blame] | 305 | size_t read, written; |
Roel Kluin | 7fc14bc | 2010-07-13 13:24:31 +0300 | [diff] [blame] | 306 | int err = 0, i, ebnum, ebnum2; |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 307 | loff_t addr0; |
| 308 | char *readbuf = twopages; |
| 309 | |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 310 | pr_info("erasecrosstest\n"); |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 311 | |
| 312 | ebnum = 0; |
| 313 | addr0 = 0; |
Roel Kluin | c6f7e7b | 2009-07-31 16:21:01 +0200 | [diff] [blame] | 314 | for (i = 0; i < ebcnt && bbt[i]; ++i) { |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 315 | addr0 += mtd->erasesize; |
| 316 | ebnum += 1; |
| 317 | } |
| 318 | |
| 319 | ebnum2 = ebcnt - 1; |
| 320 | while (ebnum2 && bbt[ebnum2]) |
| 321 | ebnum2 -= 1; |
| 322 | |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 323 | pr_info("erasing block %d\n", ebnum); |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 324 | err = erase_eraseblock(ebnum); |
| 325 | if (err) |
| 326 | return err; |
| 327 | |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 328 | pr_info("writing 1st page of block %d\n", ebnum); |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 329 | set_random_data(writebuf, pgsize); |
| 330 | strcpy(writebuf, "There is no data like this!"); |
Artem Bityutskiy | eda95cb | 2011-12-23 17:35:41 +0200 | [diff] [blame] | 331 | err = mtd_write(mtd, addr0, pgsize, &written, writebuf); |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 332 | if (err || written != pgsize) { |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 333 | pr_info("error: write failed at %#llx\n", |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 334 | (long long)addr0); |
| 335 | return err ? err : -1; |
| 336 | } |
| 337 | |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 338 | pr_info("reading 1st page of block %d\n", ebnum); |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 339 | memset(readbuf, 0, pgsize); |
Artem Bityutskiy | 329ad39 | 2011-12-23 17:30:16 +0200 | [diff] [blame] | 340 | err = mtd_read(mtd, addr0, pgsize, &read, readbuf); |
Brian Norris | d57f4054 | 2011-09-20 18:34:25 -0700 | [diff] [blame] | 341 | if (mtd_is_bitflip(err)) |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 342 | err = 0; |
| 343 | if (err || read != pgsize) { |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 344 | pr_err("error: read failed at %#llx\n", |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 345 | (long long)addr0); |
| 346 | return err ? err : -1; |
| 347 | } |
| 348 | |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 349 | pr_info("verifying 1st page of block %d\n", ebnum); |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 350 | if (memcmp(writebuf, readbuf, pgsize)) { |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 351 | pr_err("verify failed!\n"); |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 352 | errcnt += 1; |
Roel Kluin | 7fc14bc | 2010-07-13 13:24:31 +0300 | [diff] [blame] | 353 | return -1; |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 354 | } |
| 355 | |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 356 | pr_info("erasing block %d\n", ebnum); |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 357 | err = erase_eraseblock(ebnum); |
| 358 | if (err) |
| 359 | return err; |
| 360 | |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 361 | pr_info("writing 1st page of block %d\n", ebnum); |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 362 | set_random_data(writebuf, pgsize); |
| 363 | strcpy(writebuf, "There is no data like this!"); |
Artem Bityutskiy | eda95cb | 2011-12-23 17:35:41 +0200 | [diff] [blame] | 364 | err = mtd_write(mtd, addr0, pgsize, &written, writebuf); |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 365 | if (err || written != pgsize) { |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 366 | pr_err("error: write failed at %#llx\n", |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 367 | (long long)addr0); |
| 368 | return err ? err : -1; |
| 369 | } |
| 370 | |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 371 | pr_info("erasing block %d\n", ebnum2); |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 372 | err = erase_eraseblock(ebnum2); |
| 373 | if (err) |
| 374 | return err; |
| 375 | |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 376 | pr_info("reading 1st page of block %d\n", ebnum); |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 377 | memset(readbuf, 0, pgsize); |
Artem Bityutskiy | 329ad39 | 2011-12-23 17:30:16 +0200 | [diff] [blame] | 378 | err = mtd_read(mtd, addr0, pgsize, &read, readbuf); |
Brian Norris | d57f4054 | 2011-09-20 18:34:25 -0700 | [diff] [blame] | 379 | if (mtd_is_bitflip(err)) |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 380 | err = 0; |
| 381 | if (err || read != pgsize) { |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 382 | pr_err("error: read failed at %#llx\n", |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 383 | (long long)addr0); |
| 384 | return err ? err : -1; |
| 385 | } |
| 386 | |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 387 | pr_info("verifying 1st page of block %d\n", ebnum); |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 388 | if (memcmp(writebuf, readbuf, pgsize)) { |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 389 | pr_err("verify failed!\n"); |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 390 | errcnt += 1; |
Roel Kluin | 7fc14bc | 2010-07-13 13:24:31 +0300 | [diff] [blame] | 391 | return -1; |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 392 | } |
| 393 | |
Roel Kluin | 7fc14bc | 2010-07-13 13:24:31 +0300 | [diff] [blame] | 394 | if (!err) |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 395 | pr_info("erasecrosstest ok\n"); |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 396 | return err; |
| 397 | } |
| 398 | |
| 399 | static int erasetest(void) |
| 400 | { |
Artem Bityutskiy | 30fa984 | 2011-12-29 15:16:28 +0200 | [diff] [blame] | 401 | size_t read, written; |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 402 | int err = 0, i, ebnum, ok = 1; |
| 403 | loff_t addr0; |
| 404 | |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 405 | pr_info("erasetest\n"); |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 406 | |
| 407 | ebnum = 0; |
| 408 | addr0 = 0; |
Roel Kluin | c6f7e7b | 2009-07-31 16:21:01 +0200 | [diff] [blame] | 409 | for (i = 0; i < ebcnt && bbt[i]; ++i) { |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 410 | addr0 += mtd->erasesize; |
| 411 | ebnum += 1; |
| 412 | } |
| 413 | |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 414 | pr_info("erasing block %d\n", ebnum); |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 415 | err = erase_eraseblock(ebnum); |
| 416 | if (err) |
| 417 | return err; |
| 418 | |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 419 | pr_info("writing 1st page of block %d\n", ebnum); |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 420 | set_random_data(writebuf, pgsize); |
Artem Bityutskiy | eda95cb | 2011-12-23 17:35:41 +0200 | [diff] [blame] | 421 | err = mtd_write(mtd, addr0, pgsize, &written, writebuf); |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 422 | if (err || written != pgsize) { |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 423 | pr_err("error: write failed at %#llx\n", |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 424 | (long long)addr0); |
| 425 | return err ? err : -1; |
| 426 | } |
| 427 | |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 428 | pr_info("erasing block %d\n", ebnum); |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 429 | err = erase_eraseblock(ebnum); |
| 430 | if (err) |
| 431 | return err; |
| 432 | |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 433 | pr_info("reading 1st page of block %d\n", ebnum); |
Artem Bityutskiy | 329ad39 | 2011-12-23 17:30:16 +0200 | [diff] [blame] | 434 | err = mtd_read(mtd, addr0, pgsize, &read, twopages); |
Brian Norris | d57f4054 | 2011-09-20 18:34:25 -0700 | [diff] [blame] | 435 | if (mtd_is_bitflip(err)) |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 436 | err = 0; |
| 437 | if (err || read != pgsize) { |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 438 | pr_err("error: read failed at %#llx\n", |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 439 | (long long)addr0); |
| 440 | return err ? err : -1; |
| 441 | } |
| 442 | |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 443 | pr_info("verifying 1st page of block %d is all 0xff\n", |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 444 | ebnum); |
| 445 | for (i = 0; i < pgsize; ++i) |
| 446 | if (twopages[i] != 0xff) { |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 447 | pr_err("verifying all 0xff failed at %d\n", |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 448 | i); |
| 449 | errcnt += 1; |
| 450 | ok = 0; |
| 451 | break; |
| 452 | } |
| 453 | |
| 454 | if (ok && !err) |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 455 | pr_info("erasetest ok\n"); |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 456 | |
| 457 | return err; |
| 458 | } |
| 459 | |
| 460 | static int is_block_bad(int ebnum) |
| 461 | { |
| 462 | loff_t addr = ebnum * mtd->erasesize; |
| 463 | int ret; |
| 464 | |
Artem Bityutskiy | 7086c19 | 2011-12-23 19:35:30 +0200 | [diff] [blame] | 465 | ret = mtd_block_isbad(mtd, addr); |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 466 | if (ret) |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 467 | pr_info("block %d is bad\n", ebnum); |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 468 | return ret; |
| 469 | } |
| 470 | |
| 471 | static int scan_for_bad_eraseblocks(void) |
| 472 | { |
| 473 | int i, bad = 0; |
| 474 | |
Julia Lawall | 2bfefa4 | 2010-05-13 22:03:15 +0200 | [diff] [blame] | 475 | bbt = kzalloc(ebcnt, GFP_KERNEL); |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 476 | if (!bbt) { |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 477 | pr_err("error: cannot allocate memory\n"); |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 478 | return -ENOMEM; |
| 479 | } |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 480 | |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 481 | pr_info("scanning for bad eraseblocks\n"); |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 482 | for (i = 0; i < ebcnt; ++i) { |
| 483 | bbt[i] = is_block_bad(i) ? 1 : 0; |
| 484 | if (bbt[i]) |
| 485 | bad += 1; |
| 486 | cond_resched(); |
| 487 | } |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 488 | pr_info("scanned %d eraseblocks, %d are bad\n", i, bad); |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 489 | return 0; |
| 490 | } |
| 491 | |
| 492 | static int __init mtd_pagetest_init(void) |
| 493 | { |
| 494 | int err = 0; |
| 495 | uint64_t tmp; |
| 496 | uint32_t i; |
| 497 | |
| 498 | printk(KERN_INFO "\n"); |
| 499 | printk(KERN_INFO "=================================================\n"); |
Wolfram Sang | 7406060 | 2011-10-30 00:11:53 +0200 | [diff] [blame] | 500 | |
| 501 | if (dev < 0) { |
Masanari Iida | 064a769 | 2012-11-09 23:20:58 +0900 | [diff] [blame] | 502 | pr_info("Please specify a valid mtd-device via module parameter\n"); |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 503 | pr_crit("CAREFUL: This test wipes all data on the specified MTD device!\n"); |
Wolfram Sang | 7406060 | 2011-10-30 00:11:53 +0200 | [diff] [blame] | 504 | return -EINVAL; |
| 505 | } |
| 506 | |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 507 | pr_info("MTD device: %d\n", dev); |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 508 | |
| 509 | mtd = get_mtd_device(NULL, dev); |
| 510 | if (IS_ERR(mtd)) { |
| 511 | err = PTR_ERR(mtd); |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 512 | pr_err("error: cannot get MTD device\n"); |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 513 | return err; |
| 514 | } |
| 515 | |
| 516 | if (mtd->type != MTD_NANDFLASH) { |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 517 | pr_info("this test requires NAND flash\n"); |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 518 | goto out; |
| 519 | } |
| 520 | |
| 521 | tmp = mtd->size; |
| 522 | do_div(tmp, mtd->erasesize); |
| 523 | ebcnt = tmp; |
| 524 | pgcnt = mtd->erasesize / mtd->writesize; |
Artem Bityutskiy | 4c2b8a6 | 2009-11-27 16:58:08 +0200 | [diff] [blame] | 525 | pgsize = mtd->writesize; |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 526 | |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 527 | pr_info("MTD device size %llu, eraseblock size %u, " |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 528 | "page size %u, count of eraseblocks %u, pages per " |
| 529 | "eraseblock %u, OOB size %u\n", |
| 530 | (unsigned long long)mtd->size, mtd->erasesize, |
| 531 | pgsize, ebcnt, pgcnt, mtd->oobsize); |
| 532 | |
| 533 | err = -ENOMEM; |
| 534 | bufsize = pgsize * 2; |
| 535 | writebuf = kmalloc(mtd->erasesize, GFP_KERNEL); |
| 536 | if (!writebuf) { |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 537 | pr_err("error: cannot allocate memory\n"); |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 538 | goto out; |
| 539 | } |
| 540 | twopages = kmalloc(bufsize, GFP_KERNEL); |
| 541 | if (!twopages) { |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 542 | pr_err("error: cannot allocate memory\n"); |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 543 | goto out; |
| 544 | } |
| 545 | boundary = kmalloc(bufsize, GFP_KERNEL); |
| 546 | if (!boundary) { |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 547 | pr_err("error: cannot allocate memory\n"); |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 548 | goto out; |
| 549 | } |
| 550 | |
| 551 | err = scan_for_bad_eraseblocks(); |
| 552 | if (err) |
| 553 | goto out; |
| 554 | |
| 555 | /* Erase all eraseblocks */ |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 556 | pr_info("erasing whole device\n"); |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 557 | for (i = 0; i < ebcnt; ++i) { |
| 558 | if (bbt[i]) |
| 559 | continue; |
| 560 | err = erase_eraseblock(i); |
| 561 | if (err) |
| 562 | goto out; |
| 563 | cond_resched(); |
| 564 | } |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 565 | pr_info("erased %u eraseblocks\n", i); |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 566 | |
| 567 | /* Write all eraseblocks */ |
| 568 | simple_srand(1); |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 569 | pr_info("writing whole device\n"); |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 570 | for (i = 0; i < ebcnt; ++i) { |
| 571 | if (bbt[i]) |
| 572 | continue; |
| 573 | err = write_eraseblock(i); |
| 574 | if (err) |
| 575 | goto out; |
| 576 | if (i % 256 == 0) |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 577 | pr_info("written up to eraseblock %u\n", i); |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 578 | cond_resched(); |
| 579 | } |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 580 | pr_info("written %u eraseblocks\n", i); |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 581 | |
| 582 | /* Check all eraseblocks */ |
| 583 | simple_srand(1); |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 584 | pr_info("verifying all eraseblocks\n"); |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 585 | for (i = 0; i < ebcnt; ++i) { |
| 586 | if (bbt[i]) |
| 587 | continue; |
| 588 | err = verify_eraseblock(i); |
| 589 | if (err) |
| 590 | goto out; |
| 591 | if (i % 256 == 0) |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 592 | pr_info("verified up to eraseblock %u\n", i); |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 593 | cond_resched(); |
| 594 | } |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 595 | pr_info("verified %u eraseblocks\n", i); |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 596 | |
| 597 | err = crosstest(); |
| 598 | if (err) |
| 599 | goto out; |
| 600 | |
| 601 | err = erasecrosstest(); |
| 602 | if (err) |
| 603 | goto out; |
| 604 | |
| 605 | err = erasetest(); |
| 606 | if (err) |
| 607 | goto out; |
| 608 | |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 609 | pr_info("finished with %d errors\n", errcnt); |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 610 | out: |
| 611 | |
| 612 | kfree(bbt); |
| 613 | kfree(boundary); |
| 614 | kfree(twopages); |
| 615 | kfree(writebuf); |
| 616 | put_mtd_device(mtd); |
| 617 | if (err) |
Vikram Narayanan | bb99841 | 2012-10-10 23:07:40 +0530 | [diff] [blame] | 618 | pr_info("error %d occurred\n", err); |
Artem Bityutskiy | e73f217 | 2008-12-08 13:34:16 +0200 | [diff] [blame] | 619 | printk(KERN_INFO "=================================================\n"); |
| 620 | return err; |
| 621 | } |
| 622 | module_init(mtd_pagetest_init); |
| 623 | |
| 624 | static void __exit mtd_pagetest_exit(void) |
| 625 | { |
| 626 | return; |
| 627 | } |
| 628 | module_exit(mtd_pagetest_exit); |
| 629 | |
| 630 | MODULE_DESCRIPTION("NAND page test"); |
| 631 | MODULE_AUTHOR("Adrian Hunter"); |
| 632 | MODULE_LICENSE("GPL"); |