mailarchive of the ptxdist mailing list
 help / color / mirror / Atom feed
From: Alexander Dahl <ada@thorsis.com>
To: ptxdist@pengutronix.de
Cc: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Subject: [ptxdist] [PATCH 2/2] mtd-utils: Add patch for new tool 'nandmarkbad'
Date: Wed, 30 Aug 2017 16:49:42 +0200	[thread overview]
Message-ID: <1504104582-32171-3-git-send-email-ada@thorsis.com> (raw)
In-Reply-To: <1504104582-32171-1-git-send-email-ada@thorsis.com>

taken from https://patchwork.ozlabs.org/patch/807596/

Suggested-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Alexander Dahl <ada@thorsis.com>
---
 ...andmarkbad-new-util-to-mark-blocks-as-bad.patch | 158 +++++++++++++++++++++
 patches/mtd-utils-2.0.1/autogen.sh                 |   1 +
 patches/mtd-utils-2.0.1/series                     |   4 +
 rules/mtd-utils.in                                 |   6 +
 rules/mtd-utils.make                               |   4 +
 5 files changed, 173 insertions(+)
 create mode 100644 patches/mtd-utils-2.0.1/0001-nandmarkbad-new-util-to-mark-blocks-as-bad.patch
 create mode 120000 patches/mtd-utils-2.0.1/autogen.sh
 create mode 100644 patches/mtd-utils-2.0.1/series

diff --git a/patches/mtd-utils-2.0.1/0001-nandmarkbad-new-util-to-mark-blocks-as-bad.patch b/patches/mtd-utils-2.0.1/0001-nandmarkbad-new-util-to-mark-blocks-as-bad.patch
new file mode 100644
index 0000000..1cea5f2
--- /dev/null
+++ b/patches/mtd-utils-2.0.1/0001-nandmarkbad-new-util-to-mark-blocks-as-bad.patch
@@ -0,0 +1,158 @@
+From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= <u.kleine-koenig@pengutronix.de>
+Date: Wed, 30 Aug 2017 13:31:46 +0200
+Subject: [PATCH] nandmarkbad: new util to mark blocks as bad
+
+---
+ nand-utils/Makemodule.am |   5 +-
+ nand-utils/nandmarkbad.c | 119 +++++++++++++++++++++++++++++++++++++++++++++++
+ 2 files changed, 123 insertions(+), 1 deletion(-)
+ create mode 100644 nand-utils/nandmarkbad.c
+
+diff --git a/nand-utils/Makemodule.am b/nand-utils/Makemodule.am
+index d75b0cb3e36c..c31dcb01f06e 100644
+--- a/nand-utils/Makemodule.am
++++ b/nand-utils/Makemodule.am
+@@ -7,6 +7,9 @@ nandwrite_LDADD = libmtd.a
+ nandtest_SOURCES = nand-utils/nandtest.c
+ nandtest_LDADD = libmtd.a
+ 
++nandmarkbad_SOURCES = nand-utils/nandmarkbad.c
++nandmarkbad_LDADD = libmtd.a
++
+ nftldump_SOURCES = nand-utils/nftldump.c
+ nftldump_LDADD = libmtd.a
+ 
+@@ -14,7 +17,7 @@ nftl_format_SOURCES = nand-utils/nftl_format.c
+ nftl_format_LDADD = libmtd.a
+ 
+ NAND_BINS = \
+-	nanddump nandwrite nandtest nftldump nftl_format
++	nanddump nandwrite nandtest nandmarkbad nftldump nftl_format
+ 
+ NAND_SH = \
+ 	nand-utils/load_nandsim.sh
+diff --git a/nand-utils/nandmarkbad.c b/nand-utils/nandmarkbad.c
+new file mode 100644
+index 000000000000..cf05698c3609
+--- /dev/null
++++ b/nand-utils/nandmarkbad.c
+@@ -0,0 +1,119 @@
++#define PROGRAM_NAME "nandmarkbad"
++
++#include <stdio.h>
++#include <stdlib.h>
++#include <unistd.h>
++#include <getopt.h>
++
++#include "common.h"
++#include <libmtd.h>
++
++static void usage(int status)
++{
++	fprintf(status ? stderr : stdout,
++		"usage: %s [OPTIONS] <device>\n\n"
++		"  -b, --markbad=blockno        Mark block bad\n"
++		"  -h, --help                   Display this help and exit\n"
++		"  -V, --version                Output version information and exit\n"
++		"  -y, --i-know-what-i-do       really do mark blocks as bad\n",
++		PROGRAM_NAME);
++	exit(status);
++}
++
++/*
++ * Main program
++ */
++int main(int argc, char **argv)
++{
++	loff_t mark_bad[32];
++	unsigned cnt_bad = 0;
++	struct mtd_dev_info mtd;
++	libmtd_t mtd_desc;
++	int fd;
++	int error = 0;
++	int ret;
++	unsigned int i;
++	int iknowwhatido = 0;
++
++	for (;;) {
++		static const char short_options[] = "b:hVy";
++		static const struct option long_options[] = {
++			{ "help", no_argument, 0, 'h' },
++			{ "markbad", required_argument, 0, 'b' },
++			{ "version", no_argument, 0, 'V'},
++			{ "i-know-what-i-do", no_argument, 0, 'y' },
++			{0, 0, 0, 0},
++		};
++		int option_index = 0;
++		int c = getopt_long(argc, argv, short_options, long_options,
++				    &option_index);
++		if (c == EOF)
++			break;
++
++		switch (c) {
++		case '?':
++			usage(EXIT_FAILURE);
++			break;
++
++		case 'b':
++			if (cnt_bad < ARRAY_SIZE(mark_bad)) {
++				mark_bad[cnt_bad] =
++					simple_strtoll(optarg, &error);
++				++cnt_bad;
++			} else {
++				errmsg_die("Can't handle so many bad blocks\n");
++			}
++
++			break;
++
++		case 'h':
++			usage(EXIT_SUCCESS);
++			break;
++
++		case 'V':
++			common_print_version();
++			return EXIT_SUCCESS;
++
++		case 'y':
++			iknowwhatido = 1;
++			break;
++		}
++	}
++
++	argc -= optind;
++	argv += optind;
++
++	if (error)
++		usage(EXIT_FAILURE);
++
++	if (argc != 1)
++		errmsg_die("You must specify a device to operate on\n");
++
++	if (!cnt_bad)
++		errmsg_die("You must specify at least one block to mark bad\n");
++
++	if (!iknowwhatido)
++		errmsg_die(PROGRAM_NAME " does things that are hard to undo.\n"
++			   "\tPlease convince yourself you understand the risks,\n"
++			   "\tthen add --i-know-what-i-do to the options.\n");
++
++	fd = open(argv[0], O_RDWR);
++	if (fd < 0)
++		sys_errmsg_die("Failed to open mtd device\n");
++
++	mtd_desc = libmtd_open();
++	if (!mtd_desc)
++		errmsg_die("Can't initialize libmtd");
++
++	if (mtd_get_dev_info(mtd_desc, argv[0], &mtd) < 0)
++		errmsg_die("mtd_get_dev_info failed");
++
++	for (i = 0; i < cnt_bad; ++i) {
++		ret = mtd_mark_bad(&mtd, fd, mark_bad[i]);
++		if (ret)
++			sys_errmsg_die("%s: MTD Mark bad block failure",
++				       argv[0]);
++	}
++
++	return EXIT_SUCCESS;
++}
diff --git a/patches/mtd-utils-2.0.1/autogen.sh b/patches/mtd-utils-2.0.1/autogen.sh
new file mode 120000
index 0000000..9f8a4cb
--- /dev/null
+++ b/patches/mtd-utils-2.0.1/autogen.sh
@@ -0,0 +1 @@
+../autogen.sh
\ No newline at end of file
diff --git a/patches/mtd-utils-2.0.1/series b/patches/mtd-utils-2.0.1/series
new file mode 100644
index 0000000..92dc1b9
--- /dev/null
+++ b/patches/mtd-utils-2.0.1/series
@@ -0,0 +1,4 @@
+# generated by git-ptx-patches
+#tag:base --start-number 1
+0001-nandmarkbad-new-util-to-mark-blocks-as-bad.patch
+# 407ded52b82ffa3ff91d50cf6b2388e0  - git-ptx-patches magic
diff --git a/rules/mtd-utils.in b/rules/mtd-utils.in
index 552f289..6e82966 100644
--- a/rules/mtd-utils.in
+++ b/rules/mtd-utils.in
@@ -161,6 +161,12 @@ config MTD_UTILS_NANDDUMP
 comment "busybox' nanddump is selected!"
 	depends on BUSYBOX_NANDDUMP
 
