JFFS2 commands support for Flex-OneNAND
PATCH v2 3/4 JFFS2 commands support for Flex-OneNAND
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 <[email protected]>
--- common/cmd_jffs2.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 59 insertions(+), 6 deletions(-)
common/cmd_jffs2.c +59 -6
@@ -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 ;
Signature · 1 line
1.5.4.3
PATCH v2 3/4 JFFS2 commands support for Flex-OneNAND
Quoted 4 lines · 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 <[email protected]>
---
common/cmd_jffs2.c +60 -7
@@ -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 ;