2019-02-25 06:54:36 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
/*
|
|
|
|
* Integrate UEFI variables to u-boot env interface
|
|
|
|
*
|
|
|
|
* Copyright (c) 2018 AKASHI Takahiro, Linaro Limited
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <charset.h>
|
|
|
|
#include <common.h>
|
|
|
|
#include <command.h>
|
|
|
|
#include <efi_loader.h>
|
2020-06-24 17:55:13 +00:00
|
|
|
#include <efi_variable.h>
|
2019-08-01 15:46:51 +00:00
|
|
|
#include <env.h>
|
2019-02-25 06:54:36 +00:00
|
|
|
#include <exports.h>
|
|
|
|
#include <hexdump.h>
|
|
|
|
#include <malloc.h>
|
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.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-10-24 06:17:13 +00:00
|
|
|
#include <mapmem.h>
|
2020-06-24 17:55:13 +00:00
|
|
|
#include <rtc.h>
|
2020-05-10 17:39:52 +00:00
|
|
|
#include <uuid.h>
|
2019-02-25 06:54:36 +00:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* From efi_variable.c,
|
|
|
|
*
|
|
|
|
* Mapping between UEFI variables and u-boot variables:
|
|
|
|
*
|
|
|
|
* efi_$guid_$varname = {attributes}(type)value
|
|
|
|
*/
|
|
|
|
|
|
|
|
static const struct {
|
|
|
|
u32 mask;
|
|
|
|
char *text;
|
|
|
|
} efi_var_attrs[] = {
|
|
|
|
{EFI_VARIABLE_NON_VOLATILE, "NV"},
|
|
|
|
{EFI_VARIABLE_BOOTSERVICE_ACCESS, "BS"},
|
|
|
|
{EFI_VARIABLE_RUNTIME_ACCESS, "RT"},
|
|
|
|
{EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS, "AW"},
|
|
|
|
{EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS, "AT"},
|
2020-06-24 17:55:13 +00:00
|
|
|
{EFI_VARIABLE_READ_ONLY, "RO"},
|
2019-02-25 06:54:36 +00:00
|
|
|
};
|
|
|
|
|
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.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-10-24 06:17:13 +00:00
|
|
|
static const struct {
|
|
|
|
efi_guid_t guid;
|
|
|
|
char *text;
|
|
|
|
} efi_guid_text[] = {
|
|
|
|
/* signature database */
|
|
|
|
{EFI_GLOBAL_VARIABLE_GUID, "EFI_GLOBAL_VARIABLE_GUID"},
|
2020-04-14 02:51:46 +00:00
|
|
|
{EFI_IMAGE_SECURITY_DATABASE_GUID, "EFI_IMAGE_SECURITY_DATABASE_GUID"},
|
|
|
|
/* certificate type */
|
|
|
|
{EFI_CERT_SHA256_GUID, "EFI_CERT_SHA256_GUID"},
|
|
|
|
{EFI_CERT_X509_GUID, "EFI_CERT_X509_GUID"},
|
|
|
|
{EFI_CERT_TYPE_PKCS7_GUID, "EFI_CERT_TYPE_PKCS7_GUID"},
|
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.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-10-24 06:17:13 +00:00
|
|
|
};
|
|
|
|
|
2020-07-15 16:00:56 +00:00
|
|
|
static const char unknown_guid[] = "";
|
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.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-10-24 06:17:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* efi_guid_to_str() - convert guid to readable name
|
|
|
|
*
|
|
|
|
* @guid: GUID
|
|
|
|
* Return: string for GUID
|
|
|
|
*
|
|
|
|
* convert guid to readable name
|
|
|
|
*/
|
|
|
|
static const char *efi_guid_to_str(const efi_guid_t *guid)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(efi_guid_text); i++)
|
|
|
|
if (!guidcmp(guid, &efi_guid_text[i].guid))
|
|
|
|
return efi_guid_text[i].text;
|
|
|
|
|
|
|
|
return unknown_guid;
|
|
|
|
}
|
|
|
|
|
2019-02-25 06:54:36 +00:00
|
|
|
/**
|
|
|
|
* efi_dump_single_var() - show information about a UEFI variable
|
|
|
|
*
|
|
|
|
* @name: Name of the variable
|
|
|
|
* @guid: Vendor GUID
|
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.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-10-24 06:17:13 +00:00
|
|
|
* @verbose: if true, dump data
|
2019-02-25 06:54:36 +00:00
|
|
|
*
|
|
|
|
* Show information encoded in one UEFI variable
|
|
|
|
*/
|
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.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-10-24 06:17:13 +00:00
|
|
|
static void efi_dump_single_var(u16 *name, const efi_guid_t *guid, bool verbose)
|
2019-02-25 06:54:36 +00:00
|
|
|
{
|
|
|
|
u32 attributes;
|
|
|
|
u8 *data;
|
2020-06-24 17:55:13 +00:00
|
|
|
u64 time;
|
|
|
|
struct rtc_time tm;
|
2019-02-25 06:54:36 +00:00
|
|
|
efi_uintn_t size;
|
|
|
|
int count, i;
|
|
|
|
efi_status_t ret;
|
|
|
|
|
|
|
|
data = NULL;
|
|
|
|
size = 0;
|
2020-06-24 17:55:13 +00:00
|
|
|
ret = efi_get_variable_int(name, guid, &attributes, &size, data, &time);
|
2019-02-25 06:54:36 +00:00
|
|
|
if (ret == EFI_BUFFER_TOO_SMALL) {
|
|
|
|
data = malloc(size);
|
|
|
|
if (!data)
|
|
|
|
goto out;
|
|
|
|
|
2020-06-24 17:55:13 +00:00
|
|
|
ret = efi_get_variable_int(name, guid, &attributes, &size,
|
|
|
|
data, &time);
|
2019-02-25 06:54:36 +00:00
|
|
|
}
|
|
|
|
if (ret == EFI_NOT_FOUND) {
|
|
|
|
printf("Error: \"%ls\" not defined\n", name);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (ret != EFI_SUCCESS)
|
|
|
|
goto out;
|
|
|
|
|
2020-06-24 17:55:13 +00:00
|
|
|
rtc_to_tm(time, &tm);
|
2020-07-15 16:00:56 +00:00
|
|
|
printf("%ls:\n %pUl %s\n", name, guid, efi_guid_to_str(guid));
|
2020-06-24 17:55:13 +00:00
|
|
|
if (attributes & EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS)
|
|
|
|
printf(" %04d-%02d-%02d %02d:%02d:%02d\n", tm.tm_year,
|
|
|
|
tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
|
|
|
|
printf(" ");
|
2019-02-25 06:54:36 +00:00
|
|
|
for (count = 0, i = 0; i < ARRAY_SIZE(efi_var_attrs); i++)
|
|
|
|
if (attributes & efi_var_attrs[i].mask) {
|
|
|
|
if (count)
|
|
|
|
putc('|');
|
|
|
|
count++;
|
|
|
|
puts(efi_var_attrs[i].text);
|
|
|
|
}
|
|
|
|
printf(", DataSize = 0x%zx\n", size);
|
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.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-10-24 06:17:13 +00:00
|
|
|
if (verbose)
|
|
|
|
print_hex_dump(" ", DUMP_PREFIX_OFFSET, 16, 1,
|
|
|
|
data, size, true);
|
2019-02-25 06:54:36 +00:00
|
|
|
|
|
|
|
out:
|
|
|
|
free(data);
|
|
|
|
}
|
|
|
|
|
2020-05-10 17:40:03 +00:00
|
|
|
static bool match_name(int argc, char *const argv[], u16 *var_name16)
|
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.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-10-24 06:17:13 +00:00
|
|
|
{
|
|
|
|
char *buf, *p;
|
|
|
|
size_t buflen;
|
|
|
|
int i;
|
|
|
|
bool result = false;
|
|
|
|
|
|
|
|
buflen = utf16_utf8_strlen(var_name16) + 1;
|
|
|
|
buf = calloc(1, buflen);
|
|
|
|
if (!buf)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
p = buf;
|
|
|
|
utf16_utf8_strcpy(&p, var_name16);
|
|
|
|
|
|
|
|
for (i = 0; i < argc; argc--, argv++) {
|
|
|
|
if (!strcmp(buf, argv[i])) {
|
|
|
|
result = true;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
free(buf);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-02-25 06:54:36 +00:00
|
|
|
/**
|
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.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-10-24 06:17:13 +00:00
|
|
|
* efi_dump_var_all() - show information about all the UEFI variables
|
2019-02-25 06:54:36 +00:00
|
|
|
*
|
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.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-10-24 06:17:13 +00:00
|
|
|
* @argc: Number of arguments (variables)
|
|
|
|
* @argv: Argument (variable name) array
|
|
|
|
* @verbose: if true, dump data
|
2019-02-25 06:54:36 +00:00
|
|
|
* Return: CMD_RET_SUCCESS on success, or CMD_RET_RET_FAILURE
|
|
|
|
*
|
|
|
|
* Show information encoded in all the UEFI variables
|
|
|
|
*/
|
2020-05-10 17:40:03 +00:00
|
|
|
static int efi_dump_var_all(int argc, char *const argv[],
|
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.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-10-24 06:17:13 +00:00
|
|
|
const efi_guid_t *guid_p, bool verbose)
|
2019-02-25 06:54:36 +00:00
|
|
|
{
|
|
|
|
u16 *var_name16, *p;
|
|
|
|
efi_uintn_t buf_size, size;
|
|
|
|
efi_guid_t guid;
|
|
|
|
efi_status_t ret;
|
2020-07-15 16:00:56 +00:00
|
|
|
bool match = false;
|
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.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-10-24 06:17:13 +00:00
|
|
|
|
2019-02-25 06:54:36 +00:00
|
|
|
buf_size = 128;
|
|
|
|
var_name16 = malloc(buf_size);
|
|
|
|
if (!var_name16)
|
|
|
|
return CMD_RET_FAILURE;
|
|
|
|
|
|
|
|
var_name16[0] = 0;
|
|
|
|
for (;;) {
|
|
|
|
size = buf_size;
|
|
|
|
ret = EFI_CALL(efi_get_next_variable_name(&size, var_name16,
|
|
|
|
&guid));
|
|
|
|
if (ret == EFI_NOT_FOUND)
|
|
|
|
break;
|
|
|
|
if (ret == EFI_BUFFER_TOO_SMALL) {
|
|
|
|
buf_size = size;
|
|
|
|
p = realloc(var_name16, buf_size);
|
|
|
|
if (!p) {
|
|
|
|
free(var_name16);
|
|
|
|
return CMD_RET_FAILURE;
|
|
|
|
}
|
|
|
|
var_name16 = p;
|
|
|
|
ret = EFI_CALL(efi_get_next_variable_name(&size,
|
|
|
|
var_name16,
|
|
|
|
&guid));
|
|
|
|
}
|
|
|
|
if (ret != EFI_SUCCESS) {
|
|
|
|
free(var_name16);
|
|
|
|
return CMD_RET_FAILURE;
|
|
|
|
}
|
|
|
|
|
2020-07-15 16:00:56 +00:00
|
|
|
if (guid_p && guidcmp(guid_p, &guid))
|
|
|
|
continue;
|
|
|
|
if (!argc || match_name(argc, argv, var_name16)) {
|
|
|
|
match = true;
|
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.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-10-24 06:17:13 +00:00
|
|
|
efi_dump_single_var(var_name16, &guid, verbose);
|
2020-07-15 16:00:56 +00:00
|
|
|
}
|
2019-02-25 06:54:36 +00:00
|
|
|
}
|
|
|
|
free(var_name16);
|
|
|
|
|
2020-07-15 16:00:56 +00:00
|
|
|
if (!match && argc == 1)
|
|
|
|
printf("Error: \"%s\" not defined\n", argv[0]);
|
|
|
|
|
2019-02-25 06:54:36 +00:00
|
|
|
return CMD_RET_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* do_env_print_efi() - show information about UEFI variables
|
|
|
|
*
|
|
|
|
* @cmdtp: Command table
|
|
|
|
* @flag: Command flag
|
|
|
|
* @argc: Number of arguments
|
|
|
|
* @argv: Argument array
|
|
|
|
* Return: CMD_RET_SUCCESS on success, or CMD_RET_RET_FAILURE
|
|
|
|
*
|
|
|
|
* This function is for "env print -e" or "printenv -e" command:
|
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.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-10-24 06:17:13 +00:00
|
|
|
* => env print -e [-n] [-guid <guid> | -all] [var [...]]
|
2019-02-25 06:54:36 +00:00
|
|
|
* If one or more variable names are specified, show information
|
|
|
|
* named UEFI variables, otherwise show all the UEFI variables.
|
|
|
|
*/
|
2020-05-10 17:40:03 +00:00
|
|
|
int do_env_print_efi(struct cmd_tbl *cmdtp, int flag, int argc,
|
|
|
|
char *const argv[])
|
2019-02-25 06:54:36 +00:00
|
|
|
{
|
2020-07-15 16:00:56 +00:00
|
|
|
const efi_guid_t *guid_p = NULL;
|
2021-07-03 06:43:17 +00:00
|
|
|
efi_guid_t guid;
|
2020-07-15 16:00:56 +00:00
|
|
|
bool verbose = true;
|
2019-02-25 06:54:36 +00:00
|
|
|
efi_status_t ret;
|
|
|
|
|
|
|
|
/* Initialize EFI drivers */
|
|
|
|
ret = efi_init_obj_list();
|
|
|
|
if (ret != EFI_SUCCESS) {
|
|
|
|
printf("Error: Cannot initialize UEFI sub-system, r = %lu\n",
|
|
|
|
ret & ~EFI_ERROR_MASK);
|
|
|
|
return CMD_RET_FAILURE;
|
|
|
|
}
|
|
|
|
|
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.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-10-24 06:17:13 +00:00
|
|
|
for (argc--, argv++; argc > 0 && argv[0][0] == '-'; argc--, argv++) {
|
|
|
|
if (!strcmp(argv[0], "-guid")) {
|
2020-07-15 16:00:56 +00:00
|
|
|
if (argc == 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.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-10-24 06:17:13 +00:00
|
|
|
return CMD_RET_USAGE;
|
|
|
|
argc--;
|
|
|
|
argv++;
|
|
|
|
if (uuid_str_to_bin(argv[0], guid.b,
|
|
|
|
UUID_STR_FORMAT_GUID))
|
|
|
|
return CMD_RET_USAGE;
|
2020-07-15 16:00:56 +00:00
|
|
|
guid_p = (const efi_guid_t *)guid.b;
|
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.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-10-24 06:17:13 +00:00
|
|
|
} else if (!strcmp(argv[0], "-n")) {
|
|
|
|
verbose = false;
|
|
|
|
} else {
|
|
|
|
return CMD_RET_USAGE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-25 06:54:36 +00:00
|
|
|
/* enumerate and show all UEFI variables */
|
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.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-10-24 06:17:13 +00:00
|
|
|
return efi_dump_var_all(argc, argv, guid_p, verbose);
|
2019-02-25 06:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* append_value() - encode UEFI variable's value
|
|
|
|
* @bufp: Buffer of encoded UEFI variable's value
|
|
|
|
* @sizep: Size of buffer
|
|
|
|
* @data: data to be encoded into the value
|
|
|
|
* Return: 0 on success, -1 otherwise
|
|
|
|
*
|
|
|
|
* Interpret a given data string and append it to buffer.
|
|
|
|
* Buffer will be realloc'ed if necessary.
|
|
|
|
*
|
|
|
|
* Currently supported formats are:
|
|
|
|
* =0x0123...: Hexadecimal number
|
|
|
|
* =H0123...: Hexadecimal-byte array
|
|
|
|
* ="...", =S"..." or <string>:
|
|
|
|
* String
|
|
|
|
*/
|
|
|
|
static int append_value(char **bufp, size_t *sizep, char *data)
|
|
|
|
{
|
|
|
|
char *tmp_buf = NULL, *new_buf = NULL, *value;
|
|
|
|
unsigned long len = 0;
|
|
|
|
|
|
|
|
if (!strncmp(data, "=0x", 2)) { /* hexadecimal number */
|
|
|
|
union {
|
|
|
|
u8 u8;
|
|
|
|
u16 u16;
|
|
|
|
u32 u32;
|
|
|
|
u64 u64;
|
|
|
|
} tmp_data;
|
|
|
|
unsigned long hex_value;
|
|
|
|
void *hex_ptr;
|
|
|
|
|
|
|
|
data += 3;
|
|
|
|
len = strlen(data);
|
|
|
|
if ((len & 0x1)) /* not multiple of two */
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
len /= 2;
|
|
|
|
if (len > 8)
|
|
|
|
return -1;
|
|
|
|
else if (len > 4)
|
|
|
|
len = 8;
|
|
|
|
else if (len > 2)
|
|
|
|
len = 4;
|
|
|
|
|
|
|
|
/* convert hex hexadecimal number */
|
|
|
|
if (strict_strtoul(data, 16, &hex_value) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
tmp_buf = malloc(len);
|
|
|
|
if (!tmp_buf)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (len == 1) {
|
|
|
|
tmp_data.u8 = hex_value;
|
|
|
|
hex_ptr = &tmp_data.u8;
|
|
|
|
} else if (len == 2) {
|
|
|
|
tmp_data.u16 = hex_value;
|
|
|
|
hex_ptr = &tmp_data.u16;
|
|
|
|
} else if (len == 4) {
|
|
|
|
tmp_data.u32 = hex_value;
|
|
|
|
hex_ptr = &tmp_data.u32;
|
|
|
|
} else {
|
|
|
|
tmp_data.u64 = hex_value;
|
|
|
|
hex_ptr = &tmp_data.u64;
|
|
|
|
}
|
|
|
|
memcpy(tmp_buf, hex_ptr, len);
|
|
|
|
value = tmp_buf;
|
|
|
|
|
|
|
|
} else if (!strncmp(data, "=H", 2)) { /* hexadecimal-byte array */
|
|
|
|
data += 2;
|
|
|
|
len = strlen(data);
|
|
|
|
if (len & 0x1) /* not multiple of two */
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
len /= 2;
|
|
|
|
tmp_buf = malloc(len);
|
|
|
|
if (!tmp_buf)
|
|
|
|
return -1;
|
|
|
|
|
2019-04-30 05:14:09 +00:00
|
|
|
if (hex2bin((u8 *)tmp_buf, data, len) < 0) {
|
|
|
|
printf("Error: illegal hexadecimal string\n");
|
|
|
|
free(tmp_buf);
|
2019-02-25 06:54:36 +00:00
|
|
|
return -1;
|
2019-04-30 05:14:09 +00:00
|
|
|
}
|
2019-02-25 06:54:36 +00:00
|
|
|
|
|
|
|
value = tmp_buf;
|
|
|
|
} else { /* string */
|
|
|
|
if (!strncmp(data, "=\"", 2) || !strncmp(data, "=S\"", 3)) {
|
|
|
|
if (data[1] == '"')
|
|
|
|
data += 2;
|
|
|
|
else
|
|
|
|
data += 3;
|
|
|
|
value = data;
|
|
|
|
len = strlen(data) - 1;
|
|
|
|
if (data[len] != '"')
|
|
|
|
return -1;
|
|
|
|
} else {
|
|
|
|
value = data;
|
|
|
|
len = strlen(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
new_buf = realloc(*bufp, *sizep + len);
|
|
|
|
if (!new_buf)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
memcpy(new_buf + *sizep, value, len);
|
|
|
|
*bufp = new_buf;
|
|
|
|
*sizep += len;
|
|
|
|
|
|
|
|
out:
|
|
|
|
free(tmp_buf);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-10-04 04:46:25 +00:00
|
|
|
* do_env_set_efi() - set UEFI variable
|
2019-02-25 06:54:36 +00:00
|
|
|
*
|
|
|
|
* @cmdtp: Command table
|
|
|
|
* @flag: Command flag
|
|
|
|
* @argc: Number of arguments
|
|
|
|
* @argv: Argument array
|
|
|
|
* Return: CMD_RET_SUCCESS on success, or CMD_RET_RET_FAILURE
|
|
|
|
*
|
|
|
|
* This function is for "env set -e" or "setenv -e" command:
|
2020-04-14 02:51:47 +00:00
|
|
|
* => env set -e [-guid guid][-nv][-bs][-rt][-at][-a][-v]
|
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.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-10-24 06:17:13 +00:00
|
|
|
* [-i address,size] var, or
|
|
|
|
* var [value ...]
|
2019-02-25 06:54:36 +00:00
|
|
|
* Encode values specified and set given UEFI variable.
|
|
|
|
* If no value is specified, delete the variable.
|
|
|
|
*/
|
2020-05-10 17:40:03 +00:00
|
|
|
int do_env_set_efi(struct cmd_tbl *cmdtp, int flag, int argc,
|
|
|
|
char *const argv[])
|
2019-02-25 06:54:36 +00:00
|
|
|
{
|
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.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-10-24 06:17:13 +00:00
|
|
|
char *var_name, *value, *ep;
|
|
|
|
ulong addr;
|
|
|
|
efi_uintn_t size;
|
2019-02-25 06:54:36 +00:00
|
|
|
efi_guid_t guid;
|
2019-06-04 06:52:11 +00:00
|
|
|
u32 attributes;
|
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.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-10-24 06:17:13 +00:00
|
|
|
bool default_guid, verbose, value_on_memory;
|
|
|
|
u16 *var_name16 = NULL, *p;
|
|
|
|
size_t len;
|
2019-02-25 06:54:36 +00:00
|
|
|
efi_status_t ret;
|
|
|
|
|
|
|
|
if (argc == 1)
|
|
|
|
return CMD_RET_USAGE;
|
|
|
|
|
|
|
|
/* Initialize EFI drivers */
|
|
|
|
ret = efi_init_obj_list();
|
|
|
|
if (ret != EFI_SUCCESS) {
|
|
|
|
printf("Error: Cannot initialize UEFI sub-system, r = %lu\n",
|
|
|
|
ret & ~EFI_ERROR_MASK);
|
|
|
|
return CMD_RET_FAILURE;
|
|
|
|
}
|
|
|
|
|
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.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-10-24 06:17:13 +00:00
|
|
|
/*
|
|
|
|
* attributes = EFI_VARIABLE_BOOTSERVICE_ACCESS |
|
|
|
|
* EFI_VARIABLE_RUNTIME_ACCESS;
|
|
|
|
*/
|
|
|
|
value = NULL;
|
|
|
|
size = 0;
|
|
|
|
attributes = 0;
|
|
|
|
guid = efi_global_variable_guid;
|
|
|
|
default_guid = true;
|
|
|
|
verbose = false;
|
|
|
|
value_on_memory = false;
|
|
|
|
for (argc--, argv++; argc > 0 && argv[0][0] == '-'; argc--, argv++) {
|
|
|
|
if (!strcmp(argv[0], "-guid")) {
|
|
|
|
if (argc == 1)
|
|
|
|
return CMD_RET_USAGE;
|
|
|
|
|
|
|
|
argc--;
|
|
|
|
argv++;
|
|
|
|
if (uuid_str_to_bin(argv[0], guid.b,
|
|
|
|
UUID_STR_FORMAT_GUID)) {
|
2020-07-15 16:00:56 +00:00
|
|
|
return CMD_RET_USAGE;
|
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.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-10-24 06:17:13 +00:00
|
|
|
}
|
|
|
|
default_guid = false;
|
|
|
|
} else if (!strcmp(argv[0], "-bs")) {
|
|
|
|
attributes |= EFI_VARIABLE_BOOTSERVICE_ACCESS;
|
|
|
|
} else if (!strcmp(argv[0], "-rt")) {
|
|
|
|
attributes |= EFI_VARIABLE_RUNTIME_ACCESS;
|
|
|
|
} else if (!strcmp(argv[0], "-nv")) {
|
|
|
|
attributes |= EFI_VARIABLE_NON_VOLATILE;
|
2020-04-14 02:51:47 +00:00
|
|
|
} else if (!strcmp(argv[0], "-at")) {
|
|
|
|
attributes |=
|
|
|
|
EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS;
|
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.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-10-24 06:17:13 +00:00
|
|
|
} else if (!strcmp(argv[0], "-a")) {
|
|
|
|
attributes |= EFI_VARIABLE_APPEND_WRITE;
|
|
|
|
} else if (!strcmp(argv[0], "-i")) {
|
|
|
|
/* data comes from memory */
|
|
|
|
if (argc == 1)
|
|
|
|
return CMD_RET_USAGE;
|
|
|
|
|
|
|
|
argc--;
|
|
|
|
argv++;
|
|
|
|
addr = simple_strtoul(argv[0], &ep, 16);
|
2020-08-24 06:27:49 +00:00
|
|
|
if (*ep != ':')
|
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.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-10-24 06:17:13 +00:00
|
|
|
return CMD_RET_USAGE;
|
|
|
|
|
2020-04-14 02:51:46 +00:00
|
|
|
/* 0 should be allowed for delete */
|
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.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-10-24 06:17:13 +00:00
|
|
|
size = simple_strtoul(++ep, NULL, 16);
|
2020-04-14 02:51:46 +00:00
|
|
|
|
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.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-10-24 06:17:13 +00:00
|
|
|
value_on_memory = true;
|
|
|
|
} else if (!strcmp(argv[0], "-v")) {
|
|
|
|
verbose = true;
|
|
|
|
} else {
|
|
|
|
return CMD_RET_USAGE;
|
|
|
|
}
|
2019-06-04 06:52:11 +00:00
|
|
|
}
|
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.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-10-24 06:17:13 +00:00
|
|
|
if (!argc)
|
|
|
|
return CMD_RET_USAGE;
|
2019-06-04 06:52:11 +00:00
|
|
|
|
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.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-10-24 06:17:13 +00:00
|
|
|
var_name = argv[0];
|
2020-04-14 02:51:46 +00:00
|
|
|
if (default_guid) {
|
|
|
|
if (!strcmp(var_name, "db") || !strcmp(var_name, "dbx") ||
|
|
|
|
!strcmp(var_name, "dbt"))
|
|
|
|
guid = efi_guid_image_security_database;
|
|
|
|
else
|
|
|
|
guid = efi_global_variable_guid;
|
|
|
|
}
|
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.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-10-24 06:17:13 +00:00
|
|
|
|
|
|
|
if (verbose) {
|
2020-07-15 16:00:56 +00:00
|
|
|
printf("GUID: %pUl %s\n", &guid,
|
|
|
|
efi_guid_to_str((const efi_guid_t *)&guid));
|
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.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-10-24 06:17:13 +00:00
|
|
|
printf("Attributes: 0x%x\n", attributes);
|
|
|
|
}
|
2019-02-25 06:54:36 +00:00
|
|
|
|
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.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-10-24 06:17:13 +00:00
|
|
|
/* for value */
|
|
|
|
if (value_on_memory)
|
|
|
|
value = map_sysmem(addr, 0);
|
|
|
|
else if (argc > 1)
|
|
|
|
for (argc--, argv++; argc > 0; argc--, argv++)
|
2019-02-25 06:54:36 +00:00
|
|
|
if (append_value(&value, &size, argv[0]) < 0) {
|
2019-05-28 00:00:35 +00:00
|
|
|
printf("## Failed to process an argument, %s\n",
|
|
|
|
argv[0]);
|
2019-02-25 06:54:36 +00:00
|
|
|
ret = CMD_RET_FAILURE;
|
|
|
|
goto out;
|
|
|
|
}
|
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.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-10-24 06:17:13 +00:00
|
|
|
|
|
|
|
if (size && verbose) {
|
|
|
|
printf("Value:\n");
|
|
|
|
print_hex_dump(" ", DUMP_PREFIX_OFFSET,
|
|
|
|
16, 1, value, size, true);
|
2019-02-25 06:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
len = utf8_utf16_strnlen(var_name, strlen(var_name));
|
|
|
|
var_name16 = malloc((len + 1) * 2);
|
|
|
|
if (!var_name16) {
|
2019-05-28 00:00:35 +00:00
|
|
|
printf("## Out of memory\n");
|
2019-02-25 06:54:36 +00:00
|
|
|
ret = CMD_RET_FAILURE;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
p = var_name16;
|
|
|
|
utf8_utf16_strncpy(&p, var_name, len + 1);
|
|
|
|
|
2020-06-24 17:55:13 +00:00
|
|
|
ret = efi_set_variable_int(var_name16, &guid, attributes, size, value,
|
|
|
|
true);
|
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.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-10-24 06:17:13 +00:00
|
|
|
unmap_sysmem(value);
|
2019-05-28 00:00:35 +00:00
|
|
|
if (ret == EFI_SUCCESS) {
|
|
|
|
ret = CMD_RET_SUCCESS;
|
|
|
|
} else {
|
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.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-10-24 06:17:13 +00:00
|
|
|
const char *msg;
|
|
|
|
|
|
|
|
switch (ret) {
|
|
|
|
case EFI_NOT_FOUND:
|
|
|
|
msg = " (not found)";
|
|
|
|
break;
|
|
|
|
case EFI_WRITE_PROTECTED:
|
|
|
|
msg = " (read only)";
|
|
|
|
break;
|
|
|
|
case EFI_INVALID_PARAMETER:
|
|
|
|
msg = " (invalid parameter)";
|
|
|
|
break;
|
|
|
|
case EFI_SECURITY_VIOLATION:
|
|
|
|
msg = " (validation failed)";
|
|
|
|
break;
|
|
|
|
case EFI_OUT_OF_RESOURCES:
|
|
|
|
msg = " (out of memory)";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
msg = "";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
printf("## Failed to set EFI variable%s\n", msg);
|
2019-05-28 00:00:35 +00:00
|
|
|
ret = CMD_RET_FAILURE;
|
|
|
|
}
|
2019-02-25 06:54:36 +00:00
|
|
|
out:
|
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.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-10-24 06:17:13 +00:00
|
|
|
if (value_on_memory)
|
|
|
|
unmap_sysmem(value);
|
|
|
|
else
|
|
|
|
free(value);
|
2019-02-25 06:54:36 +00:00
|
|
|
free(var_name16);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|