cmd: env: extend "env [set|print] -e" to manage UEFI variables
v6 cover cmd: env: extend "env [set|print] -e" to manage UEFI variables
This is my sixth version of "env -e" extension.
Changes in v6 (Oct 24, 2019)
* change default action of "env print -e" to dumping variables' values. Meanwhile a new "-n" option will suppress it.
* improve an error message for wrong guid format
* remove all the checks against option parameters as they are far from perfect and quite arguable. They will be checked any way in API call.
Changes in v5 (Oct 15, 2019)
* improve a message in case of wrong guid format
* improve a message in case that BOOTSERVICE_ACCESS is required
Changes in v4 (Oct 7, 2019)
* print usage message if "-guid guid" has a wrong format
* add "-guid guid" and "-all" option to "env print -e" command to specify a specific guid (or any guids)
Changes in v3 (Oct 4, 2019)
* add verbose messages when SetVariable() fails
* add "-v" option
Changes in v2 (Sept 6, 2019)
* remove "-at" option
AKASHI Takahiro (1):
cmd: env: extend "env [set|print] -e" to manage UEFI variables
cmd/nvedit.c | 19 +++- cmd/nvedit_efi.c | 277 ++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 252 insertions(+), 44 deletions(-)
Signature · 1 line
2.21.0
PATCH v6 1/1 cmd: env: extend "env [set|print] -e" to manage UEFI variables
With this patch, when setting UEFI variable with "env set -e" command, we will be able to
- specify vendor guid with "-guid guid",
- specify variable attributes, BOOTSERVICE_ACCESS, RUNTIME_ACCESS, respectively with "-bs" and "-rt",
- append a value instead of overwriting with "-a",
- use memory as variable's value instead of explicit values given at the command line with "-i address,size"
If guid is not explicitly given, default value will be used.
Meanwhile, "env print -e," will be modified so that it will NOT dump a variable's value if '-n' is specified.
--- cmd/nvedit.c | 19 +++- cmd/nvedit_efi.c | 277 ++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 252 insertions(+), 44 deletions(-)
cmd/nvedit.c +14 -5
@@ -1387,7 +1387,7 @@ static char env_help_text[] =#endif "env print [-a | name ...] - print environment\n"#if defined(CONFIG_CMD_NVEDIT_EFI ) - "env print -e [name ...] - print UEFI environment\n" + "env print -e [-guid guid|-all][-n] [name ...] - print UEFI environment\n"#endif #if defined(CONFIG_CMD_RUN )"env run var [...] - run commands in an environment variable\n"
@@ -1399,7 +1399,8 @@ static char env_help_text[] =#endif #endif #if defined(CONFIG_CMD_NVEDIT_EFI ) - "env set -e name [arg ...] - set UEFI variable; unset if 'arg' not specified\n" +"env set -e [-nv][-bs][-rt][-a][-i addr,size][-v] name [arg ...]\n" + " - set UEFI variable; unset if '-i' or 'arg' not specified\n"#endif "env set [-f] name [arg ...]\n" ;#endif
@@ -1428,8 +1429,9 @@ U_BOOT_CMD_COMPLETE("print environment variables" , "[-a]\n - print [all] values of all environment variables\n"#if defined(CONFIG_CMD_NVEDIT_EFI ) -"printenv -e [name ...]\n" +"printenv -e [-guid guid|-all][-n] [name ...]\n" " - print UEFI variable 'name' or all the variables\n" + " \"-n\": suppress dumping variable's value\n"#endif "printenv name ...\n" " - print value of environment variable 'name'",
@@ -1459,9 +1461,16 @@ U_BOOT_CMD_COMPLETE( setenv, CONFIG_SYS_MAXARGS, 0, do_env_set, "set environment variables", #if defined(CONFIG_CMD_NVEDIT_EFI) - "-e [-nv] name [value ...]\n" + "-e [-guid guid][-nv][-bs][-rt][-a][-v]\n" + " [-i addr,size name], or [name [value ...]]\n" " - set UEFI variable 'name' to 'value' ...'\n" - " 'nv' option makes the variable non-volatile\n" + " \"-guid\": set vendor guid\n" + " \"-nv\": set non-volatile attribute\n" + " \"-bs\": set boot-service attribute\n" + " \"-rt\": set runtime attribute\n" + " \"-a\": append-write\n" + " \"-i addr,size\": use <addr,size> as variable's value\n" + " \"-v\": verbose message\n" " - delete UEFI variable 'name' if 'value' not specified\n" #endif"setenv [-f] name value ...\n"
cmd/nvedit_efi.c +238 -39
410 lines not on this page · raw message
Signature · 1 line
2.21.0
PATCH v6 1/1 cmd: env: extend "env [set|print] -e" to manage UEFI variables
Quoted 9 lines · AKASHI Takahiro
With this patch, when setting UEFI variable with "env set -e" command, we will be able to
- specify vendor guid with "-guid guid",
- specify variable attributes,BOOTSERVICE_ACCESS,RUNTIME_ACCESS, respectively with "-bs" and "-rt",
- append a value instead of overwriting with "-a",
- use memory as variable's value instead of explicit values given at the command line with "-i address,size"
Quoted 6 lines
If guid is not explicitly given, default value will be used.
Meanwhile, "env print -e," will be modified so that it will NOT dump a variable's value if '-n' is specified.
Signed-off-by AKASHI Takahiro <[email protected]>
Looks fine to me. The only strange behavior is:
=> printenv -e
OsIndicationsSupported:
EFI_GLOBAL_VARIABLE_GUID: BS|RT, DataSize = 0x8
00000000: 00 00 00 00 00 00 00 00 ........
PlatformLang:
EFI_GLOBAL_VARIABLE_GUID: NV|BS|RT, DataSize = 0x6
00000000: 65 6e 2d 55 53 00 en-US.
PlatformLangCodes:
EFI_GLOBAL_VARIABLE_GUID: BS|RT, DataSize = 0x6
00000000: 65 6e 2d 55 53 00 en-US.RuntimeServicesSupported:
EFI_GLOBAL_VARIABLE_GUID: BS|RT, DataSize = 0x2
00000000: 80 05 ..
=> env set -e -guid 00000001-0002-0003-0004-010203040506 a b
EFI: Entry efi_set_variable("a" 00000001-0002-0003-0004-010203040506 0 1 000000007eef7610)
EFI: Exit: efi_set_variable: 14
## Failed to set EFI variable (not found)
I would have expected
## Failed to set EFI variable (invalid parameter)
The UEFI spec has:
If a preexisting variable is rewritten with no access attributes specified, the variable will be deleted.
But "a" is not a preexisting variable. Instead the attributes are invalid.
But as this is a bug in a code that you did not touch:
PATCH v6 1/1 cmd: env: extend "env [set|print] -e" to manage UEFI variables
Quoted 38 lines · Heinrich Schuchardt
Quoted 9 lines · AKASHI Takahiro
With this patch, when setting UEFI variable with "env set -e" command, we will be able to
- specify vendor guid with "-guid guid",
- specify variable attributes,BOOTSERVICE_ACCESS,RUNTIME_ACCESS, respectively with "-bs" and "-rt",
- append a value instead of overwriting with "-a",
- use memory as variable's value instead of explicit values given at the command line with "-i address,size"Quoted 6 lines
If guid is not explicitly given, default value will be used.
Meanwhile, "env print -e," will be modified so that it will NOT dump a variable's value if '-n' is specified.
Signed-off-by AKASHI Takahiro <[email protected]>Looks fine to me. The only strange behavior is:
=> printenv -e
OsIndicationsSupported:EFI_GLOBAL_VARIABLE_GUID: BS|RT, DataSize = 0x8 00000000: 00 00 00 00 00 00 00 00 ........ PlatformLang: EFI_GLOBAL_VARIABLE_GUID: NV|BS|RT, DataSize = 0x6 00000000: 65 6e 2d 55 53 00 en-US. PlatformLangCodes: EFI_GLOBAL_VARIABLE_GUID: BS|RT, DataSize = 0x6 00000000: 65 6e 2d 55 53 00 en-US.RuntimeServicesSupported:
EFI_GLOBAL_VARIABLE_GUID: BS|RT, DataSize =0x2
00000000: 80 05 ..
=> env set -e -guid 00000001-0002-0003-0004-010203040506 a b
EFI: Entryefi_set_variable("a" 00000001-0002-0003-0004-010203040506 0 1 000000007eef7610)
EFI: Exit:efi_set_variable: 14
## Failed to set EFI variable (not found)
Quoted 8 lines
I would have expected
## Failed to set EFI variable (invalid parameter)The UEFI spec has:
If a preexisting variable is rewritten with no access attributes specified, the variable will be deleted.But "a" is not a preexisting variable. Instead the attributes are invalid.
This might justify all arbitrary attribute/option checks being removed at command level, at least for test purpose.
Thank you for your review.
-Takahiro Akashi
Quoted 3 lines
But as this is a bug in a code that you did not touch:
Reviewed-by Heinrich Schuchardt <[email protected]>