mirror of
https://github.com/brain-hackers/u-boot-brain
synced 2024-10-03 01:50:43 +09:00
efi_loader: fix 'efidebug boot dump'
* Do not recreate a variable name that we already have as u16 string. * Check the return value of malloc() * EFI_NOT_FOUND cannot occur for a variable name returned by GetNextVariableName(). Remove a print statement. * Don't copy a GUID for no reason. * Don't use the run-time service table to call exported functions. * Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338). Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
This commit is contained in:
parent
661c02ceb2
commit
b5f4e9e384
@ -682,13 +682,13 @@ static int do_efi_boot_rm(cmd_tbl_t *cmdtp, int flag,
|
|||||||
/**
|
/**
|
||||||
* show_efi_boot_opt_data() - dump UEFI load option
|
* show_efi_boot_opt_data() - dump UEFI load option
|
||||||
*
|
*
|
||||||
* @id: load option number
|
* @varname16: variable name
|
||||||
* @data: value of UEFI load option variable
|
* @data: value of UEFI load option variable
|
||||||
* @size: size of the boot option
|
* @size: size of the boot option
|
||||||
*
|
*
|
||||||
* Decode the value of UEFI load option variable and print information.
|
* Decode the value of UEFI load option variable and print information.
|
||||||
*/
|
*/
|
||||||
static void show_efi_boot_opt_data(int id, void *data, size_t size)
|
static void show_efi_boot_opt_data(u16 *varname16, void *data, size_t size)
|
||||||
{
|
{
|
||||||
struct efi_load_option lo;
|
struct efi_load_option lo;
|
||||||
char *label, *p;
|
char *label, *p;
|
||||||
@ -705,8 +705,8 @@ static void show_efi_boot_opt_data(int id, void *data, size_t size)
|
|||||||
p = label;
|
p = label;
|
||||||
utf16_utf8_strncpy(&p, lo.label, label_len16);
|
utf16_utf8_strncpy(&p, lo.label, label_len16);
|
||||||
|
|
||||||
printf("Boot%04X:\n", id);
|
printf("%ls:\nattributes: %c%c%c (0x%08x)\n",
|
||||||
printf(" attributes: %c%c%c (0x%08x)\n",
|
varname16,
|
||||||
/* ACTIVE */
|
/* ACTIVE */
|
||||||
lo.attributes & LOAD_OPTION_ACTIVE ? 'A' : '-',
|
lo.attributes & LOAD_OPTION_ACTIVE ? 'A' : '-',
|
||||||
/* FORCE RECONNECT */
|
/* FORCE RECONNECT */
|
||||||
@ -730,37 +730,32 @@ static void show_efi_boot_opt_data(int id, void *data, size_t size)
|
|||||||
/**
|
/**
|
||||||
* show_efi_boot_opt() - dump UEFI load option
|
* show_efi_boot_opt() - dump UEFI load option
|
||||||
*
|
*
|
||||||
* @id: Load option number
|
* @varname16: variable name
|
||||||
*
|
*
|
||||||
* Dump information defined by UEFI load option.
|
* Dump information defined by UEFI load option.
|
||||||
*/
|
*/
|
||||||
static void show_efi_boot_opt(int id)
|
static void show_efi_boot_opt(u16 *varname16)
|
||||||
{
|
{
|
||||||
char var_name[9];
|
void *data;
|
||||||
u16 var_name16[9], *p;
|
|
||||||
efi_guid_t guid;
|
|
||||||
void *data = NULL;
|
|
||||||
efi_uintn_t size;
|
efi_uintn_t size;
|
||||||
efi_status_t ret;
|
efi_status_t ret;
|
||||||
|
|
||||||
sprintf(var_name, "Boot%04X", id);
|
|
||||||
p = var_name16;
|
|
||||||
utf8_utf16_strncpy(&p, var_name, 9);
|
|
||||||
guid = efi_global_variable_guid;
|
|
||||||
|
|
||||||
size = 0;
|
size = 0;
|
||||||
ret = EFI_CALL(RT->get_variable(var_name16, &guid, NULL, &size, NULL));
|
ret = EFI_CALL(efi_get_variable(varname16, &efi_global_variable_guid,
|
||||||
|
NULL, &size, NULL));
|
||||||
if (ret == EFI_BUFFER_TOO_SMALL) {
|
if (ret == EFI_BUFFER_TOO_SMALL) {
|
||||||
data = malloc(size);
|
data = malloc(size);
|
||||||
ret = EFI_CALL(RT->get_variable(var_name16, &guid, NULL, &size,
|
if (!data) {
|
||||||
data));
|
printf("ERROR: Out of memory\n");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
ret = EFI_CALL(efi_get_variable(varname16,
|
||||||
|
&efi_global_variable_guid,
|
||||||
|
NULL, &size, data));
|
||||||
if (ret == EFI_SUCCESS)
|
if (ret == EFI_SUCCESS)
|
||||||
show_efi_boot_opt_data(id, data, size);
|
show_efi_boot_opt_data(varname16, data, size);
|
||||||
else if (ret == EFI_NOT_FOUND)
|
|
||||||
printf("Boot%04X: not found\n", id);
|
|
||||||
|
|
||||||
free(data);
|
free(data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int u16_tohex(u16 c)
|
static int u16_tohex(u16 c)
|
||||||
@ -839,7 +834,7 @@ static int do_efi_boot_dump(cmd_tbl_t *cmdtp, int flag,
|
|||||||
id = (id << 4) + digit;
|
id = (id << 4) + digit;
|
||||||
}
|
}
|
||||||
if (i == 4 && !var_name16[8])
|
if (i == 4 && !var_name16[8])
|
||||||
show_efi_boot_opt(id);
|
show_efi_boot_opt(var_name16);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(var_name16);
|
free(var_name16);
|
||||||
|
Loading…
Reference in New Issue
Block a user