From patchwork Tue Dec 14 09:20:03 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: 75475 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 CCC871007D1 for ; Tue, 14 Dec 2010 20:24:15 +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 1PSR3M-00083K-Mb; Tue, 14 Dec 2010 09:20:12 +0000 Received: from cpanel5.proisp.no ([209.85.100.29]) by canuck.infradead.org with esmtps (Exim 4.72 #1 (Red Hat Linux)) id 1PSR3J-00082z-6R for linux-mtd@lists.infradead.org; Tue, 14 Dec 2010 09:20:10 +0000 Received: from mail-gx0-f171.google.com ([209.85.161.171]:40516) by cpanel5.proisp.no with esmtpsa (TLSv1:RC4-MD5:128) (Exim 4.69) (envelope-from ) id 1PSR3D-0002eW-Gl for linux-mtd@lists.infradead.org; Tue, 14 Dec 2010 10:20:03 +0100 Received: by gxk8 with SMTP id 8so229182gxk.16 for ; Tue, 14 Dec 2010 01:20:03 -0800 (PST) MIME-Version: 1.0 Received: by 10.236.95.140 with SMTP id p12mr2612674yhf.38.1292318403085; Tue, 14 Dec 2010 01:20:03 -0800 (PST) Received: by 10.236.110.40 with HTTP; Tue, 14 Dec 2010 01:20:03 -0800 (PST) Date: Tue, 14 Dec 2010 10:20:03 +0100 Message-ID: Subject: Faster flash_eraseall for NOR flash From: =?UTF-8?Q?=C3=98yvind_Harboe?= To: linux-mtd@lists.infradead.org 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_042009_425822_AA5D1C89 X-CRM114-Status: GOOD ( 13.67 ) 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 ---- ---------------------- -------------------------------------------------- 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 CFI erase performance can be 10x slower than write performance on CFI flashes. I've added an option to skip already erased CFI blocks. This includes checking if the JFFS2 cleanmarker is written. --- Øyvind Harboe Can Zylin Consulting help on your project? US toll free 1-866-980-3434 / International +47 51 63 25 00 http://www.zylin.com/zy1000.html ARM7 ARM9 ARM11 XScale Cortex JTAG debugger and flash programmer From 066f501b253c84550e6959be527aa0aa75fff631 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Harboe?= Date: Fri, 10 Dec 2010 10:05:43 +0100 Subject: [PATCH] mtd-utils: add fast NOR flash erase MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit do not erase sector (which can be 10x slower than write's on CFI's) if it is already erased. This includes a check for a cleanmarker. Signed-off-by: Øyvind Harboe --- .../flash_eraseall.c | 60 +++++++++++++++++++- 1 files changed, 59 insertions(+), 1 deletions(-) diff --git a/user/mtd-utils/606f38a2221648ca5c5fa292c9f71d2ddd59fa66/flash_eraseall.c b/user/mtd-utils/606f38a2221648ca5c5fa292c9f71d2ddd59fa66/flash_eraseall.c index a22fc49..f6da1ff 100644 --- a/user/mtd-utils/606f38a2221648ca5c5fa292c9f71d2ddd59fa66/flash_eraseall.c +++ b/user/mtd-utils/606f38a2221648ca5c5fa292c9f71d2ddd59fa66/flash_eraseall.c @@ -47,6 +47,7 @@ static const char *exe_name; static const char *mtd_device; static int quiet; /* true -- don't output progress */ static int jffs2; // format for jffs2 usage +static int fast; // Fast - check if the block is erased before erasing static void process_options (int argc, char *argv[]); void show_progress (mtd_info_t *meminfo, erase_info_t *erase); @@ -146,9 +147,61 @@ 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 (fast && !isNAND) { + if (lseek (fd, erase.start, SEEK_SET) < 0) { + fprintf(stderr, "\n%s: %s: MTD lseek failure: %s\n", exe_name, mtd_device, strerror(errno)); + return 1; + } + uint8_t *tmp = malloc(meminfo.erasesize); + if (tmp == NULL) + { + fprintf(stderr, "Out of memory\n"); + return 1; + } + ssize_t actual = read(fd, tmp, meminfo.erasesize); + if (actual != meminfo.erasesize) { + fprintf(stderr, "\n%s: %s: MTD read failure: %s\n", exe_name, mtd_device, strerror(errno)); + return 1; + } + ssize_t i = 0; + int ok = 1; + + if (jffs2) { + ok = memcmp(tmp, &cleanmarker, sizeof (cleanmarker)) == 0; + i = sizeof (cleanmarker); + } + + if (ok) + { + for (; i < meminfo.erasesize; i++) + { + if (tmp[i] != 0xff) + break; + } + if (i == meminfo.erasesize) + { + /* Yup! we can skip! Here we could improve things by + * adding support for NAND cleanmarkers + */ + skip = 1; + } + } + free(tmp); + } + if (!quiet) show_progress(&meminfo, &erase); + if (skip) + continue; + if (ioctl(fd, MEMERASE, &erase) != 0) { fprintf(stderr, "\n%s: %s: MTD Erase failure: %s\n", exe_name, mtd_device, strerror(errno)); continue; @@ -198,11 +251,12 @@ void process_options (int argc, char *argv[]) for (;;) { int option_index = 0; - static const char *short_options = "jq"; + static const char *short_options = "jqf"; static const struct option long_options[] = { {"help", no_argument, 0, 0}, {"version", no_argument, 0, 0}, {"jffs2", no_argument, 0, 'j'}, + {"fast", no_argument, 0, 'f'}, {"quiet", no_argument, 0, 'q'}, {"silent", no_argument, 0, 'q'}, @@ -232,6 +286,9 @@ void process_options (int argc, char *argv[]) case 'j': jffs2 = 1; break; + case 'f': + fast = 1; + break; case '?': error = 1; break; @@ -265,6 +322,7 @@ void display_help (void) "\n" " -j, --jffs2 format the device for jffs2\n" " -q, --quiet don't display progress messages\n" + " -f, --fast do not re-erase sectors that are erased\n" " --silent same as --quiet\n" " --help display this help and exit\n" " --version output version information and exit\n", -- 1.7.0.4