[openwrt/openwrt] kernel: generic: improve FIT partition parser
LEDE Commits
lede-commits at lists.infradead.org
Wed Mar 23 19:29:04 PDT 2022
dangole pushed a commit to openwrt/openwrt.git, branch master:
https://git.openwrt.org/ab143647efef2a13bcce2f28a2797899fbc83946
commit ab143647efef2a13bcce2f28a2797899fbc83946
Author: Daniel Golle <daniel at makrotopia.org>
AuthorDate: Wed Mar 23 19:29:07 2022 +0000
kernel: generic: improve FIT partition parser
* only map filesystems configured in 'loadables'
* allow mapping more than one filesystem (e.g. customization/branding
or localization in addition to rootfs)
* small cleaning here and there
Signed-off-by: Daniel Golle <daniel at makrotopia.org>
---
target/linux/generic/files/block/partitions/fit.c | 52 +++++++++++++++++-----
.../hack-5.10/410-block-fit-partition-parser.patch | 2 +-
2 files changed, 41 insertions(+), 13 deletions(-)
diff --git a/target/linux/generic/files/block/partitions/fit.c b/target/linux/generic/files/block/partitions/fit.c
index 89b5fb3454..f6f15f538a 100644
--- a/target/linux/generic/files/block/partitions/fit.c
+++ b/target/linux/generic/files/block/partitions/fit.c
@@ -89,12 +89,10 @@ int parse_fit_partitions(struct parsed_partitions *state, u64 fit_start_sector,
size_t label_min;
struct device_node *np = NULL;
const char *bootconf;
-
- np = of_find_node_by_path("/chosen");
- if (np)
- bootconf = of_get_property(np, "bootconf", NULL);
- else
- bootconf = NULL;
+ char *loadable;
+ char *select_rootfs = NULL;
+ bool found;
+ int loadables_rem_len, loadable_len;
if (fit_start_sector % (1<<(PAGE_SHIFT - SECTOR_SHIFT)))
return -ERANGE;
@@ -123,7 +121,6 @@ int parse_fit_partitions(struct parsed_partitions *state, u64 fit_start_sector,
dsectors = (dsectors>sectors)?sectors:dsectors;
dsize = dsectors << SECTOR_SHIFT;
-
size = fdt_totalsize(init_fit);
/* silently skip non-external-data legacy FIT images */
@@ -143,6 +140,12 @@ int parse_fit_partitions(struct parsed_partitions *state, u64 fit_start_sector,
if (!fit)
return -ENOMEM;
+ np = of_find_node_by_path("/chosen");
+ if (np)
+ bootconf = of_get_property(np, "bootconf", NULL);
+ else
+ bootconf = NULL;
+
config = fdt_path_offset(fit, FIT_CONFS_PATH);
if (config < 0) {
printk(KERN_ERR "FIT: Cannot find %s node: %d\n", FIT_CONFS_PATH, images);
@@ -172,6 +175,12 @@ int parse_fit_partitions(struct parsed_partitions *state, u64 fit_start_sector,
bootconf?"Selected":"Default", bootconf?:config_default,
config_description?" (":"", config_description?:"", config_description?")":"");
+ if (!config_loadables || !config_loadables_len) {
+ printk(KERN_ERR "FIT: No loadables configured in \"%s\"\n", bootconf?:config_default);
+ ret = -ENOENT;
+ goto ret_out;
+ }
+
images = fdt_path_offset(fit, FIT_IMAGES_PATH);
if (images < 0) {
printk(KERN_ERR "FIT: Cannot find %s node: %d\n", FIT_IMAGES_PATH, images);
@@ -208,6 +217,22 @@ int parse_fit_partitions(struct parsed_partitions *state, u64 fit_start_sector,
if (strcmp(image_type, FIT_FILESYSTEM_PROP))
continue;
+ /* check if sub-image is part of configured loadables */
+ found = false;
+ loadable = config_loadables;
+ loadables_rem_len = config_loadables_len;
+ while (loadables_rem_len > 1) {
+ loadable_len = strnlen(loadable, loadables_rem_len - 1) + 1;
+ loadables_rem_len -= loadable_len;
+ if (!strncmp(image_name, loadable, loadable_len)) {
+ found = true;
+ break;
+ }
+ loadable += loadable_len;
+ }
+ if (!found)
+ continue;
+
if (image_pos & ((1 << PAGE_SHIFT)-1)) {
printk(KERN_ERR "FIT: image %s start not aligned to page boundaries, skipping\n", image_name);
continue;
@@ -228,7 +253,8 @@ int parse_fit_partitions(struct parsed_partitions *state, u64 fit_start_sector,
}
put_partition(state, ++(*slot), fit_start_sector + start_sect, nr_sects);
- state->parts[*slot].flags = 0;
+ state->parts[*slot].flags = ADDPART_FLAG_READONLY;
+ state->parts[*slot].has_info = true;
info = &state->parts[*slot].info;
label_min = min_t(int, sizeof(info->volname) - 1, image_name_len);
@@ -238,14 +264,16 @@ int parse_fit_partitions(struct parsed_partitions *state, u64 fit_start_sector,
snprintf(tmp, sizeof(tmp), "(%s)", info->volname);
strlcat(state->pp_buf, tmp, PAGE_SIZE);
- state->parts[*slot].has_info = true;
- state->parts[*slot].flags |= ADDPART_FLAG_READONLY;
- if (config_loadables && !strcmp(image_name, config_loadables)) {
- printk(KERN_DEBUG "FIT: selecting configured loadable \"%s\" to be root filesystem\n", image_name);
+ /* Mark first loadable listed to be mounted as rootfs */
+ if (!strcmp(image_name, config_loadables)) {
+ select_rootfs = image_name;
state->parts[*slot].flags |= ADDPART_FLAG_ROOTDEV;
}
}
+ if (select_rootfs)
+ printk(KERN_DEBUG "FIT: selecting configured loadable \"%s\" to be root filesystem\n", select_rootfs);
+
if (add_remain && (imgmaxsect + MIN_FREE_SECT) < dsectors) {
put_partition(state, ++(*slot), fit_start_sector + imgmaxsect, dsectors - imgmaxsect);
state->parts[*slot].flags = 0;
diff --git a/target/linux/generic/hack-5.10/410-block-fit-partition-parser.patch b/target/linux/generic/hack-5.10/410-block-fit-partition-parser.patch
index bc48296d9c..7816356227 100644
--- a/target/linux/generic/hack-5.10/410-block-fit-partition-parser.patch
+++ b/target/linux/generic/hack-5.10/410-block-fit-partition-parser.patch
@@ -156,7 +156,7 @@
.name = "mtdblock",
.major = MTD_BLOCK_MAJOR,
+#ifdef CONFIG_FIT_PARTITION
-+ .part_bits = 1,
++ .part_bits = 2,
+#else
.part_bits = 0,
+#endif
More information about the lede-commits
mailing list