aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/generic/files
diff options
context:
space:
mode:
authorDaniel Golle <daniel@makrotopia.org>2021-02-27 03:18:46 +0000
committerDaniel Golle <daniel@makrotopia.org>2021-02-28 00:09:09 +0000
commit6b0295a47d0e101a9c423b76fd4b6e12deebe651 (patch)
tree0407984a419c080c1537c95f07d817ed5ac8417c /target/linux/generic/files
parentdc5328e7e9d97ea779fa06621ce6da8deaac56c9 (diff)
downloadupstream-6b0295a47d0e101a9c423b76fd4b6e12deebe651.tar.gz
upstream-6b0295a47d0e101a9c423b76fd4b6e12deebe651.tar.bz2
upstream-6b0295a47d0e101a9c423b76fd4b6e12deebe651.zip
image: extend FIT partition parser for use on eMMC/SDcard
Introduce a magic GUID_PARTITION_LINUX_FIT_GUID to designate a GPT partition to be interpreted by the FIT partition parser. In that way, sub-partitions for (external-data) uImage.FIT stored directly in a partition can be split, similar like we do for devices with raw flash storage. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Diffstat (limited to 'target/linux/generic/files')
-rw-r--r--target/linux/generic/files/block/partitions/fit.c45
1 files changed, 33 insertions, 12 deletions
diff --git a/target/linux/generic/files/block/partitions/fit.c b/target/linux/generic/files/block/partitions/fit.c
index 8ccbcf2fc2..c0d9642505 100644
--- a/target/linux/generic/files/block/partitions/fit.c
+++ b/target/linux/generic/files/block/partitions/fit.c
@@ -67,17 +67,20 @@
#define FIT_MAX_HASH_LEN HASH_MAX_DIGEST_SIZE
-int fit_partition(struct parsed_partitions *state)
+#define MIN_FREE_SECT 16
+#define REMAIN_VOLNAME "rootfs_data"
+
+int parse_fit_partitions(struct parsed_partitions *state, u64 fit_start_sector, u64 sectors, int *slot, int add_remain)
{
struct address_space *mapping = state->bdev->bd_inode->i_mapping;
- struct page *page = read_mapping_page(mapping, 0, NULL);
+ struct page *page;
void *fit, *init_fit;
struct partition_meta_info *info;
char tmp[sizeof(info->volname)];
- u64 dsize, dsectors;
+ u64 dsize, dsectors, imgmaxsect = 0;
u32 size, image_pos, image_len;
const u32 *image_offset_be, *image_len_be, *image_pos_be;
- int ret = 1, node, images, config, slot;
+ int ret = 1, node, images, config;
const char *image_name, *image_type, *image_description, *config_default,
*config_description, *config_loadables;
int image_name_len, image_type_len, image_description_len, config_default_len,
@@ -85,6 +88,10 @@ int fit_partition(struct parsed_partitions *state)
sector_t start_sect, nr_sects;
size_t label_min;
+ if (fit_start_sector % (1<<(PAGE_SHIFT - SECTOR_SHIFT)))
+ return -ERANGE;
+
+ page = read_mapping_page(mapping, fit_start_sector >> (PAGE_SHIFT - SECTOR_SHIFT), NULL);
if (!page)
return -ENOMEM;
@@ -101,6 +108,9 @@ int fit_partition(struct parsed_partitions *state)
}
dsectors = get_capacity(state->bdev->bd_disk);
+ if (sectors)
+ dsectors = (dsectors>sectors)?sectors:dsectors;
+
dsize = dsectors << SECTOR_SHIFT;
printk(KERN_DEBUG "FIT: volume size: %llu sectors (%llu bytes)\n", dsectors, dsize);
@@ -158,7 +168,6 @@ int fit_partition(struct parsed_partitions *state)
goto ret_out;
}
- slot = 1;
fdt_for_each_subnode(node, fit, images) {
image_name = fdt_get_name(fit, node, &image_name_len);
image_type = fdt_getprop(fit, node, FIT_TYPE_PROP, &image_type_len);
@@ -200,15 +209,16 @@ int fit_partition(struct parsed_partitions *state)
start_sect = image_pos >> SECTOR_SHIFT;
nr_sects = image_len >> SECTOR_SHIFT;
+ imgmaxsect = (imgmaxsect < (start_sect + nr_sects))?(start_sect + nr_sects):imgmaxsect;
if (start_sect + nr_sects > dsectors) {
state->access_beyond_eod = 1;
continue;
}
- put_partition(state, slot, start_sect, nr_sects);
- state->parts[slot].flags = 0;
- info = &state->parts[slot].info;
+ put_partition(state, ++(*slot), fit_start_sector + start_sect, nr_sects);
+ state->parts[*slot].flags = 0;
+ info = &state->parts[*slot].info;
label_min = min_t(int, sizeof(info->volname) - 1, image_name_len);
strncpy(info->volname, image_name, label_min);
@@ -217,17 +227,28 @@ int fit_partition(struct parsed_partitions *state)
snprintf(tmp, sizeof(tmp), "(%s)", info->volname);
strlcat(state->pp_buf, tmp, PAGE_SIZE);
- state->parts[slot].has_info = true;
+ state->parts[*slot].has_info = true;
if (config_loadables && !strcmp(image_name, config_loadables)) {
printk(KERN_DEBUG "FIT: selecting configured loadable %s to be root filesystem\n", image_name);
- state->parts[slot].flags |= ADDPART_FLAG_ROOTDEV;
+ state->parts[*slot].flags |= ADDPART_FLAG_ROOTDEV;
}
-
- ++slot;
}
+ if (add_remain && (imgmaxsect + MIN_FREE_SECT) < dsectors) {
+ put_partition(state, ++(*slot), fit_start_sector + imgmaxsect, dsectors - imgmaxsect);
+ state->parts[*slot].flags = 0;
+ info = &state->parts[*slot].info;
+ strcpy(info->volname, REMAIN_VOLNAME);
+ snprintf(tmp, sizeof(tmp), "(%s)", REMAIN_VOLNAME);
+ strlcat(state->pp_buf, tmp, PAGE_SIZE);
+ }
ret_out:
kfree(fit);
return ret;
}
+
+int fit_partition(struct parsed_partitions *state) {
+ int slot = 0;
+ return parse_fit_partitions(state, 0, 0, &slot, 0);
+}