* [PATCH 0/2] mtd-utils: add nandmarkblk tool
@ 2014-04-23 15:11 Stas Sergeev
2014-04-23 15:12 ` [PATCH 1/2] nandmarkblk: initial version Stas Sergeev
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Stas Sergeev @ 2014-04-23 15:11 UTC (permalink / raw)
To: linux-mtd; +Cc: Stas Sergeev
Hello.
I have googled and queried this list, and it seems, as
unbelievable as it is, there is no tool to mark nand blocks as
bad. So I wrote one myself.
The patches will follow.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] nandmarkblk: initial version
2014-04-23 15:11 [PATCH 0/2] mtd-utils: add nandmarkblk tool Stas Sergeev
@ 2014-04-23 15:12 ` Stas Sergeev
2014-04-23 15:13 ` [PATCH 2/2] nandmarkblk: erase block before marking bad Stas Sergeev
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Stas Sergeev @ 2014-04-23 15:12 UTC (permalink / raw)
To: linux-mtd; +Cc: Stas Sergeev
[-- Attachment #1: Type: text/plain, Size: 1 bytes --]
[-- Attachment #2: 0001-nandmarkblk-initial-version.patch --]
[-- Type: application/x-patch, Size: 4670 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/2] nandmarkblk: erase block before marking bad
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 ` Stas Sergeev
2014-04-23 15:50 ` [PATCH 1/2] nandmarkblk: initial version Stas Sergeev
2014-04-23 15:54 ` [PATCH 2/2] nandmarkblk: erase block before marking bad Stas Sergeev
3 siblings, 0 replies; 5+ messages in thread
From: Stas Sergeev @ 2014-04-23 15:13 UTC (permalink / raw)
To: linux-mtd; +Cc: Stas Sergeev
[-- Attachment #1: Type: text/plain, Size: 1 bytes --]
[-- Attachment #2: 0002-nandmarkblk-erase-block-before-marking-bad.patch --]
[-- Type: application/x-patch, Size: 2606 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] nandmarkblk: initial version
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 ` Stas Sergeev
2014-04-23 15:54 ` [PATCH 2/2] nandmarkblk: erase block before marking bad Stas Sergeev
3 siblings, 0 replies; 5+ messages in thread
From: Stas Sergeev @ 2014-04-23 15:50 UTC (permalink / raw)
To: linux-mtd; +Cc: Stas Sergeev
Trying again, with inlined patch...
-=-=-=-=-=-=-=-=-=# Don't remove this line #=-=-=-=-=-=-=-=-=-
The tool to mark nand blocks as bad.
In the future - also as good.
Signed-off-by: Stas Sergeev <stsp@users.sourceforge.net>
---
Makefile | 2 +-
nandmarkblk.c | 151
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 152 insertions(+), 1 deletion(-)
create mode 100644 nandmarkblk.c
diff --git a/Makefile b/Makefile
index d316a3d..acb9837 100644
--- a/Makefile
+++ b/Makefile
@@ -20,7 +20,7 @@ MTD_BINS = \
ftl_format flash_erase nanddump doc_loadbios \
ftl_check mkfs.jffs2 flash_lock flash_unlock \
flash_otp_info flash_otp_dump flash_otp_lock flash_otp_write \
- mtd_debug flashcp nandwrite nandtest \
+ mtd_debug flashcp nandwrite nandtest nandmarkblk \
jffs2dump \
nftldump nftl_format docfdisk \
rfddump rfdformat \
diff --git a/nandmarkblk.c b/nandmarkblk.c
new file mode 100644
index 0000000..127219c
--- /dev/null
+++ b/nandmarkblk.c
@@ -0,0 +1,151 @@
+/*
+ * nandmarkblk.c
+ *
+ * Author: Stas Sergeev <stsp@users.sourceforge.net>
+ *
+ * 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.
+ *
+ */
+
+#define PROGRAM_NAME "nandmarkblk"
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <getopt.h>
+#include <sys/ioctl.h>
+#include "mtd/mtd-user.h"
+#include "common.h"
+#include <libmtd.h>
+
+static void display_help(int status)
+{
+ fprintf(status == EXIT_SUCCESS ? stdout : stderr,
+"Usage: nandwrite [OPTION] MTD_DEVICE [INPUTFILE|-]\n"
+"Writes to the specified MTD device.\n"
+"\n"
+" -b num, --markbad=num Mark block 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"
+ );
+ exit(status);
+}
+
+static void display_version(void)
+{
+ printf("%1$s " VERSION "\n"
+ "\n"
+ "%1$s comes with NO WARRANTY\n"
+ "to the extent permitted by law.\n"
+ "\n"
+ "You may redistribute copies of %1$s\n"
+ "under the terms of the GNU General Public Licence.\n"
+ "See the file `COPYING' for more information.\n",
+ PROGRAM_NAME);
+ exit(EXIT_SUCCESS);
+}
+
+static const char *mtd_device;
+static bool quiet = false;
+static int markbad = -1;
+static int markgood = -1;
+
+static void process_options(int argc, char * const argv[])
+{
+ int error = 0;
+
+ for (;;) {
+ int option_index = 0;
+ static const char short_options[] = "vhb:g:q";
+ 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'},
+ {"quiet", no_argument, 0, 'q'},
+ {0, 0, 0, 0},
+ };
+
+ int c = getopt_long(argc, argv, short_options,
+ long_options, &option_index);
+ if (c == EOF)
+ break;
+
+ switch (c) {
+ case 'v':
+ display_version();
+ break;
+ case 'q':
+ quiet = true;
+ break;
+ case 'g':
+ markgood = simple_strtoll(optarg, &error);
+ break;
+ case 'b':
+ markbad = simple_strtoll(optarg, &error);
+ break;
+ case 'h':
+ display_help(EXIT_SUCCESS);
+ break;
+ case '?':
+ error++;
+ break;
+ }
+ }
+
+ argc -= optind;
+ argv += optind;
+
+ if (argc != 1 || error)
+ display_help(EXIT_FAILURE);
+
+ mtd_device = argv[0];
+}
+
+/*
+ * Main program
+ */
+int main(int argc, char * const argv[])
+{
+ int fd = -1;
+ struct mtd_dev_info mtd;
+ /* contains all the data read from the file so far for the current
eraseblock */
+ libmtd_t mtd_desc;
+
+ process_options(argc, argv);
+
+ /* Open the device */
+ if ((fd = open(mtd_device, O_RDWR)) == -1)
+ sys_errmsg_die("%s", mtd_device);
+
+ mtd_desc = libmtd_open();
+ if (!mtd_desc)
+ errmsg_die("can't initialize libmtd");
+
+ /* Fill in MTD device capability structure */
+ 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 (markgood != -1) {
+ sys_errmsg("%s: MTD Mark good is not implemented", mtd_device);
+ goto closeall;
+ }
+
+closeall:
+ libmtd_close(mtd_desc);
+ close(fd);
+
+ /* Return happy */
+ return EXIT_SUCCESS;
+}
--
1.7.11.7
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] nandmarkblk: erase block before marking bad
2014-04-23 15:11 [PATCH 0/2] mtd-utils: add nandmarkblk tool Stas Sergeev
` (2 preceding siblings ...)
2014-04-23 15:50 ` [PATCH 1/2] nandmarkblk: initial version Stas Sergeev
@ 2014-04-23 15:54 ` Stas Sergeev
3 siblings, 0 replies; 5+ messages in thread
From: Stas Sergeev @ 2014-04-23 15:54 UTC (permalink / raw)
To: linux-mtd; +Cc: Stas Sergeev
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
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-04-23 15:55 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH 2/2] nandmarkblk: erase block before marking bad Stas Sergeev
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).