From patchwork Tue Sep 4 09:07:50 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huang Shijie X-Patchwork-Id: 181533 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from merlin.infradead.org (unknown [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 CBF962C0085 for ; Tue, 4 Sep 2012 19:31:32 +1000 (EST) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1T8pSr-0001DF-T1; Tue, 04 Sep 2012 09:30:34 +0000 Received: from am1ehsobe003.messaging.microsoft.com ([213.199.154.206] helo=am1outboundpool.messaging.microsoft.com) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1T8pSn-0001CS-Nq for linux-mtd@lists.infradead.org; Tue, 04 Sep 2012 09:30:31 +0000 Received: from mail29-am1-R.bigfish.com (10.3.201.232) by AM1EHSOBE009.bigfish.com (10.3.204.29) with Microsoft SMTP Server id 14.1.225.23; Tue, 4 Sep 2012 09:30:25 +0000 Received: from mail29-am1 (localhost [127.0.0.1]) by mail29-am1-R.bigfish.com (Postfix) with ESMTP id F0F9F400A7; Tue, 4 Sep 2012 09:30:24 +0000 (UTC) X-Forefront-Antispam-Report: CIP:70.37.183.190; KIP:(null); UIP:(null); IPV:NLI; H:mail.freescale.net; RD:none; EFVD:NLI X-SpamScore: 3 X-BigFish: VS3(zzzz1202h1082kzz8275bhz2dh2a8h668h839hd24he5bhf0ah107ah1155h) Received: from mail29-am1 (localhost.localdomain [127.0.0.1]) by mail29-am1 (MessageSwitch) id 1346751022480382_26284; Tue, 4 Sep 2012 09:30:22 +0000 (UTC) Received: from AM1EHSMHS004.bigfish.com (unknown [10.3.201.241]) by mail29-am1.bigfish.com (Postfix) with ESMTP id 697B9240048; Tue, 4 Sep 2012 09:30:22 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by AM1EHSMHS004.bigfish.com (10.3.207.104) with Microsoft SMTP Server (TLS) id 14.1.225.23; Tue, 4 Sep 2012 09:30:21 +0000 Received: from az84smr01.freescale.net (10.64.34.197) by 039-SN1MMR1-004.039d.mgd.msft.net (10.84.1.14) with Microsoft SMTP Server (TLS) id 14.2.309.3; Tue, 4 Sep 2012 04:29:58 -0500 Received: from localhost.localdomain (shlinux2.ap.freescale.net [10.192.224.44]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id q849TsWd027710; Tue, 4 Sep 2012 02:29:54 -0700 From: Huang Shijie To: Subject: [PATCH v3] mtd: cmdlinepart: check the partitions Date: Tue, 4 Sep 2012 17:07:50 +0800 Message-ID: <1346749670-23944-1-git-send-email-b32955@freescale.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1346746785.12610.12.camel@sauron.fi.intel.com> References: <1346746785.12610.12.camel@sauron.fi.intel.com> MIME-Version: 1.0 X-OriginatorOrg: freescale.com X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [213.199.154.206 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: linux-mtd@lists.infradead.org, dwmw2@infradead.org, shmulik.ladkani@gmail.com, Huang Shijie 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: , Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org The partitions are all sorted well by the @offset. But we should check if there are errors in the partitions. The following cases are regarded as errors: [1] There is a hole in the partitions, such as #gpmi-nand:100m(boot),100m@100m(kernel),1g@200m(rootfs) [2] There is a overlap in the partitions, such as #gpmi-nand:100m@0(boot),100m@50m(kernel),1g@150m(rootfs) [3] Not all the partitions are set with @offset, and there are more then one partion whose offset is OFFSET_CONTINUOUS. #gpmi-nand:100m@0(boot),100m(kernel),-(usr) Signed-off-by: Huang Shijie --- drivers/mtd/cmdlinepart.c | 55 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 55 insertions(+), 0 deletions(-) diff --git a/drivers/mtd/cmdlinepart.c b/drivers/mtd/cmdlinepart.c index edd17e0..5a603d1 100644 --- a/drivers/mtd/cmdlinepart.c +++ b/drivers/mtd/cmdlinepart.c @@ -225,6 +225,55 @@ static inline void sort_partitons(struct mtd_partition *parts, int num_parts) return; } +/* The partitions have been sorted well by the @offset. */ +static inline int check_partitions(struct mtd_partition *parts, int num_parts) +{ + int i; + uint64_t offset = 0; + int offset_continuous_cnt = 0; + + for (i = 0; i < num_parts; i++) { + if (parts[i].offset == OFFSET_CONTINUOUS) { + offset_continuous_cnt++; + continue; + } + + /* find a hole. */ + if (parts[i].offset > offset) { + printk(KERN_ERR ERRP "There is a hole in the " + "partitions, please check the cmdline, " + "and fix it.\n"); + return -EINVAL; + } + + /* find an overlapped partition. */ + if (parts[i].offset < offset) { + printk(KERN_ERR ERRP "The partitions overlap," + "please check the cmdline, and fix it.\n"); + return -EINVAL; + } + + offset += parts[i].size; + } + + if (offset_continuous_cnt) { + /* We do not set partitions with the @offset in the cmdline. */ + if (offset_continuous_cnt == num_parts) + return 0; + + /* It's ok if there is only one OFFSET_CONTINUOUS partition. */ + if (offset_continuous_cnt == 1) + return 0; + + printk(KERN_ERR ERRP "The offset is not right," + "please check the cmdline, and fix it.\n"); + return -EINVAL; + } + + /* We set with @offset for all the partitions in the cmdline. */ + return 0; +} + /* * Parse the command line. */ @@ -238,6 +287,7 @@ static int mtdpart_setup_real(char *s) struct mtd_partition *parts; int mtd_id_len, num_parts; char *p, *mtd_id; + int ret; mtd_id = s; @@ -285,6 +335,11 @@ static int mtdpart_setup_real(char *s) /* sort the partitions */ sort_partitons(parts, num_parts); + /* check the partitions */ + ret = check_partitions(parts, num_parts); + if (ret) + return ret; + /* link into chain */ this_mtd->next = partitions; partitions = this_mtd;