+config MTD_UTILS_NANDMARKBAD
+	bool
+	prompt "nandmarkbad"
+	help
+	  Mark block bad.
+
 config MTD_UTILS_NANDTEST
 	bool
 	prompt "nandtest"
diff --git a/rules/mtd-utils.make b/rules/mtd-utils.make
index d8a8972..5919ac2 100644
--- a/rules/mtd-utils.make
+++ b/rules/mtd-utils.make
@@ -118,6 +118,10 @@ ifdef PTXCONF_MTD_UTILS_NANDDUMP
 	@$(call install_copy, mtd-utils, 0, 0, 0755, -, \
 		/usr/sbin/nanddump)
 endif
+ifdef PTXCONF_MTD_UTILS_NANDMARKBAD
+	@$(call install_copy, mtd-utils, 0, 0, 0755, -, \
+		/usr/sbin/nandmarkbad)
+endif
 ifdef PTXCONF_MTD_UTILS_NANDTEST
 	@$(call install_copy, mtd-utils, 0, 0, 0755, -, \
 		/usr/sbin/nandtest)
-- 
2.1.4


_______________________________________________
ptxdist mailing list
ptxdist@pengutronix.de

      parent reply	other threads:[~2017-08-30 14:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-30 14:49 [ptxdist] [PATCH 0/2] mtd-utils: Upgrade and new tool nandmarkbad Alexander Dahl
2017-08-30 14:49 ` [ptxdist] [PATCH 1/2] mtd-utils: Upgrade from 1.5.2 to 2.0.1 Alexander Dahl
2017-08-30 14:49 ` Alexander Dahl [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=1504104582-32171-3-git-send-email-ada@thorsis.com \
    --to=ada@thorsis.com \
    --cc=ptxdist@pengutronix.de \
    --cc=u.kleine-koenig@pengutronix.de \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox