diff options
Diffstat (limited to 'drivers/mtd/tests/mtd_torturetest.c')
| -rw-r--r-- | drivers/mtd/tests/mtd_torturetest.c | 73 |
1 files changed, 37 insertions, 36 deletions
diff --git a/drivers/mtd/tests/mtd_torturetest.c b/drivers/mtd/tests/mtd_torturetest.c index b65861bc7b8e..c4cde1e9eddb 100644 --- a/drivers/mtd/tests/mtd_torturetest.c +++ b/drivers/mtd/tests/mtd_torturetest.c | |||
| @@ -23,6 +23,8 @@ | |||
| 23 | * damage caused by this program. | 23 | * damage caused by this program. |
| 24 | */ | 24 | */ |
| 25 | 25 | ||
| 26 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
| 27 | |||
| 26 | #include <linux/init.h> | 28 | #include <linux/init.h> |
| 27 | #include <linux/module.h> | 29 | #include <linux/module.h> |
| 28 | #include <linux/moduleparam.h> | 30 | #include <linux/moduleparam.h> |
| @@ -31,7 +33,6 @@ | |||
| 31 | #include <linux/slab.h> | 33 | #include <linux/slab.h> |
| 32 | #include <linux/sched.h> | 34 | #include <linux/sched.h> |
| 33 | 35 | ||
| 34 | #define PRINT_PREF KERN_INFO "mtd_torturetest: " | ||
| 35 | #define RETRIES 3 | 36 | #define RETRIES 3 |
| 36 | 37 | ||
| 37 | static int eb = 8; | 38 | static int eb = 8; |
| @@ -107,12 +108,12 @@ static inline int erase_eraseblock(int ebnum) | |||
| 107 | 108 | ||
| 108 | err = mtd_erase(mtd, &ei); | 109 | err = mtd_erase(mtd, &ei); |
| 109 | if (err) { | 110 | if (err) { |
| 110 | printk(PRINT_PREF "error %d while erasing EB %d\n", err, ebnum); | 111 | pr_err("error %d while erasing EB %d\n", err, ebnum); |
| 111 | return err; | 112 | return err; |
| 112 | } | 113 | } |
| 113 | 114 | ||
| 114 | if (ei.state == MTD_ERASE_FAILED) { | 115 | if (ei.state == MTD_ERASE_FAILED) { |
| 115 | printk(PRINT_PREF "some erase error occurred at EB %d\n", | 116 | pr_err("some erase error occurred at EB %d\n", |
| 116 | ebnum); | 117 | ebnum); |
| 117 | return -EIO; | 118 | return -EIO; |
| 118 | } | 119 | } |
| @@ -139,40 +140,40 @@ static inline int check_eraseblock(int ebnum, unsigned char *buf) | |||
| 139 | retry: | 140 | retry: |
| 140 | err = mtd_read(mtd, addr, len, &read, check_buf); | 141 | err = mtd_read(mtd, addr, len, &read, check_buf); |
| 141 | if (mtd_is_bitflip(err)) | 142 | if (mtd_is_bitflip(err)) |
| 142 | printk(PRINT_PREF "single bit flip occurred at EB %d " | 143 | pr_err("single bit flip occurred at EB %d " |
| 143 | "MTD reported that it was fixed.\n", ebnum); | 144 | "MTD reported that it was fixed.\n", ebnum); |
| 144 | else if (err) { | 145 | else if (err) { |
| 145 | printk(PRINT_PREF "error %d while reading EB %d, " | 146 | pr_err("error %d while reading EB %d, " |
| 146 | "read %zd\n", err, ebnum, read); | 147 | "read %zd\n", err, ebnum, read); |
| 147 | return err; | 148 | return err; |
| 148 | } | 149 | } |
| 149 | 150 | ||
| 150 | if (read != len) { | 151 | if (read != len) { |
| 151 | printk(PRINT_PREF "failed to read %zd bytes from EB %d, " | 152 | pr_err("failed to read %zd bytes from EB %d, " |
| 152 | "read only %zd, but no error reported\n", | 153 | "read only %zd, but no error reported\n", |
| 153 | len, ebnum, read); | 154 | len, ebnum, read); |
| 154 | return -EIO; | 155 | return -EIO; |
| 155 | } | 156 | } |
| 156 | 157 | ||
| 157 | if (memcmp(buf, check_buf, len)) { | 158 | if (memcmp(buf, check_buf, len)) { |
| 158 | printk(PRINT_PREF "read wrong data from EB %d\n", ebnum); | 159 | pr_err("read wrong data from EB %d\n", ebnum); |
| 159 | report_corrupt(check_buf, buf); | 160 | report_corrupt(check_buf, buf); |
| 160 | 161 | ||
| 161 | if (retries++ < RETRIES) { | 162 | if (retries++ < RETRIES) { |
| 162 | /* Try read again */ | 163 | /* Try read again */ |
| 163 | yield(); | 164 | yield(); |
| 164 | printk(PRINT_PREF "re-try reading data from EB %d\n", | 165 | pr_info("re-try reading data from EB %d\n", |
| 165 | ebnum); | 166 | ebnum); |
| 166 | goto retry; | 167 | goto retry; |
| 167 | } else { | 168 | } else { |
| 168 | printk(PRINT_PREF "retried %d times, still errors, " | 169 | pr_info("retried %d times, still errors, " |
| 169 | "give-up\n", RETRIES); | 170 | "give-up\n", RETRIES); |
| 170 | return -EINVAL; | 171 | return -EINVAL; |
| 171 | } | 172 | } |
| 172 | } | 173 | } |
| 173 | 174 | ||
| 174 | if (retries != 0) | 175 | if (retries != 0) |
| 175 | printk(PRINT_PREF "only attempt number %d was OK (!!!)\n", | 176 | pr_info("only attempt number %d was OK (!!!)\n", |
| 176 | retries); | 177 | retries); |
| 177 | 178 | ||
| 178 | return 0; | 179 | return 0; |
| @@ -191,12 +192,12 @@ static inline int write_pattern(int ebnum, void *buf) | |||
| 191 | } | 192 | } |
| 192 | err = mtd_write(mtd, addr, len, &written, buf); | 193 | err = mtd_write(mtd, addr, len, &written, buf); |
| 193 | if (err) { | 194 | if (err) { |
| 194 | printk(PRINT_PREF "error %d while writing EB %d, written %zd" | 195 | pr_err("error %d while writing EB %d, written %zd" |
| 195 | " bytes\n", err, ebnum, written); | 196 | " bytes\n", err, ebnum, written); |
| 196 | return err; | 197 | return err; |
| 197 | } | 198 | } |
| 198 | if (written != len) { | 199 | if (written != len) { |
| 199 | printk(PRINT_PREF "written only %zd bytes of %zd, but no error" | 200 | pr_info("written only %zd bytes of %zd, but no error" |
| 200 | " reported\n", written, len); | 201 | " reported\n", written, len); |
| 201 | return -EIO; | 202 | return -EIO; |
| 202 | } | 203 | } |
| @@ -211,64 +212,64 @@ static int __init tort_init(void) | |||
| 211 | 212 | ||
| 212 | printk(KERN_INFO "\n"); | 213 | printk(KERN_INFO "\n"); |
| 213 | printk(KERN_INFO "=================================================\n"); | 214 | printk(KERN_INFO "=================================================\n"); |
| 214 | printk(PRINT_PREF "Warning: this program is trying to wear out your " | 215 | pr_info("Warning: this program is trying to wear out your " |
| 215 | "flash, stop it if this is not wanted.\n"); | 216 | "flash, stop it if this is not wanted.\n"); |
| 216 | 217 | ||
| 217 | if (dev < 0) { | 218 | if (dev < 0) { |
| 218 | printk(PRINT_PREF "Please specify a valid mtd-device via module paramter\n"); | 219 | pr_info("Please specify a valid mtd-device via module parameter\n"); |
| 219 | printk(KERN_CRIT "CAREFUL: This test wipes all data on the specified MTD device!\n"); | 220 | pr_crit("CAREFUL: This test wipes all data on the specified MTD device!\n"); |
| 220 | return -EINVAL; | 221 | return -EINVAL; |
| 221 | } | 222 | } |
| 222 | 223 | ||
| 223 | printk(PRINT_PREF "MTD device: %d\n", dev); | 224 | pr_info("MTD device: %d\n", dev); |
| 224 | printk(PRINT_PREF "torture %d eraseblocks (%d-%d) of mtd%d\n", | 225 | pr_info("torture %d eraseblocks (%d-%d) of mtd%d\n", |
| 225 | ebcnt, eb, eb + ebcnt - 1, dev); | 226 | ebcnt, eb, eb + ebcnt - 1, dev); |
| 226 | if (pgcnt) | 227 | if (pgcnt) |
| 227 | printk(PRINT_PREF "torturing just %d pages per eraseblock\n", | 228 | pr_info("torturing just %d pages per eraseblock\n", |
| 228 | pgcnt); | 229 | pgcnt); |
| 229 | printk(PRINT_PREF "write verify %s\n", check ? "enabled" : "disabled"); | 230 | pr_info("write verify %s\n", check ? "enabled" : "disabled"); |
| 230 | 231 | ||
| 231 | mtd = get_mtd_device(NULL, dev); | 232 | mtd = get_mtd_device(NULL, dev); |
| 232 | if (IS_ERR(mtd)) { | 233 | if (IS_ERR(mtd)) { |
| 233 | err = PTR_ERR(mtd); | 234 | err = PTR_ERR(mtd); |
| 234 | printk(PRINT_PREF "error: cannot get MTD device\n"); | 235 | pr_err("error: cannot get MTD device\n"); |
| 235 | return err; | 236 | return err; |
| 236 | } | 237 | } |
| 237 | 238 | ||
| 238 | if (mtd->writesize == 1) { | 239 | if (mtd->writesize == 1) { |
| 239 | printk(PRINT_PREF "not NAND flash, assume page size is 512 " | 240 | pr_info("not NAND flash, assume page size is 512 " |
| 240 | "bytes.\n"); | 241 | "bytes.\n"); |
| 241 | pgsize = 512; | 242 | pgsize = 512; |
| 242 | } else | 243 | } else |
| 243 | pgsize = mtd->writesize; | 244 | pgsize = mtd->writesize; |
| 244 | 245 | ||
| 245 | if (pgcnt && (pgcnt > mtd->erasesize / pgsize || pgcnt < 0)) { | 246 | if (pgcnt && (pgcnt > mtd->erasesize / pgsize || pgcnt < 0)) { |
| 246 | printk(PRINT_PREF "error: invalid pgcnt value %d\n", pgcnt); | 247 | pr_err("error: invalid pgcnt value %d\n", pgcnt); |
| 247 | goto out_mtd; | 248 | goto out_mtd; |
| 248 | } | 249 | } |
| 249 | 250 | ||
| 250 | err = -ENOMEM; | 251 | err = -ENOMEM; |
| 251 | patt_5A5 = kmalloc(mtd->erasesize, GFP_KERNEL); | 252 | patt_5A5 = kmalloc(mtd->erasesize, GFP_KERNEL); |
| 252 | if (!patt_5A5) { | 253 | if (!patt_5A5) { |
| 253 | printk(PRINT_PREF "error: cannot allocate memory\n"); | 254 | pr_err("error: cannot allocate memory\n"); |
| 254 | goto out_mtd; | 255 | goto out_mtd; |
| 255 | } | 256 | } |
| 256 | 257 | ||
| 257 | patt_A5A = kmalloc(mtd->erasesize, GFP_KERNEL); | 258 | patt_A5A = kmalloc(mtd->erasesize, GFP_KERNEL); |
| 258 | if (!patt_A5A) { | 259 | if (!patt_A5A) { |
| 259 | printk(PRINT_PREF "error: cannot allocate memory\n"); | 260 | pr_err("error: cannot allocate memory\n"); |
| 260 | goto out_patt_5A5; | 261 | goto out_patt_5A5; |
| 261 | } | 262 | } |
| 262 | 263 | ||
| 263 | patt_FF = kmalloc(mtd->erasesize, GFP_KERNEL); | 264 | patt_FF = kmalloc(mtd->erasesize, GFP_KERNEL); |
| 264 | if (!patt_FF) { | 265 | if (!patt_FF) { |
| 265 | printk(PRINT_PREF "error: cannot allocate memory\n"); | 266 | pr_err("error: cannot allocate memory\n"); |
| 266 | goto out_patt_A5A; | 267 | goto out_patt_A5A; |
| 267 | } | 268 | } |
| 268 | 269 | ||
| 269 | check_buf = kmalloc(mtd->erasesize, GFP_KERNEL); | 270 | check_buf = kmalloc(mtd->erasesize, GFP_KERNEL); |
| 270 | if (!check_buf) { | 271 | if (!check_buf) { |
| 271 | printk(PRINT_PREF "error: cannot allocate memory\n"); | 272 | pr_err("error: cannot allocate memory\n"); |
| 272 | goto out_patt_FF; | 273 | goto out_patt_FF; |
| 273 | } | 274 | } |
| 274 | 275 | ||
| @@ -295,13 +296,13 @@ static int __init tort_init(void) | |||
| 295 | err = mtd_block_isbad(mtd, (loff_t)i * mtd->erasesize); | 296 | err = mtd_block_isbad(mtd, (loff_t)i * mtd->erasesize); |
| 296 | 297 | ||
| 297 | if (err < 0) { | 298 | if (err < 0) { |
| 298 | printk(PRINT_PREF "block_isbad() returned %d " | 299 | pr_info("block_isbad() returned %d " |
| 299 | "for EB %d\n", err, i); | 300 | "for EB %d\n", err, i); |
| 300 | goto out; | 301 | goto out; |
| 301 | } | 302 | } |
| 302 | 303 | ||
| 303 | if (err) { | 304 | if (err) { |
| 304 | printk("EB %d is bad. Skip it.\n", i); | 305 | pr_err("EB %d is bad. Skip it.\n", i); |
| 305 | bad_ebs[i - eb] = 1; | 306 | bad_ebs[i - eb] = 1; |
| 306 | } | 307 | } |
| 307 | } | 308 | } |
| @@ -329,7 +330,7 @@ static int __init tort_init(void) | |||
| 329 | continue; | 330 | continue; |
| 330 | err = check_eraseblock(i, patt_FF); | 331 | err = check_eraseblock(i, patt_FF); |
| 331 | if (err) { | 332 | if (err) { |
| 332 | printk(PRINT_PREF "verify failed" | 333 | pr_info("verify failed" |
| 333 | " for 0xFF... pattern\n"); | 334 | " for 0xFF... pattern\n"); |
| 334 | goto out; | 335 | goto out; |
| 335 | } | 336 | } |
| @@ -362,7 +363,7 @@ static int __init tort_init(void) | |||
| 362 | patt = patt_A5A; | 363 | patt = patt_A5A; |
| 363 | err = check_eraseblock(i, patt); | 364 | err = check_eraseblock(i, patt); |
| 364 | if (err) { | 365 | if (err) { |
| 365 | printk(PRINT_PREF "verify failed for %s" | 366 | pr_info("verify failed for %s" |
| 366 | " pattern\n", | 367 | " pattern\n", |
| 367 | ((eb + erase_cycles) & 1) ? | 368 | ((eb + erase_cycles) & 1) ? |
| 368 | "0x55AA55..." : "0xAA55AA..."); | 369 | "0x55AA55..." : "0xAA55AA..."); |
| @@ -380,7 +381,7 @@ static int __init tort_init(void) | |||
| 380 | stop_timing(); | 381 | stop_timing(); |
| 381 | ms = (finish.tv_sec - start.tv_sec) * 1000 + | 382 | ms = (finish.tv_sec - start.tv_sec) * 1000 + |
| 382 | (finish.tv_usec - start.tv_usec) / 1000; | 383 | (finish.tv_usec - start.tv_usec) / 1000; |
| 383 | printk(PRINT_PREF "%08u erase cycles done, took %lu " | 384 | pr_info("%08u erase cycles done, took %lu " |
| 384 | "milliseconds (%lu seconds)\n", | 385 | "milliseconds (%lu seconds)\n", |
| 385 | erase_cycles, ms, ms / 1000); | 386 | erase_cycles, ms, ms / 1000); |
| 386 | start_timing(); | 387 | start_timing(); |
| @@ -391,7 +392,7 @@ static int __init tort_init(void) | |||
| 391 | } | 392 | } |
| 392 | out: | 393 | out: |
| 393 | 394 | ||
| 394 | printk(PRINT_PREF "finished after %u erase cycles\n", | 395 | pr_info("finished after %u erase cycles\n", |
| 395 | erase_cycles); | 396 | erase_cycles); |
| 396 | kfree(check_buf); | 397 | kfree(check_buf); |
| 397 | out_patt_FF: | 398 | out_patt_FF: |
| @@ -403,7 +404,7 @@ out_patt_5A5: | |||
| 403 | out_mtd: | 404 | out_mtd: |
| 404 | put_mtd_device(mtd); | 405 | put_mtd_device(mtd); |
| 405 | if (err) | 406 | if (err) |
| 406 | printk(PRINT_PREF "error %d occurred during torturing\n", err); | 407 | pr_info("error %d occurred during torturing\n", err); |
| 407 | printk(KERN_INFO "=================================================\n"); | 408 | printk(KERN_INFO "=================================================\n"); |
| 408 | return err; | 409 | return err; |
| 409 | } | 410 | } |
| @@ -441,9 +442,9 @@ static void report_corrupt(unsigned char *read, unsigned char *written) | |||
| 441 | &bits) >= 0) | 442 | &bits) >= 0) |
| 442 | pages++; | 443 | pages++; |
| 443 | 444 | ||
| 444 | printk(PRINT_PREF "verify fails on %d pages, %d bytes/%d bits\n", | 445 | pr_info("verify fails on %d pages, %d bytes/%d bits\n", |
| 445 | pages, bytes, bits); | 446 | pages, bytes, bits); |
| 446 | printk(PRINT_PREF "The following is a list of all differences between" | 447 | pr_info("The following is a list of all differences between" |
| 447 | " what was read from flash and what was expected\n"); | 448 | " what was read from flash and what was expected\n"); |
| 448 | 449 | ||
| 449 | for (i = 0; i < check_len; i += pgsize) { | 450 | for (i = 0; i < check_len; i += pgsize) { |
| @@ -457,7 +458,7 @@ static void report_corrupt(unsigned char *read, unsigned char *written) | |||
| 457 | printk("-------------------------------------------------------" | 458 | printk("-------------------------------------------------------" |
| 458 | "----------------------------------\n"); | 459 | "----------------------------------\n"); |
| 459 | 460 | ||
| 460 | printk(PRINT_PREF "Page %zd has %d bytes/%d bits failing verify," | 461 | pr_info("Page %zd has %d bytes/%d bits failing verify," |
| 461 | " starting at offset 0x%x\n", | 462 | " starting at offset 0x%x\n", |
| 462 | (mtd->erasesize - check_len + i) / pgsize, | 463 | (mtd->erasesize - check_len + i) / pgsize, |
| 463 | bytes, bits, first); | 464 | bytes, bits, first); |
