mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sohaib Mohamed <sohaib.amhmd@gmail.com>
To: Sascha Hauer <s.hauer@pengutronix.de>,
	 BAREBOX <barebox@lists.infradead.org>
Cc: Sohaib Mohamed <sohaib.amhmd@gmail.com>
Subject: [PATCH 1/3] common: bbu: refactor flash operations into separate function
Date: Fri, 28 Nov 2025 01:51:17 +0100	[thread overview]
Message-ID: <20251128-avenger96-v1-1-009b13bd8df7@gmail.com> (raw)
In-Reply-To: <20251128-avenger96-v1-0-009b13bd8df7@gmail.com>

Extract flash logic (protect, erase, write) from bbu_std_file_handler()
into a new flash() function that accepts an offset parameter, so it can
be used from further barebox update handlers as well.

Signed-off-by: Sohaib Mohamed <sohaib.amhmd@gmail.com>
---
 common/bbu.c  | 17 +++++++++++------
 include/bbu.h |  2 ++
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/common/bbu.c b/common/bbu.c
index 03261583fe..39db87e823 100644
--- a/common/bbu.c
+++ b/common/bbu.c
@@ -431,8 +431,7 @@ int bbu_mmcboot_register_handler(const char *name,
 	return ret;
 }
 
-int bbu_std_file_handler(struct bbu_handler *handler,
-			 struct bbu_data *data)
+int bbu_flash(struct bbu_data *data, loff_t offset)
 {
 	int fd, ret;
 	struct stat s;
@@ -458,25 +457,25 @@ int bbu_std_file_handler(struct bbu_handler *handler,
 	if (fd < 0)
 		return fd;
 
-	ret = protect(fd, data->len, 0, 0);
+	ret = protect(fd, data->len, offset, 0);
 	if (ret && (ret != -ENOSYS) && (ret != -ENOTSUPP)) {
 		printf("unprotecting %s failed with %pe\n", data->devicefile,
 				ERR_PTR(ret));
 		goto err_close;
 	}
 
-	ret = erase(fd, data->len, 0, ERASE_TO_WRITE);
+	ret = erase(fd, data->len, offset, ERASE_TO_WRITE);
 	if (ret && ret != -ENOSYS) {
 		printf("erasing %s failed with %pe\n", data->devicefile,
 				ERR_PTR(ret));
 		goto err_close;
 	}
 
-	ret = write_full(fd, data->image, data->len);
+	ret = pwrite_full(fd, data->image, data->len, offset);
 	if (ret < 0)
 		goto err_close;
 
-	protect(fd, data->len, 0, 1);
+	protect(fd, data->len, offset, 1);
 
 	ret = 0;
 
@@ -486,6 +485,12 @@ int bbu_std_file_handler(struct bbu_handler *handler,
 	return ret;
 }
 
+int bbu_std_file_handler(struct bbu_handler *handler,
+			 struct bbu_data *data)
+{
+	return bbu_flash(data, 0);
+}
+
 static int bbu_std_file_handler_checked(struct bbu_handler *handler,
 					struct bbu_data *data)
 {
diff --git a/include/bbu.h b/include/bbu.h
index 94006563c9..f5b74b32ac 100644
--- a/include/bbu.h
+++ b/include/bbu.h
@@ -56,6 +56,8 @@ int bbu_mmcboot_handler(struct bbu_handler *, struct bbu_data *,
 int bbu_std_file_handler(struct bbu_handler *handler,
 			 struct bbu_data *data);
 
+int bbu_flash(struct bbu_data *data, loff_t offset);
+
 #ifdef CONFIG_BAREBOX_UPDATE
 
 bool bbu_handlers_available(void);

-- 
2.43.0




  reply	other threads:[~2025-11-28  0:52 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-28  0:51 [PATCH 0/3] ARM: stm32mp: Add Avenger96 board support Sohaib Mohamed
2025-11-28  0:51 ` Sohaib Mohamed [this message]
2025-11-28  9:35   ` [PATCH 1/3] common: bbu: refactor flash operations into separate function Ahmad Fatoum
2025-11-28  0:51 ` [PATCH 2/3] ARM: stm32mp: bbu: add NOR flash FIP update handler Sohaib Mohamed
2025-11-28  9:39   ` Ahmad Fatoum
2025-12-01 10:38   ` Sascha Hauer
2025-11-28  0:51 ` [PATCH 3/3] ARM: stm32mp: add support for STM32MP157A Avenger96 board Sohaib Mohamed
2025-11-28  9:40   ` 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=20251128-avenger96-v1-1-009b13bd8df7@gmail.com \
    --to=sohaib.amhmd@gmail.com \
    --cc=barebox@lists.infradead.org \
    --cc=s.hauer@pengutronix.de \
    /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