public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v4 1/4] env: register erase command
Date: Mon, 24 Jun 2019 21:26:09 +0200	[thread overview]
Message-ID: <8d1509b7-d2dd-6f58-b8aa-4d454b71e3d4@gmail.com> (raw)
In-Reply-To: <20190428085128.8479-2-frank-w@public-files.de>

Am 28.04.2019 um 10:51 schrieb Frank Wunderlich:
> this patch adds basic changes for adding a erase-subcommand to env
> 
> with this command the environment stored on non-volatile storage written
> by saveenv can be cleared.
> 
> Signed-off-by: Frank Wunderlich <frank-w@public-files.de>

Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>

However, due to changes, this doesn't apply any more, so a v5 is needed.

Regards,
Simon

> 
> squashed fixes
>   - start message with "Erasing"
>   - mark erase-function as optional
>   - env: separate eraseenv from saveenv
> 
> Suggested-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
> =2D--
>   cmd/Kconfig           |  8 ++++++++
>   cmd/nvedit.c          | 19 +++++++++++++++++++
>   env/env.c             | 30 ++++++++++++++++++++++++++++++
>   include/environment.h | 17 +++++++++++++++++
>   4 files changed, 74 insertions(+)
> 
> diff --git a/cmd/Kconfig b/cmd/Kconfig
> index 0b07b3b9d7..e8a99cb5a3 100644
> =2D-- a/cmd/Kconfig
> +++ b/cmd/Kconfig
> @@ -397,6 +397,14 @@ config CMD_SAVEENV
>   	  Save all environment variables into the compiled-in persistent
>   	  storage.
> 
> +config CMD_ERASEENV
> +	bool "eraseenv"
> +	default n
> +	depends on CMD_SAVEENV
> +	help
> +	  Erase environment variables from the compiled-in persistent
> +	  storage.
> +
>   config CMD_ENV_EXISTS
>   	bool "env exists"
>   	default y
> diff --git a/cmd/nvedit.c b/cmd/nvedit.c
> index 24a6cf7824..0cbd8e8984 100644
> =2D-- a/cmd/nvedit.c
> +++ b/cmd/nvedit.c
> @@ -761,6 +761,19 @@ U_BOOT_CMD(
>   	"save environment variables to persistent storage",
>   	""
>   );
> +
> +#if defined(CONFIG_CMD_ERASEENV)
> +static int do_env_erase(cmd_tbl_t *cmdtp, int flag, int argc,
> +			char * const argv[])
> +{
> +	return env_erase() ? 1 : 0;
> +}
> +U_BOOT_CMD(
> +	eraseenv, 1, 0,	do_env_erase,
> +	"erase environment variables from persistent storage",
> +	""
> +);
> +#endif
>   #endif
>   #endif /* CONFIG_SPL_BUILD */
> 
> @@ -1207,6 +1220,9 @@ static cmd_tbl_t cmd_env_sub[] =3D {
>   #endif
>   #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
>   	U_BOOT_CMD_MKENT(save, 1, 0, do_env_save, "", ""),
> +#if defined(CONFIG_CMD_ERASEENV)
> +	U_BOOT_CMD_MKENT(erase, 1, 0, do_env_erase, "", ""),
> +#endif
>   #endif
>   	U_BOOT_CMD_MKENT(set, CONFIG_SYS_MAXARGS, 0, do_env_set, "", ""),
>   #if defined(CONFIG_CMD_ENV_EXISTS)
> @@ -1282,6 +1298,9 @@ static char env_help_text[] =3D
>   #endif
>   #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
>   	"env save - save environment\n"
> +#if defined(CONFIG_CMD_ERASEENV)
> +	"env erase - erase environment\n"
> +#endif
>   #endif
>   #if defined(CONFIG_CMD_NVEDIT_EFI)
>   	"env set -e name [arg ...] - set UEFI variable; unset if 'arg' not speci=
> fied\n"
> diff --git a/env/env.c b/env/env.c
> index 4b417b90a2..d3cbe2f915 100644
> =2D-- a/env/env.c
> +++ b/env/env.c
> @@ -24,6 +24,8 @@ void env_fix_drivers(void)
>   			entry->load +=3D gd->reloc_off;
>   		if (entry->save)
>   			entry->save +=3D gd->reloc_off;
> +		if (entry->erase)
> +			entry->erase +=3D gd->reloc_off;
>   		if (entry->init)
>   			entry->init +=3D gd->reloc_off;
>   	}
> @@ -254,6 +256,34 @@ int env_save(void)
>   	return -ENODEV;
>   }
> 
> +int env_erase(void)
> +{
> +	struct env_driver *drv;
> +
> +	drv =3D env_driver_lookup(ENVOP_ERASE, gd->env_load_prio);
> +	if (drv) {
> +		int ret;
> +
> +		if (!drv->erase)
> +			return -ENODEV;
> +
> +		if (!env_has_inited(drv->location))
> +			return -ENODEV;
> +
> +		printf("Erasing Environment on %s... ", drv->name);
> +		ret =3D drv->erase();
> +		if (ret)
> +			printf("Failed (%d)\n", ret);
> +		else
> +			printf("OK\n");
> +
> +		if (!ret)
> +			return 0;
> +	}
> +
> +	return -ENODEV;
> +}
> +
>   int env_init(void)
>   {
>   	struct env_driver *drv;
> diff --git a/include/environment.h b/include/environment.h
> index cd96676141..de67cf4f0e 100644
> =2D-- a/include/environment.h
> +++ b/include/environment.h
> @@ -200,6 +200,7 @@ enum env_operation {
>   	ENVOP_INIT,	/* we want to call the init function */
>   	ENVOP_LOAD,	/* we want to call the load function */
>   	ENVOP_SAVE,	/* we want to call the save function */
> +	ENVOP_ERASE,	/* we want to call the erase function */
>   };
> 
>   struct env_driver {
> @@ -225,6 +226,15 @@ struct env_driver {
>   	 */
>   	int (*save)(void);
> 
> +	/**
> +	 * erase() - Erase the environment on storage
> +	 *
> +	 * This method is optional and required for 'eraseenv' to work.
> +	 *
> +	 * @return 0 if OK, -ve on error
> +	 */
> +	int (*erase)(void);
> +
>   	/**
>   	 * init() - Set up the initial pre-relocation environment
>   	 *
> @@ -303,6 +313,13 @@ int env_load(void);
>    */
>   int env_save(void);
> 
> +/**
> + * env_erase() - Erase the environment on storage
> + *
> + * @return 0 if OK, -ve on error
> + */
> +int env_erase(void);
> +
>   /**
>    * env_fix_drivers() - Updates envdriver as per relocation
>    */
> =2D-
> 2.17.1
> 

  reply	other threads:[~2019-06-24 19:26 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-28  8:51 [U-Boot] [PATCH v4 0/4] add command env erase Frank Wunderlich
2019-04-28  8:51 ` [U-Boot] [PATCH v4 1/4] env: register erase command Frank Wunderlich
2019-06-24 19:26   ` Simon Goldschmidt [this message]
2019-04-28  8:51 ` [U-Boot] [PATCH v4 2/4] env: mmc: add erase-function Frank Wunderlich
2019-06-24 19:40   ` Simon Goldschmidt
2019-06-24 20:08     ` Frank Wunderlich
2019-06-24 20:19       ` Simon Goldschmidt
2019-04-28  8:51 ` [U-Boot] [PATCH v4 3/4] env: add option to use redundant offset Frank Wunderlich
2019-04-28  8:51 ` [U-Boot] [PATCH v4 4/4] [RFC] env: call env_erase twice if CONFIG_ENV_OFFSET_REDUND is set Frank Wunderlich
2019-05-20 18:34 ` [U-Boot] [PATCH v4 0/4] add command env erase Frank Wunderlich
2019-06-24 10:30   ` Frank Wunderlich
2019-06-24 18:16     ` Tom Rini
2019-06-24 19:25     ` Simon Goldschmidt

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=8d1509b7-d2dd-6f58-b8aa-4d454b71e3d4@gmail.com \
    --to=simon.k.r.goldschmidt@gmail.com \
    --cc=u-boot@lists.denx.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