From patchwork Mon Jan 3 15:39:36 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefani Seibold X-Patchwork-Id: 77286 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 82004B70EF for ; Tue, 4 Jan 2011 02:42:18 +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 1PZmUi-00070r-MN; Mon, 03 Jan 2011 15:38:48 +0000 Received: from www84.your-server.de ([213.133.104.84]) by canuck.infradead.org with esmtps (Exim 4.72 #1 (Red Hat Linux)) id 1PZmUe-00070D-Th for linux-mtd@lists.infradead.org; Mon, 03 Jan 2011 15:38:46 +0000 Received: from [88.64.4.48] (helo=localhost.localdomain) by www84.your-server.de with esmtpa (Exim 4.72) (envelope-from ) id 1PZmUT-0002Mh-9H; Mon, 03 Jan 2011 16:38:33 +0100 From: stefani@seibold.net To: dedekind1@gmail.com, dwmw2@infradead.org, linux-mtd@lists.infradead.org, Artem.Bityutskiy@nokia.com Subject: [PATCH] Add an option do not erase pristine blocks in ubiformat Date: Mon, 3 Jan 2011 16:39:36 +0100 Message-Id: <1294069176-27123-1-git-send-email-stefani@seibold.net> X-Mailer: git-send-email 1.7.3.4 X-Authenticated-Sender: stefani@seibold.net X-Virus-Scanned: Clear (ClamAV 0.96.5/12472/Mon Jan 3 11:41:47 2011) X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20110103_103845_299758_9F00ADE6 X-CRM114-Status: GOOD ( 12.88 ) 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: stefani@seibold.net 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: , MIME-Version: 1.0 Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Stefani Seibold This patch add a pristine option which skips erasing of pristine flash blocks. This is useful for first time production environments where the flash arrived erased. The patch is against the current mtd git tree. Signed-off-by: Stefani Seibold --- ubi-utils/src/ubiformat.c | 34 +++++++++++++++++++++++++++++----- 1 files changed, 29 insertions(+), 5 deletions(-) diff --git a/ubi-utils/src/ubiformat.c b/ubi-utils/src/ubiformat.c index 098da7d..83e3485 100644 --- a/ubi-utils/src/ubiformat.c +++ b/ubi-utils/src/ubiformat.c @@ -29,7 +29,7 @@ */ #define MAX_CONSECUTIVE_BAD_BLOCKS 4 -#define PROGRAM_VERSION "1.5" +#define PROGRAM_VERSION "1.6" #define PROGRAM_NAME "ubiformat" #include @@ -55,6 +55,7 @@ struct args { unsigned int verbose:1; unsigned int override_ec:1; unsigned int novtbl:1; + unsigned int pristine:1; unsigned int manual_subpage; int subpage_size; int vid_hdr_offs; @@ -94,6 +95,7 @@ static const char optionsstr[] = " (default is 1)\n" "-Q, --image-seq= 32-bit UBI image sequence number to use\n" " (by default a random number is picked)\n" +"-P, --pristine do not erase pristine blocks\n" "-y, --yes assume the answer is \"yes\" for all question\n" " this program would otherwise ask\n" "-q, --quiet suppress progress percentage information\n" @@ -106,7 +108,7 @@ static const char usage[] = "\t\t\t[-f ] [-S ] [-e ] [-x ] [-y] [-q] [-v] [-h] [-v]\n" "\t\t\t[--sub-page-size=] [--vid-hdr-offset=] [--no-volume-table]\n" "\t\t\t[--flash-image=] [--image-size=] [--erase-counter=]\n" -"\t\t\t[--ubi-ver=] [--yes] [--quiet] [--verbose] [--help] [--version]\n\n" +"\t\t\t[--ubi-ver=] [--pristine] [--yes] [--quiet] [--verbose] [--help] [--version]\n\n" "Example 1: " PROGRAM_NAME " /dev/mtd0 -y - format MTD device number 0 and do\n" " not ask questions.\n" "Example 2: " PROGRAM_NAME " /dev/mtd0 -q -e 0 - format MTD device number 0,\n" @@ -125,6 +127,7 @@ static const struct option long_options[] = { { .name = "ubi-ver", .has_arg = 1, .flag = NULL, .val = 'x' }, { .name = "help", .has_arg = 0, .flag = NULL, .val = 'h' }, { .name = "version", .has_arg = 0, .flag = NULL, .val = 'V' }, + { .name = "pristine", .has_arg = 0, .flag = NULL, .val = 'P' }, { NULL, 0, NULL, 0}, }; @@ -138,7 +141,7 @@ static int parse_opt(int argc, char * const argv[]) char *endp; unsigned long int image_seq; - key = getopt_long(argc, argv, "nh?Vyqve:x:s:O:f:S:", long_options, NULL); + key = getopt_long(argc, argv, "nh?Vyqve:x:s:O:f:S:P:", long_options, NULL); if (key == -1) break; @@ -202,6 +205,10 @@ static int parse_opt(int argc, char * const argv[]) break; + case 'P': + args.pristine = 1; + break; + case 'v': args.verbose = 1; break; @@ -577,7 +584,7 @@ static int format(libmtd_t libmtd, const struct mtd_dev_info *mtd, write_size = UBI_EC_HDR_SIZE + mtd->subpage_size - 1; write_size /= mtd->subpage_size; write_size *= mtd->subpage_size; - hdr = malloc(write_size); + hdr = malloc(mtd->eb_size); if (!hdr) return sys_errmsg("cannot allocate %d bytes of memory", write_size); memset(hdr, 0xFF, write_size); @@ -600,7 +607,21 @@ static int format(libmtd_t libmtd, const struct mtd_dev_info *mtd, ec = si->ec[eb] + 1; else ec = si->mean_ec; - ubigen_init_ec_hdr(ui, hdr, ec); + + if (args.pristine) { + err = mtd_read(mtd, args.node_fd, eb, 0, hdr, mtd->eb_size); + if (!err) { + int i; + + for(i = 0; i != mtd->eb_size; i++) { + if (((unsigned char *)hdr)[i] != 0xff) + break; + } + if (i == mtd->eb_size) + goto skip_erase; + } + memset(hdr, 0xFF, write_size); + } if (args.verbose) { normsg_cont("eraseblock %d: erase", eb); @@ -621,6 +642,9 @@ static int format(libmtd_t libmtd, const struct mtd_dev_info *mtd, continue; } +skip_erase: + ubigen_init_ec_hdr(ui, hdr, ec); + if ((eb1 == -1 || eb2 == -1) && !novtbl) { if (eb1 == -1) { eb1 = eb;