From: Marco Felsch <m.felsch@pengutronix.de>
To: Sascha Hauer <s.hauer@pengutronix.de>,
BAREBOX <barebox@lists.infradead.org>
Cc: Marco Felsch <m.felsch@pengutronix.de>
Subject: [PATCH v4 02/11] FIT: fit_open_configuration: add match function support
Date: Tue, 29 Jul 2025 17:34:27 +0200 [thread overview]
Message-ID: <20250729-v2024-05-0-topic-fit-overlay-v4-2-af3ad99acde2@pengutronix.de> (raw)
In-Reply-To: <20250729-v2024-05-0-topic-fit-overlay-v4-0-af3ad99acde2@pengutronix.de>
The FIT spec is not very specific and was growing over the past years,
e.g. according U-Boot (doc/usage/fit/source_file_format.rst) either a
"kernel" or "firmware" property is mandatory whereas the fit-overlay
example (doc/usage/fit/overlay-fdt-boot.rst) doesn't fulfil this
requirement. Instead it allows nodes which contain only a "fdt"
property.
This inconsistency makes it hard to detect the purpose of a
configuration node. So far we have three different configuration nodes
- bootable nodes (the usual use-case):
| config-0 {
| compatible = "machine-compatible";
| kernel = "kernel-img-name";
| fdt = "fdt-img-name";
| }
- firmware only nodes like (doc/usage/fit/sec_firmware_ppa.rst):
| config-1 {
| description = "PPA Secure firmware";
| firmware = "firmware@1";
| loadables = "trustedOS@1", "fuse_scr";
| };
- overlay only nodes:
| config-2 {
| fdt = "fdt-overlay-img-name";
| }
This commit adds an optional match function which can be passed to the
fit_open_configuration() to sort out config nodes which are not
interessting, e.g. the bootm code is only interested in config nodes
which do provide a "kernel" image.
This new match function gets called if no explicit configuration node
name was specified.
Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
common/bootm.c | 13 ++++++++++++-
common/image-fit.c | 22 ++++++++++++++++------
include/image-fit.h | 4 +++-
3 files changed, 31 insertions(+), 8 deletions(-)
diff --git a/common/bootm.c b/common/bootm.c
index 95211011fe8bf5f52ce3155de419bc9b09ff2228..7f37c74eb41e5c7a89aa4038bae46cee5f056f5f 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -609,6 +609,16 @@ static int bootm_open_os_uimage(struct image_data *data)
return 0;
}
+static bool bootm_fit_config_valid(struct fit_handle *fit,
+ struct device_node *config)
+{
+ /*
+ * Consider only FIT configurations which do provide a loadable kernel
+ * image.
+ */
+ return !!fit_has_image(fit, config, "kernel");
+}
+
static int bootm_open_fit(struct image_data *data)
{
struct fit_handle *fit;
@@ -634,7 +644,8 @@ static int bootm_open_fit(struct image_data *data)
data->os_fit = fit;
data->fit_config = fit_open_configuration(data->os_fit,
- data->os_part);
+ data->os_part,
+ bootm_fit_config_valid);
if (IS_ERR(data->fit_config)) {
pr_err("Cannot open FIT image configuration '%s'\n",
data->os_part ? data->os_part : "default");
diff --git a/common/image-fit.c b/common/image-fit.c
index 4d5c5bfe12472af85b26cd1ee93e7c99316b283c..0fc3b2e4aa7217a47710ef613426456420e81324 100644
--- a/common/image-fit.c
+++ b/common/image-fit.c
@@ -782,7 +782,9 @@ static int fit_fdt_is_compatible(struct fit_handle *handle,
static int fit_find_compatible_unit(struct fit_handle *handle,
struct device_node *conf_node,
- const char **unit)
+ const char **unit,
+ bool (*config_node_valid)(struct fit_handle *handle,
+ struct device_node *config))
{
struct device_node *child = NULL;
struct device_node *barebox_root;
@@ -799,7 +801,12 @@ static int fit_find_compatible_unit(struct fit_handle *handle,
return -ENOENT;
for_each_child_of_node(conf_node, child) {
- int score = of_device_is_compatible(child, machine);
+ int score;
+
+ if (config_node_valid && !config_node_valid(handle, child))
+ continue;
+
+ score = of_device_is_compatible(child, machine);
if (!score)
score = fit_fdt_is_compatible(handle, child, machine);
@@ -857,7 +864,9 @@ static int fit_find_last_unit(struct fit_handle *handle,
* Return: If successful a pointer to a valid configuration node,
* otherwise a ERR_PTR()
*/
-void *fit_open_configuration(struct fit_handle *handle, const char *name)
+void *fit_open_configuration(struct fit_handle *handle, const char *name,
+ bool (*match_valid)(struct fit_handle *handle,
+ struct device_node *config))
{
struct device_node *conf_node = handle->configurations;
const char *unit, *desc = "(no description)";
@@ -869,7 +878,8 @@ void *fit_open_configuration(struct fit_handle *handle, const char *name)
if (name) {
unit = name;
} else {
- ret = fit_find_compatible_unit(handle, conf_node, &unit);
+ ret = fit_find_compatible_unit(handle, conf_node, &unit,
+ match_valid);
if (ret) {
pr_info("Couldn't get a valid configuration. Aborting.\n");
return ERR_PTR(ret);
@@ -1044,12 +1054,12 @@ static int fuzz_fit(const u8 *data, size_t size)
if (ret)
goto out;
- config = fit_open_configuration(&handle, NULL);
+ config = fit_open_configuration(&handle, NULL, NULL);
if (IS_ERR(config)) {
ret = fit_find_last_unit(&handle, &unit);
if (ret)
goto out;
- config = fit_open_configuration(&handle, unit);
+ config = fit_open_configuration(&handle, unit, NULL);
}
if (IS_ERR(config)) {
ret = PTR_ERR(config);
diff --git a/include/image-fit.h b/include/image-fit.h
index 0b8e94bf46357a1fe01ef90cd8b0fca0c41641c3..416f1f2c1896949d2bcb7ab1a31f1aa6b5682edf 100644
--- a/include/image-fit.h
+++ b/include/image-fit.h
@@ -26,7 +26,9 @@ struct fit_handle *fit_open(const char *filename, bool verbose,
enum bootm_verify verify, loff_t max_size);
struct fit_handle *fit_open_buf(const void *buf, size_t len, bool verbose,
enum bootm_verify verify);
-void *fit_open_configuration(struct fit_handle *handle, const char *name);
+void *fit_open_configuration(struct fit_handle *handle, const char *name,
+ bool (*match_valid)(struct fit_handle *handle,
+ struct device_node *config));
int fit_has_image(struct fit_handle *handle, void *configuration,
const char *name);
int fit_open_image(struct fit_handle *handle, void *configuration,
--
2.39.5
next prev parent reply other threads:[~2025-07-29 15:35 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-29 15:34 [PATCH v4 00/11] Add FIT image overlay support Marco Felsch
2025-07-29 15:34 ` [PATCH v4 01/11] FIT: fix missing free in fit_open error path Marco Felsch
2025-07-29 15:34 ` Marco Felsch [this message]
2025-07-29 15:34 ` [PATCH v4 03/11] of: overlay: make the pattern match function more generic Marco Felsch
2025-07-29 15:34 ` [PATCH v4 04/11] of: overlay: make search dir " Marco Felsch
2025-07-29 15:34 ` [PATCH v4 05/11] of: overlay: refactor of_overlay_global_fixup Marco Felsch
2025-07-29 15:34 ` [PATCH v4 06/11] FIT: make fit_config_verify_signature public Marco Felsch
2025-07-29 15:34 ` [PATCH v4 07/11] of: overlay: add FIT image overlay support Marco Felsch
2025-08-05 10:57 ` Sascha Hauer
2025-08-05 20:14 ` Marco Felsch
2025-07-29 15:34 ` [PATCH v4 08/11] of: overlay: replace filename with an more unique name Marco Felsch
2025-07-29 15:34 ` [PATCH v4 09/11] FIT: fit_open: make filename handling more robust Marco Felsch
2025-07-29 15:34 ` [PATCH v4 10/11] FIT: fit_open: save the filename Marco Felsch
2025-07-29 15:34 ` [PATCH v4 11/11] FIT: add support to cache opened fit images Marco Felsch
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=20250729-v2024-05-0-topic-fit-overlay-v4-2-af3ad99acde2@pengutronix.de \
--to=m.felsch@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=s.hauer@pengutronix.de \
/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