public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Rohit Hagargundgi <h.rohit@samsung.com>
To: u-boot@lists.denx.de
Subject: [U-Boot]  [PATCH v2 3/4] JFFS2 commands support for Flex-OneNAND
Date: Thu, 11 Dec 2008 19:57:42 +0530	[thread overview]
Message-ID: <4941235E.6040105@samsung.com> (raw)

Add sanity check for the partitions.
Some special cases handled by the check are:
	- A partition can span across erase regions.
	- A region can have odd number of blocks.

Signed-off-by: Rohit Hagargundgi <h.rohit@samsung.com>
---
 common/cmd_jffs2.c |   65 +++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 59 insertions(+), 6 deletions(-)

diff --git a/common/cmd_jffs2.c b/common/cmd_jffs2.c
index 791a572..5d2d69c 100644
--- a/common/cmd_jffs2.c
+++ b/common/cmd_jffs2.c
@@ -421,17 +421,70 @@ static int part_validate_onenand(struct mtdids *id, struct part_info *part)
 #if defined(CONFIG_CMD_ONENAND)
 	/* info for OneNAND chips */
 	struct mtd_info *mtd;
+	int erasesize = 0;
 
 	mtd = &onenand_mtd;
 
-	if ((unsigned long)(part->offset) % mtd->erasesize) {
-		printf("%s%d: partition (%s) start offset"
-			"alignment incorrect\n",
-				MTD_DEV_TYPE(id->type), id->num, part->name);
-		return 1;
+	if (mtd->numeraseregions > 1) {
+		int i, rgn, max = mtd->numeraseregions;
+		unsigned end = part->offset + part->size;
+		struct mtd_erase_region_info *regions = mtd->eraseregions;
+		unsigned portion_start, portion_end, region_end;
+
+		/* Find the first erase regions which is part of this
+		 * partition.
+		 */
+		i = flexonenand_region(mtd, part->offset);
+
+		/* Partition offset within region must align
+		 * on region's erase size
+		 */
+		if ((part->offset - regions[i].offset) % regions[i].erasesize) {
+			printf("%s%d: partition (%s) doesn't start on an erase"
+				" block boundary\n", MTD_DEV_TYPE(id->type),
+				id->num, part->name);
+			return 1;
+		}
+
+		erasesize = regions[i].erasesize;
+
+		/* A  partition spanning across multiple erase regions has
+		 * erase size equal to greatest erase size among the regions.
+		 */
+		rgn = i;
+		for (; i < max && regions[i].offset < end; i++)
+			if (erasesize < regions[i].erasesize)
+				erasesize = regions[i].erasesize;
+
+		/* If partition spans many erase regions,
+		 * the partition portion present in each region
+		 * should be multiple of biggest erase size
+		 */
+		for (i = rgn; i < max && regions[i].offset < end; i++) {
+			portion_start = max(regions[i].offset, part->offset);
+			region_end = regions[i].offset +
+				     regions[i].erasesize * regions[i].numblocks;
+			portion_end = min(end, region_end);
+
+			if ((portion_end - portion_start) % erasesize) {
+				printf("%s%d: partition (%s) is not erase block"
+					" aligned within erase region\n",
+					MTD_DEV_TYPE(id->type), id->num, part->name);
+				return 1;
+			}
+		}
+	} else {
+		/* Single erase size */
+		erasesize = mtd->erasesize;
+		if ((unsigned long)(part->offset) % erasesize) {
+			printf("%s%d: partition (%s) start offset"
+				"alignment incorrect\n",
+					MTD_DEV_TYPE(id->type), id->num, part->name);
+			return 1;
+		}
 	}
 
-	if (part->size % mtd->erasesize) {
+	if (part->size % erasesize) {
 		printf("%s%d: partition (%s) size alignment incorrect\n",
 				MTD_DEV_TYPE(id->type), id->num, part->name);
 		return 1;
-- 
1.5.4.3

             reply	other threads:[~2008-12-11 14:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-11 14:27 Rohit Hagargundgi [this message]
2009-03-08  6:40 ` [U-Boot] [PATCH v2 3/4] JFFS2 commands support for Flex-OneNAND Rohit Hagargundgi

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=4941235E.6040105@samsung.com \
    --to=h.rohit@samsung.com \
    --cc=u-boot@lists.denx.de \
    /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