[U-Boot] [PATCH v2 3/4] JFFS2 commands support for Flex-OneNAND

Rohit Hagargundgi h.rohit at samsung.com
Thu Dec 11 15:27:42 CET 2008


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 at 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




More information about the U-Boot mailing list