[U-Boot] [PATCH 2/4] cmd: efishell: support -nv option to setvar sub-command

AKASHI Takahiro takahiro.akashi at linaro.org
Wed Nov 28 06:00:57 UTC 2018


With -nv specified, a variable to be created will have NON_VOLATILE
attribute.

Signed-off-by: AKASHI Takahiro <takahiro.akashi at linaro.org>
---
 cmd/efishell.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/cmd/efishell.c b/cmd/efishell.c
index 7cd3ca489559..7cdff757b06c 100644
--- a/cmd/efishell.c
+++ b/cmd/efishell.c
@@ -249,11 +249,22 @@ static int _do_efi_set_var(int argc, char * const argv[])
 	unsigned long size = 0;
 	u16 *var_name16, *p;
 	efi_guid_t guid;
+	u32 attributes;
 	efi_status_t ret;
 
 	if (argc == 1)
 		return CMD_RET_SUCCESS;
 
+	attributes = EFI_VARIABLE_BOOTSERVICE_ACCESS |
+		     EFI_VARIABLE_RUNTIME_ACCESS;
+	if (!strcmp(argv[1], "-nv")) {
+		attributes |= EFI_VARIABLE_NON_VOLATILE;
+		argc--;
+		argv++;
+		if (argc == 1)
+			return CMD_RET_SUCCESS;
+	}
+
 	var_name = argv[1];
 	if (argc == 2) {
 		/* remove */
@@ -275,9 +286,7 @@ static int _do_efi_set_var(int argc, char * const argv[])
 	utf8_utf16_strncpy(&p, var_name, strlen(var_name) + 1);
 
 	guid = efi_global_variable_guid;
-	ret = efi_set_variable(var_name16, &guid,
-			       EFI_VARIABLE_BOOTSERVICE_ACCESS |
-			       EFI_VARIABLE_RUNTIME_ACCESS, size, value);
+	ret = efi_set_variable(var_name16, &guid, attributes, size, value);
 	ret = (ret == EFI_SUCCESS ? CMD_RET_SUCCESS : CMD_RET_FAILURE);
 out:
 	return ret;
@@ -978,7 +987,7 @@ static char efishell_help_text[] =
 	"\n"
 	"efishell dumpvar [<name>]\n"
 	"  - get uefi variable's value\n"
-	"efishell setvar <name> [<value>]\n"
+	"efishell setvar [-nv] <name> [<value>]\n"
 	"  - set/delete uefi variable's value\n"
 	"    <value> may be \"=\"...\"\", \"=0x...\" (set) or \"=\" (delete)\n"
 	"efishell devices\n"
-- 
2.19.1



More information about the U-Boot mailing list