mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 1/2] bbu: create a standard bbu handler for eMMC boot
Date: Thu,  8 Feb 2024 08:52:16 +0100	[thread overview]
Message-ID: <20240208075217.697668-1-s.hauer@pengutronix.de> (raw)

This adds a standard bbu handler to be used when an update is just
a matter of writing an image to the eMMC boot partitions.
As these may also want to set the BBU_FLAG_MMC_BOOT_ACK flag, it is
moved up one level to struct bbu_handler::flags to make it configurable
when struct bbu_data is not yet instantiated.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/mach-stm32mp/bbu.c |  2 +-
 common/bbu.c                | 38 ++++++++++++++++++++++++++++++++-----
 include/bbu.h               | 13 ++++++++++++-
 3 files changed, 46 insertions(+), 7 deletions(-)

diff --git a/arch/arm/mach-stm32mp/bbu.c b/arch/arm/mach-stm32mp/bbu.c
index 56fd4941d0..5d6d61db7d 100644
--- a/arch/arm/mach-stm32mp/bbu.c
+++ b/arch/arm/mach-stm32mp/bbu.c
@@ -129,7 +129,7 @@ static int stm32mp_bbu_mmc_fip_handler(struct bbu_handler *handler,
 
 	pr_debug("Handling %s\n", file_type_to_string(filetype));
 
-	data->flags |= BBU_FLAG_MMC_BOOT_ACK;
+	handler->flags |= BBU_HANDLER_FLAG_MMC_BOOT_ACK;
 
 	ret = bbu_mmcboot_handler(handler, data, stm32mp_bbu_mmc_update);
 	if (ret == -ENOENT) {
diff --git a/common/bbu.c b/common/bbu.c
index ed41c92f38..f08ce7e0d5 100644
--- a/common/bbu.c
+++ b/common/bbu.c
@@ -360,11 +360,7 @@ int bbu_mmcboot_handler(struct bbu_handler *handler, struct bbu_data *data,
 	if (ret < 0)
 		goto out;
 
-	/*
-	 * This flag can be set in the chained handler or by
-	 * bbu_mmcboot_handler's caller
-	 */
-	if ((_data.flags | data->flags) & BBU_FLAG_MMC_BOOT_ACK) {
+	if (handler->flags & BBU_HANDLER_FLAG_MMC_BOOT_ACK) {
 		ret = asprintf(&bootackvar, "%s.boot_ack", devname);
 		if (ret < 0)
 			goto out;
@@ -385,6 +381,38 @@ int bbu_mmcboot_handler(struct bbu_handler *handler, struct bbu_data *data,
 	return ret;
 }
 
+static int bbu_internal_mmcboot_update(struct bbu_handler *handler,
+				       struct bbu_data *data)
+{
+	int ret;
+
+	ret = bbu_mmcboot_handler(handler, data, bbu_std_file_handler);
+	if (ret == -ENOENT)
+		pr_err("Couldn't read the value of .boot parameter\n");
+
+	return ret;
+}
+
+int bbu_mmcboot_register_handler(const char *name,
+				 const char *devicefile,
+				 unsigned long flags)
+{
+	struct bbu_handler *handler;
+	int ret;
+
+	handler = xzalloc(sizeof(*handler));
+	handler->devicefile = devicefile;
+	handler->name = name;
+	handler->handler = bbu_internal_mmcboot_update;
+	handler->flags = flags;
+
+	ret = bbu_register_handler(handler);
+	if (ret)
+		free(handler);
+
+	return ret;
+}
+
 int bbu_std_file_handler(struct bbu_handler *handler,
 			 struct bbu_data *data)
 {
diff --git a/include/bbu.h b/include/bbu.h
index 0a4f324ade..5105d2ac70 100644
--- a/include/bbu.h
+++ b/include/bbu.h
@@ -10,7 +10,6 @@
 struct bbu_data {
 #define BBU_FLAG_FORCE	(1 << 0)
 #define BBU_FLAG_YES	(1 << 1)
-#define BBU_FLAG_MMC_BOOT_ACK	(1 << 2)
 	unsigned long flags;
 	int force;
 	const void *image;
@@ -27,6 +26,7 @@ struct bbu_handler {
 	struct list_head list;
 #define BBU_HANDLER_FLAG_DEFAULT	(1 << 0)
 #define BBU_HANDLER_CAN_REFRESH		(1 << 1)
+#define BBU_HANDLER_FLAG_MMC_BOOT_ACK	(1 << 16)
 	/*
 	 * The lower 16bit are generic flags, the upper 16bit are reserved
 	 * for handler specific flags.
@@ -66,6 +66,10 @@ int bbu_register_std_file_update(const char *name, unsigned long flags,
 
 void bbu_append_handlers_to_file_list(struct file_list *files);
 
+int bbu_mmcboot_register_handler(const char *name,
+				 const char *devicefile,
+				 unsigned long flags);
+
 #else
 
 static inline int bbu_register_handler(struct bbu_handler *unused)
@@ -84,6 +88,13 @@ static inline void bbu_append_handlers_to_file_list(struct file_list *files)
 	/* none could be registered, so nothing to do */
 }
 
+static inline int bbu_mmcboot_register_handler(const char *name,
+					       const char *devicefile,
+					       unsigned long flags)
+{
+	return -ENOSYS;
+}
+
 #endif
 
 #if defined(CONFIG_BAREBOX_UPDATE_IMX_NAND_FCB)
-- 
2.39.2




             reply	other threads:[~2024-02-08  7:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-08  7:52 Sascha Hauer [this message]
2024-02-08  7:52 ` [PATCH 2/2] ARM: i.MX: bbu: fix i.MX9 eMMC boot bbu handler Sascha Hauer
2024-02-09 12:34 ` [PATCH 1/2] bbu: create a standard bbu handler for eMMC boot Sascha Hauer

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=20240208075217.697668-1-s.hauer@pengutronix.de \
    --to=s.hauer@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