[PATCH 1/2] bbu: create a standard bbu handler for eMMC boot
Sascha Hauer
s.hauer at pengutronix.de
Wed Feb 7 23:52:16 PST 2024
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 at 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
More information about the barebox
mailing list