From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 4/4] FIT: support finding compatible configuration by FDT compatible
Date: Fri, 1 Mar 2024 14:04:45 +0100 [thread overview]
Message-ID: <20240301130445.171385-5-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20240301130445.171385-1-a.fatoum@pengutronix.de>
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@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
next prev parent reply other threads:[~2024-03-01 13:36 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-01 13:04 [PATCH 0/4] of: fdt: read blspec/FIT DT compat without unflattening Ahmad Fatoum
2024-03-01 13:04 ` [PATCH 1/4] of: fdt: factor out FDT header parsing Ahmad Fatoum
2024-03-01 13:04 ` [PATCH 2/4] of: fdt: implement fdt_machine_is_compatible Ahmad Fatoum
2024-03-04 9:37 ` Sascha Hauer
2024-03-04 9:49 ` Sascha Hauer
2024-03-04 9:50 ` Ahmad Fatoum
2024-03-01 13:04 ` [PATCH 3/4] blspec: don't parse whole device tree to compare compatibles Ahmad Fatoum
2024-03-01 13:04 ` Ahmad Fatoum [this message]
2024-03-04 9:49 ` [PATCH 0/4] of: fdt: read blspec/FIT DT compat without unflattening Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240301130445.171385-5-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox