diff mbox series

[v4,9/9] cmd: env: add "-e" option for handling UEFI variables

Message ID 20190115025522.12060-10-takahiro.akashi@linaro.org
State Superseded
Headers show
Series cmd: add efitool for efi environment | expand

Commit Message

AKASHI Takahiro Jan. 15, 2019, 2:55 a.m. UTC
"env [print|set] -e" allows for handling uefi variables without
knowing details about mapping to corresponding u-boot variables.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
---
 cmd/nvedit.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 59 insertions(+), 2 deletions(-)

Comments

Heinrich Schuchardt Jan. 15, 2019, 3:47 a.m. UTC | #1
On 1/15/19 3:55 AM, AKASHI Takahiro wrote:
> "env [print|set] -e" allows for handling uefi variables without
> knowing details about mapping to corresponding u-boot variables.

Why do we need two alternative ways to achieve the same result?
We already have 'efitool setvar' and 'efitool dumpvar'.

Best regards

Heinrich

> 
> Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
> ---
Alexander Graf Jan. 15, 2019, 1:23 p.m. UTC | #2
On 01/15/2019 04:47 AM, Heinrich Schuchardt wrote:
> On 1/15/19 3:55 AM, AKASHI Takahiro wrote:
>> "env [print|set] -e" allows for handling uefi variables without
>> knowing details about mapping to corresponding u-boot variables.
> Why do we need two alternative ways to achieve the same result?
> We already have 'efitool setvar' and 'efitool dumpvar'.

I asked for it.

If it was me, I would just drop the "efitool" versions. The more we can 
have in common code / CLI, the better for everyone.

But if Takahiro is passionate about having everything accessible through 
a single efi helper command for his debugging, I wouldn't oppose to it :).


Alex
Alexander Graf Jan. 15, 2019, 1:26 p.m. UTC | #3
On 01/15/2019 03:55 AM, AKASHI Takahiro wrote:
> "env [print|set] -e" allows for handling uefi variables without
> knowing details about mapping to corresponding u-boot variables.
>
> Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
> ---
>   cmd/nvedit.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++--
>   1 file changed, 59 insertions(+), 2 deletions(-)
>
> diff --git a/cmd/nvedit.c b/cmd/nvedit.c
> index ce746bbf1b3e..44f6c3759253 100644
> --- a/cmd/nvedit.c
> +++ b/cmd/nvedit.c
> @@ -27,6 +27,8 @@
>   #include <cli.h>
>   #include <command.h>
>   #include <console.h>
> +#include <efi.h>
> +#include <efi_loader.h>
>   #include <environment.h>
>   #include <search.h>
>   #include <errno.h>
> @@ -119,6 +121,25 @@ static int do_env_print(cmd_tbl_t *cmdtp, int flag, int argc,
>   	int rcode = 0;
>   	int env_flag = H_HIDE_DOT;
>   
> +#if defined(CONFIG_CMD_EFITOOL)

This needs to be available without your EFITOOL (which really is a DEBUG 
command). So this needs to be accessible using only CONFIG_EFI_LOADER I 
think. Maybe we can add a CONFIG_CMD_EFI_SUBCMD or so that these bits 
are guarded by if you think that someone really wants to live without.


Alex
diff mbox series

Patch

diff --git a/cmd/nvedit.c b/cmd/nvedit.c
index ce746bbf1b3e..44f6c3759253 100644
--- a/cmd/nvedit.c
+++ b/cmd/nvedit.c
@@ -27,6 +27,8 @@ 
 #include <cli.h>
 #include <command.h>
 #include <console.h>
+#include <efi.h>
+#include <efi_loader.h>
 #include <environment.h>
 #include <search.h>
 #include <errno.h>
@@ -119,6 +121,25 @@  static int do_env_print(cmd_tbl_t *cmdtp, int flag, int argc,
 	int rcode = 0;
 	int env_flag = H_HIDE_DOT;
 
+#if defined(CONFIG_CMD_EFITOOL)
+	if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'e') {
+		efi_status_t r;
+
+		argc--;
+		argv++;
+
+		/* Initialize EFI drivers */
+		r = efi_init_obj_list();
+		if (r != EFI_SUCCESS) {
+			printf("Error: Cannot set up EFI drivers, r = %lu\n",
+			       r & ~EFI_ERROR_MASK);
+			return CMD_RET_FAILURE;
+		}
+
+		return do_efi_dump_var(argc, argv);
+	}
+#endif
+
 	if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'a') {
 		argc--;
 		argv++;
@@ -216,6 +237,26 @@  static int _do_env_set(int flag, int argc, char * const argv[], int env_flag)
 	ENTRY e, *ep;
 
 	debug("Initial value for argc=%d\n", argc);
+
+#if defined(CONFIG_CMD_EFITOOL)
+	if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'e') {
+		efi_status_t r;
+
+		argc--;
+		argv++;
+
+		/* Initialize EFI drivers */
+		r = efi_init_obj_list();
+		if (r != EFI_SUCCESS) {
+			printf("Error: Cannot set up EFI drivers, r = %lu\n",
+			       r & ~EFI_ERROR_MASK);
+			return CMD_RET_FAILURE;
+		}
+
+		return do_efi_set_var(argc, argv);
+	}
+#endif
+
 	while (argc > 1 && **(argv + 1) == '-') {
 		char *arg = *++argv;
 
@@ -1262,15 +1303,23 @@  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_EFITOOL)
+	"env print [-a | -e [name] | name ...] - print environment\n"
+#else
 	"env print [-a | name ...] - print environment\n"
+#endif
 #if defined(CONFIG_CMD_RUN)
 	"env run var [...] - run commands in an environment variable\n"
 #endif
 #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
 	"env save - save environment\n"
 #endif
+#if defined(CONFIG_CMD_EFITOOL)
+	"env set [-e | -f] name [arg ...]\n";
+#else
 	"env set [-f] name [arg ...]\n";
 #endif
+#endif
 
 U_BOOT_CMD(
 	env, CONFIG_SYS_MAXARGS, 1, do_env,
@@ -1295,6 +1344,10 @@  U_BOOT_CMD_COMPLETE(
 	printenv, CONFIG_SYS_MAXARGS, 1,	do_env_print,
 	"print environment variables",
 	"[-a]\n    - print [all] values of all environment variables\n"
+#if defined(CONFIG_CMD_EFITOOL)
+	"printenv -e [<name>]\n"
+	"    - print UEFI variable 'name' or all the variables\n"
+#endif
 	"printenv name ...\n"
 	"    - print value of environment variable 'name'",
 	var_complete
@@ -1322,7 +1375,11 @@  U_BOOT_CMD_COMPLETE(
 U_BOOT_CMD_COMPLETE(
 	setenv, CONFIG_SYS_MAXARGS, 0,	do_env_set,
 	"set environment variables",
-	"[-f] name value ...\n"
+#if defined(CONFIG_CMD_EFITOOL)
+	"-e <name> [<value>]\n"
+	"    - set UEFI variable 'name' to 'value' ...'\n"
+#endif
+	"setenv [-f] name value ...\n"
 	"    - [forcibly] set environment variable 'name' to 'value ...'\n"
 	"setenv [-f] name\n"
 	"    - [forcibly] delete environment variable 'name'",
@@ -1345,7 +1402,7 @@  U_BOOT_CMD_COMPLETE(
 	"run commands in an environment variable",
 	"var [...]\n"
 	"    - run the commands in the environment variable(s) 'var'"
-#if defined(CONFIG_CMD_BOOTEFI)
+#if defined(CONFIG_CMD_EFITOOL)
 	"\n"
 	"run -e [BootXXXX]\n"
 	"    - load and run UEFI app based on 'BootXXXX' UEFI variable",