mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 01/15] FIT: implement fit_count_images
Date: Tue, 27 Jan 2026 09:39:11 +0100	[thread overview]
Message-ID: <20260127084546.3751357-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20260127084546.3751357-1-a.fatoum@pengutronix.de>

A FIT image can contain multiple images of the same type, e.g. a device
tree followed by overlays or multiple initrds.

To allow checking for that case, let's implement fit_count_images().

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/image-fit.c  | 12 ++++--------
 include/image-fit.h | 27 +++++++++++++++++++++++++--
 2 files changed, 29 insertions(+), 10 deletions(-)

diff --git a/common/image-fit.c b/common/image-fit.c
index 26bd8e265b25..85096aff31e6 100644
--- a/common/image-fit.c
+++ b/common/image-fit.c
@@ -495,19 +495,15 @@ static int fit_image_verify_signature(struct fit_handle *handle,
 	return ret;
 }
 
-bool fit_has_image(struct fit_handle *handle, void *configuration,
-		   const char *name)
+int fit_count_images(struct fit_handle *handle, void *configuration,
+		     const char *name)
 {
-	const char *unit;
 	struct device_node *conf_node = configuration;
 
 	if (!conf_node)
-		return false;
+		return -EINVAL;
 
-	if (of_property_read_string(conf_node, name, &unit))
-		return false;
-
-	return true;
+	return of_property_count_strings(conf_node, name);
 }
 
 static int fit_get_address(struct device_node *image, const char *property,
diff --git a/include/image-fit.h b/include/image-fit.h
index c332f77bd374..31b8b54e272d 100644
--- a/include/image-fit.h
+++ b/include/image-fit.h
@@ -34,8 +34,31 @@ struct fit_handle *fit_open_buf(const void *buf, size_t len, bool verbose,
 void *fit_open_configuration(struct fit_handle *handle, const char *name,
 			     bool (*match_valid)(struct fit_handle *handle,
 						 struct device_node *config));
-bool fit_has_image(struct fit_handle *handle, void *configuration,
-		   const char *name);
+/**
+ * fit_count_images() - count images of a given type in a FIT configuration
+ * @handle: FIT handle as returned by fit_open() or fit_open_buf()
+ * @configuration: configuration node as returned by fit_open_configuration()
+ * @name: image type property name (e.g., "kernel", "fdt", "ramdisk")
+ *
+ * Return: number of images on success, negative error code on failure
+ */
+int fit_count_images(struct fit_handle *handle, void *configuration,
+		     const char *name);
+
+/**
+ * fit_has_image() - check if a FIT configuration contains an image type
+ * @handle: FIT handle as returned by fit_open() or fit_open_buf()
+ * @configuration: configuration node as returned by fit_open_configuration()
+ * @name: image type property name (e.g., "kernel", "fdt", "ramdisk")
+ *
+ * Return: true if at least one image of the given type exists, false otherwise
+ */
+static inline bool fit_has_image(struct fit_handle *handle, void *configuration,
+				 const char *name)
+{
+	return fit_count_images(handle, configuration, name) > 0;
+}
+
 int fit_open_image(struct fit_handle *handle, void *configuration,
 		   const char *name, const void **outdata,
 		   unsigned long *outsize);
-- 
2.47.3




  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 ` Ahmad Fatoum [this message]
2026-01-27  8:39 ` [PATCH 02/15] FIT: add image index argument to fit_open_image Ahmad Fatoum
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-2-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