All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] env: ubi: add support of command env erase
@ 2022-12-14 15:51 Patrick Delaunay
  2022-12-14 15:51 ` [PATCH 2/2] env: add failing trace in env_erase Patrick Delaunay
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Patrick Delaunay @ 2022-12-14 15:51 UTC (permalink / raw)
  To: u-boot
  Cc: Patrick Delaunay, Heiko Schocher, Joe Hershberger, Wolfgang Denk,
	U-Boot STM32

Add support of opts erase for ubi env backend, this opts is used by
command 'env erase'.

This command only zero-fill the env UBI volume CONFIG_ENV_UBI_VOLUME
and CONFIG_ENV_UBI_VOLUME_REDUND, so the saved environment becomes
invalid.

This patch introduces a local define ENV_UBI_VOLUME_REDUND
only to avoid #if in the code, as CONFIG_ENV_UBI_VOLUME_REDUND
is only defined when CONFIG_SYS_REDUNDAND_ENVIRONMENT is defined.

Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
---

 env/ubi.c | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/env/ubi.c b/env/ubi.c
index eb21c4f38b49..445d34fedb89 100644
--- a/env/ubi.c
+++ b/env/ubi.c
@@ -28,6 +28,12 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
+#if CONFIG_SYS_REDUNDAND_ENVIRONMENT
+#define ENV_UBI_VOLUME_REDUND CONFIG_ENV_UBI_VOLUME_REDUND
+#else
+#define ENV_UBI_VOLUME_REDUND "invalid"
+#endif
+
 #ifdef CONFIG_CMD_SAVEENV
 #ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT
 static int env_ubi_save(void)
@@ -177,9 +183,43 @@ static int env_ubi_load(void)
 }
 #endif /* CONFIG_SYS_REDUNDAND_ENVIRONMENT */
 
+static int env_ubi_erase(void)
+{
+	ALLOC_CACHE_ALIGN_BUFFER(char, env_buf, CONFIG_ENV_SIZE);
+	int ret = 0;
+
+	if (ubi_part(CONFIG_ENV_UBI_PART, UBI_VID_OFFSET)) {
+		printf("\n** Cannot find mtd partition \"%s\"\n",
+		       CONFIG_ENV_UBI_PART);
+		return 1;
+	}
+
+	memset(env_buf, 0x0, CONFIG_ENV_SIZE);
+
+	if (ubi_volume_write(CONFIG_ENV_UBI_VOLUME,
+			     (void *)env_buf, CONFIG_ENV_SIZE)) {
+		printf("\n** Unable to erase env to %s:%s **\n",
+		       CONFIG_ENV_UBI_PART,
+		       CONFIG_ENV_UBI_VOLUME);
+		ret = 1;
+	}
+	if (IS_ENABLED(CONFIG_SYS_REDUNDAND_ENVIRONMENT)) {
+		if (ubi_volume_write(ENV_UBI_VOLUME_REDUND,
+				     (void *)env_buf, CONFIG_ENV_SIZE)) {
+			printf("\n** Unable to erase env to %s:%s **\n",
+			       CONFIG_ENV_UBI_PART,
+			       ENV_UBI_VOLUME_REDUND);
+			ret = 1;
+		}
+	}
+
+	return ret;
+}
+
 U_BOOT_ENV_LOCATION(ubi) = {
 	.location	= ENVL_UBI,
 	ENV_NAME("UBI")
 	.load		= env_ubi_load,
 	.save		= env_save_ptr(env_ubi_save),
+	.erase		= ENV_ERASE_PTR(env_ubi_erase),
 };
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/2] env: add failing trace in env_erase
  2022-12-14 15:51 [PATCH 1/2] env: ubi: add support of command env erase Patrick Delaunay
@ 2022-12-14 15:51 ` Patrick Delaunay
  2023-01-03 13:13   ` [Uboot-stm32] " Patrice CHOTARD
                     ` (2 more replies)
  2023-01-03 13:13 ` [Uboot-stm32] [PATCH 1/2] env: ubi: add support of command env erase Patrice CHOTARD
                   ` (2 subsequent siblings)
  3 siblings, 3 replies; 8+ messages in thread
