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 1/3] bootm: allow custom struct image_handler::check_image callbacks
Date: Fri,  7 Nov 2025 22:37:47 +0100	[thread overview]
Message-ID: <20251107213752.3547508-1-a.fatoum@pengutronix.de> (raw)

uImage support used to be very intertwined with the bootm code. This
changed now, but we still have uImage specific logic in
bootm_find_handler().

Instead of push more image format specific logic into
bootm_find_handler(), let's allow bootm handlers to specify a "full
custom" check by means of a check_image callback.

To keep changes elsewhere to a minimum, we keep the uImage logic
installed in common code, but inside register_image_handler() for now.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/bootm.c  | 30 ++++++++++++++++++++++++------
 include/bootm.h |  3 +++
 2 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/common/bootm.c b/common/bootm.c
index 17792b2a1d81..298a193e3f62 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -23,10 +23,32 @@ static struct sconfig_notifier_block sconfig_notifier;
 
 static __maybe_unused struct bootm_overrides bootm_overrides;
 
+static bool uimage_check(struct image_handler *handler,
+			 struct image_data *data,
+			 enum filetype detected_filetype)
+{
+	return detected_filetype == filetype_uimage &&
+		handler->ih_os == data->os->header.ih_os;
+}
+
+static bool filetype_check(struct image_handler *handler,
+			   struct image_data *data,
+			   enum filetype detected_filetype)
+{
+	return handler->filetype == detected_filetype;
+}
+
 int register_image_handler(struct image_handler *handler)
 {
-	list_add_tail(&handler->list, &handler_list);
+	if (!handler->check_image) {
+		if (IS_ENABLED(CONFIG_BOOTM_UIMAGE) &&
+		    handler->filetype == filetype_uimage)
+			handler->check_image = uimage_check;
+		else
+			handler->check_image = filetype_check;
+	}
 
+	list_add_tail(&handler->list, &handler_list);
 	return 0;
 }
 
@@ -36,11 +58,7 @@ static struct image_handler *bootm_find_handler(enum filetype filetype,
 	struct image_handler *handler;
 
 	list_for_each_entry(handler, &handler_list, list) {
-		if (filetype != filetype_uimage &&
-				handler->filetype == filetype)
-			return handler;
-		if  (filetype == filetype_uimage &&
-				handler->ih_os == data->os->header.ih_os)
+		if (handler->check_image(handler, data, filetype))
 			return handler;
 	}
 
diff --git a/include/bootm.h b/include/bootm.h
index b35deb25bf8f..bed0263b2eec 100644
--- a/include/bootm.h
+++ b/include/bootm.h
@@ -117,6 +117,9 @@ struct image_handler {
 	int ih_os;
 
 	enum filetype filetype;
+	bool (*check_image)(struct image_handler *handler,
+			    struct image_data *data,
+			    enum filetype detected_filetype);
 	int (*bootm)(struct image_data *data);
 };
 
-- 
2.47.3




             reply	other threads:[~2025-11-07 21:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-07 21:37 Ahmad Fatoum [this message]
2025-11-07 21:37 ` [PATCH 2/3] efi: payload: bootm: allow compiling without FIT support Ahmad Fatoum
2025-11-07 21:37 ` [PATCH 3/3] efi: payload: x86: make handover vs startimage a runtime decision 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=20251107213752.3547508-1-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