From patchwork Tue Dec 14 19:27:18 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?=C3=98yvind_Harboe?= X-Patchwork-Id: 75526 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from canuck.infradead.org (canuck.infradead.org [134.117.69.58]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 1BD48B6F07 for ; Wed, 15 Dec 2010 06:36:14 +1100 (EST) Received: from localhost ([127.0.0.1] helo=canuck.infradead.org) by canuck.infradead.org with esmtp (Exim 4.72 #1 (Red Hat Linux)) id 1PSaX6-0003jn-9V; Tue, 14 Dec 2010 19:27:32 +0000 Received: from cpanel5.proisp.no ([209.85.100.29]) by canuck.infradead.org with esmtps (Exim 4.72 #1 (Red Hat Linux)) id 1PSaX2-0003jR-2V for linux-mtd@lists.infradead.org; Tue, 14 Dec 2010 19:27:29 +0000 Received: from mail-gx0-f176.google.com ([209.85.161.176]:38586) by cpanel5.proisp.no with esmtpsa (TLSv1:RC4-MD5:128) (Exim 4.69) (envelope-from ) id 1PSaWz-0006WT-Aj for linux-mtd@lists.infradead.org; Tue, 14 Dec 2010 20:27:25 +0100 Received: by gxk4 with SMTP id 4so717692gxk.21 for ; Tue, 14 Dec 2010 11:27:24 -0800 (PST) MIME-Version: 1.0 Received: by 10.236.95.5 with SMTP id o5mr12155716yhf.25.1292354839839; Tue, 14 Dec 2010 11:27:19 -0800 (PST) Received: by 10.236.110.40 with HTTP; Tue, 14 Dec 2010 11:27:18 -0800 (PST) In-Reply-To: References: Date: Tue, 14 Dec 2010 20:27:18 +0100 Message-ID: Subject: Re: Faster flash_eraseall for NOR flash From: =?UTF-8?Q?=C3=98yvind_Harboe?= To: Mike Frysinger X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - cpanel5.proisp.no X-AntiAbuse: Original Domain - lists.infradead.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - zylin.com X-Source: X-Source-Args: X-Source-Dir: X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20101214_142728_294082_17F127F8 X-CRM114-Status: GOOD ( 17.26 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.3.1 on canuck.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- Cc: linux-mtd@lists.infradead.org X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org On Tue, Dec 14, 2010 at 4:47 PM, Mike Frysinger wrote: > On Tue, Dec 14, 2010 at 10:46, Øyvind Harboe wrote: >> I'll see about getting this done. Don't know when though, if >> someone beats me to the punch here, no loss :-) > > np; take your time.  thanks for the improvements! This is the server, right? http://git.infradead.org/mtd-utils.git I made a stab at trying to get something to build at least. From 89aaa5dc801c05e1d11141fa7d0789b072bde655 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Harboe?= Date: Tue, 14 Dec 2010 20:24:10 +0100 Subject: [PATCH] flash_erase: wip to add NOR skip erased block option --- flash_erase.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 52 insertions(+), 1 deletions(-) diff --git a/flash_erase.c b/flash_erase.c index 1a7b52e..1000397 100644 --- a/flash_erase.c +++ b/flash_erase.c @@ -46,6 +46,7 @@ static int quiet; /* true -- don't output progress */ static int jffs2; /* format for jffs2 usage */ static int noskipbad; /* do not skip bad blocks */ static int unlock; /* unlock sectors before erasing */ +static int skip_erased; /* Skip erased NOR flash blocks, including cleanmarker check */ static struct jffs2_unknown_node cleanmarker; int target_endian = __BYTE_ORDER; @@ -68,6 +69,7 @@ static void display_help (void) " -N, --noskipbad don't skip bad blocks\n" " -u, --unlock unlock sectors before erasing\n" " -q, --quiet display progress messages\n" + " -s, --skip-erased skip erased NOR sectors\n" " --silent same as --quiet\n" " --help display this help and exit\n" " --version output version information and exit\n", @@ -104,7 +106,7 @@ int main(int argc, char *argv[]) */ for (;;) { int option_index = 0; - static const char *short_options = "jNqu"; + static const char *short_options = "sjNqu"; static const struct option long_options[] = { {"help", no_argument, 0, 0}, {"version", no_argument, 0, 0}, @@ -113,6 +115,7 @@ int main(int argc, char *argv[]) {"quiet", no_argument, 0, 'q'}, {"silent", no_argument, 0, 'q'}, {"unlock", no_argument, 0, 'u'}, + {"skip-erased", no_argument, 0, 's'}, {0, 0, 0, 0}, }; @@ -145,6 +148,9 @@ int main(int argc, char *argv[]) case 'u': unlock = 1; break; + case 's': + skip_erased = 1; + break; case '?': error = 1; break; @@ -250,8 +256,53 @@ int main(int argc, char *argv[]) } } + /* Can we skip this one if it is already erased? + * Perhaps NAND performance could be improved by adding support for + * those cleanmarkers as well? + * + * Currently this only works with JFFS2 NOR clean markers + */ + int skip = 0; + if (skip_erased && !isNAND) { + uint8_t *tmp = malloc(mtd.eb_size); + if (tmp == NULL) { + return errmsg("Out of memory"); + } + ssize_t actual = pread(fd, tmp, mtd.eb_size, offset); + if (actual != mtd.eb_size) { + return errmsg("%s: MTD read failure: %s", mtd_device, strerror(errno)); + } + ssize_t i = 0; + int ok = 1; + + if (jffs2) { + ok = memcmp(tmp, &cleanmarker, sizeof (cleanmarker)) == 0; + i = sizeof (cleanmarker); + } + + if (ok) + { + for (; i < mtd.eb_size; i++) + { + if (tmp[i] != 0xff) + break; + } + if (i == mtd.eb_size) + { + /* Yup! we can skip! Here we could improve things by + * adding support for NAND cleanmarkers + */ + skip = 1; + } + } + free(tmp); + } + show_progress(&mtd, offset, eb, eb_start, eb_cnt); + if (skip) + continue; + if (unlock) { if (mtd_unlock(&mtd, fd, eb) != 0) { sys_errmsg("%s: MTD unlock failure", mtd_device); -- 1.7.0.4