Commit ff827b4e authored by Linus Walleij's avatar Linus Walleij Committed by Richard Weinberger

mtd: afs: factor footer parsing into the v1 part parsing

This simplifies the code by factoring in the image footer
parsing into the single function parsing the AFSv1 partitions.

Cc: Ryan Harkin <ryan.harkin@linaro.org>
Acked-by: default avatarLiviu Dudau <liviu.dudau@arm.com>
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
parent 4aeb1594
...@@ -88,63 +88,6 @@ static bool afs_is_v1(struct mtd_info *mtd, u_int off) ...@@ -88,63 +88,6 @@ static bool afs_is_v1(struct mtd_info *mtd, u_int off)
return (magic == AFSV1_FOOTER_MAGIC); return (magic == AFSV1_FOOTER_MAGIC);
} }
static int
afs_read_footer_v1(struct mtd_info *mtd, u_int *img_start, u_int *iis_start,
u_int off, u_int mask)
{
struct footer_v1 fs;
u_int ptr = off + mtd->erasesize - sizeof(fs);
size_t sz;
int ret;
ret = mtd_read(mtd, ptr, sizeof(fs), &sz, (u_char *)&fs);
if (ret >= 0 && sz != sizeof(fs))
ret = -EINVAL;
if (ret < 0) {
printk(KERN_ERR "AFS: mtd read failed at 0x%x: %d\n",
ptr, ret);
return ret;
}
/*
* Does it contain the magic number?
*/
if (fs.signature != AFSV1_FOOTER_MAGIC)
return 0;
/*
* Check the checksum.
*/
if (word_sum(&fs, sizeof(fs) / sizeof(u32)) != 0xffffffff)
return 0;
/*
* Don't touch the SIB.
*/
if (fs.type == 2)
return 0;
*iis_start = fs.image_info_base & mask;
*img_start = fs.image_start & mask;
/*
* Check the image info base. This can not
* be located after the footer structure.
*/
if (*iis_start >= ptr)
return 0;
/*
* Check the start of this image. The image
* data can not be located after this block.
*/
if (*img_start > off)
return 0;
return 1;
}
static int static int
afs_read_iis_v1(struct mtd_info *mtd, struct image_info_v1 *iis, u_int ptr) afs_read_iis_v1(struct mtd_info *mtd, struct image_info_v1 *iis, u_int ptr)
{ {
...@@ -184,6 +127,7 @@ afs_read_iis_v1(struct mtd_info *mtd, struct image_info_v1 *iis, u_int ptr) ...@@ -184,6 +127,7 @@ afs_read_iis_v1(struct mtd_info *mtd, struct image_info_v1 *iis, u_int ptr)
static int afs_parse_v1_partition(struct mtd_info *mtd, static int afs_parse_v1_partition(struct mtd_info *mtd,
u_int off, struct mtd_partition *part) u_int off, struct mtd_partition *part)
{ {
struct footer_v1 fs;
struct image_info_v1 iis; struct image_info_v1 iis;
u_int mask; u_int mask;
/* /*
...@@ -192,6 +136,8 @@ static int afs_parse_v1_partition(struct mtd_info *mtd, ...@@ -192,6 +136,8 @@ static int afs_parse_v1_partition(struct mtd_info *mtd,
*/ */
u_int uninitialized_var(iis_ptr); u_int uninitialized_var(iis_ptr);
u_int uninitialized_var(img_ptr); u_int uninitialized_var(img_ptr);
u_int ptr;
size_t sz;
int ret; int ret;
/* /*
...@@ -200,9 +146,43 @@ static int afs_parse_v1_partition(struct mtd_info *mtd, ...@@ -200,9 +146,43 @@ static int afs_parse_v1_partition(struct mtd_info *mtd,
*/ */
mask = mtd->size - 1; mask = mtd->size - 1;
ret = afs_read_footer_v1(mtd, &img_ptr, &iis_ptr, off, mask); ptr = off + mtd->erasesize - sizeof(fs);
if (ret < 0) ret = mtd_read(mtd, ptr, sizeof(fs), &sz, (u_char *)&fs);
if (ret >= 0 && sz != sizeof(fs))
ret = -EINVAL;
if (ret < 0) {
printk(KERN_ERR "AFS: mtd read failed at 0x%x: %d\n",
ptr, ret);
return ret; return ret;
}
/*
* Check the checksum.
*/
if (word_sum(&fs, sizeof(fs) / sizeof(u32)) != 0xffffffff)
return -EINVAL;
/*
* Hide the SIB (System Information Block)
*/
if (fs.type == 2)
return 0;
iis_ptr = fs.image_info_base & mask;
img_ptr = fs.image_start & mask;
/*
* Check the image info base. This can not
* be located after the footer structure.
*/
if (iis_ptr >= ptr)
return 0;
/*
* Check the start of this image. The image
* data can not be located after this block.
*/
if (img_ptr > off)
return 0;
/* Read the image info block */ /* Read the image info block */
ret = afs_read_iis_v1(mtd, &iis, iis_ptr); ret = afs_read_iis_v1(mtd, &iis, iis_ptr);
......
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