Message ID | 20221214165126.1.I8d5c1748a43a5bba6c8470c6a3715d2c9143014a@changeid |
---|---|
State | Accepted |
Commit | 91fc785834194c7cf2f686a8861a67154e56e817 |
Delegated to: | Tom Rini |
Headers | show |
Series | [1/2] env: ubi: add support of command env erase | expand |
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
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), > }; >
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!
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), };
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(+)