From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 02/15] FIT: add image index argument to fit_open_image
Date: Tue, 27 Jan 2026 09:39:12 +0100 [thread overview]
Message-ID: <20260127084546.3751357-3-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20260127084546.3751357-1-a.fatoum@pengutronix.de>
A FIT configuration can specify multiple images of the same type, e.g.
for device tree overlays. Add an index parameter to fit_open_image()
to allow callers to select which image to open. Existing callers pass
idx=0 to maintain current behavior of opening the first image.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
arch/arm/lib32/bootm.c | 2 +-
common/bootm-fit.c | 6 ++---
common/image-fit.c | 50 ++++++++++++++++++++----------------------
drivers/of/overlay.c | 2 +-
efi/payload/bootm.c | 4 ++--
include/image-fit.h | 4 ++--
6 files changed, 33 insertions(+), 35 deletions(-)
diff --git a/arch/arm/lib32/bootm.c b/arch/arm/lib32/bootm.c
index 533c3ea946ff..e659d3c1a554 100644
--- a/arch/arm/lib32/bootm.c
+++ b/arch/arm/lib32/bootm.c
@@ -178,7 +178,7 @@ static int bootm_load_tee_from_fit(struct image_data *data)
const void *tee;
unsigned long tee_size;
- ret = fit_open_image(data->os_fit, data->fit_config, "tee",
+ ret = fit_open_image(data->os_fit, data->fit_config, "tee", 0,
&tee, &tee_size);
if (ret) {
pr_err("Error opening tee fit image: %pe\n", ERR_PTR(ret));
diff --git a/common/bootm-fit.c b/common/bootm-fit.c
index 3b2252ca8810..a0e808e31b40 100644
--- a/common/bootm-fit.c
+++ b/common/bootm-fit.c
@@ -61,7 +61,7 @@ struct resource *bootm_load_fit_initrd(struct image_data *data, unsigned long lo
if (!fitconfig_has_ramdisk(data))
return NULL;
- ret = fit_open_image(data->os_fit, data->fit_config, "ramdisk",
+ ret = fit_open_image(data->os_fit, data->fit_config, "ramdisk", 0,
&initrd, &initrd_size);
if (ret) {
pr_err("Cannot open ramdisk image in FIT image: %pe\n",
@@ -96,7 +96,7 @@ void *bootm_get_fit_devicetree(struct image_data *data)
const void *of_tree;
unsigned long of_size;
- ret = fit_open_image(data->os_fit, data->fit_config, "fdt",
+ ret = fit_open_image(data->os_fit, data->fit_config, "fdt", 0,
&of_tree, &of_size);
if (ret)
return ERR_PTR(ret);
@@ -144,7 +144,7 @@ int bootm_open_fit(struct image_data *data)
return PTR_ERR(data->fit_config);
}
- ret = fit_open_image(data->os_fit, data->fit_config, kernel_img,
+ ret = fit_open_image(data->os_fit, data->fit_config, kernel_img, 0,
&data->fit_kernel, &data->fit_kernel_size);
if (ret)
return ret;
diff --git a/common/image-fit.c b/common/image-fit.c
index 85096aff31e6..75592766941c 100644
--- a/common/image-fit.c
+++ b/common/image-fit.c
@@ -522,24 +522,20 @@ static int fit_get_address(struct device_node *image, const char *property,
return 0;
}
-static int
+static struct device_node *
fit_get_image(struct fit_handle *handle, void *configuration,
- const char **unit, struct device_node **image)
+ const char **unit, int idx)
{
struct device_node *conf_node = configuration;
if (conf_node) {
- if (of_property_read_string(conf_node, *unit, unit)) {
+ if (of_property_read_string_index(conf_node, *unit, idx, unit)) {
pr_err("No image named '%s'\n", *unit);
- return -ENOENT;
+ return NULL;
}
}
- *image = of_get_child_by_name(handle->images, *unit);
- if (!*image)
- return -ENOENT;
-
- return 0;
+ return of_get_child_by_name(handle->images, *unit);
}
/**
@@ -569,9 +565,9 @@ int fit_get_image_address(struct fit_handle *handle, void *configuration,
if (!address || !property || !name)
return -EINVAL;
- ret = fit_get_image(handle, configuration, &unit, &image);
- if (ret)
- return ret;
+ image = fit_get_image(handle, configuration, &unit, 0);
+ if (!image)
+ return -ENOENT;
/* Treat type = "kernel_noload" as if entry/load address is missing */
ret = of_property_read_string(image, "type", &type);
@@ -647,22 +643,22 @@ static int fit_handle_decompression(struct device_node *image,
/**
* fit_open_image - Open an image in a FIT image
* @handle: The FIT image handle
+ * @configuration: configuration cookie from fit_open_configuration(), or NULL
* @name: The name of the image to open
+ * @idx: The index of image to open (for multi-image properties like overlays)
* @outdata: The returned image
* @outsize: Size of the returned image
*
* Open an image in a FIT image. The returned image is freed during fit_close().
- * @configuration holds the cookie returned from fit_open_configuration() if
- * the image is opened as part of a configuration, or NULL if the image is
- * opened without a configuration. If @configuration is NULL then the RSA
- * signature of the image is checked if desired, if @configuration is non NULL,
- * then only the hash is checked (because opening the configuration already
- * checks the RSA signature of all involved nodes).
+ *
+ * If @configuration is NULL then the RSA signature of the image is checked
+ * if desired; otherwise only the hash is checked (because opening the
+ * configuration already checks the RSA signature of all involved nodes).
*
* Return: 0 for success, negative error code otherwise
*/
int fit_open_image(struct fit_handle *handle, void *configuration,
- const char *name, const void **outdata,
+ const char *name, int idx, const void **outdata,
unsigned long *outsize)
{
struct device_node *image;
@@ -671,9 +667,9 @@ int fit_open_image(struct fit_handle *handle, void *configuration,
int data_len;
int ret = 0;
- ret = fit_get_image(handle, configuration, &unit, &image);
- if (ret)
- return ret;
+ image = fit_get_image(handle, configuration, &unit, idx);
+ if (!image)
+ return -ENOENT;
of_property_read_string(image, "description", &desc);
if (handle->verbose)
@@ -765,9 +761,11 @@ static int fit_fdt_is_compatible(struct fit_handle *handle,
if (!of_property_present(child, "fdt"))
return 0;
- ret = fit_get_image(handle, child, &unit, &image);
- if (ret)
+ image = fit_get_image(handle, child, &unit, 0);
+ if (!image) {
+ ret = -ENOENT;
goto err;
+ }
data = of_get_property(image, "data", &data_len);
if (!data)
@@ -1134,14 +1132,14 @@ static int fuzz_fit(const u8 *data, size_t size)
goto out;
}
- ret = fit_open_image(&handle, config, imgname, &outdata, &outsize);
+ ret = fit_open_image(&handle, config, imgname, 0, &outdata, &outsize);
if (ret)
goto out;
fit_get_image_address(&handle, config, imgname, "load", &addr);
fit_get_image_address(&handle, config, imgname, "entry", &addr);
- ret = fit_open_image(&handle, NULL, imgname, &outdata, &outsize);
+ ret = fit_open_image(&handle, NULL, imgname, 0, &outdata, &outsize);
out:
__fit_close(&handle);
diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c
index d2cf2fa3f371..b11edebd2080 100644
--- a/drivers/of/overlay.c
+++ b/drivers/of/overlay.c
@@ -487,7 +487,7 @@ static int of_overlay_apply_fit(struct device_node *root, struct fit_handle *fit
if (!of_overlay_matches_filter(name, NULL))
return 0;
- ret = fit_open_image(fit, config, "fdt", &ovl, &ovl_sz);
+ ret = fit_open_image(fit, config, "fdt", 0, &ovl, &ovl_sz);
if (ret)
return ret;
diff --git a/efi/payload/bootm.c b/efi/payload/bootm.c
index ea5b1265aeaa..8e7ba4561f3f 100644
--- a/efi/payload/bootm.c
+++ b/efi/payload/bootm.c
@@ -129,7 +129,7 @@ static int efi_load_ramdisk(struct image_data *data, void **initrd)
int ret;
if (ramdisk_is_fit(data)) {
- ret = fit_open_image(data->os_fit, data->fit_config, "ramdisk",
+ ret = fit_open_image(data->os_fit, data->fit_config, "ramdisk", 0,
(const void **)&initrd_mem, &initrd_size);
if (ret) {
pr_err("Cannot open ramdisk image in FIT image: %m\n");
@@ -175,7 +175,7 @@ static int efi_load_fdt(struct image_data *data, void **fdt)
int ret;
if (fdt_is_fit(data)) {
- ret = fit_open_image(data->os_fit, data->fit_config, "fdt",
+ ret = fit_open_image(data->os_fit, data->fit_config, "fdt", 0,
(const void **)&of_tree, &of_size);
if (ret) {
pr_err("Cannot open FDT image in FIT image: %m\n");
diff --git a/include/image-fit.h b/include/image-fit.h
index 31b8b54e272d..50f0482b65ad 100644
--- a/include/image-fit.h
+++ b/include/image-fit.h
@@ -60,8 +60,8 @@ static inline bool fit_has_image(struct fit_handle *handle, void *configuration,
}
int fit_open_image(struct fit_handle *handle, void *configuration,
- const char *name, const void **outdata,
- unsigned long *outsize);
+ const char *name, int idx,
+ const void **outdata, unsigned long *outsize);
int fit_get_image_address(struct fit_handle *handle, void *configuration,
const char *name, const char *property,
unsigned long *address);
--
2.47.3
next prev parent reply other threads:[~2026-01-27 8:46 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-27 8:39 [PATCH 00/15] bootm: prepare loadable abstraction rework Ahmad Fatoum
2026-01-27 8:39 ` [PATCH 01/15] FIT: implement fit_count_images Ahmad Fatoum
2026-01-27 8:39 ` Ahmad Fatoum [this message]
2026-01-27 8:39 ` [PATCH 03/15] resource: implement gap-aware lookup_region Ahmad Fatoum
2026-01-27 8:39 ` [PATCH 04/15] bootm: give bootm_load_ functions an end address Ahmad Fatoum
2026-01-27 15:31 ` Ahmad Fatoum
2026-01-30 13:35 ` Sascha Hauer
2026-01-27 8:39 ` [PATCH 05/15] bootm: store separate image_type and kernel_type Ahmad Fatoum
2026-01-27 8:39 ` [PATCH 06/15] bootm: cache os_file for appendroot purposes Ahmad Fatoum
2026-01-27 8:39 ` [PATCH 07/15] bootm: fit: move length calculation into fit_open Ahmad Fatoum
2026-01-27 8:39 ` [PATCH 08/15] libfile: factor out zero-page resistant read_file as __read_full_anywhere Ahmad Fatoum
2026-01-27 8:39 ` [PATCH 09/15] resource: implement resize_region Ahmad Fatoum
2026-01-30 12:38 ` Sascha Hauer
2026-01-27 8:39 ` [PATCH 10/15] bootm: rename image_data::os/initrd with _uimage suffix Ahmad Fatoum
2026-01-27 8:39 ` [PATCH 11/15] uimage: record original file name in uimage_handle Ahmad Fatoum
2026-01-27 8:39 ` [PATCH 12/15] bootm: factor out file detection into helper Ahmad Fatoum
2026-01-27 8:39 ` [PATCH 13/15] efi: payload: bootm: add dry run support Ahmad Fatoum
2026-01-27 8:39 ` [PATCH 14/15] efi: payload: bootm: fix memory corruption on initrd load error Ahmad Fatoum
2026-01-27 8:39 ` [PATCH 15/15] efi: initrd: make efi_initrd_register initrd pointer param const Ahmad Fatoum
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=20260127084546.3751357-3-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