From: Huang Shijie <b32955@freescale.com>
To: <dedekind1@gmail.com>
Cc: linux-mtd@lists.infradead.org, dwmw2@infradead.org,
shmulik.ladkani@gmail.com, Huang Shijie <b32955@freescale.com>
Subject: [PATCH v3] mtd: cmdlinepart: check the partitions
Date: Tue, 4 Sep 2012 17:07:50 +0800 [thread overview]
Message-ID: <1346749670-23944-1-git-send-email-b32955@freescale.com> (raw)
In-Reply-To: <1346746785.12610.12.camel@sauron.fi.intel.com>
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 <b32955@freescale.com>
---
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;
--
1.7.0.4
prev parent reply other threads:[~2012-09-04 9:30 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-04 7:43 [PATCH v2 1/3] mtd: cmdlinepart: sort the unsorted partitions Huang Shijie
2012-09-04 7:43 ` [PATCH v2 2/3] mtd: cmdlinepart: fix the wrong partitions number when truncating occurs Huang Shijie
2012-09-04 7:43 ` [PATCH v2 3/3] mtd: cmdlinepart: check the partitions Huang Shijie
2012-09-04 8:19 ` Artem Bityutskiy
2012-09-04 8:25 ` Huang Shijie
2012-09-04 8:50 ` Artem Bityutskiy
2012-09-04 9:07 ` Huang Shijie [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1346749670-23944-1-git-send-email-b32955@freescale.com \
--to=b32955@freescale.com \
--cc=dedekind1@gmail.com \
--cc=dwmw2@infradead.org \
--cc=linux-mtd@lists.infradead.org \
--cc=shmulik.ladkani@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox