mtd: factor out v1 partition parsing

This breaks out the parsing of v1 partitions so we can later add
a v2 partition parser.

Cc: Ryan Harkin <ryan.harkin@linaro.org>
Acked-by: Liviu Dudau <liviu.dudau@arm.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Richard Weinberger <richard@nod.at>
This commit is contained in:
Linus Walleij 2019-05-02 16:30:31 +02:00 committed by Richard Weinberger
parent 2070017192
commit 4aeb159479

View File

@ -181,14 +181,18 @@ afs_read_iis_v1(struct mtd_info *mtd, struct image_info_v1 *iis, u_int ptr)
return ret; return ret;
} }
static int parse_afs_partitions(struct mtd_info *mtd, static int afs_parse_v1_partition(struct mtd_info *mtd,
const struct mtd_partition **pparts, u_int off, struct mtd_partition *part)
struct mtd_part_parser_data *data)
{ {
struct mtd_partition *parts; struct image_info_v1 iis;
u_int mask, off, sz; u_int mask;
int ret = 0; /*
int i; * Static checks cannot see that we bail out if we have an error
* reading the footer.
*/
u_int uninitialized_var(iis_ptr);
u_int uninitialized_var(img_ptr);
int ret;
/* /*
* This is the address mask; we use this to mask off out of * This is the address mask; we use this to mask off out of
@ -196,6 +200,39 @@ static int parse_afs_partitions(struct mtd_info *mtd,
*/ */
mask = mtd->size - 1; mask = mtd->size - 1;
ret = afs_read_footer_v1(mtd, &img_ptr, &iis_ptr, off, mask);
if (ret < 0)
return ret;
/* Read the image info block */
ret = afs_read_iis_v1(mtd, &iis, iis_ptr);
if (ret < 0)
return ret;
part->name = kstrdup(iis.name, GFP_KERNEL);
if (!part->name)
return -ENOMEM;
part->size = (iis.length + mtd->erasesize - 1) & ~(mtd->erasesize - 1);
part->offset = img_ptr;
part->mask_flags = 0;
printk(" mtd: at 0x%08x, %5lluKiB, %8u, %s\n",
img_ptr, part->size / 1024,
iis.imageNumber, part->name);
return 0;
}
static int parse_afs_partitions(struct mtd_info *mtd,
const struct mtd_partition **pparts,
struct mtd_part_parser_data *data)
{
struct mtd_partition *parts;
u_int off, sz;
int ret = 0;
int i;
/* Count the partitions by looping over all erase blocks */ /* Count the partitions by looping over all erase blocks */
for (i = off = sz = 0; off < mtd->size; off += mtd->erasesize) { for (i = off = sz = 0; off < mtd->size; off += mtd->erasesize) {
if (afs_is_v1(mtd, off)) { if (afs_is_v1(mtd, off)) {
@ -215,38 +252,13 @@ static int parse_afs_partitions(struct mtd_info *mtd,
* Identify the partitions * Identify the partitions
*/ */
for (i = off = 0; off < mtd->size; off += mtd->erasesize) { for (i = off = 0; off < mtd->size; off += mtd->erasesize) {
struct image_info_v1 iis;
u_int iis_ptr, img_ptr;
/* Read the footer. */ if (afs_is_v1(mtd, off)) {
ret = afs_read_footer_v1(mtd, &img_ptr, &iis_ptr, off, mask); ret = afs_parse_v1_partition(mtd, off, &parts[i]);
if (ret < 0) if (ret)
goto out_free_parts; goto out_free_parts;
if (ret == 0) i++;
continue;
/* Read the image info block */
ret = afs_read_iis_v1(mtd, &iis, iis_ptr);
if (ret < 0)
goto out_free_parts;
if (ret == 0)
continue;
parts[i].name = kstrdup(iis.name, GFP_KERNEL);
if (!parts[i].name) {
ret = -ENOMEM;
goto out_free_parts;
} }
parts[i].size = (iis.length + mtd->erasesize - 1) & ~(mtd->erasesize - 1);
parts[i].offset = img_ptr;
parts[i].mask_flags = 0;
printk(" mtd%d: at 0x%08x, %5lluKiB, %8u, %s\n",
i, img_ptr, parts[i].size / 1024,
iis.imageNumber, parts[i].name);
i += 1;
} }
*pparts = parts; *pparts = parts;