From: Stas Sergeev <stsp@list.ru>
To: linux-mtd@lists.infradead.org
Cc: Stas Sergeev <stsp@users.sourceforge.net>
Subject: [PATCH 2/2] nandmarkblk: erase block before marking bad
Date: Wed, 23 Apr 2014 19:54:48 +0400 [thread overview]
Message-ID: <5357E248.20109@list.ru> (raw)
In-Reply-To: <5357D808.5070101@list.ru>
Add ability to erase blocks before marking, and an option to
not do that.
Signed-off-by: Stas Sergeev <stsp@users.sourceforge.net>
---
nandmarkblk.c | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/nandmarkblk.c b/nandmarkblk.c
index 127219c..e5efb26 100644
--- a/nandmarkblk.c
+++ b/nandmarkblk.c
@@ -29,6 +29,7 @@ static void display_help(int status)
"Writes to the specified MTD device.\n"
"\n"
" -b num, --markbad=num Mark block bad\n"
+" -n --noerase Don't erase block before marking it bad\n"
" -q, --quiet Don't display progress messages\n"
" -h, --help Display this help and exit\n"
" --version Output version information and exit\n"
@@ -54,6 +55,7 @@ static const char *mtd_device;
static bool quiet = false;
static int markbad = -1;
static int markgood = -1;
+static bool noerase = false;
static void process_options(int argc, char * const argv[])
{
@@ -61,13 +63,14 @@ static void process_options(int argc, char * const
argv[])
for (;;) {
int option_index = 0;
- static const char short_options[] = "vhb:g:q";
+ static const char short_options[] = "vhb:g:nq";
static const struct option long_options[] = {
/* Order of these args with val==0 matters; see
option_index. */
{"version", no_argument, 0, 'v'},
{"help", no_argument, 0, 'h'},
{"markbad", required_argument, 0, 'b'},
{"markgood", required_argument, 0, 'g'},
+ {"noerase", no_argument, 0, 'n'},
{"quiet", no_argument, 0, 'q'},
{0, 0, 0, 0},
};
@@ -90,6 +93,9 @@ static void process_options(int argc, char * const argv[])
case 'b':
markbad = simple_strtoll(optarg, &error);
break;
+ case 'n':
+ noerase = true;
+ break;
case 'h':
display_help(EXIT_SUCCESS);
break;
@@ -132,9 +138,15 @@ int main(int argc, char * const argv[])
if (mtd_get_dev_info(mtd_desc, mtd_device, &mtd) < 0)
errmsg_die("mtd_get_dev_info failed");
- if (markbad != -1 && mtd_mark_bad(&mtd, fd, markbad)) {
- sys_errmsg("%s: MTD Mark bad block failure", mtd_device);
- goto closeall;
+ if (markbad != -1) {
+ if (!noerase && mtd_erase(mtd_desc, &mtd, fd, markbad) != 0) {
+ sys_errmsg("%s: MTD Erase failure", mtd_device);
+ goto closeall;
+ }
+ if (mtd_mark_bad(&mtd, fd, markbad)) {
+ sys_errmsg("%s: MTD Mark bad block failure", mtd_device);
+ goto closeall;
+ }
}
if (markgood != -1) {
--
1.7.11.7
prev parent reply other threads:[~2014-04-23 15:55 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-23 15:11 [PATCH 0/2] mtd-utils: add nandmarkblk tool Stas Sergeev
2014-04-23 15:12 ` [PATCH 1/2] nandmarkblk: initial version Stas Sergeev
2014-04-23 15:13 ` [PATCH 2/2] nandmarkblk: erase block before marking bad Stas Sergeev
2014-04-23 15:50 ` [PATCH 1/2] nandmarkblk: initial version Stas Sergeev
2014-04-23 15:54 ` Stas Sergeev [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5357E248.20109@list.ru \
--to=stsp@list.ru \
--cc=linux-mtd@lists.infradead.org \
--cc=stsp@users.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.