{"id":807596,"url":"http://patchwork.ozlabs.org/api/patches/807596/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-mtd/patch/20170830113146.26929-1-u.kleine-koenig@pengutronix.de/","project":{"id":3,"url":"http://patchwork.ozlabs.org/api/projects/3/?format=json","name":"Linux MTD development","link_name":"linux-mtd","list_id":"linux-mtd.lists.infradead.org","list_email":"linux-mtd@lists.infradead.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20170830113146.26929-1-u.kleine-koenig@pengutronix.de>","list_archive_url":null,"date":"2017-08-30T11:31:46","name":"[mtd-utils,v3] nandmarkbad: new util to mark blocks as bad","commit_ref":null,"pull_url":null,"state":"rejected","archived":false,"hash":"00e39608daad2f8714f25ba74f70e70e8be8fea6","submitter":{"id":1476,"url":"http://patchwork.ozlabs.org/api/people/1476/?format=json","name":"Uwe Kleine-König","email":"u.kleine-koenig@pengutronix.de"},"delegate":{"id":61034,"url":"http://patchwork.ozlabs.org/api/users/61034/?format=json","username":"goliath","first_name":"David","last_name":"Oberhollenzer","email":"david.oberhollenzer@sigma-star.at"},"mbox":"http://patchwork.ozlabs.org/project/linux-mtd/patch/20170830113146.26929-1-u.kleine-koenig@pengutronix.de/mbox/","series":[{"id":592,"url":"http://patchwork.ozlabs.org/api/series/592/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-mtd/list/?series=592","date":"2017-08-30T11:31:46","name":"[mtd-utils,v3] nandmarkbad: new util to mark blocks as bad","version":3,"mbox":"http://patchwork.ozlabs.org/series/592/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/807596/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/807596/checks/","tags":{},"related":[],"headers":{"Return-Path":"<linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org; spf=none (mailfrom)\n\tsmtp.mailfrom=lists.infradead.org (client-ip=65.50.211.133;\n\thelo=bombadil.infradead.org;\n\tenvelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (2048-bit key;\n\tunprotected) header.d=lists.infradead.org\n\theader.i=@lists.infradead.org header.b=\"qB7vD2eK\"; \n\tdkim-atps=neutral"],"Received":["from bombadil.infradead.org (bombadil.infradead.org\n\t[65.50.211.133])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xj3K13p6Jz9t1t\n\tfor <incoming@patchwork.ozlabs.org>;\n\tWed, 30 Aug 2017 21:32:53 +1000 (AEST)","from localhost ([127.0.0.1] helo=bombadil.infradead.org)\n\tby bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux))\n\tid 1dn1En-0008UU-GT; Wed, 30 Aug 2017 11:32:49 +0000","from metis.ext.pengutronix.de\n\t([2001:67c:670:201:290:27ff:fe1d:cc33])\n\tby bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux))\n\tid 1dn1EM-0008Qo-TE\n\tfor linux-mtd@lists.infradead.org; Wed, 30 Aug 2017 11:32:25 +0000","from [2001:67c:670:100:5054:ff:fe2a:3aa]\n\t(helo=pty.hi.pengutronix.de)\n\tby metis.ext.pengutronix.de with esmtps\n\t(TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2)\n\t(envelope-from <ukl@pengutronix.de>)\n\tid 1dn1E0-00052A-0Z; Wed, 30 Aug 2017 13:32:00 +0200","from ukl by pty.hi.pengutronix.de with local (Exim 4.89)\n\t(envelope-from <ukl@pengutronix.de>)\n\tid 1dn1Dz-0007xV-OS; Wed, 30 Aug 2017 13:31:59 +0200"],"DKIM-Signature":"v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;\n\td=lists.infradead.org; s=bombadil.20170209; h=Sender:\n\tContent-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe:\n\tList-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References:\n\tIn-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID:\n\tContent-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc\n\t:Resent-Message-ID:List-Owner;\n\tbh=ragFECeIEwoMWPkLNHzTLzc7q9ENMBQXTIb4wWPV4S0=;\n\tb=qB7vD2eKrOO+mQLdVRSvOtnXd4\n\taiET4PCJ/C9ElubMI7mKChH0K+O8OQrLtO39PflBelG6SX7L2KJ1ciAvKtMPEI+uDLGHkm+SdYp21\n\tjRxuM8ZdKst4WbPLd2XhezRBXygQSvppObxbH8Uitomij5/1ix2sQrRqIfECEmUXy2MjvDqHRPtE/\n\toU5wL0bPrWsMAWR4bHimJjwnsqxoo59hIZroJ6FVx+qEKvWUqXZsbB70yr62f1+5ES7TSGrljg4EO\n\t/VE0B164wUfMKSKuMZAt8vBDd4oSSZXTi++0qSFjcanewYBnHKjzukpx2bL6GRDlXmnvpBBz4LwdB\n\tYoI5lqAQ==;","From":"=?utf-8?q?Uwe_Kleine-K=C3=B6nig?= <u.kleine-koenig@pengutronix.de>","To":"David Oberhollenzer <david.oberhollenzer@sigma-star.at>","Subject":"[PATCH mtd-utils v3] nandmarkbad: new util to mark blocks as bad","Date":"Wed, 30 Aug 2017 13:31:46 +0200","Message-Id":"<20170830113146.26929-1-u.kleine-koenig@pengutronix.de>","X-Mailer":"git-send-email 2.14.1","In-Reply-To":"<20170824152227.30394-1-ukleinek@debian.org>","References":"<20170824152227.30394-1-ukleinek@debian.org>","X-SA-Exim-Connect-IP":"2001:67c:670:100:5054:ff:fe2a:3aa","X-SA-Exim-Mail-From":"ukl@pengutronix.de","X-SA-Exim-Scanned":"No (on metis.ext.pengutronix.de);\n\tSAEximRunCond expanded to false","X-PTX-Original-Recipient":"linux-mtd@lists.infradead.org","X-CRM114-Version":"20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 ","X-CRM114-CacheID":"sfid-20170830_043223_253424_64C5539E ","X-CRM114-Status":"GOOD (  18.38  )","X-Spam-Score":"-1.9 (-)","X-Spam-Report":"SpamAssassin version 3.4.1 on bombadil.infradead.org summary:\n\tContent analysis details:   (-1.9 points)\n\tpts rule name              description\n\t---- ----------------------\n\t--------------------------------------------------\n\t-0.0 RP_MATCHES_RCVD Envelope sender domain matches handover relay\n\tdomain\n\t-1.9 BAYES_00               BODY: Bayes spam probability is 0 to 1%\n\t[score: 0.0000]","X-BeenThere":"linux-mtd@lists.infradead.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"Linux MTD discussion mailing list <linux-mtd.lists.infradead.org>","List-Unsubscribe":"<http://lists.infradead.org/mailman/options/linux-mtd>,\n\t<mailto:linux-mtd-request@lists.infradead.org?subject=unsubscribe>","List-Archive":"<http://lists.infradead.org/pipermail/linux-mtd/>","List-Post":"<mailto:linux-mtd@lists.infradead.org>","List-Help":"<mailto:linux-mtd-request@lists.infradead.org?subject=help>","List-Subscribe":"<http://lists.infradead.org/mailman/listinfo/linux-mtd>,\n\t<mailto:linux-mtd-request@lists.infradead.org?subject=subscribe>","Cc":"Richard Weinberger <richard@nod.at>, linux-mtd@lists.infradead.org,\n\tkernel@pengutronix.de","MIME-Version":"1.0","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Sender":"\"linux-mtd\" <linux-mtd-bounces@lists.infradead.org>","Errors-To":"linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org"},"content":"---\nchanges since v2, sent with Message-Id: 20170830112145.26586-1-u.kleine-koenig@pengutronix.de:\n - actually committed the changes advertised for v2 (sigh)\n\nchanges since (implicit) v1 sent with Message-Id: 20170824152227.30394-1-ukleinek@debian.org:\n\n - fix printf format resulting in crash\n   (suggested by gcc and David Oberhollenzer)\n - add options --help, --version, -V (suggested by David Oberhollenzer)\n - add options --i-know-what-i-do, -y (suggested by Richard Weinberger)\n - add an error message if no device was given\n - make usage static\n - use right author email address\n\n .gitignore               |   1 +\n nand-utils/Makemodule.am |   5 +-\n nand-utils/nandmarkbad.c | 119 +++++++++++++++++++++++++++++++++++++++++++++++\n 3 files changed, 124 insertions(+), 1 deletion(-)\n create mode 100644 nand-utils/nandmarkbad.c","diff":"diff --git a/.gitignore b/.gitignore\nindex 38bd04deb34e..754da97b43bf 100644\n--- a/.gitignore\n+++ b/.gitignore\n@@ -36,6 +36,7 @@ mkfs.jffs2\n mtd_debug\n mtdpart\n nanddump\n+nandmarkbad\n nandtest\n nandwrite\n nftl_format\ndiff --git a/nand-utils/Makemodule.am b/nand-utils/Makemodule.am\nindex d75b0cb3e36c..c31dcb01f06e 100644\n--- a/nand-utils/Makemodule.am\n+++ b/nand-utils/Makemodule.am\n@@ -7,6 +7,9 @@ nandwrite_LDADD = libmtd.a\n nandtest_SOURCES = nand-utils/nandtest.c\n nandtest_LDADD = libmtd.a\n \n+nandmarkbad_SOURCES = nand-utils/nandmarkbad.c\n+nandmarkbad_LDADD = libmtd.a\n+\n nftldump_SOURCES = nand-utils/nftldump.c\n nftldump_LDADD = libmtd.a\n \n@@ -14,7 +17,7 @@ nftl_format_SOURCES = nand-utils/nftl_format.c\n nftl_format_LDADD = libmtd.a\n \n NAND_BINS = \\\n-\tnanddump nandwrite nandtest nftldump nftl_format\n+\tnanddump nandwrite nandtest nandmarkbad nftldump nftl_format\n \n NAND_SH = \\\n \tnand-utils/load_nandsim.sh\ndiff --git a/nand-utils/nandmarkbad.c b/nand-utils/nandmarkbad.c\nnew file mode 100644\nindex 000000000000..cf05698c3609\n--- /dev/null\n+++ b/nand-utils/nandmarkbad.c\n@@ -0,0 +1,119 @@\n+#define PROGRAM_NAME \"nandmarkbad\"\n+\n+#include <stdio.h>\n+#include <stdlib.h>\n+#include <unistd.h>\n+#include <getopt.h>\n+\n+#include \"common.h\"\n+#include <libmtd.h>\n+\n+static void usage(int status)\n+{\n+\tfprintf(status ? stderr : stdout,\n+\t\t\"usage: %s [OPTIONS] <device>\\n\\n\"\n+\t\t\"  -b, --markbad=blockno        Mark block bad\\n\"\n+\t\t\"  -h, --help                   Display this help and exit\\n\"\n+\t\t\"  -V, --version                Output version information and exit\\n\"\n+\t\t\"  -y, --i-know-what-i-do       really do mark blocks as bad\\n\",\n+\t\tPROGRAM_NAME);\n+\texit(status);\n+}\n+\n+/*\n+ * Main program\n+ */\n+int main(int argc, char **argv)\n+{\n+\tloff_t mark_bad[32];\n+\tunsigned cnt_bad = 0;\n+\tstruct mtd_dev_info mtd;\n+\tlibmtd_t mtd_desc;\n+\tint fd;\n+\tint error = 0;\n+\tint ret;\n+\tunsigned int i;\n+\tint iknowwhatido = 0;\n+\n+\tfor (;;) {\n+\t\tstatic const char short_options[] = \"b:hVy\";\n+\t\tstatic const struct option long_options[] = {\n+\t\t\t{ \"help\", no_argument, 0, 'h' },\n+\t\t\t{ \"markbad\", required_argument, 0, 'b' },\n+\t\t\t{ \"version\", no_argument, 0, 'V'},\n+\t\t\t{ \"i-know-what-i-do\", no_argument, 0, 'y' },\n+\t\t\t{0, 0, 0, 0},\n+\t\t};\n+\t\tint option_index = 0;\n+\t\tint c = getopt_long(argc, argv, short_options, long_options,\n+\t\t\t\t    &option_index);\n+\t\tif (c == EOF)\n+\t\t\tbreak;\n+\n+\t\tswitch (c) {\n+\t\tcase '?':\n+\t\t\tusage(EXIT_FAILURE);\n+\t\t\tbreak;\n+\n+\t\tcase 'b':\n+\t\t\tif (cnt_bad < ARRAY_SIZE(mark_bad)) {\n+\t\t\t\tmark_bad[cnt_bad] =\n+\t\t\t\t\tsimple_strtoll(optarg, &error);\n+\t\t\t\t++cnt_bad;\n+\t\t\t} else {\n+\t\t\t\terrmsg_die(\"Can't handle so many bad blocks\\n\");\n+\t\t\t}\n+\n+\t\t\tbreak;\n+\n+\t\tcase 'h':\n+\t\t\tusage(EXIT_SUCCESS);\n+\t\t\tbreak;\n+\n+\t\tcase 'V':\n+\t\t\tcommon_print_version();\n+\t\t\treturn EXIT_SUCCESS;\n+\n+\t\tcase 'y':\n+\t\t\tiknowwhatido = 1;\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\n+\targc -= optind;\n+\targv += optind;\n+\n+\tif (error)\n+\t\tusage(EXIT_FAILURE);\n+\n+\tif (argc != 1)\n+\t\terrmsg_die(\"You must specify a device to operate on\\n\");\n+\n+\tif (!cnt_bad)\n+\t\terrmsg_die(\"You must specify at least one block to mark bad\\n\");\n+\n+\tif (!iknowwhatido)\n+\t\terrmsg_die(PROGRAM_NAME \" does things that are hard to undo.\\n\"\n+\t\t\t   \"\\tPlease convince yourself you understand the risks,\\n\"\n+\t\t\t   \"\\tthen add --i-know-what-i-do to the options.\\n\");\n+\n+\tfd = open(argv[0], O_RDWR);\n+\tif (fd < 0)\n+\t\tsys_errmsg_die(\"Failed to open mtd device\\n\");\n+\n+\tmtd_desc = libmtd_open();\n+\tif (!mtd_desc)\n+\t\terrmsg_die(\"Can't initialize libmtd\");\n+\n+\tif (mtd_get_dev_info(mtd_desc, argv[0], &mtd) < 0)\n+\t\terrmsg_die(\"mtd_get_dev_info failed\");\n+\n+\tfor (i = 0; i < cnt_bad; ++i) {\n+\t\tret = mtd_mark_bad(&mtd, fd, mark_bad[i]);\n+\t\tif (ret)\n+\t\t\tsys_errmsg_die(\"%s: MTD Mark bad block failure\",\n+\t\t\t\t       argv[0]);\n+\t}\n+\n+\treturn EXIT_SUCCESS;\n+}\n","prefixes":["mtd-utils","v3"]}