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 4/7] bbu: export bbu_std_file_handler for use in custom handlers
Date: Thu,  2 Jun 2022 11:01:30 +0200	[thread overview]
Message-ID: <20220602090133.3190450-5-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20220602090133.3190450-1-a.fatoum@pengutronix.de>

bbu_register_std_file_update() registers an update handler that updates
a single file, usually a partition. Depending on SoC, we may want to
compute the file path at install time. To save custom bbu code the
hassle of reimplementing bbu_std_file_handler(), export it.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/bbu.c  | 33 ++++++++++++++++++++-------------
 include/bbu.h |  3 +++
 2 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/common/bbu.c b/common/bbu.c
index 26b997c02ed1..d243ac89dd9f 100644
--- a/common/bbu.c
+++ b/common/bbu.c
@@ -371,23 +371,13 @@ out:
 	return ret;
 }
 
-static int bbu_std_file_handler(struct bbu_handler *handler,
-					struct bbu_data *data)
+int bbu_std_file_handler(struct bbu_handler *handler,
+			 struct bbu_data *data)
 {
-	struct bbu_std *std = container_of(handler, struct bbu_std, handler);
 	int fd, ret;
-	enum filetype filetype;
 	struct stat s;
 	unsigned oflags = O_WRONLY;
 
-	filetype = file_detect_type(data->image, data->len);
-	if (filetype != std->filetype) {
-		if (!bbu_force(data, "incorrect image type. Expected: %s, got %s",
-				file_type_to_string(std->filetype),
-				file_type_to_string(filetype)))
-			return -EINVAL;
-	}
-
 	device_detect_by_name(devpath_to_name(data->devicefile));
 
 	ret = stat(data->devicefile, &s);
@@ -436,6 +426,23 @@ err_close:
 	return ret;
 }
 
+static int bbu_std_file_handler_checked(struct bbu_handler *handler,
+					struct bbu_data *data)
+{
+	struct bbu_std *std = container_of(handler, struct bbu_std, handler);
+	enum filetype filetype;
+
+	filetype = file_detect_type(data->image, data->len);
+	if (filetype != std->filetype) {
+		if (!bbu_force(data, "incorrect image type. Expected: %s, got %s",
+				file_type_to_string(std->filetype),
+				file_type_to_string(filetype)))
+			return -EINVAL;
+	}
+
+	return bbu_std_file_handler(handler, data);
+}
+
 /**
  * bbu_register_std_file_update() - register a barebox update handler for a
  *                                  standard file-to-device-copy operation
@@ -466,7 +473,7 @@ int bbu_register_std_file_update(const char *name, unsigned long flags,
 	handler->flags = flags;
 	handler->devicefile = devicefile;
 	handler->name = name;
-	handler->handler = bbu_std_file_handler;
+	handler->handler = bbu_std_file_handler_checked;
 
 	ret = bbu_register_handler(handler);
 	if (ret)
diff --git a/include/bbu.h b/include/bbu.h
index bd19fa187faf..2dad26a12788 100644
--- a/include/bbu.h
+++ b/include/bbu.h
@@ -54,6 +54,9 @@ struct file_list;
 int bbu_mmcboot_handler(struct bbu_handler *, struct bbu_data *,
 			int (*chained_handler)(struct bbu_handler *, struct bbu_data *));
 
+int bbu_std_file_handler(struct bbu_handler *handler,
+			 struct bbu_data *data);
+
 #ifdef CONFIG_BAREBOX_UPDATE
 
 int bbu_register_handler(struct bbu_handler *);
-- 
2.30.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


  parent reply	other threads:[~2022-06-02  9:03 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-02  9:01 [PATCH 0/7] ARM: stm32mp: bbu: add FIP update handler Ahmad Fatoum
2022-06-02  9:01 ` [PATCH 1/7] bbu: move barebox_update eMMC boot handling into common code Ahmad Fatoum
2022-06-02  9:01 ` [PATCH 2/7] bbu: use free(NULL) to simplify function cleanup Ahmad Fatoum
2022-06-02  9:01 ` [PATCH 3/7] bbu: add flag for enabling eMMC boot ack Ahmad Fatoum
2022-06-02  9:01 ` Ahmad Fatoum [this message]
2022-06-02  9:01 ` [PATCH 5/7] filetype: differentiate between STM32MP FSBL and SSBL images Ahmad Fatoum
2022-06-02  9:01 ` [PATCH 6/7] ARM: stm32mp: bbu: add FIP update handler Ahmad Fatoum
2022-06-02  9:01 ` [PATCH 7/7] fastboot: support TF-A FSBL and FIP images for barebox update Ahmad Fatoum
2022-06-03  7:17 ` [PATCH 0/7] ARM: stm32mp: bbu: add FIP update handler 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=20220602090133.3190450-5-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