mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/3] bootm: allow custom struct image_handler::check_image callbacks
@ 2025-11-07 21:37 Ahmad Fatoum
  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
  0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2025-11-07 21:37 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

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




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-11-07 21:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-07 21:37 [PATCH 1/3] bootm: allow custom struct image_handler::check_image callbacks Ahmad Fatoum
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox