| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (C) 2006-2008 Artem Bityutskiy |
|---|
| 3 | 4 | * Copyright (C) 2006-2008 Jarkko Lavinen |
|---|
| 4 | 5 | * Copyright (C) 2006-2008 Adrian Hunter |
|---|
| 5 | | - * |
|---|
| 6 | | - * This program is free software; you can redistribute it and/or modify it |
|---|
| 7 | | - * under the terms of the GNU General Public License version 2 as published by |
|---|
| 8 | | - * the Free Software Foundation. |
|---|
| 9 | | - * |
|---|
| 10 | | - * This program is distributed in the hope that it will be useful, but WITHOUT |
|---|
| 11 | | - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|---|
| 12 | | - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
|---|
| 13 | | - * more details. |
|---|
| 14 | | - * |
|---|
| 15 | | - * You should have received a copy of the GNU General Public License along with |
|---|
| 16 | | - * this program; see the file COPYING. If not, write to the Free Software |
|---|
| 17 | | - * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 18 | 6 | * |
|---|
| 19 | 7 | * Authors: Artem Bityutskiy, Jarkko Lavinen, Adria Hunter |
|---|
| 20 | 8 | * |
|---|
| .. | .. |
|---|
| 31 | 19 | #include <linux/moduleparam.h> |
|---|
| 32 | 20 | #include <linux/err.h> |
|---|
| 33 | 21 | #include <linux/mtd/mtd.h> |
|---|
| 22 | +#include <linux/random.h> |
|---|
| 34 | 23 | #include <linux/slab.h> |
|---|
| 35 | 24 | #include <linux/sched.h> |
|---|
| 36 | 25 | #include "mtd_test.h" |
|---|
| .. | .. |
|---|
| 66 | 55 | MODULE_PARM_DESC(cycles_count, "how many erase cycles to do " |
|---|
| 67 | 56 | "(infinite by default)"); |
|---|
| 68 | 57 | |
|---|
| 58 | +static int random_pattern; |
|---|
| 59 | +module_param(random_pattern, int, S_IRUGO); |
|---|
| 60 | +MODULE_PARM_DESC(random_pattern, "if choose random pattern to program"); |
|---|
| 61 | + |
|---|
| 69 | 62 | static struct mtd_info *mtd; |
|---|
| 70 | 63 | |
|---|
| 64 | +/* This buffer contains random pattern */ |
|---|
| 65 | +static unsigned char *patt_random; |
|---|
| 71 | 66 | /* This buffer contains 0x555555...0xAAAAAA... pattern */ |
|---|
| 72 | 67 | static unsigned char *patt_5A5; |
|---|
| 73 | 68 | /* This buffer contains 0xAAAAAA...0x555555... pattern */ |
|---|
| .. | .. |
|---|
| 222 | 217 | } |
|---|
| 223 | 218 | |
|---|
| 224 | 219 | err = -ENOMEM; |
|---|
| 220 | + patt_random = kmalloc(mtd->erasesize, GFP_KERNEL); |
|---|
| 221 | + if (!patt_random) |
|---|
| 222 | + goto out_mtd; |
|---|
| 223 | + |
|---|
| 225 | 224 | patt_5A5 = kmalloc(mtd->erasesize, GFP_KERNEL); |
|---|
| 226 | 225 | if (!patt_5A5) |
|---|
| 227 | | - goto out_mtd; |
|---|
| 226 | + goto out_patt_random; |
|---|
| 228 | 227 | |
|---|
| 229 | 228 | patt_A5A = kmalloc(mtd->erasesize, GFP_KERNEL); |
|---|
| 230 | 229 | if (!patt_A5A) |
|---|
| .. | .. |
|---|
| 255 | 254 | memset(patt_A5A + i * pgsize, 0x55, pgsize); |
|---|
| 256 | 255 | } |
|---|
| 257 | 256 | } |
|---|
| 257 | + |
|---|
| 258 | + prandom_bytes(patt_random, mtd->erasesize); |
|---|
| 258 | 259 | |
|---|
| 259 | 260 | err = mtdtest_scan_for_bad_eraseblocks(mtd, bad_ebs, eb, ebcnt); |
|---|
| 260 | 261 | if (err) |
|---|
| .. | .. |
|---|
| 295 | 296 | patt = patt_5A5; |
|---|
| 296 | 297 | else |
|---|
| 297 | 298 | patt = patt_A5A; |
|---|
| 299 | + if (random_pattern) |
|---|
| 300 | + patt = patt_random; |
|---|
| 298 | 301 | err = write_pattern(i, patt); |
|---|
| 299 | 302 | if (err) |
|---|
| 300 | 303 | goto out; |
|---|
| .. | .. |
|---|
| 313 | 316 | patt = patt_5A5; |
|---|
| 314 | 317 | else |
|---|
| 315 | 318 | patt = patt_A5A; |
|---|
| 319 | + if (random_pattern) |
|---|
| 320 | + patt = patt_random; |
|---|
| 316 | 321 | err = check_eraseblock(i, patt); |
|---|
| 317 | 322 | if (err) { |
|---|
| 323 | + if (random_pattern) { |
|---|
| 324 | + pr_info("verify failed for random pattern\n"); |
|---|
| 325 | + goto out; |
|---|
| 326 | + } |
|---|
| 318 | 327 | pr_info("verify failed for %s" |
|---|
| 319 | 328 | " pattern\n", |
|---|
| 320 | 329 | ((eb + erase_cycles) & 1) ? |
|---|
| .. | .. |
|---|
| 357 | 366 | kfree(patt_A5A); |
|---|
| 358 | 367 | out_patt_5A5: |
|---|
| 359 | 368 | kfree(patt_5A5); |
|---|
| 369 | +out_patt_random: |
|---|
| 370 | + kfree(patt_random); |
|---|
| 360 | 371 | out_mtd: |
|---|
| 361 | 372 | put_mtd_device(mtd); |
|---|
| 362 | 373 | if (err) |
|---|