mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: Sohaib Mohamed <sohaib.amhmd@gmail.com>,
	Sascha Hauer <s.hauer@pengutronix.de>,
	BAREBOX <barebox@lists.infradead.org>
Subject: Re: [PATCH 1/3] common: bbu: refactor flash operations into separate function
Date: Fri, 28 Nov 2025 10:35:44 +0100	[thread overview]
Message-ID: <d9e0dfea-6f2b-44dc-9feb-b552f12a5c90@pengutronix.de> (raw)
In-Reply-To: <20251128-avenger96-v1-1-009b13bd8df7@gmail.com>

On 11/28/25 1:51 AM, Sohaib Mohamed wrote:
> 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>

Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>

> ---
>  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);
> 

-- 
Pengutronix e.K.                  |                             |
Steuerwalder Str. 21              | http://www.pengutronix.de/  |
31137 Hildesheim, Germany         | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686  | Fax:   +49-5121-206917-5555 |




  reply	other threads:[~2025-11-28  9:36 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 ` [PATCH 1/3] common: bbu: refactor flash operations into separate function Sohaib Mohamed
2025-11-28  9:35   ` Ahmad Fatoum [this message]
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=d9e0dfea-6f2b-44dc-9feb-b552f12a5c90@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=s.hauer@pengutronix.de \
    --cc=sohaib.amhmd@gmail.com \
    /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