From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.sigma-star.at ([95.130.255.111]) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1auolT-0004nw-0L for linux-mtd@lists.infradead.org; Mon, 25 Apr 2016 22:14:00 +0000 From: Richard Weinberger To: linux-mtd@lists.infradead.org Cc: david.oberhollenzer@sigma-star.at, Richard Weinberger Subject: [PATCH 4/8] mtd-utils: Add flash stress test Utility Date: Tue, 26 Apr 2016 00:13:25 +0200 Message-Id: <1461622409-14970-5-git-send-email-richard@nod.at> In-Reply-To: <1461622409-14970-1-git-send-email-richard@nod.at> References: <1461622409-14970-1-git-send-email-richard@nod.at> List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: David Oberhollenzer Basically a user space port of the mtd stress test kernel module. In addition to the block offset and count module parameters, the utility supports a block stride and can restore the block contents after test. Signed-off-by: David Oberhollenzer Signed-off-by: Richard Weinberger --- .gitignore | 1 + Makefile | 2 +- misc-utils/flash_stress.c | 276 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 278 insertions(+), 1 deletion(-) create mode 100644 misc-utils/flash_stress.c diff --git a/.gitignore b/.gitignore index 5b529d1..3d03708 100644 --- a/.gitignore +++ b/.gitignore @@ -36,6 +36,7 @@ /misc-utils/mtd_debug /misc-utils/mtdpart /misc-utils/flash_torture +/misc-utils/flash_stress /nand-utils/nanddump /nand-utils/nandtest /nand-utils/nandwrite diff --git a/Makefile b/Makefile index af3d1fd..1bc41e0 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ MISC_BINS = \ ftl_format doc_loadbios ftl_check mtd_debug docfdisk \ serve_image recv_image mtdpart flash_erase flash_lock \ flash_unlock flash_otp_info flash_otp_dump flash_otp_lock \ - flash_otp_write flashcp flash_torture + flash_otp_write flashcp flash_torture flash_stress UBI_BINS = \ ubiupdatevol ubimkvol ubirmvol ubicrc32 ubinfo ubiattach \ ubidetach ubinize ubiformat ubirename mtdinfo ubirsvol ubiblock diff --git a/misc-utils/flash_stress.c b/misc-utils/flash_stress.c new file mode 100644 index 0000000..2dd2da1 --- /dev/null +++ b/misc-utils/flash_stress.c @@ -0,0 +1,276 @@ +/* + * Copyright (C) 2006-2008 Nokia Corporation + * Copyright (C) 2015 sigma star gmbh + * + * 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. + * + * Test random reads, writes and erases on MTD device. + * + * Author: David Oberhollenzer + * + * Based on linux stresstest.c + * Author: Adrian Hunter + */ +#define PROGRAM_NAME "flash_stress" + +#define KEEP_CONTENTS 0x01 +#define COUNT_CHANGED 0x02 +#define SEED_SET 0x04 + +#include +#include +#include +#include +#include +#include +#include + +#include "common.h" + +static struct mtd_dev_info mtd; +static const char *mtddev; +static libmtd_t mtd_desc; +static int fd; + +static unsigned char *writebuf; +static unsigned char *readbuf; +static unsigned char *old; +static unsigned char *bbt; + +static int pgsize; +static int pgcnt; + +static int count = 10000; +static int flags = 0; + +static void usage(int status) +{ + fputs( + "Usage: "PROGRAM_NAME" [OPTIONS] \n\n" + "Options:\n" + " -h, --help Display this help output\n" + " -c, --count Number of operations to do (default is 10000)\n" + " -s, --seed Seed for pseudor random number generator\n" + " -k, --keep Restore existing contents after test\n", + status==EXIT_SUCCESS ? stdout : stderr); + exit(status); +} + +static long read_num(int idx, int argidx, int argc, char **argv) +{ + char *end; + long num; + + if (argidx >= argc) { + fprintf(stderr, "%s: missing argument\n", argv[idx]); + exit(EXIT_FAILURE); + } + + num = strtol(argv[argidx], &end, 0); + + if (!end || *end!='\0') { + fprintf(stderr, "%s: expected integer argument\n", argv[idx]); + exit(EXIT_FAILURE); + } + return num; +} + +static void process_options(int argc, char **argv) +{ + int i; + + for (i=1; i