[PATCH 4/4] FIT: support finding compatible configuration by FDT compatible
Ahmad Fatoum
a.fatoum at pengutronix.de
Fri Mar 1 05:04:45 PST 2024
So far, we only supported finding compatible configurations that have
a compatible property inside the configuration's device tree node.
According to spec, this is optional however, and e.g. Yocto's
kernel-fitimage.bbclass don't generate it.
Instead, the bootloader is expected to lookup the compatible inside the
referenced FDT. With fdt_machine_is_compatible, this is much less of a
performance hit than with of_machine_is_compatible, so let's implement
support for this.
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
common/image-fit.c | 39 +++++++++++++++++++++++++++++++++++++--
include/of.h | 5 +++++
2 files changed, 42 insertions(+), 2 deletions(-)
diff --git a/common/image-fit.c b/common/image-fit.c
index b16752de05bc..251fda97b3fc 100644
--- a/common/image-fit.c
+++ b/common/image-fit.c
@@ -715,7 +715,8 @@ static int fit_config_verify_signature(struct fit_handle *handle, struct device_
return ret;
}
-static int fit_find_compatible_unit(struct device_node *conf_node,
+static int fit_find_compatible_unit(struct fit_handle *handle,
+ struct device_node *conf_node,
const char **unit)
{
struct device_node *child = NULL;
@@ -734,6 +735,40 @@ static int fit_find_compatible_unit(struct device_node *conf_node,
for_each_child_of_node(conf_node, child) {
int score = of_device_is_compatible(child, machine);
+
+ if (!score && !of_property_present(child, "compatible") &&
+ of_property_present(child, "fdt")) {
+ struct device_node *image;
+ const char *unit = "fdt";
+ int data_len;
+ const void *data;
+ int ret;
+
+ ret = fit_get_image(handle, child, &unit, &image);
+ if (ret)
+ goto next;
+
+ data = of_get_property(image, "data", &data_len);
+ if (!data) {
+ ret = -EINVAL;
+ goto next;
+ }
+
+ ret = fit_handle_decompression(image, "fdt", &data, &data_len);
+ if (ret) {
+ ret = -EILSEQ;
+ goto next;
+ }
+
+ score = fdt_machine_is_compatible(data, data_len, machine);
+
+ of_delete_property_by_name(image, "uncompressed-data");
+next:
+ if (ret)
+ pr_warn("skipping malformed configuration: %pOF (%pe)\n",
+ child, ERR_PTR(ret));
+ }
+
if (score > best_score) {
best_score = score;
*unit = child->name;
@@ -779,7 +814,7 @@ void *fit_open_configuration(struct fit_handle *handle, const char *name)
if (name) {
unit = name;
} else {
- ret = fit_find_compatible_unit(conf_node, &unit);
+ ret = fit_find_compatible_unit(handle, conf_node, &unit);
if (ret) {
pr_info("Couldn't get a valid configuration. Aborting.\n");
return ERR_PTR(ret);
diff --git a/include/of.h b/include/of.h
index b00940c8532e..f0214fb13c49 100644
--- a/include/of.h
+++ b/include/of.h
@@ -1226,6 +1226,11 @@ static inline int of_property_write_u64(struct device_node *np,
return of_property_write_u64_array(np, propname, &value, 1);
}
+static inline void of_delete_property_by_name(struct device_node *np, const char *name)
+{
+ of_delete_property(of_find_property(np, name, NULL));
+}
+
extern const struct of_device_id of_default_bus_match_table[];
int of_device_enable(struct device_node *node);
--
2.39.2
More information about the barebox
mailing list