mirror of
https://github.com/openwrt/openwrt.git
synced 2024-12-20 14:13:16 +00:00
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@makrotopia.org>
This commit is contained in:
parent
1bf94b6797
commit
ab143647ef
@ -89,12 +89,10 @@ int parse_fit_partitions(struct parsed_partitions *state, u64 fit_start_sector,
|
|||||||
size_t label_min;
|
size_t label_min;
|
||||||
struct device_node *np = NULL;
|
struct device_node *np = NULL;
|
||||||
const char *bootconf;
|
const char *bootconf;
|
||||||
|
char *loadable;
|
||||||
np = of_find_node_by_path("/chosen");
|
char *select_rootfs = NULL;
|
||||||
if (np)
|
bool found;
|
||||||
bootconf = of_get_property(np, "bootconf", NULL);
|
int loadables_rem_len, loadable_len;
|
||||||
else
|
|
||||||
bootconf = NULL;
|
|
||||||
|
|
||||||
if (fit_start_sector % (1<<(PAGE_SHIFT - SECTOR_SHIFT)))
|
if (fit_start_sector % (1<<(PAGE_SHIFT - SECTOR_SHIFT)))
|
||||||
return -ERANGE;
|
return -ERANGE;
|
||||||
@ -123,7 +121,6 @@ int parse_fit_partitions(struct parsed_partitions *state, u64 fit_start_sector,
|
|||||||
dsectors = (dsectors>sectors)?sectors:dsectors;
|
dsectors = (dsectors>sectors)?sectors:dsectors;
|
||||||
|
|
||||||
dsize = dsectors << SECTOR_SHIFT;
|
dsize = dsectors << SECTOR_SHIFT;
|
||||||
|
|
||||||
size = fdt_totalsize(init_fit);
|
size = fdt_totalsize(init_fit);
|
||||||
|
|
||||||
/* silently skip non-external-data legacy FIT images */
|
/* 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)
|
if (!fit)
|
||||||
return -ENOMEM;
|
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);
|
config = fdt_path_offset(fit, FIT_CONFS_PATH);
|
||||||
if (config < 0) {
|
if (config < 0) {
|
||||||
printk(KERN_ERR "FIT: Cannot find %s node: %d\n", FIT_CONFS_PATH, images);
|
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,
|
bootconf?"Selected":"Default", bootconf?:config_default,
|
||||||
config_description?" (":"", config_description?:"", config_description?")":"");
|
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);
|
images = fdt_path_offset(fit, FIT_IMAGES_PATH);
|
||||||
if (images < 0) {
|
if (images < 0) {
|
||||||
printk(KERN_ERR "FIT: Cannot find %s node: %d\n", FIT_IMAGES_PATH, images);
|
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))
|
if (strcmp(image_type, FIT_FILESYSTEM_PROP))
|
||||||
continue;
|
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)) {
|
if (image_pos & ((1 << PAGE_SHIFT)-1)) {
|
||||||
printk(KERN_ERR "FIT: image %s start not aligned to page boundaries, skipping\n", image_name);
|
printk(KERN_ERR "FIT: image %s start not aligned to page boundaries, skipping\n", image_name);
|
||||||
continue;
|
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);
|
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;
|
info = &state->parts[*slot].info;
|
||||||
|
|
||||||
label_min = min_t(int, sizeof(info->volname) - 1, image_name_len);
|
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);
|
snprintf(tmp, sizeof(tmp), "(%s)", info->volname);
|
||||||
strlcat(state->pp_buf, tmp, PAGE_SIZE);
|
strlcat(state->pp_buf, tmp, PAGE_SIZE);
|
||||||
|
|
||||||
state->parts[*slot].has_info = true;
|
/* Mark first loadable listed to be mounted as rootfs */
|
||||||
state->parts[*slot].flags |= ADDPART_FLAG_READONLY;
|
if (!strcmp(image_name, config_loadables)) {
|
||||||
if (config_loadables && !strcmp(image_name, config_loadables)) {
|
select_rootfs = image_name;
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
if (add_remain && (imgmaxsect + MIN_FREE_SECT) < dsectors) {
|
||||||
put_partition(state, ++(*slot), fit_start_sector + imgmaxsect, dsectors - imgmaxsect);
|
put_partition(state, ++(*slot), fit_start_sector + imgmaxsect, dsectors - imgmaxsect);
|
||||||
state->parts[*slot].flags = 0;
|
state->parts[*slot].flags = 0;
|
||||||
|
@ -156,7 +156,7 @@
|
|||||||
.name = "mtdblock",
|
.name = "mtdblock",
|
||||||
.major = MTD_BLOCK_MAJOR,
|
.major = MTD_BLOCK_MAJOR,
|
||||||
+#ifdef CONFIG_FIT_PARTITION
|
+#ifdef CONFIG_FIT_PARTITION
|
||||||
+ .part_bits = 1,
|
+ .part_bits = 2,
|
||||||
+#else
|
+#else
|
||||||
.part_bits = 0,
|
.part_bits = 0,
|
||||||
+#endif
|
+#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user