From: Patrick Delaunay @ 2022-12-14 15:51 UTC (permalink / raw)
  To: u-boot
  Cc: Patrick Delaunay, Patrick Delaunay, Joe Hershberger,
	Wolfgang Denk, U-Boot STM32

Add trace in env save to indicate any errors to end user and avoid
silent output when the command 'env erase' is not executed as it is
done in env_save with commit 8968288cb477 ("env: add failing trace in
env_save")

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
---

 env/env.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/env/env.c b/env/env.c
index 69848fb06080..06078c7f3744 100644
--- a/env/env.c
+++ b/env/env.c
@@ -311,11 +311,15 @@ int env_erase(void)
 	if (drv) {
 		int ret;
 
-		if (!drv->erase)
+		if (!drv->erase) {
+			printf("not possible\n");
 			return -ENODEV;
+		}
 
-		if (!env_has_inited(drv->location))
+		if (!env_has_inited(drv->location)) {
+			printf("not initialized\n");
 			return -ENODEV;
+		}
 
 		printf("Erasing Environment on %s... ", drv->name);
 		ret = drv->erase();
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [Uboot-stm32] [PATCH 1/2] env: ubi: add support of command env erase
  2022-12-14 15:51 [PATCH 1/2] env: ubi: add support of command env erase Patrick Delaunay
  2022-12-14 15:51 ` [PATCH 2/2] env: add failing trace in env_erase Patrick Delaunay
@ 2023-01-03 13:13 ` Patrice CHOTARD
  2023-01-11 11:01 ` Heiko Schocher
  2023-01-12 15:18 ` Tom Rini
  3 siblings, 0 replies; 8+ messages in thread
From: Patrice CHOTARD @ 2023-01-03 13:13 UTC (permalink / raw)
  To: Patrick Delaunay, u-boot
  Cc: Joe Hershberger, U-Boot STM32, Heiko Schocher, Wolfgang Denk

Hi Patrick

On 12/14/22 16:51, Patrick Delaunay wrote:
> Add support of opts erase for ubi env backend, this opts is used by
> command 'env erase'.
> 
> This command only zero-fill the env UBI volume CONFIG_ENV_UBI_VOLUME
> and CONFIG_ENV_UBI_VOLUME_REDUND, so the saved environment becomes
> invalid.
> 
> This patch introduces a local define ENV_UBI_VOLUME_REDUND
> only to avoid #if in the code, as CONFIG_ENV_UBI_VOLUME_REDUND
> is only defined when CONFIG_SYS_REDUNDAND_ENVIRONMENT is defined.
> 
> Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
> ---
> 
>  env/ubi.c | 40 ++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 40 insertions(+)
> 
> diff --git a/env/ubi.c b/env/ubi.c
> index eb21c4f38b49..445d34fedb89 100644
> --- a/env/ubi.c
> +++ b/env/ubi.c
> @@ -28,6 +28,12 @@
>  
>  DECLARE_GLOBAL_DATA_PTR;
>  
> +#if CONFIG_SYS_REDUNDAND_ENVIRONMENT
> +#define ENV_UBI_VOLUME_REDUND CONFIG_ENV_UBI_VOLUME_REDUND
> +#else
> +#define ENV_UBI_VOLUME_REDUND "invalid"
> +#endif
> +
>  #ifdef CONFIG_CMD_SAVEENV
>  #ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT
>  static int env_ubi_save(void)
> @@ -177,9 +183,43 @@ static int env_ubi_load(void)
>  }
>  #endif /* CONFIG_SYS_REDUNDAND_ENVIRONMENT */
>  
> +static int env_ubi_erase(void)
> +{
> +	ALLOC_CACHE_ALIGN_BUFFER(char, env_buf, CONFIG_ENV_SIZE);
> +	int ret = 0;
> +
> +	if (ubi_part(CONFIG_ENV_UBI_PART, UBI_VID_OFFSET)) {
> +		printf("\n** Cannot find mtd partition \"%s\"\n",
> +		       CONFIG_ENV_UBI_PART);
> +		return 1;
> +	}
> +
> +	memset(env_buf, 0x0, CONFIG_ENV_SIZE);
> +
> +	if (ubi_volume_write(CONFIG_ENV_UBI_VOLUME,
> +			     (void *)env_buf, CONFIG_ENV_SIZE)) {
> +		printf("\n** Unable to erase env to %s:%s **\n",
> +		       CONFIG_ENV_UBI_PART,
> +		       CONFIG_ENV_UBI_VOLUME);
> +		ret = 1;
> +	}
> +	if (IS_ENABLED(CONFIG_SYS_REDUNDAND_ENVIRONMENT)) {
> +		if (ubi_volume_write(ENV_UBI_VOLUME_REDUND,
> +				     (void *)env_buf, CONFIG_ENV_SIZE)) {
> +			printf("\n** Unable to erase env to %s:%s **\n",
> +			       CONFIG_ENV_UBI_PART,
> +			       ENV_UBI_VOLUME_REDUND);
> +			ret = 1;
> +		}
> +	}
> +
> +	return ret;
> +}
> +
>  U_BOOT_ENV_LOCATION(ubi) = {
>  	.location	= ENVL_UBI,
>  	ENV_NAME("UBI")
>  	.load		= env_ubi_load,
>  	.save		= env_save_ptr(env_ubi_save),
> +	.erase		= ENV_ERASE_PTR(env_ubi_erase),
>  };

Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>

Thanks
Patrice

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Uboot-stm32] [PATCH 2/2] env: add failing trace in env_erase
  2022-12-14 15:51 ` [PATCH 2/2] env: add failing trace in env_erase Patrick Delaunay
@ 2023-01-03 13:13   ` Patrice CHOTARD
  2023-01-11 11:04   ` Heiko Schocher
  2023-01-12 15:18   ` Tom Rini
  2 siblings, 0 replies; 8+ messages in thread
