2008-12-08 04:38:34 -07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2006-2008 Artem Bityutskiy
|
|
|
|
* Copyright (C) 2006-2008 Jarkko Lavinen
|
|
|
|
* Copyright (C) 2006-2008 Adrian Hunter
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 as published by
|
|
|
|
* the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program; see the file COPYING. If not, write to the Free Software
|
|
|
|
* Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* Authors: Artem Bityutskiy, Jarkko Lavinen, Adria Hunter
|
|
|
|
*
|
|
|
|
* WARNING: this test program may kill your flash and your device. Do not
|
|
|
|
* use it unless you know what you do. Authors are not responsible for any
|
|
|
|
* damage caused by this program.
|
|
|
|
*/
|
|
|
|
|
2012-10-10 11:41:37 -06:00
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
2008-12-08 04:38:34 -07:00
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/moduleparam.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/mtd/mtd.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 02:04:11 -06:00
|
|
|
#include <linux/slab.h>
|
2008-12-08 04:38:34 -07:00
|
|
|
#include <linux/sched.h>
|
2013-08-03 03:52:15 -06:00
|
|
|
#include "mtd_test.h"
|
2008-12-08 04:38:34 -07:00
|
|
|
|
|
|
|
#define RETRIES 3
|
|
|
|
|
|
|
|
static int eb = 8;
|
|
|
|
module_param(eb, int, S_IRUGO);
|
|
|
|
MODULE_PARM_DESC(eb, "eraseblock number within the selected MTD device");
|
|
|
|
|
|
|
|
static int ebcnt = 32;
|
|
|
|
module_param(ebcnt, int, S_IRUGO);
|
|
|
|
MODULE_PARM_DESC(ebcnt, "number of consecutive eraseblocks to torture");
|
|
|
|
|
|
|
|
static int pgcnt;
|
|
|
|
module_param(pgcnt, int, S_IRUGO);
|
|
|
|
MODULE_PARM_DESC(pgcnt, "number of pages per eraseblock to torture (0 => all)");
|
|
|
|
|
2011-10-29 16:11:53 -06:00
|
|
|
static int dev = -EINVAL;
|
2008-12-08 04:38:34 -07:00
|
|
|
module_param(dev, int, S_IRUGO);
|
|
|
|
MODULE_PARM_DESC(dev, "MTD device number to use");
|
|
|
|
|
|
|
|
static int gran = 512;
|
|
|
|
module_param(gran, int, S_IRUGO);
|
|
|
|
MODULE_PARM_DESC(gran, "how often the status information should be printed");
|
|
|
|
|
|
|
|
static int check = 1;
|
|
|
|
module_param(check, int, S_IRUGO);
|
|
|
|
MODULE_PARM_DESC(check, "if the written data should be checked");
|
|
|
|
|
|
|
|
static unsigned int cycles_count;
|
|
|
|
module_param(cycles_count, uint, S_IRUGO);
|
|
|
|
MODULE_PARM_DESC(cycles_count, "how many erase cycles to do "
|
|
|
|
"(infinite by default)");
|
|
|
|
|
|
|
|
static struct mtd_info *mtd;
|
|
|
|
|
|
|
|
/* This buffer contains 0x555555...0xAAAAAA... pattern */
|
|
|
|
static unsigned char *patt_5A5;
|
|
|
|
/* This buffer contains 0xAAAAAA...0x555555... pattern */
|
|
|
|
static unsigned char *patt_A5A;
|
|
|
|
/* This buffer contains all 0xFF bytes */
|
|
|
|
static unsigned char *patt_FF;
|
|
|
|
/* This a temporary buffer is use when checking data */
|
|
|
|
static unsigned char *check_buf;
|
|
|
|
/* How many erase cycles were done */
|
|
|
|
static unsigned int erase_cycles;
|
|
|
|
|
|
|
|
static int pgsize;
|
|
|
|
static struct timeval start, finish;
|
|
|
|
|
|
|
|
static void report_corrupt(unsigned char *read, unsigned char *written);
|
|
|
|
|
|
|
|
static inline void start_timing(void)
|
|
|
|
{
|
|
|
|
do_gettimeofday(&start);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void stop_timing(void)
|
|
|
|
{
|
|
|
|
do_gettimeofday(&finish);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check that the contents of eraseblock number @enbum is equivalent to the
|
|
|
|
* @buf buffer.
|
|
|
|
*/
|
|
|
|
static inline int check_eraseblock(int ebnum, unsigned char *buf)
|
|
|
|
{
|
|
|
|
int err, retries = 0;
|
mtd: remove extra retlen assignment
MTD functions always assign the 'retlen' argument to 0 at the very
beginning - the callers do not have to do this.
I used the following semantic patch to find these places:
@@
identifier retlen;
expression a, b, c, d, e;
constant C;
type T;
@@
(
- retlen = C;
|
T
-retlen = C
+ retlen
;
)
... when != retlen
when exists
(
mtd_read(a, b, c, &retlen, d)
|
mtd_write(a, b, c, &retlen, d)
|
mtd_panic_write(a, b, c, &retlen, d)
|
mtd_point(a, b, c, &retlen, d, e)
|
mtd_read_fact_prot_reg(a, b, c, &retlen, d)
|
mtd_write_user_prot_reg(a, b, c, &retlen, d)
|
mtd_read_user_prot_reg(a, b, c, &retlen, d)
|
mtd_writev(a, b, c, d, &retlen)
)
I ran it twice, because there were cases of double zero assigments
in mtd tests. Then I went through the patch to verify that spatch
did not find any false positives.
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
2011-12-29 06:16:28 -07:00
|
|
|
size_t read;
|
2015-02-28 03:02:26 -07:00
|
|
|
loff_t addr = (loff_t)ebnum * mtd->erasesize;
|
2008-12-08 04:38:34 -07:00
|
|
|
size_t len = mtd->erasesize;
|
|
|
|
|
|
|
|
if (pgcnt) {
|
2015-02-28 03:02:26 -07:00
|
|
|
addr = (loff_t)(ebnum + 1) * mtd->erasesize - pgcnt * pgsize;
|
2008-12-08 04:38:34 -07:00
|
|
|
len = pgcnt * pgsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
retry:
|
2011-12-23 08:30:16 -07:00
|
|
|
err = mtd_read(mtd, addr, len, &read, check_buf);
|
2011-09-20 19:34:25 -06:00
|
|
|
if (mtd_is_bitflip(err))
|
2012-10-10 11:41:37 -06:00
|
|
|
pr_err("single bit flip occurred at EB %d "
|
2008-12-08 04:38:34 -07:00
|
|
|
"MTD reported that it was fixed.\n", ebnum);
|
|
|
|
else if (err) {
|
2012-10-10 11:41:37 -06:00
|
|
|
pr_err("error %d while reading EB %d, "
|
2008-12-08 04:38:34 -07:00
|
|
|
"read %zd\n", err, ebnum, read);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (read != len) {
|
2012-10-10 11:41:37 -06:00
|
|
|
pr_err("failed to read %zd bytes from EB %d, "
|
2008-12-08 04:38:34 -07:00
|
|
|
"read only %zd, but no error reported\n",
|
|
|
|
len, ebnum, read);
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (memcmp(buf, check_buf, len)) {
|
2012-10-10 11:41:37 -06:00
|
|
|
pr_err("read wrong data from EB %d\n", ebnum);
|
2008-12-08 04:38:34 -07:00
|
|
|
report_corrupt(check_buf, buf);
|
|
|
|
|
|
|
|
if (retries++ < RETRIES) {
|
|
|
|
/* Try read again */
|
|
|
|
yield();
|
2012-10-10 11:41:37 -06:00
|
|
|
pr_info("re-try reading data from EB %d\n",
|
2008-12-08 04:38:34 -07:00
|
|
|
ebnum);
|
|
|
|
goto retry;
|
|
|
|
} else {
|
2012-10-10 11:41:37 -06:00
|
|
|
pr_info("retried %d times, still errors, "
|
2008-12-08 04:38:34 -07:00
|
|
|
"give-up\n", RETRIES);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (retries != 0)
|
2012-10-10 11:41:37 -06:00
|
|
|
pr_info("only attempt number %d was OK (!!!)\n",
|
2008-12-08 04:38:34 -07:00
|
|
|
retries);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int write_pattern(int ebnum, void *buf)
|
|
|
|
{
|
|
|
|
int err;
|
mtd: remove extra retlen assignment
MTD functions always assign the 'retlen' argument to 0 at the very
beginning - the callers do not have to do this.
I used the following semantic patch to find these places:
@@
identifier retlen;
expression a, b, c, d, e;
constant C;
type T;
@@
(
- retlen = C;
|
T
-retlen = C
+ retlen
;
)
... when != retlen
when exists
(
mtd_read(a, b, c, &retlen, d)
|
mtd_write(a, b, c, &retlen, d)
|
mtd_panic_write(a, b, c, &retlen, d)
|
mtd_point(a, b, c, &retlen, d, e)
|
mtd_read_fact_prot_reg(a, b, c, &retlen, d)
|
mtd_write_user_prot_reg(a, b, c, &retlen, d)
|
mtd_read_user_prot_reg(a, b, c, &retlen, d)
|
mtd_writev(a, b, c, d, &retlen)
)
I ran it twice, because there were cases of double zero assigments
in mtd tests. Then I went through the patch to verify that spatch
did not find any false positives.
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
2011-12-29 06:16:28 -07:00
|
|
|
size_t written;
|
2015-02-28 03:02:26 -07:00
|
|
|
loff_t addr = (loff_t)ebnum * mtd->erasesize;
|
2008-12-08 04:38:34 -07:00
|
|
|
size_t len = mtd->erasesize;
|
|
|
|
|
|
|
|
if (pgcnt) {
|
2015-02-28 03:02:26 -07:00
|
|
|
addr = (loff_t)(ebnum + 1) * mtd->erasesize - pgcnt * pgsize;
|
2008-12-08 04:38:34 -07:00
|
|
|
len = pgcnt * pgsize;
|
|
|
|
}
|
2011-12-23 08:35:41 -07:00
|
|
|
err = mtd_write(mtd, addr, len, &written, buf);
|
2008-12-08 04:38:34 -07:00
|
|
|
if (err) {
|
2012-10-10 11:41:37 -06:00
|
|
|
pr_err("error %d while writing EB %d, written %zd"
|
2008-12-08 04:38:34 -07:00
|
|
|
" bytes\n", err, ebnum, written);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
if (written != len) {
|
2012-10-10 11:41:37 -06:00
|
|
|
pr_info("written only %zd bytes of %zd, but no error"
|
2008-12-08 04:38:34 -07:00
|
|
|
" reported\n", written, len);
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __init tort_init(void)
|
|
|
|
{
|
|
|
|
int err = 0, i, infinite = !cycles_count;
|
2013-08-03 03:52:15 -06:00
|
|
|
unsigned char *bad_ebs;
|
2008-12-08 04:38:34 -07:00
|
|
|
|
|
|
|
printk(KERN_INFO "\n");
|
|
|
|
printk(KERN_INFO "=================================================\n");
|
2012-10-10 11:41:37 -06:00
|
|
|
pr_info("Warning: this program is trying to wear out your "
|
2008-12-08 04:38:34 -07:00
|
|
|
"flash, stop it if this is not wanted.\n");
|
2011-10-29 16:11:53 -06:00
|
|
|
|
|
|
|
if (dev < 0) {
|
2012-11-09 07:20:58 -07:00
|
|
|
pr_info("Please specify a valid mtd-device via module parameter\n");
|
2012-10-10 11:41:37 -06:00
|
|
|
pr_crit("CAREFUL: This test wipes all data on the specified MTD device!\n");
|
2011-10-29 16:11:53 -06:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2012-10-10 11:41:37 -06:00
|
|
|
pr_info("MTD device: %d\n", dev);
|
|
|
|
pr_info("torture %d eraseblocks (%d-%d) of mtd%d\n",
|
2008-12-08 04:38:34 -07:00
|
|
|
ebcnt, eb, eb + ebcnt - 1, dev);
|
|
|
|
if (pgcnt)
|
2012-10-10 11:41:37 -06:00
|
|
|
pr_info("torturing just %d pages per eraseblock\n",
|
2008-12-08 04:38:34 -07:00
|
|
|
pgcnt);
|
2012-10-10 11:41:37 -06:00
|
|
|
pr_info("write verify %s\n", check ? "enabled" : "disabled");
|
2008-12-08 04:38:34 -07:00
|
|
|
|
|
|
|
mtd = get_mtd_device(NULL, dev);
|
|
|
|
if (IS_ERR(mtd)) {
|
|
|
|
err = PTR_ERR(mtd);
|
2012-10-10 11:41:37 -06:00
|
|
|
pr_err("error: cannot get MTD device\n");
|
2008-12-08 04:38:34 -07:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mtd->writesize == 1) {
|
2012-10-10 11:41:37 -06:00
|
|
|
pr_info("not NAND flash, assume page size is 512 "
|
2008-12-08 04:38:34 -07:00
|
|
|
"bytes.\n");
|
|
|
|
pgsize = 512;
|
|
|
|
} else
|
|
|
|
pgsize = mtd->writesize;
|
|
|
|
|
|
|
|
if (pgcnt && (pgcnt > mtd->erasesize / pgsize || pgcnt < 0)) {
|
2012-10-10 11:41:37 -06:00
|
|
|
pr_err("error: invalid pgcnt value %d\n", pgcnt);
|
2008-12-08 04:38:34 -07:00
|
|
|
goto out_mtd;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = -ENOMEM;
|
|
|
|
patt_5A5 = kmalloc(mtd->erasesize, GFP_KERNEL);
|
2013-02-05 07:08:10 -07:00
|
|
|
if (!patt_5A5)
|
2008-12-08 04:38:34 -07:00
|
|
|
goto out_mtd;
|
|
|
|
|
|
|
|
patt_A5A = kmalloc(mtd->erasesize, GFP_KERNEL);
|
2013-02-05 07:08:10 -07:00
|
|
|
if (!patt_A5A)
|
2008-12-08 04:38:34 -07:00
|
|
|
goto out_patt_5A5;
|
|
|
|
|
|
|
|
patt_FF = kmalloc(mtd->erasesize, GFP_KERNEL);
|
2013-02-05 07:08:10 -07:00
|
|
|
if (!patt_FF)
|
2008-12-08 04:38:34 -07:00
|
|
|
goto out_patt_A5A;
|
|
|
|
|
|
|
|
check_buf = kmalloc(mtd->erasesize, GFP_KERNEL);
|
2013-02-05 07:08:10 -07:00
|
|
|
if (!check_buf)
|
2008-12-08 04:38:34 -07:00
|
|
|
goto out_patt_FF;
|
2013-02-05 07:08:10 -07:00
|
|
|
|
2013-08-03 03:52:15 -06:00
|
|
|
bad_ebs = kzalloc(ebcnt, GFP_KERNEL);
|
2013-02-05 07:08:10 -07:00
|
|
|
if (!bad_ebs)
|
|
|
|
goto out_check_buf;
|
2008-12-08 04:38:34 -07:00
|
|
|
|
|
|
|
err = 0;
|
|
|
|
|
|
|
|
/* Initialize patterns */
|
|
|
|
memset(patt_FF, 0xFF, mtd->erasesize);
|
|
|
|
for (i = 0; i < mtd->erasesize / pgsize; i++) {
|
|
|
|
if (!(i & 1)) {
|
|
|
|
memset(patt_5A5 + i * pgsize, 0x55, pgsize);
|
|
|
|
memset(patt_A5A + i * pgsize, 0xAA, pgsize);
|
|
|
|
} else {
|
|
|
|
memset(patt_5A5 + i * pgsize, 0xAA, pgsize);
|
|
|
|
memset(patt_A5A + i * pgsize, 0x55, pgsize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-03 03:52:15 -06:00
|
|
|
err = mtdtest_scan_for_bad_eraseblocks(mtd, bad_ebs, eb, ebcnt);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
2008-12-08 04:38:34 -07:00
|
|
|
|
|
|
|
start_timing();
|
|
|
|
while (1) {
|
|
|
|
int i;
|
|
|
|
void *patt;
|
|
|
|
|
2014-11-21 11:24:29 -07:00
|
|
|
err = mtdtest_erase_good_eraseblocks(mtd, bad_ebs, eb, ebcnt);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
2008-12-08 04:38:34 -07:00
|
|
|
|
|
|
|
/* Check if the eraseblocks contain only 0xFF bytes */
|
|
|
|
if (check) {
|
|
|
|
for (i = eb; i < eb + ebcnt; i++) {
|
|
|
|
if (bad_ebs[i - eb])
|
|
|
|
continue;
|
|
|
|
err = check_eraseblock(i, patt_FF);
|
|
|
|
if (err) {
|
2012-10-10 11:41:37 -06:00
|
|
|
pr_info("verify failed"
|
2008-12-08 04:38:34 -07:00
|
|
|
" for 0xFF... pattern\n");
|
|
|
|
goto out;
|
|
|
|
}
|
2015-03-29 13:52:06 -06:00
|
|
|
|
|
|
|
err = mtdtest_relax();
|
|
|
|
if (err)
|
|
|
|
goto out;
|
2008-12-08 04:38:34 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write the pattern */
|
|
|
|
for (i = eb; i < eb + ebcnt; i++) {
|
|
|
|
if (bad_ebs[i - eb])
|
|
|
|
continue;
|
|
|
|
if ((eb + erase_cycles) & 1)
|
|
|
|
patt = patt_5A5;
|
|
|
|
else
|
|
|
|
patt = patt_A5A;
|
|
|
|
err = write_pattern(i, patt);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
2015-03-29 13:52:06 -06:00
|
|
|
|
|
|
|
err = mtdtest_relax();
|
|
|
|
if (err)
|
|
|
|
goto out;
|
2008-12-08 04:38:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Verify what we wrote */
|
|
|
|
if (check) {
|
|
|
|
for (i = eb; i < eb + ebcnt; i++) {
|
|
|
|
if (bad_ebs[i - eb])
|
|
|
|
continue;
|
|
|
|
if ((eb + erase_cycles) & 1)
|
|
|
|
patt = patt_5A5;
|
|
|
|
else
|
|
|
|
patt = patt_A5A;
|
|
|
|
err = check_eraseblock(i, patt);
|
|
|
|
if (err) {
|
2012-10-10 11:41:37 -06:00
|
|
|
pr_info("verify failed for %s"
|
2008-12-08 04:38:34 -07:00
|
|
|
" pattern\n",
|
|
|
|
((eb + erase_cycles) & 1) ?
|
|
|
|
"0x55AA55..." : "0xAA55AA...");
|
|
|
|
goto out;
|
|
|
|
}
|
2015-03-29 13:52:06 -06:00
|
|
|
|
|
|
|
err = mtdtest_relax();
|
|
|
|
if (err)
|
|
|
|
goto out;
|
2008-12-08 04:38:34 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
erase_cycles += 1;
|
|
|
|
|
|
|
|
if (erase_cycles % gran == 0) {
|
|
|
|
long ms;
|
|
|
|
|
|
|
|
stop_timing();
|
|
|
|
ms = (finish.tv_sec - start.tv_sec) * 1000 +
|
|
|
|
(finish.tv_usec - start.tv_usec) / 1000;
|
2012-10-10 11:41:37 -06:00
|
|
|
pr_info("%08u erase cycles done, took %lu "
|
2008-12-08 04:38:34 -07:00
|
|
|
"milliseconds (%lu seconds)\n",
|
|
|
|
erase_cycles, ms, ms / 1000);
|
|
|
|
start_timing();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!infinite && --cycles_count == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
|
2012-10-10 11:41:37 -06:00
|
|
|
pr_info("finished after %u erase cycles\n",
|
2008-12-08 04:38:34 -07:00
|
|
|
erase_cycles);
|
2013-02-05 07:08:10 -07:00
|
|
|
kfree(bad_ebs);
|
|
|
|
out_check_buf:
|
2008-12-08 04:38:34 -07:00
|
|
|
kfree(check_buf);
|
|
|
|
out_patt_FF:
|
|
|
|
kfree(patt_FF);
|
|
|
|
out_patt_A5A:
|
|
|
|
kfree(patt_A5A);
|
|
|
|
out_patt_5A5:
|
|
|
|
kfree(patt_5A5);
|
|
|
|
out_mtd:
|
|
|
|
put_mtd_device(mtd);
|
|
|
|
if (err)
|
2012-10-10 11:41:37 -06:00
|
|
|
pr_info("error %d occurred during torturing\n", err);
|
2008-12-08 04:38:34 -07:00
|
|
|
printk(KERN_INFO "=================================================\n");
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
module_init(tort_init);
|
|
|
|
|
|
|
|
static void __exit tort_exit(void)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
module_exit(tort_exit);
|
|
|
|
|
|
|
|
static int countdiffs(unsigned char *buf, unsigned char *check_buf,
|
|
|
|
unsigned offset, unsigned len, unsigned *bytesp,
|
|
|
|
unsigned *bitsp);
|
|
|
|
static void print_bufs(unsigned char *read, unsigned char *written, int start,
|
|
|
|
int len);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Report the detailed information about how the read EB differs from what was
|
|
|
|
* written.
|
|
|
|
*/
|
|
|
|
static void report_corrupt(unsigned char *read, unsigned char *written)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int bytes, bits, pages, first;
|
|
|
|
int offset, len;
|
|
|
|
size_t check_len = mtd->erasesize;
|
|
|
|
|
|
|
|
if (pgcnt)
|
|
|
|
check_len = pgcnt * pgsize;
|
|
|
|
|
|
|
|
bytes = bits = pages = 0;
|
|
|
|
for (i = 0; i < check_len; i += pgsize)
|
|
|
|
if (countdiffs(written, read, i, pgsize, &bytes,
|
|
|
|
&bits) >= 0)
|
|
|
|
pages++;
|
|
|
|
|
2012-10-10 11:41:37 -06:00
|
|
|
pr_info("verify fails on %d pages, %d bytes/%d bits\n",
|
2008-12-08 04:38:34 -07:00
|
|
|
pages, bytes, bits);
|
2012-10-10 11:41:37 -06:00
|
|
|
pr_info("The following is a list of all differences between"
|
2008-12-08 04:38:34 -07:00
|
|
|
" what was read from flash and what was expected\n");
|
|
|
|
|
|
|
|
for (i = 0; i < check_len; i += pgsize) {
|
|
|
|
cond_resched();
|
|
|
|
bytes = bits = 0;
|
|
|
|
first = countdiffs(written, read, i, pgsize, &bytes,
|
|
|
|
&bits);
|
|
|
|
if (first < 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
printk("-------------------------------------------------------"
|
|
|
|
"----------------------------------\n");
|
|
|
|
|
2012-10-10 11:41:37 -06:00
|
|
|
pr_info("Page %zd has %d bytes/%d bits failing verify,"
|
2008-12-08 04:38:34 -07:00
|
|
|
" starting at offset 0x%x\n",
|
|
|
|
(mtd->erasesize - check_len + i) / pgsize,
|
|
|
|
bytes, bits, first);
|
|
|
|
|
|
|
|
offset = first & ~0x7;
|
|
|
|
len = ((first + bytes) | 0x7) + 1 - offset;
|
|
|
|
|
|
|
|
print_bufs(read, written, offset, len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print_bufs(unsigned char *read, unsigned char *written, int start,
|
|
|
|
int len)
|
|
|
|
{
|
|
|
|
int i = 0, j1, j2;
|
|
|
|
char *diff;
|
|
|
|
|
|
|
|
printk("Offset Read Written\n");
|
|
|
|
while (i < len) {
|
|
|
|
printk("0x%08x: ", start + i);
|
|
|
|
diff = " ";
|
|
|
|
for (j1 = 0; j1 < 8 && i + j1 < len; j1++) {
|
|
|
|
printk(" %02x", read[start + i + j1]);
|
|
|
|
if (read[start + i + j1] != written[start + i + j1])
|
|
|
|
diff = "***";
|
|
|
|
}
|
|
|
|
|
|
|
|
while (j1 < 8) {
|
|
|
|
printk(" ");
|
|
|
|
j1 += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
printk(" %s ", diff);
|
|
|
|
|
|
|
|
for (j2 = 0; j2 < 8 && i + j2 < len; j2++)
|
|
|
|
printk(" %02x", written[start + i + j2]);
|
|
|
|
printk("\n");
|
|
|
|
i += 8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Count the number of differing bytes and bits and return the first differing
|
|
|
|
* offset.
|
|
|
|
*/
|
|
|
|
static int countdiffs(unsigned char *buf, unsigned char *check_buf,
|
|
|
|
unsigned offset, unsigned len, unsigned *bytesp,
|
|
|
|
unsigned *bitsp)
|
|
|
|
{
|
|
|
|
unsigned i, bit;
|
|
|
|
int first = -1;
|
|
|
|
|
|
|
|
for (i = offset; i < offset + len; i++)
|
|
|
|
if (buf[i] != check_buf[i]) {
|
|
|
|
first = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (i < offset + len) {
|
|
|
|
if (buf[i] != check_buf[i]) {
|
|
|
|
(*bytesp)++;
|
|
|
|
bit = 1;
|
|
|
|
while (bit < 256) {
|
|
|
|
if ((buf[i] & bit) != (check_buf[i] & bit))
|
|
|
|
(*bitsp)++;
|
|
|
|
bit <<= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return first;
|
|
|
|
}
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("Eraseblock torturing module");
|
|
|
|
MODULE_AUTHOR("Artem Bityutskiy, Jarkko Lavinen, Adrian Hunter");
|
|
|
|
MODULE_LICENSE("GPL");
|