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

Rohit Hagargundgi h.rohit at samsung.com
Sun Mar 8 07:40:27 CET 2009


On Thursday 11 December 2008 19:57:42 Rohit Hagargundgi wrote:
> 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>
---
diff --git a/common/cmd_jffs2.c b/common/cmd_jffs2.c
index 7866c80..7a8c07b 100644
--- a/common/cmd_jffs2.c
+++ b/common/cmd_jffs2.c
@@ -433,19 +433,72 @@ 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;
 
-	part->sector_size = mtd->erasesize;
+	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;
+		}
 
-	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;
+		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) {
+	part->sector_size = 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;


More information about the U-Boot mailing list