From: Patrice CHOTARD @ 2023-01-03 13:13 UTC (permalink / raw)
  To: Patrick Delaunay, u-boot
  Cc: Joe Hershberger, U-Boot STM32, Wolfgang Denk, Patrick Delaunay

Hi Patrick

On 12/14/22 16:51, Patrick Delaunay wrote:
> Add trace in env save to indicate any errors to end user and avoid
> silent output when the command 'env erase' is not executed as it is
> done in env_save with commit 8968288cb477 ("env: add failing trace in
> env_save")
> 
> Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
> Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
> ---
> 
>  env/env.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/env/env.c b/env/env.c
> index 69848fb06080..06078c7f3744 100644
> --- a/env/env.c
> +++ b/env/env.c
> @@ -311,11 +311,15 @@ int env_erase(void)
>  	if (drv) {
>  		int ret;
>  
> -		if (!drv->erase)
> +		if (!drv->erase) {
> +			printf("not possible\n");
>  			return -ENODEV;
> +		}
>  
> -		if (!env_has_inited(drv->location))
> +		if (!env_has_inited(drv->location)) {
> +			printf("not initialized\n");
>  			return -ENODEV;
> +		}
>  
>  		printf("Erasing Environment on %s... ", drv->name);
>  		ret = drv->erase();
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>

Thanks
Patrice

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/2] env: ubi: add support of command env erase
  2022-12-14 15:51 [PATCH 1/2] env: ubi: add support of command env erase Patrick Delaunay
  2022-12-14 15:51 ` [PATCH 2/2] env: add failing trace in env_erase Patrick Delaunay
  2023-01-03 13:13 ` [Uboot-stm32] [PATCH 1/2] env: ubi: add support of command env erase Patrice CHOTARD
@ 2023-01-11 11:01 ` Heiko Schocher
  2023-01-12 15:18 ` Tom Rini
  3 siblings, 0 replies; 8+ messages in thread
From: Heiko Schocher @ 2023-01-11 11:01 UTC (permalink / raw)
  To: Patrick Delaunay, u-boot; +Cc: Joe Hershberger, Wolfgang Denk, U-Boot STM32

Hello Patrick,

On 14.12.22 16:51, Patrick Delaunay wrote:
> Add support of opts erase for ubi env backend, this opts is used by
> command 'env erase'.
> 
> This command only zero-fill the env UBI volume CONFIG_ENV_UBI_VOLUME
> and CONFIG_ENV_UBI_VOLUME_REDUND, so the saved environment becomes
> invalid.
> 
> This patch introduces a local define ENV_UBI_VOLUME_REDUND
> only to avoid #if in the code, as CONFIG_ENV_UBI_VOLUME_REDUND
> is only defined when CONFIG_SYS_REDUNDAND_ENVIRONMENT is defined.
> 
> Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
> ---
> 
>  env/ubi.c | 40 ++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 40 insertions(+)

Reviewed-by: Heiko Schocher <hs@denx.de>

bye,
Heiko
> 
> diff --git a/env/ubi.c b/env/ubi.c
> index eb21c4f38b49..445d34fedb89 100644
> --- a/env/ubi.c
> +++ b/env/ubi.c
> @@ -28,6 +28,12 @@
>  
>  DECLARE_GLOBAL_DATA_PTR;
>  
> +#if CONFIG_SYS_REDUNDAND_ENVIRONMENT
> +#define ENV_UBI_VOLUME_REDUND CONFIG_ENV_UBI_VOLUME_REDUND
> +#else
> +#define ENV_UBI_VOLUME_REDUND "invalid"
> +#endif
> +
>  #ifdef CONFIG_CMD_SAVEENV
>  #ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT
>  static int env_ubi_save(void)
> @@ -177,9 +183,43 @@ static int env_ubi_load(void)
>  }
>  #endif /* CONFIG_SYS_REDUNDAND_ENVIRONMENT */
>  
> +static int env_ubi_erase(void)
> +{
> +	ALLOC_CACHE_ALIGN_BUFFER(char, env_buf, CONFIG_ENV_SIZE);
> +	int ret = 0;
> +
> +	if (ubi_part(CONFIG_ENV_UBI_PART, UBI_VID_OFFSET)) {
> +		printf("\n** Cannot find mtd partition \"%s\"\n",
> +		       CONFIG_ENV_UBI_PART);
> +		return 1;
> +	}
> +
> +	memset(env_buf, 0x0, CONFIG_ENV_SIZE);
> +
> +	if (ubi_volume_write(CONFIG_ENV_UBI_VOLUME,
> +			     (void *)env_buf, CONFIG_ENV_SIZE)) {
> +		printf("\n** Unable to erase env to %s:%s **\n",
> +		       CONFIG_ENV_UBI_PART,
> +		       CONFIG_ENV_UBI_VOLUME);
> +		ret = 1;
> +	}
> +	if (IS_ENABLED(CONFIG_SYS_REDUNDAND_ENVIRONMENT)) {
> +		if (ubi_volume_write(ENV_UBI_VOLUME_REDUND,
> +				     (void *)env_buf, CONFIG_ENV_SIZE)) {
> +			printf("\n** Unable to erase env to %s:%s **\n",
> +			       CONFIG_ENV_UBI_PART,
> +			       ENV_UBI_VOLUME_REDUND);
> +			ret = 1;
> +		}
> +	}
> +
> +	return ret;
> +}
> +
>  U_BOOT_ENV_LOCATION(ubi) = {
>  	.location	= ENVL_UBI,
>  	ENV_NAME("UBI")
>  	.load		= env_ubi_load,
>  	.save		= env_save_ptr(env_ubi_save),
> +	.erase		= ENV_ERASE_PTR(env_ubi_erase),
>  };
> 

