X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=cmd%2Fnvedit_efi.c;h=ed6d09a530466e9fe8e6817e6876bb6709e32df7;hb=25e51e90feec10b7d534b123cd9c4ed7a3a2dc1a;hp=e65b38dbf399b9fbb22969de561b3abb2d215d04;hpb=66c433ed4342e5761ee9b048c85fe47d31130b2e;p=oweals%2Fu-boot.git diff --git a/cmd/nvedit_efi.c b/cmd/nvedit_efi.c index e65b38dbf3..ed6d09a530 100644 --- a/cmd/nvedit_efi.c +++ b/cmd/nvedit_efi.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -291,8 +292,11 @@ static int append_value(char **bufp, size_t *sizep, char *data) if (!tmp_buf) return -1; - if (hex2bin((u8 *)tmp_buf, data, len) < 0) + if (hex2bin((u8 *)tmp_buf, data, len) < 0) { + printf("Error: illegal hexadecimal string\n"); + free(tmp_buf); return -1; + } value = tmp_buf; } else { /* string */ @@ -346,6 +350,7 @@ int do_env_set_efi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) u16 *var_name16 = NULL, *p; size_t len; efi_guid_t guid; + u32 attributes; efi_status_t ret; if (argc == 1) @@ -359,6 +364,16 @@ int do_env_set_efi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) return CMD_RET_FAILURE; } + 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) { /* delete */ @@ -370,6 +385,8 @@ int do_env_set_efi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) for ( ; argc > 0; argc--, argv++) if (append_value(&value, &size, argv[0]) < 0) { + printf("## Failed to process an argument, %s\n", + argv[0]); ret = CMD_RET_FAILURE; goto out; } @@ -378,6 +395,7 @@ int do_env_set_efi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) len = utf8_utf16_strnlen(var_name, strlen(var_name)); var_name16 = malloc((len + 1) * 2); if (!var_name16) { + printf("## Out of memory\n"); ret = CMD_RET_FAILURE; goto out; } @@ -385,11 +403,14 @@ int do_env_set_efi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) utf8_utf16_strncpy(&p, var_name, len + 1); guid = efi_global_variable_guid; - ret = EFI_CALL(efi_set_variable(var_name16, &guid, - EFI_VARIABLE_BOOTSERVICE_ACCESS | - EFI_VARIABLE_RUNTIME_ACCESS, + ret = EFI_CALL(efi_set_variable(var_name16, &guid, attributes, size, value)); - ret = (ret == EFI_SUCCESS ? CMD_RET_SUCCESS : CMD_RET_FAILURE); + if (ret == EFI_SUCCESS) { + ret = CMD_RET_SUCCESS; + } else { + printf("## Failed to set EFI variable\n"); + ret = CMD_RET_FAILURE; + } out: free(value); free(var_name16);