From patchwork Wed Aug 22 16:04:36 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Genoud X-Patchwork-Id: 179346 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:4978:20e::2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id C8A992C0086 for ; Thu, 23 Aug 2012 02:06:57 +1000 (EST) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1T4DRT-0002Mz-9y; Wed, 22 Aug 2012 16:06:03 +0000 Received: from mail-wi0-f171.google.com ([209.85.212.171]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1T4DRF-0002Dc-L7 for linux-mtd@lists.infradead.org; Wed, 22 Aug 2012 16:05:54 +0000 Received: by wibhq4 with SMTP id hq4so4384866wib.0 for ; Wed, 22 Aug 2012 09:05:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=KCBuDUNsAQClzugqrVXmcFNbV3Zdez15EWlnbgLQDKc=; b=L5fG0ZRTBb8deuC45zQTXTq3u0z4Q6ZRdaLaAdYcQhHbCQduAwdGwOo1dtmfe0uDfv E9Ock9QkwmT/KWxVc43dzfrd6zSCwM3XOOviRLbPmANgSQE1qDUuPiKTXVrt5wZy+Fjx 1v193YNoCrjfx8dDrvcy5/3ufySFtJTIL1RL0v0npXYZt0yXxqX7mN3uJUziJJquy3cK i4//VXKOIdXMz5iNucwoaBMg4h9dR25d8CF5mse5KZEBqR3E8UdmaW1A03NFKYLZEkh+ y8phZFo63tpkmJ5UTtOW3mtDIs/cLATS294D4cRpoRV4njiNC/u7mDWFG1+d6RMPw8tz RbtA== Received: by 10.216.153.207 with SMTP id f57mr11679643wek.196.1345651528536; Wed, 22 Aug 2012 09:05:28 -0700 (PDT) Received: from localhost.localdomain (lyon.paratronic.fr. [213.41.177.106]) by mx.google.com with ESMTPS id l5sm13499971wix.5.2012.08.22.09.05.27 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 22 Aug 2012 09:05:27 -0700 (PDT) From: Richard Genoud To: Artem Bityutskiy Subject: [PATCH MTD-UTILS v2 3/4] ubiattach: introduce max_beb_per1024 in UBI_IOCATT Date: Wed, 22 Aug 2012 18:04:36 +0200 Message-Id: <1345651477-5301-4-git-send-email-richard.genoud@gmail.com> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1345651477-5301-1-git-send-email-richard.genoud@gmail.com> References: <1345651477-5301-1-git-send-email-richard.genoud@gmail.com> X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.212.171 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (richard.genoud[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Cc: Richard Genoud , linux-mtd@lists.infradead.org, Shmulik Ladkani X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.14 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 The ioctl UBI_IOCATT has been extended with max_beb_per1024 parameter. This parameter is used for adjusting the "maximum expected number of bad blocks per 1024 blocks" for each mtd device. The number of physical erase blocks (PEB) that UBI will reserve for bad block handling is now: whole_flash_chipset__PEB_number * max_beb_per1024 / 1024 This means that for a 4096 PEB NAND device with 3 MTD partitions: mtd0: 512 PEB mtd1: 1536 PEB mtd2: 2048 PEB the commands: ubiattach -m 0 -d 0 -b 20 /dev/ubi_ctrl ubiattach -m 1 -d 1 -b 20 /dev/ubi_ctrl ubiattach -m 2 -d 2 -b 20 /dev/ubi_ctrl will attach mtdx to UBIx and reserve: 80 PEB for bad block handling on UBI0 80 PEB for bad block handling on UBI1 80 PEB for bad block handling on UBI2 => for the whole device, 240 PEB will be reserved for bad block handling. This may seems a waste of space, but as far as the bad blocks can appear every where on a flash device, in the worst case scenario they can all appear in one MTD partition. So the maximum number of expected erase blocks given by the NAND manufacturer should be reserve on each MTD partition. Signed-off-by: Richard Genoud --- tests/fs-tests/integrity/integck.c | 1 + ubi-utils/include/libubi.h | 2 + ubi-utils/libubi.c | 1 + ubi-utils/ubiattach.c | 38 ++++++++++++++++++++++++++++------- 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/tests/fs-tests/integrity/integck.c b/tests/fs-tests/integrity/integck.c index 30322cd..f12dfac 100644 --- a/tests/fs-tests/integrity/integck.c +++ b/tests/fs-tests/integrity/integck.c @@ -3152,6 +3152,7 @@ static int reattach(void) req.mtd_num = args.mtdn; req.vid_hdr_offset = 0; req.mtd_dev_node = NULL; + req.max_beb_per1024 = 0; err = ubi_attach(libubi, "/dev/ubi_ctrl", &req); if (err) diff --git a/ubi-utils/include/libubi.h b/ubi-utils/include/libubi.h index bbaa78c..28c8782 100644 --- a/ubi-utils/include/libubi.h +++ b/ubi-utils/include/libubi.h @@ -50,6 +50,7 @@ typedef void * libubi_t; * @mtd_dev_node: path to MTD device node to attach * @vid_hdr_offset: VID header offset (%0 means default offset and this is what * most of the users want) + * @max_beb_per1024: Maximum expected bad eraseblocks per 1024 eraseblocks */ struct ubi_attach_request { @@ -57,6 +58,7 @@ struct ubi_attach_request int mtd_num; const char *mtd_dev_node; int vid_hdr_offset; + int max_beb_per1024; }; /** diff --git a/ubi-utils/libubi.c b/ubi-utils/libubi.c index dec72c7..1b62e59 100644 --- a/ubi-utils/libubi.c +++ b/ubi-utils/libubi.c @@ -719,6 +719,7 @@ int ubi_attach_mtd(libubi_t desc, const char *node, r.ubi_num = req->dev_num; r.mtd_num = req->mtd_num; r.vid_hdr_offset = req->vid_hdr_offset; + r.max_beb_per1024 = req->max_beb_per1024; ret = do_attach(node, &r); if (ret == 0) diff --git a/ubi-utils/ubiattach.c b/ubi-utils/ubiattach.c index 27e7c09..4521788 100644 --- a/ubi-utils/ubiattach.c +++ b/ubi-utils/ubiattach.c @@ -42,6 +42,7 @@ struct args { int vidoffs; const char *node; const char *dev; + int max_beb_per1024; }; static struct args args = { @@ -50,6 +51,7 @@ static struct args args = { .vidoffs = 0, .node = NULL, .dev = NULL, + .max_beb_per1024 = 0, }; static const char doc[] = PROGRAM_NAME " version " VERSION @@ -63,6 +65,9 @@ static const char optionsstr[] = " if the character device node does not exist)\n" "-O, --vid-hdr-offset VID header offset (do not specify this unless you really\n" " know what you are doing, the default should be optimal)\n" +"-b, --max-beb-per1024 Maximum expected bad block number per 1024 eraseblock.\n" +" The default value is correct for most NAND devices.\n" +" (Range 1-768, 0 for default kernel value).\n" "-h, --help print help message\n" "-V, --version print program version"; @@ -71,19 +76,25 @@ static const char usage[] = "\t[-m ] [-d ] [-p ]\n" "\t[--mtdn=] [--devn=]\n" "\t[--dev-path=]\n" +"\t[--max-beb-per1024=]\n" "UBI control device defaults to " DEFAULT_CTRL_DEV " if not supplied.\n" "Example 1: " PROGRAM_NAME " -p /dev/mtd0 - attach /dev/mtd0 to UBI\n" "Example 2: " PROGRAM_NAME " -m 0 - attach MTD device 0 (mtd0) to UBI\n" "Example 3: " PROGRAM_NAME " -m 0 -d 3 - attach MTD device 0 (mtd0) to UBI\n" -" and create UBI device number 3 (ubi3)"; +" and create UBI device number 3 (ubi3)\n" +"Example 4: " PROGRAM_NAME " -m 1 -b 25 - attach /dev/mtd1 to UBI and reserve \n" +" 25*nand_size_in_blocks/1024 erase blocks for bad block handling.\n" +" (e.g. if the NAND *chipset* has 4096 PEB, 100 will be reserved \n" +" for this UBI device)."; static const struct option long_options[] = { - { .name = "devn", .has_arg = 1, .flag = NULL, .val = 'd' }, - { .name = "dev-path", .has_arg = 1, .flag = NULL, .val = 'p' }, - { .name = "mtdn", .has_arg = 1, .flag = NULL, .val = 'm' }, - { .name = "vid-hdr-offset", .has_arg = 1, .flag = NULL, .val = 'O' }, - { .name = "help", .has_arg = 0, .flag = NULL, .val = 'h' }, - { .name = "version", .has_arg = 0, .flag = NULL, .val = 'V' }, + { .name = "devn", .has_arg = 1, .flag = NULL, .val = 'd' }, + { .name = "dev-path", .has_arg = 1, .flag = NULL, .val = 'p' }, + { .name = "mtdn", .has_arg = 1, .flag = NULL, .val = 'm' }, + { .name = "vid-hdr-offset", .has_arg = 1, .flag = NULL, .val = 'O' }, + { .name = "help", .has_arg = 0, .flag = NULL, .val = 'h' }, + { .name = "version", .has_arg = 0, .flag = NULL, .val = 'V' }, + { .name = "max-beb-per1024", .has_arg = 1, .flag = NULL, .val = 'b' }, { NULL, 0, NULL, 0}, }; @@ -92,7 +103,7 @@ static int parse_opt(int argc, char * const argv[]) while (1) { int key, error = 0; - key = getopt_long(argc, argv, "p:m:d:O:hV", long_options, NULL); + key = getopt_long(argc, argv, "p:m:d:O:hVb:", long_options, NULL); if (key == -1) break; @@ -134,6 +145,16 @@ static int parse_opt(int argc, char * const argv[]) case ':': return errmsg("parameter is missing"); + case 'b': + args.max_beb_per1024 = simple_strtoul(optarg, &error); + if (error || args.max_beb_per1024 < 0 || args.max_beb_per1024 > 768) + return errmsg("bad maximum of expected bad blocks (0-768): \"%s\"", optarg); + + if (args.max_beb_per1024 == 0) + warnmsg("default kernel value will be used for maximum expected bad blocks\n"); + + break; + default: fprintf(stderr, "Use -h for help\n"); return -1; @@ -190,6 +211,7 @@ int main(int argc, char * const argv[]) req.mtd_num = args.mtdn; req.vid_hdr_offset = args.vidoffs; req.mtd_dev_node = args.dev; + req.max_beb_per1024 = args.max_beb_per1024; err = ubi_attach(libubi, args.node, &req); if (err) {