-- 
DENX Software Engineering GmbH,      Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: hs@denx.de

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] env: add failing trace in env_erase
  2022-12-14 15:51 ` [PATCH 2/2] env: add failing trace in env_erase Patrick Delaunay
  2023-01-03 13:13   ` [Uboot-stm32] " Patrice CHOTARD
@ 2023-01-11 11:04   ` Heiko Schocher
  2023-01-12 15:18   ` Tom Rini
  2 siblings, 0 replies; 8+ messages in thread
From: Heiko Schocher @ 2023-01-11 11:04 UTC (permalink / raw)
  To: Patrick Delaunay, u-boot
  Cc: Patrick Delaunay, Joe Hershberger, Wolfgang Denk, U-Boot STM32

Hello Patrick,

On 14.12.22 16:51, Patrick Delaunay wrote:
> Add trace in env save to indicate any errors to end user and avoid
> silent output when the command 'env erase' is not executed as it is
> done in env_save with commit 8968288cb477 ("env: add failing trace in
> env_save")
> 
> Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
> Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
> Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
> ---
> 
>  env/env.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)

Reviewed-by: Heiko Schocher <hs@denx.de>

bye,
Heiko

-- 
DENX Software Engineering GmbH,      Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: hs@denx.de

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/2] env: ubi: add support of command env erase
  2022-12-14 15:51 [PATCH 1/2] env: ubi: add support of command env erase Patrick Delaunay
                   ` (2 preceding siblings ...)
  2023-01-11 11:01 ` Heiko Schocher
