Commit d2fd05bb authored by Linus Walleij's avatar Linus Walleij Committed by Brian Norris

mtd: afs: refactor v1 partition parsing

Return immediately if we are not finding a valid v1 partition
in afs_read_footer_v1(), invert scanning logic so we continue
to read image information on v1 if we found a footer. This is
needed for the logic we introduce to parse v2 footers.

Cc: Ryan Harkin <ryan.harkin@linaro.org>
Cc: Liviu Dudau <liviu.dudau@arm.com>
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Signed-off-by: default avatarBrian Norris <computersforpeace@gmail.com>
parent 9498440f
...@@ -87,25 +87,23 @@ afs_read_footer_v1(struct mtd_info *mtd, u_int *img_start, u_int *iis_start, ...@@ -87,25 +87,23 @@ afs_read_footer_v1(struct mtd_info *mtd, u_int *img_start, u_int *iis_start,
return ret; return ret;
} }
ret = 1;
/* /*
* Does it contain the magic number? * Does it contain the magic number?
*/ */
if (fs.signature != AFSV1_FOOTER_MAGIC) if (fs.signature != AFSV1_FOOTER_MAGIC)
ret = 0; return 0;
/* /*
* Check the checksum. * Check the checksum.
*/ */
if (word_sum(&fs, sizeof(fs) / sizeof(u32)) != 0xffffffff) if (word_sum(&fs, sizeof(fs) / sizeof(u32)) != 0xffffffff)
ret = 0; return 0;
/* /*
* Don't touch the SIB. * Don't touch the SIB.
*/ */
if (fs.type == 2) if (fs.type == 2)
ret = 0; return 0;
*iis_start = fs.image_info_base & mask; *iis_start = fs.image_info_base & mask;
*img_start = fs.image_start & mask; *img_start = fs.image_start & mask;
...@@ -115,16 +113,16 @@ afs_read_footer_v1(struct mtd_info *mtd, u_int *img_start, u_int *iis_start, ...@@ -115,16 +113,16 @@ afs_read_footer_v1(struct mtd_info *mtd, u_int *img_start, u_int *iis_start,
* be located after the footer structure. * be located after the footer structure.
*/ */
if (*iis_start >= ptr) if (*iis_start >= ptr)
ret = 0; return 0;
/* /*
* Check the start of this image. The image * Check the start of this image. The image
* data can not be located after this block. * data can not be located after this block.
*/ */
if (*img_start > off) if (*img_start > off)
ret = 0; return 0;
return ret; return 1;
} }
static int static int
...@@ -190,18 +188,17 @@ static int parse_afs_partitions(struct mtd_info *mtd, ...@@ -190,18 +188,17 @@ static int parse_afs_partitions(struct mtd_info *mtd,
ret = afs_read_footer_v1(mtd, &img_ptr, &iis_ptr, off, mask); ret = afs_read_footer_v1(mtd, &img_ptr, &iis_ptr, off, mask);
if (ret < 0) if (ret < 0)
break; break;
if (ret == 0) if (ret) {
continue; ret = afs_read_iis_v1(mtd, &iis, iis_ptr);
if (ret < 0)
ret = afs_read_iis_v1(mtd, &iis, iis_ptr); break;
if (ret < 0) if (ret == 0)
break; continue;
if (ret == 0)
continue; sz += sizeof(struct mtd_partition);
sz += strlen(iis.name) + 1;
sz += sizeof(struct mtd_partition); idx += 1;
sz += strlen(iis.name) + 1; }
idx += 1;
} }
if (!sz) if (!sz)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment