* [U-Boot] [PATCH] cmd: nvedit: Add sub-command 'env info'
@ 2019-05-24 15:20 Mark Jonas
2019-06-22 19:09 ` Simon Glass
2019-07-14 13:07 ` Tom Rini
0 siblings, 2 replies; 3+ messages in thread
From: Mark Jonas @ 2019-05-24 15:20 UTC (permalink / raw)
To: u-boot
From: Leo Ruan <tingquan.ruan@cn.bosch.com>
Add sub-command 'env info' to display environment information:
- env_valid : is environment valid
- env_ready : is environment imported into hash table
- env_use_default : is default environment using
This command can be optionally used for evaluation in scripts:
[-d] : evaluate whether default environment is used
[-p] : evaluate whether environment can be persisted
The result of multiple evaluations will be combined with AND.
Signed-off-by: Leo Ruan <tingquan.ruan@cn.bosch.com>
Signed-off-by: Mark Jonas <mark.jonas@de.bosch.com>
---
cmd/Kconfig | 14 ++++++++
cmd/nvedit.c | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 122 insertions(+)
diff --git a/cmd/Kconfig b/cmd/Kconfig
index 0d36da2..b249597 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -441,6 +441,20 @@ config CMD_NVEDIT_EFI
If enabled, we are allowed to set/print UEFI variables using
"env" command with "-e" option without knowing details.
+config CMD_NVEDIT_INFO
+ bool "env info - print or evaluate environment information"
+ default y
+ help
+ Print environment information:
+ - env_valid : is environment valid
+ - env_ready : is environment imported into hash table
+ - env_use_default : is default environment used
+
+ This command can be optionally used for evaluation in scripts:
+ [-d] : evaluate whether default environment is used
+ [-p] : evaluate whether environment can be persisted
+ The result of multiple evaluations will be combined with AND.
+
endmenu
menu "Memory commands"
diff --git a/cmd/nvedit.c b/cmd/nvedit.c
index 24a6cf7..fe53276 100644
--- a/cmd/nvedit.c
+++ b/cmd/nvedit.c
@@ -1157,6 +1157,106 @@ sep_err:
}
#endif
+#if defined(CONFIG_CMD_NVEDIT_INFO)
+/*
+ * print_env_info - print environment information
+ */
+static int print_env_info(void)
+{
+ const char *value;
+
+ /* print environment validity value */
+ switch (gd->env_valid) {
+ case ENV_INVALID:
+ value = "invalid";
+ break;
+ case ENV_VALID:
+ value = "valid";
+ break;
+ case ENV_REDUND:
+ value = "redundant";
+ break;
+ default:
+ value = "unknown";
+ break;
+ }
+ printf("env_valid = %s\n", value);
+
+ /* print environment ready flag */
+ value = gd->flags & GD_FLG_ENV_READY ? "true" : "false";
+ printf("env_ready = %s\n", value);
+
+ /* print environment using default flag */
+ value = gd->flags & GD_FLG_ENV_DEFAULT ? "true" : "false";
+ printf("env_use_default = %s\n", value);
+
+ return CMD_RET_SUCCESS;
+}
+
+#define ENV_INFO_IS_DEFAULT BIT(0) /* default environment bit mask */
+#define ENV_INFO_IS_PERSISTED BIT(1) /* environment persistence bit mask */
+
+/*
+ * env info - display environment information
+ * env info [-d] - evaluate whether default environment is used
+ * env info [-p] - evaluate whether environment can be persisted
+ */
+static int do_env_info(cmd_tbl_t *cmdtp, int flag,
+ int argc, char * const argv[])
+{
+ int eval_flags = 0;
+ int eval_results = 0;
+
+ /* display environment information */
+ if (argc <= 1)
+ return print_env_info();
+
+ /* process options */
+ while (--argc > 0 && **++argv == '-') {
+ char *arg = *argv;
+
+ while (*++arg) {
+ switch (*arg) {
+ case 'd':
+ eval_flags |= ENV_INFO_IS_DEFAULT;
+ break;
+ case 'p':
+ eval_flags |= ENV_INFO_IS_PERSISTED;
+ break;
+ default:
+ return CMD_RET_USAGE;
+ }
+ }
+ }
+
+ /* evaluate whether default environment is used */
+ if (eval_flags & ENV_INFO_IS_DEFAULT) {
+ if (gd->flags & GD_FLG_ENV_DEFAULT) {
+ printf("Default environment is used\n");
+ eval_results |= ENV_INFO_IS_DEFAULT;
+ } else {
+ printf("Environment was loaded from persistent storage\n");
+ }
+ }
+
+ /* evaluate whether environment can be persisted */
+ if (eval_flags & ENV_INFO_IS_PERSISTED) {
+#if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
+ printf("Environment can be persisted\n");
+ eval_results |= ENV_INFO_IS_PERSISTED;
+#else
+ printf("Environment cannot be persisted\n");
+#endif
+ }
+
+ /* The result of evaluations is combined with AND */
+ if (eval_flags != eval_results)
+ return CMD_RET_FAILURE;
+
+ return CMD_RET_SUCCESS;
+}
+#endif
+
#if defined(CONFIG_CMD_ENV_EXISTS)
static int do_env_exists(cmd_tbl_t *cmdtp, int flag, int argc,
char * const argv[])
@@ -1201,6 +1301,9 @@ static cmd_tbl_t cmd_env_sub[] = {
#if defined(CONFIG_CMD_IMPORTENV)
U_BOOT_CMD_MKENT(import, 5, 0, do_env_import, "", ""),
#endif
+#if defined(CONFIG_CMD_NVEDIT_INFO)
+ U_BOOT_CMD_MKENT(info, 2, 0, do_env_info, "", ""),
+#endif
U_BOOT_CMD_MKENT(print, CONFIG_SYS_MAXARGS, 1, do_env_print, "", ""),
#if defined(CONFIG_CMD_RUN)
U_BOOT_CMD_MKENT(run, CONFIG_SYS_MAXARGS, 1, do_run, "", ""),
@@ -1273,6 +1376,11 @@ static char env_help_text[] =
#if defined(CONFIG_CMD_IMPORTENV)
"env import [-d] [-t [-r] | -b | -c] addr [size] [var ...] - import environment\n"
#endif
+#if defined(CONFIG_CMD_NVEDIT_INFO)
+ "env info - display environment information\n"
+ "env info [-d] - whether default environment is used\n"
+ "env info [-p] - whether environment can be persisted\n"
+#endif
"env print [-a | name ...] - print environment\n"
#if defined(CONFIG_CMD_NVEDIT_EFI)
"env print -e [name ...] - print UEFI environment\n"
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [U-Boot] [PATCH] cmd: nvedit: Add sub-command 'env info'
2019-05-24 15:20 [U-Boot] [PATCH] cmd: nvedit: Add sub-command 'env info' Mark Jonas
@ 2019-06-22 19:09 ` Simon Glass
2019-07-14 13:07 ` Tom Rini
1 sibling, 0 replies; 3+ messages in thread
From: Simon Glass @ 2019-06-22 19:09 UTC (permalink / raw)
To: u-boot
On Fri, 24 May 2019 at 16:20, Mark Jonas <mark.jonas@de.bosch.com> wrote:
>
> From: Leo Ruan <tingquan.ruan@cn.bosch.com>
>
> Add sub-command 'env info' to display environment information:
> - env_valid : is environment valid
> - env_ready : is environment imported into hash table
> - env_use_default : is default environment using
>
> This command can be optionally used for evaluation in scripts:
> [-d] : evaluate whether default environment is used
> [-p] : evaluate whether environment can be persisted
> The result of multiple evaluations will be combined with AND.
>
> Signed-off-by: Leo Ruan <tingquan.ruan@cn.bosch.com>
> Signed-off-by: Mark Jonas <mark.jonas@de.bosch.com>
> ---
> cmd/Kconfig | 14 ++++++++
> cmd/nvedit.c | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 122 insertions(+)
Reviewed-by: Simon Glass <sjg@chromium.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
* [U-Boot] [PATCH] cmd: nvedit: Add sub-command 'env info'
2019-05-24 15:20 [U-Boot] [PATCH] cmd: nvedit: Add sub-command 'env info' Mark Jonas
2019-06-22 19:09 ` Simon Glass
@ 2019-07-14 13:07 ` Tom Rini
1 sibling, 0 replies; 3+ messages in thread
From: Tom Rini @ 2019-07-14 13:07 UTC (permalink / raw)
To: u-boot
On Fri, May 24, 2019 at 05:20:19PM +0200, Mark Jonas wrote:
> From: Leo Ruan <tingquan.ruan@cn.bosch.com>
>
> Add sub-command 'env info' to display environment information:
> - env_valid : is environment valid
> - env_ready : is environment imported into hash table
> - env_use_default : is default environment using
>
> This command can be optionally used for evaluation in scripts:
> [-d] : evaluate whether default environment is used
> [-p] : evaluate whether environment can be persisted
> The result of multiple evaluations will be combined with AND.
>
> Signed-off-by: Leo Ruan <tingquan.ruan@cn.bosch.com>
> Signed-off-by: Mark Jonas <mark.jonas@de.bosch.com>
> Reviewed-by: Simon Glass <sjg@chromium.org>
Applied to u-boot/master, thanks!
--
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190714/9275698c/attachment.sig>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-07-14 13:07 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-05-24 15:20 [U-Boot] [PATCH] cmd: nvedit: Add sub-command 'env info' Mark Jonas
2019-06-22 19:09 ` Simon Glass
2019-07-14 13:07 ` 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.