@ 2023-01-12 15:18 ` Tom Rini
  3 siblings, 0 replies; 8+ messages in thread
From: Tom Rini @ 2023-01-12 15:18 UTC (permalink / raw)
  To: Patrick Delaunay
  Cc: u-boot, Heiko Schocher, Joe Hershberger, Wolfgang Denk, U-Boot STM32

[-- Attachment #1: Type: text/plain, Size: 748 bytes --]

On Wed, Dec 14, 2022 at 04:51:31PM +0100, Patrick Delaunay wrote:

> Add support of opts erase for ubi env backend, this opts is used by
> command 'env erase'.
> 
> This command only zero-fill the env UBI volume CONFIG_ENV_UBI_VOLUME
> and CONFIG_ENV_UBI_VOLUME_REDUND, so the saved environment becomes
> invalid.
> 
> This patch introduces a local define ENV_UBI_VOLUME_REDUND
> only to avoid #if in the code, as CONFIG_ENV_UBI_VOLUME_REDUND
> is only defined when CONFIG_SYS_REDUNDAND_ENVIRONMENT is defined.
> 
> Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
> Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
> Reviewed-by: Heiko Schocher <hs@denx.de>

Applied to u-boot/master, thanks!

-- 
Tom

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] env: add failing trace in env_erase
  2022-12-14 15:51 ` [PATCH 2/2] env: add failing trace in env_erase Patrick Delaunay
  2023-01-03 13:13   ` [Uboot-stm32] " Patrice CHOTARD
  2023-01-11 11:04   ` Heiko Schocher
@ 2023-01-12 15:18   ` Tom Rini
  2 siblings, 0 replies; 8+ messages in thread
From: Tom Rini @ 2023-01-12 15:18 UTC (permalink / raw)
  To: Patrick Delaunay
  Cc: u-boot, Patrick Delaunay, Joe Hershberger, Wolfgang Denk, U-Boot STM32

[-- Attachment #1: Type: text/plain, Size: 583 bytes --]

On Wed, Dec 14, 2022 at 04:51:32PM +0100, Patrick Delaunay wrote:

> Add trace in env save to indicate any errors to end user and avoid
> silent output when the command 'env erase' is not executed as it is
> done in env_save with commit 8968288cb477 ("env: add failing trace in
> env_save")
> 
> Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
> Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
> Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
> Reviewed-by: Heiko Schocher <hs@denx.de>

Applied to u-boot/master, thanks!

-- 
Tom

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-01-12 15:19 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-14 15:51 [PATCH 1/2] env: ubi: add support of command env erase Patrick Delaunay
2022-12-14 15:51 ` [PATCH 2/2] env: add failing trace in env_erase Patrick Delaunay
2023-01-03 13:13   ` [Uboot-stm32] " Patrice CHOTARD
2023-01-11 11:04   ` Heiko Schocher
2023-01-12 15:18   ` Tom Rini
2023-01-03 13:13 ` [Uboot-stm32] [PATCH 1/2] env: ubi: add support of command env erase Patrice CHOTARD
2023-01-11 11:01 ` Heiko Schocher
2023-01-12 15:18 ` Tom Rini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.