From patchwork Mon Dec 5 16:14:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Trommel X-Patchwork-Id: 702772 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2001:1868:205::9]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tXVHN0nBjz9sDB for ; Tue, 6 Dec 2016 03:16:00 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1cDvuR-0006oD-TX; Mon, 05 Dec 2016 16:14:31 +0000 Received: from outbound01.mx-relay.com ([5.39.185.33] helo=outbound01-a.mx-relay.com) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1cDvuN-0006ht-1D for linux-mtd@lists.infradead.org; Mon, 05 Dec 2016 16:14:28 +0000 X-ASG-Debug-ID: 1480954443-0a1697415149fc0001-6YE7NY Received: from [145.131.171.178] (rt171bb131-145-178.routit.net [145.131.171.178]) by outbound01-a.mx-relay.com with ESMTP id kBRIDCZVHpTZrlfI (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 05 Dec 2016 17:14:03 +0100 (CET) X-Barracuda-Envelope-From: ctrommel@aimvalley.nl X-Barracuda-Effective-Source-IP: rt171bb131-145-178.routit.net[145.131.171.178] X-Barracuda-Apparent-Source-IP: 145.131.171.178 Received: from localhost (localhost.localhost [127.0.0.1]) by router38.aimvalley.nl (Postfix) with ESMTP id 9138E639F7 for ; Mon, 5 Dec 2016 17:14:03 +0100 (CET) X-Virus-Scanned: by Endian Firewall X-Spam-Flag: NO X-Spam-Score: 0.5 X-Spam-Level: X-Spam-Status: No, score=0.5 tagged_above=-20 required=9 tests=[ALL_TRUSTED=-1, TOOMANYSPACES=1.5] autolearn=no X-Spam-CTCH-RefID: Received: from mail3.aimsys.nl (mail.aimsys.nl [10.10.0.114]) by router38.aimvalley.nl (Postfix) with ESMTPS id 8FFA2639F5 for ; Mon, 5 Dec 2016 17:14:02 +0100 (CET) Received: from linvm302.aimsys.nl (linvm302.aimsys.nl [10.10.23.2]) by mail3.aimsys.nl (8.14.2/8.14.2) with ESMTP id uB5GH0Iq008542 for ; Mon, 5 Dec 2016 17:17:01 +0100 From: Kees Trommel Subject: Add --skip-all-ffs option to mtd-utils nandwrite To: linux-mtd@lists.infradead.org X-ASG-Orig-Subj: Add --skip-all-ffs option to mtd-utils nandwrite Message-ID: <82cbfdbc-c79b-01b0-bc64-a4259d7a150e@aimvalley.nl> Date: Mon, 5 Dec 2016 17:14:02 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 X-Barracuda-Connect: rt171bb131-145-178.routit.net[145.131.171.178] X-Barracuda-Start-Time: 1480954443 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://outbound01.mx-relay.com:443/cgi-mod/mark.cgi X-Barracuda-Scan-Msg-Size: 953 X-Virus-Scanned: by bsmtpd at mx-relay.com X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=7.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.34946 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161205_081427_442457_2CD6721E X-CRM114-Status: GOOD ( 21.19 ) X-Spam-Score: -1.8 (-) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-1.8 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [5.39.185.33 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [5.39.185.33 listed in wl.mailspike.net] 0.8 SPF_NEUTRAL SPF: sender does not match SPF record (neutral) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org All, Would it be possible to add an option --skip-all-ffs option to mtd-utils nandwrite? With this option pages that contain only 0xFF bytes will be skipped and not written to flash. This option is useful when you want to write using nandwrite an UBI image to NAND devices with a HW ECC. Without this option the OOB of a page that is written with all 0xFFs is no longer erased because the HW adds an non 0xFFs ECC to the OOB. If the data of the page contains only 0xFFs then UBI/UBIFS assumes that the page is erased and writes to it without erasing the page first. This causes that a read of this page fails with unrecoverable ECC errors and a subsequent corruption of the UBIFS. Attached is a patch file that adds the --skip-all-ffs option. A nandwrite of UBI image with this option will be successful while it fails without this option. Regards, Kees Trommel From f5dd8f13b45a37f0375f01a05a3ed41b39b50beb Mon Sep 17 00:00:00 2001 From: Kees Trommel Date: Mon, 5 Dec 2016 16:37:11 +0100 Subject: [PATCH] skip-all-ff-pages-option Signed-off-by: Kees Trommel --- nandwrite.c | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/nandwrite.c b/nandwrite.c index 9c3fe8f..722b1bd 100644 --- a/nandwrite.c +++ b/nandwrite.c @@ -49,6 +49,7 @@ static void display_help(int status) "Writes to the specified MTD device.\n" "\n" " -a, --autoplace Use auto OOB layout\n" +" -k, --skip-all-ffs Skip pages that contain only ff bytes\n" " -m, --markbad Mark blocks bad if write fails\n" " -n, --noecc Write without ecc\n" " -N, --noskipbad Write without bad block skipping\n" @@ -93,6 +94,7 @@ static bool onlyoob = false; static bool markbad = false; static bool noecc = false; static bool autoplace = false; +static bool skipallffs = false; static bool noskipbad = false; static bool pad = false; static int blockalign = 1; /* default to using actual block size */ @@ -103,7 +105,7 @@ static void process_options(int argc, char * const argv[]) for (;;) { int option_index = 0; - static const char short_options[] = "hb:mnNoOpqs:a"; + static const char short_options[] = "hb:mnNoOpqs:ak"; static const struct option long_options[] = { /* Order of these args with val==0 matters; see option_index. */ {"version", no_argument, 0, 0}, @@ -120,6 +122,7 @@ static void process_options(int argc, char * const argv[]) {"quiet", no_argument, 0, 'q'}, {"start", required_argument, 0, 's'}, {"autoplace", no_argument, 0, 'a'}, + {"skip-all-ffs", no_argument, 0, 'k'}, {0, 0, 0, 0}, }; @@ -173,6 +176,9 @@ static void process_options(int argc, char * const argv[]) case 'a': autoplace = true; break; + case 'k': + skipallffs = true; + break; case 'h': display_help(EXIT_SUCCESS); break; @@ -231,6 +237,8 @@ static void erase_buffer(void *buffer, size_t size) */ int main(int argc, char * const argv[]) { + int allffs; + int ii; int fd = -1; int ifd = -1; int pagelen; @@ -516,14 +524,29 @@ int main(int argc, char * const argv[]) } } - /* Write out data */ - ret = mtd_write(mtd_desc, &mtd, fd, mtdoffset / mtd.eb_size, - mtdoffset % mtd.eb_size, - onlyoob ? NULL : writebuf, - onlyoob ? 0 : mtd.min_io_size, - writeoob ? oobbuf : NULL, - writeoob ? mtd.oob_size : 0, - write_mode); + allffs = 0; + if (skipallffs) + { + for (ii = 0; ii < mtd.min_io_size; ii += sizeof(uint32_t)) + { + if (*(uint32_t*)(writebuf + ii) != 0xffffffff) + break; + } + if (ii == mtd.min_io_size) + allffs = 1; + } + if (!allffs) { + /* Write out data */ + ret = mtd_write(mtd_desc, &mtd, fd, mtdoffset / mtd.eb_size, + mtdoffset % mtd.eb_size, + onlyoob ? NULL : writebuf, + onlyoob ? 0 : mtd.min_io_size, + writeoob ? oobbuf : NULL, + writeoob ? mtd.oob_size : 0, + write_mode); + } else { + ret = 0; + } if (ret) { long long i; if (errno != EIO) { -- 2.5.5