* [PATCH 0/4] efi_loader: simplify efidebug implementation
@ 2021-05-24 9:56 Heinrich Schuchardt
2021-05-24 9:56 ` [PATCH 1/4] efi_loader: simplify show_efi_boot_opt_data() Heinrich Schuchardt
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: Heinrich Schuchardt @ 2021-05-24 9:56 UTC (permalink / raw)
To: Alexander Graf
Cc: AKASHI Takahiro, Ilias Apalodimas, u-boot, Heinrich Schuchardt
This series contains several patches reducing the code size of the efidebug
command implementation.
Heinrich Schuchardt (4):
efi_loader: simplify show_efi_boot_opt_data()
efi_loader: simplify show_efi_boot_order()
efi_loader: use efi_create_indexed_name()
efi_loader: simplify accessing variables
cmd/efidebug.c | 96 +++++++++++++++++---------------------------------
1 file changed, 33 insertions(+), 63 deletions(-)
--
2.30.2
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 1/4] efi_loader: simplify show_efi_boot_opt_data()
2021-05-24 9:56 [PATCH 0/4] efi_loader: simplify efidebug implementation Heinrich Schuchardt
@ 2021-05-24 9:56 ` Heinrich Schuchardt
2021-05-24 13:51 ` Ilias Apalodimas
2021-05-24 9:56 ` [PATCH 2/4] efi_loader: simplify show_efi_boot_order() Heinrich Schuchardt
` (2 subsequent siblings)
3 siblings, 1 reply; 9+ messages in thread
From: Heinrich Schuchardt @ 2021-05-24 9:56 UTC (permalink / raw)
To: Alexander Graf
Cc: AKASHI Takahiro, Ilias Apalodimas, u-boot, Heinrich Schuchardt
To print a UTF-16 string use %ls instead of converting string to UTF-8.
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
cmd/efidebug.c | 13 +------------
1 file changed, 1 insertion(+), 12 deletions(-)
diff --git a/cmd/efidebug.c b/cmd/efidebug.c
index 0bf7b8856c..9444eca49c 100644
--- a/cmd/efidebug.c
+++ b/cmd/efidebug.c
@@ -1147,8 +1147,6 @@ static void show_efi_boot_opt_data(u16 *varname16, void *data, size_t *size)
{
struct efi_device_path *initrd_path = NULL;
struct efi_load_option lo;
- char *label, *p;
- size_t label_len16, label_len;
u16 *dp_str;
efi_status_t ret;
efi_uintn_t initrd_dp_size;
@@ -1160,14 +1158,6 @@ static void show_efi_boot_opt_data(u16 *varname16, void *data, size_t *size)
return;
}
- label_len16 = u16_strlen(lo.label);
- label_len = utf16_utf8_strnlen(lo.label, label_len16);
- label = malloc(label_len + 1);
- if (!label)
- return;
- p = label;
- utf16_utf8_strncpy(&p, lo.label, label_len16);
-
printf("%ls:\nattributes: %c%c%c (0x%08x)\n",
varname16,
/* ACTIVE */
@@ -1177,7 +1167,7 @@ static void show_efi_boot_opt_data(u16 *varname16, void *data, size_t *size)
/* HIDDEN */
lo.attributes & LOAD_OPTION_HIDDEN ? 'H' : '-',
lo.attributes);
- printf(" label: %s\n", label);
+ printf(" label: %ls\n", lo.label);
dp_str = efi_dp_str(lo.file_path);
printf(" file_path: %ls\n", dp_str);
@@ -1194,7 +1184,6 @@ static void show_efi_boot_opt_data(u16 *varname16, void *data, size_t *size)
printf(" data:\n");
print_hex_dump(" ", DUMP_PREFIX_OFFSET, 16, 1,
lo.optional_data, *size, true);
- free(label);
}
/**
--
2.30.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/4] efi_loader: simplify show_efi_boot_order()
2021-05-24 9:56 [PATCH 0/4] efi_loader: simplify efidebug implementation Heinrich Schuchardt
2021-05-24 9:56 ` [PATCH 1/4] efi_loader: simplify show_efi_boot_opt_data() Heinrich Schuchardt
@ 2021-05-24 9:56 ` Heinrich Schuchardt
2021-05-24 13:52 ` Ilias Apalodimas
2021-05-24 9:56 ` [PATCH 3/4] efi_loader: use efi_create_indexed_name() Heinrich Schuchardt
2021-05-24 9:56 ` [PATCH 4/4] efi_loader: simplify accessing variables Heinrich Schuchardt
3 siblings, 1 reply; 9+ messages in thread
From: Heinrich Schuchardt @ 2021-05-24 9:56 UTC (permalink / raw)
To: Alexander Graf
Cc: AKASHI Takahiro, Ilias Apalodimas, u-boot, Heinrich Schuchardt
To print a UTF-16 string use %ls instead of converting string to UTF-8.
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
cmd/efidebug.c | 15 +--------------
1 file changed, 1 insertion(+), 14 deletions(-)
diff --git a/cmd/efidebug.c b/cmd/efidebug.c
index 9444eca49c..4c0facd26c 100644
--- a/cmd/efidebug.c
+++ b/cmd/efidebug.c
@@ -1317,8 +1317,6 @@ static int show_efi_boot_order(void)
u16 var_name16[9], *p16;
void *data;
struct efi_load_option lo;
- char *label, *p;
- size_t label_len16, label_len;
efi_status_t ret;
size = 0;
@@ -1380,18 +1378,7 @@ static int show_efi_boot_order(void)
goto out;
}
- label_len16 = u16_strlen(lo.label);
- label_len = utf16_utf8_strnlen(lo.label, label_len16);
- label = malloc(label_len + 1);
- if (!label) {
- free(data);
- ret = CMD_RET_FAILURE;
- goto out;
- }
- p = label;
- utf16_utf8_strncpy(&p, lo.label, label_len16);
- printf("%2d: %s: %s\n", i + 1, var_name, label);
- free(label);
+ printf("%2d: %s: %ls\n", i + 1, var_name, lo.label);
free(data);
}
--
2.30.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 3/4] efi_loader: use efi_create_indexed_name()
2021-05-24 9:56 [PATCH 0/4] efi_loader: simplify efidebug implementation Heinrich Schuchardt
2021-05-24 9:56 ` [PATCH 1/4] efi_loader: simplify show_efi_boot_opt_data() Heinrich Schuchardt
2021-05-24 9:56 ` [PATCH 2/4] efi_loader: simplify show_efi_boot_order() Heinrich Schuchardt
@ 2021-05-24 9:56 ` Heinrich Schuchardt
2021-05-24 13:52 ` Ilias Apalodimas
2021-05-24 9:56 ` [PATCH 4/4] efi_loader: simplify accessing variables Heinrich Schuchardt
3 siblings, 1 reply; 9+ messages in thread
From: Heinrich Schuchardt @ 2021-05-24 9:56 UTC (permalink / raw)
To: Alexander Graf
Cc: AKASHI Takahiro, Ilias Apalodimas, u-boot, Heinrich Schuchardt
Simplify the creation of indexed variable names like 'Boot0000' by using
function efi_create_indexed_name().
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
cmd/efidebug.c | 37 ++++++++++++++-----------------------
1 file changed, 14 insertions(+), 23 deletions(-)
diff --git a/cmd/efidebug.c b/cmd/efidebug.c
index 4c0facd26c..9c3ba73d61 100644
--- a/cmd/efidebug.c
+++ b/cmd/efidebug.c
@@ -227,8 +227,7 @@ static int do_efi_capsule_res(struct cmd_tbl *cmdtp, int flag,
{
int capsule_id;
char *endp;
- char var_name[12];
- u16 var_name16[12], *p;
+ u16 var_name16[12];
efi_guid_t guid;
struct efi_capsule_result_variable_header *result = NULL;
efi_uintn_t size;
@@ -259,9 +258,8 @@ static int do_efi_capsule_res(struct cmd_tbl *cmdtp, int flag,
if (capsule_id < 0 || capsule_id > 0xffff)
return CMD_RET_USAGE;
- sprintf(var_name, "Capsule%04X", capsule_id);
- p = var_name16;
- utf8_utf16_strncpy(&p, var_name, 9);
+ efi_create_indexed_name(var_name16, sizeof(var_name16),
+ "Capsule", capsule_id);
}
size = 0;
@@ -954,8 +952,7 @@ static int do_efi_boot_add(struct cmd_tbl *cmdtp, int flag,
{
int id;
char *endp;
- char var_name[9];
- u16 var_name16[9], *p;
+ u16 var_name16[9];
efi_guid_t guid;
size_t label_len, label_len16;
u16 *label;
@@ -988,9 +985,8 @@ static int do_efi_boot_add(struct cmd_tbl *cmdtp, int flag,
if (*endp != '\0' || id > 0xffff)
return CMD_RET_USAGE;
- sprintf(var_name, "Boot%04X", id);
- p = var_name16;
- utf8_utf16_strncpy(&p, var_name, 9);
+ efi_create_indexed_name(var_name16, sizeof(var_name16),
+ "Boot", id);
/* label */
label_len = strlen(argv[2]);
@@ -1107,8 +1103,7 @@ static int do_efi_boot_rm(struct cmd_tbl *cmdtp, int flag,
efi_guid_t guid;
int id, i;
char *endp;
- char var_name[9];
- u16 var_name16[9], *p;
+ u16 var_name16[9];
efi_status_t ret;
if (argc == 1)
@@ -1120,10 +1115,8 @@ static int do_efi_boot_rm(struct cmd_tbl *cmdtp, int flag,
if (*endp != '\0' || id > 0xffff)
return CMD_RET_FAILURE;
- sprintf(var_name, "Boot%04X", id);
- p = var_name16;
- utf8_utf16_strncpy(&p, var_name, 9);
-
+ efi_create_indexed_name(var_name16, sizeof(var_name16),
+ "Boot", id);
ret = EFI_CALL(efi_set_variable(var_name16, &guid, 0, 0, NULL));
if (ret) {
printf("Cannot remove %ls\n", var_name16);
@@ -1313,8 +1306,7 @@ static int show_efi_boot_order(void)
u16 *bootorder;
efi_uintn_t size;
int num, i;
- char var_name[9];
- u16 var_name16[9], *p16;
+ u16 var_name16[9];
void *data;
struct efi_load_option lo;
efi_status_t ret;
@@ -1344,16 +1336,15 @@ static int show_efi_boot_order(void)
num = size / sizeof(u16);
for (i = 0; i < num; i++) {
- sprintf(var_name, "Boot%04X", bootorder[i]);
- p16 = var_name16;
- utf8_utf16_strncpy(&p16, var_name, 9);
+ efi_create_indexed_name(var_name16, sizeof(var_name16),
+ "Boot", i);
size = 0;
ret = EFI_CALL(efi_get_variable(var_name16,
&efi_global_variable_guid, NULL,
&size, NULL));
if (ret != EFI_BUFFER_TOO_SMALL) {
- printf("%2d: %s: (not defined)\n", i + 1, var_name);
+ printf("%2d: %ls: (not defined)\n", i + 1, var_name16);
continue;
}
@@ -1378,7 +1369,7 @@ static int show_efi_boot_order(void)
goto out;
}
- printf("%2d: %s: %ls\n", i + 1, var_name, lo.label);
+ printf("%2d: %ls: %ls\n", i + 1, var_name16, lo.label);
free(data);
}
--
2.30.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 4/4] efi_loader: simplify accessing variables
2021-05-24 9:56 [PATCH 0/4] efi_loader: simplify efidebug implementation Heinrich Schuchardt
` (2 preceding siblings ...)
2021-05-24 9:56 ` [PATCH 3/4] efi_loader: use efi_create_indexed_name() Heinrich Schuchardt
@ 2021-05-24 9:56 ` Heinrich Schuchardt
2021-05-24 13:55 ` Ilias Apalodimas
3 siblings, 1 reply; 9+ messages in thread
From: Heinrich Schuchardt @ 2021-05-24 9:56 UTC (permalink / raw)
To: Alexander Graf
Cc: AKASHI Takahiro, Ilias Apalodimas, u-boot, Heinrich Schuchardt
Use efi_get_variable_int() instead of EFI_CALL(RT->get_variable()).
Use efi_set_variable_int() instead of EFI_CALL(efi_set_variable()).
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
cmd/efidebug.c | 33 ++++++++++++++++++---------------
1 file changed, 18 insertions(+), 15 deletions(-)
diff --git a/cmd/efidebug.c b/cmd/efidebug.c
index 9c3ba73d61..c6352719dd 100644
--- a/cmd/efidebug.c
+++ b/cmd/efidebug.c
@@ -12,6 +12,7 @@
#include <efi_load_initrd.h>
#include <efi_loader.h>
#include <efi_rng.h>
+#include <efi_variable.h>
#include <exports.h>
#include <hexdump.h>
#include <log.h>
@@ -239,8 +240,9 @@ static int do_efi_capsule_res(struct cmd_tbl *cmdtp, int flag,
guid = efi_guid_capsule_report;
if (argc == 1) {
size = sizeof(var_name16);
- ret = EFI_CALL(RT->get_variable(L"CapsuleLast", &guid, NULL,
- &size, var_name16));
+ ret = efi_get_variable_int(L"CapsuleLast", &guid, NULL,
+ &size, var_name16, NULL);
+
if (ret != EFI_SUCCESS) {
if (ret == EFI_NOT_FOUND)
printf("CapsuleLast doesn't exist\n");
@@ -263,13 +265,13 @@ static int do_efi_capsule_res(struct cmd_tbl *cmdtp, int flag,
}
size = 0;
- ret = EFI_CALL(RT->get_variable(var_name16, &guid, NULL, &size, NULL));
+ ret = efi_get_variable_int(var_name16, &guid, NULL, &size, NULL, NULL);
if (ret == EFI_BUFFER_TOO_SMALL) {
result = malloc(size);
if (!result)
return CMD_RET_FAILURE;
- ret = EFI_CALL(RT->get_variable(var_name16, &guid, NULL, &size,
- result));
+ ret = efi_get_variable_int(var_name16, &guid, NULL, &size,
+ result, NULL);
}
if (ret != EFI_SUCCESS) {
free(result);
@@ -1062,11 +1064,11 @@ static int do_efi_boot_add(struct cmd_tbl *cmdtp, int flag,
goto out;
}
- ret = EFI_CALL(efi_set_variable(var_name16, &guid,
- EFI_VARIABLE_NON_VOLATILE |
- EFI_VARIABLE_BOOTSERVICE_ACCESS |
- EFI_VARIABLE_RUNTIME_ACCESS,
- size, data));
+ ret = efi_set_variable_int(var_name16, &guid,
+ EFI_VARIABLE_NON_VOLATILE |
+ EFI_VARIABLE_BOOTSERVICE_ACCESS |
+ EFI_VARIABLE_RUNTIME_ACCESS,
+ size, data, false);
if (ret != EFI_SUCCESS) {
printf("Cannot set %ls\n", var_name16);
r = CMD_RET_FAILURE;
@@ -1117,7 +1119,8 @@ static int do_efi_boot_rm(struct cmd_tbl *cmdtp, int flag,
efi_create_indexed_name(var_name16, sizeof(var_name16),
"Boot", id);
- ret = EFI_CALL(efi_set_variable(var_name16, &guid, 0, 0, NULL));
+ ret = efi_set_variable_int(var_name16, &guid, 0, 0, NULL,
+ false);
if (ret) {
printf("Cannot remove %ls\n", var_name16);
return CMD_RET_FAILURE;
@@ -1416,11 +1419,11 @@ static int do_efi_boot_next(struct cmd_tbl *cmdtp, int flag,
guid = efi_global_variable_guid;
size = sizeof(u16);
- ret = EFI_CALL(efi_set_variable(L"BootNext", &guid,
+ ret = efi_set_variable_int(L"BootNext", &guid,
EFI_VARIABLE_NON_VOLATILE |
EFI_VARIABLE_BOOTSERVICE_ACCESS |
EFI_VARIABLE_RUNTIME_ACCESS,
- size, &bootnext));
+ size, &bootnext, false);
if (ret != EFI_SUCCESS) {
printf("Cannot set BootNext\n");
r = CMD_RET_FAILURE;
@@ -1477,11 +1480,11 @@ static int do_efi_boot_order(struct cmd_tbl *cmdtp, int flag,
}
guid = efi_global_variable_guid;
- ret = EFI_CALL(efi_set_variable(L"BootOrder", &guid,
+ ret = efi_set_variable_int(L"BootOrder", &guid,
EFI_VARIABLE_NON_VOLATILE |
EFI_VARIABLE_BOOTSERVICE_ACCESS |
EFI_VARIABLE_RUNTIME_ACCESS,
- size, bootorder));
+ size, bootorder, true);
if (ret != EFI_SUCCESS) {
printf("Cannot set BootOrder\n");
r = CMD_RET_FAILURE;
--
2.30.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 1/4] efi_loader: simplify show_efi_boot_opt_data()
2021-05-24 9:56 ` [PATCH 1/4] efi_loader: simplify show_efi_boot_opt_data() Heinrich Schuchardt
@ 2021-05-24 13:51 ` Ilias Apalodimas
0 siblings, 0 replies; 9+ messages in thread
From: Ilias Apalodimas @ 2021-05-24 13:51 UTC (permalink / raw)
To: Heinrich Schuchardt; +Cc: Alexander Graf, AKASHI Takahiro, u-boot
On Mon, May 24, 2021 at 11:56:53AM +0200, Heinrich Schuchardt wrote:
> To print a UTF-16 string use %ls instead of converting string to UTF-8.
>
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
> cmd/efidebug.c | 13 +------------
> 1 file changed, 1 insertion(+), 12 deletions(-)
>
> diff --git a/cmd/efidebug.c b/cmd/efidebug.c
> index 0bf7b8856c..9444eca49c 100644
> --- a/cmd/efidebug.c
> +++ b/cmd/efidebug.c
> @@ -1147,8 +1147,6 @@ static void show_efi_boot_opt_data(u16 *varname16, void *data, size_t *size)
> {
> struct efi_device_path *initrd_path = NULL;
> struct efi_load_option lo;
> - char *label, *p;
> - size_t label_len16, label_len;
> u16 *dp_str;
> efi_status_t ret;
> efi_uintn_t initrd_dp_size;
> @@ -1160,14 +1158,6 @@ static void show_efi_boot_opt_data(u16 *varname16, void *data, size_t *size)
> return;
> }
>
> - label_len16 = u16_strlen(lo.label);
> - label_len = utf16_utf8_strnlen(lo.label, label_len16);
> - label = malloc(label_len + 1);
> - if (!label)
> - return;
> - p = label;
> - utf16_utf8_strncpy(&p, lo.label, label_len16);
> -
> printf("%ls:\nattributes: %c%c%c (0x%08x)\n",
> varname16,
> /* ACTIVE */
> @@ -1177,7 +1167,7 @@ static void show_efi_boot_opt_data(u16 *varname16, void *data, size_t *size)
> /* HIDDEN */
> lo.attributes & LOAD_OPTION_HIDDEN ? 'H' : '-',
> lo.attributes);
> - printf(" label: %s\n", label);
> + printf(" label: %ls\n", lo.label);
>
> dp_str = efi_dp_str(lo.file_path);
> printf(" file_path: %ls\n", dp_str);
> @@ -1194,7 +1184,6 @@ static void show_efi_boot_opt_data(u16 *varname16, void *data, size_t *size)
> printf(" data:\n");
> print_hex_dump(" ", DUMP_PREFIX_OFFSET, 16, 1,
> lo.optional_data, *size, true);
> - free(label);
> }
>
> /**
> --
> 2.30.2
>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 2/4] efi_loader: simplify show_efi_boot_order()
2021-05-24 9:56 ` [PATCH 2/4] efi_loader: simplify show_efi_boot_order() Heinrich Schuchardt
@ 2021-05-24 13:52 ` Ilias Apalodimas
0 siblings, 0 replies; 9+ messages in thread
From: Ilias Apalodimas @ 2021-05-24 13:52 UTC (permalink / raw)
To: Heinrich Schuchardt; +Cc: Alexander Graf, AKASHI Takahiro, u-boot
On Mon, May 24, 2021 at 11:56:54AM +0200, Heinrich Schuchardt wrote:
> To print a UTF-16 string use %ls instead of converting string to UTF-8.
>
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
> cmd/efidebug.c | 15 +--------------
> 1 file changed, 1 insertion(+), 14 deletions(-)
>
> diff --git a/cmd/efidebug.c b/cmd/efidebug.c
> index 9444eca49c..4c0facd26c 100644
> --- a/cmd/efidebug.c
> +++ b/cmd/efidebug.c
> @@ -1317,8 +1317,6 @@ static int show_efi_boot_order(void)
> u16 var_name16[9], *p16;
> void *data;
> struct efi_load_option lo;
> - char *label, *p;
> - size_t label_len16, label_len;
> efi_status_t ret;
>
> size = 0;
> @@ -1380,18 +1378,7 @@ static int show_efi_boot_order(void)
> goto out;
> }
>
> - label_len16 = u16_strlen(lo.label);
> - label_len = utf16_utf8_strnlen(lo.label, label_len16);
> - label = malloc(label_len + 1);
> - if (!label) {
> - free(data);
> - ret = CMD_RET_FAILURE;
> - goto out;
> - }
> - p = label;
> - utf16_utf8_strncpy(&p, lo.label, label_len16);
> - printf("%2d: %s: %s\n", i + 1, var_name, label);
> - free(label);
> + printf("%2d: %s: %ls\n", i + 1, var_name, lo.label);
>
> free(data);
> }
> --
> 2.30.2
>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 3/4] efi_loader: use efi_create_indexed_name()
2021-05-24 9:56 ` [PATCH 3/4] efi_loader: use efi_create_indexed_name() Heinrich Schuchardt
@ 2021-05-24 13:52 ` Ilias Apalodimas
0 siblings, 0 replies; 9+ messages in thread
From: Ilias Apalodimas @ 2021-05-24 13:52 UTC (permalink / raw)
To: Heinrich Schuchardt; +Cc: Alexander Graf, AKASHI Takahiro, u-boot
On Mon, May 24, 2021 at 11:56:55AM +0200, Heinrich Schuchardt wrote:
> Simplify the creation of indexed variable names like 'Boot0000' by using
> function efi_create_indexed_name().
>
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
> cmd/efidebug.c | 37 ++++++++++++++-----------------------
> 1 file changed, 14 insertions(+), 23 deletions(-)
>
> diff --git a/cmd/efidebug.c b/cmd/efidebug.c
> index 4c0facd26c..9c3ba73d61 100644
> --- a/cmd/efidebug.c
> +++ b/cmd/efidebug.c
> @@ -227,8 +227,7 @@ static int do_efi_capsule_res(struct cmd_tbl *cmdtp, int flag,
> {
> int capsule_id;
> char *endp;
> - char var_name[12];
> - u16 var_name16[12], *p;
> + u16 var_name16[12];
> efi_guid_t guid;
> struct efi_capsule_result_variable_header *result = NULL;
> efi_uintn_t size;
> @@ -259,9 +258,8 @@ static int do_efi_capsule_res(struct cmd_tbl *cmdtp, int flag,
> if (capsule_id < 0 || capsule_id > 0xffff)
> return CMD_RET_USAGE;
>
> - sprintf(var_name, "Capsule%04X", capsule_id);
> - p = var_name16;
> - utf8_utf16_strncpy(&p, var_name, 9);
> + efi_create_indexed_name(var_name16, sizeof(var_name16),
> + "Capsule", capsule_id);
> }
>
> size = 0;
> @@ -954,8 +952,7 @@ static int do_efi_boot_add(struct cmd_tbl *cmdtp, int flag,
> {
> int id;
> char *endp;
> - char var_name[9];
> - u16 var_name16[9], *p;
> + u16 var_name16[9];
> efi_guid_t guid;
> size_t label_len, label_len16;
> u16 *label;
> @@ -988,9 +985,8 @@ static int do_efi_boot_add(struct cmd_tbl *cmdtp, int flag,
> if (*endp != '\0' || id > 0xffff)
> return CMD_RET_USAGE;
>
> - sprintf(var_name, "Boot%04X", id);
> - p = var_name16;
> - utf8_utf16_strncpy(&p, var_name, 9);
> + efi_create_indexed_name(var_name16, sizeof(var_name16),
> + "Boot", id);
>
> /* label */
> label_len = strlen(argv[2]);
> @@ -1107,8 +1103,7 @@ static int do_efi_boot_rm(struct cmd_tbl *cmdtp, int flag,
> efi_guid_t guid;
> int id, i;
> char *endp;
> - char var_name[9];
> - u16 var_name16[9], *p;
> + u16 var_name16[9];
> efi_status_t ret;
>
> if (argc == 1)
> @@ -1120,10 +1115,8 @@ static int do_efi_boot_rm(struct cmd_tbl *cmdtp, int flag,
> if (*endp != '\0' || id > 0xffff)
> return CMD_RET_FAILURE;
>
> - sprintf(var_name, "Boot%04X", id);
> - p = var_name16;
> - utf8_utf16_strncpy(&p, var_name, 9);
> -
> + efi_create_indexed_name(var_name16, sizeof(var_name16),
> + "Boot", id);
> ret = EFI_CALL(efi_set_variable(var_name16, &guid, 0, 0, NULL));
> if (ret) {
> printf("Cannot remove %ls\n", var_name16);
> @@ -1313,8 +1306,7 @@ static int show_efi_boot_order(void)
> u16 *bootorder;
> efi_uintn_t size;
> int num, i;
> - char var_name[9];
> - u16 var_name16[9], *p16;
> + u16 var_name16[9];
> void *data;
> struct efi_load_option lo;
> efi_status_t ret;
> @@ -1344,16 +1336,15 @@ static int show_efi_boot_order(void)
>
> num = size / sizeof(u16);
> for (i = 0; i < num; i++) {
> - sprintf(var_name, "Boot%04X", bootorder[i]);
> - p16 = var_name16;
> - utf8_utf16_strncpy(&p16, var_name, 9);
> + efi_create_indexed_name(var_name16, sizeof(var_name16),
> + "Boot", i);
>
> size = 0;
> ret = EFI_CALL(efi_get_variable(var_name16,
> &efi_global_variable_guid, NULL,
> &size, NULL));
> if (ret != EFI_BUFFER_TOO_SMALL) {
> - printf("%2d: %s: (not defined)\n", i + 1, var_name);
> + printf("%2d: %ls: (not defined)\n", i + 1, var_name16);
> continue;
> }
>
> @@ -1378,7 +1369,7 @@ static int show_efi_boot_order(void)
> goto out;
> }
>
> - printf("%2d: %s: %ls\n", i + 1, var_name, lo.label);
> + printf("%2d: %ls: %ls\n", i + 1, var_name16, lo.label);
>
> free(data);
> }
> --
> 2.30.2
>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 4/4] efi_loader: simplify accessing variables
2021-05-24 9:56 ` [PATCH 4/4] efi_loader: simplify accessing variables Heinrich Schuchardt
@ 2021-05-24 13:55 ` Ilias Apalodimas
0 siblings, 0 replies; 9+ messages in thread
From: Ilias Apalodimas @ 2021-05-24 13:55 UTC (permalink / raw)
To: Heinrich Schuchardt; +Cc: Alexander Graf, AKASHI Takahiro, u-boot
On Mon, May 24, 2021 at 11:56:56AM +0200, Heinrich Schuchardt wrote:
> Use efi_get_variable_int() instead of EFI_CALL(RT->get_variable()).
> Use efi_set_variable_int() instead of EFI_CALL(efi_set_variable()).
>
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
> cmd/efidebug.c | 33 ++++++++++++++++++---------------
> 1 file changed, 18 insertions(+), 15 deletions(-)
>
> diff --git a/cmd/efidebug.c b/cmd/efidebug.c
> index 9c3ba73d61..c6352719dd 100644
> --- a/cmd/efidebug.c
> +++ b/cmd/efidebug.c
> @@ -12,6 +12,7 @@
> #include <efi_load_initrd.h>
> #include <efi_loader.h>
> #include <efi_rng.h>
> +#include <efi_variable.h>
> #include <exports.h>
> #include <hexdump.h>
> #include <log.h>
> @@ -239,8 +240,9 @@ static int do_efi_capsule_res(struct cmd_tbl *cmdtp, int flag,
> guid = efi_guid_capsule_report;
> if (argc == 1) {
> size = sizeof(var_name16);
> - ret = EFI_CALL(RT->get_variable(L"CapsuleLast", &guid, NULL,
> - &size, var_name16));
> + ret = efi_get_variable_int(L"CapsuleLast", &guid, NULL,
> + &size, var_name16, NULL);
> +
> if (ret != EFI_SUCCESS) {
> if (ret == EFI_NOT_FOUND)
> printf("CapsuleLast doesn't exist\n");
> @@ -263,13 +265,13 @@ static int do_efi_capsule_res(struct cmd_tbl *cmdtp, int flag,
> }
>
> size = 0;
> - ret = EFI_CALL(RT->get_variable(var_name16, &guid, NULL, &size, NULL));
> + ret = efi_get_variable_int(var_name16, &guid, NULL, &size, NULL, NULL);
> if (ret == EFI_BUFFER_TOO_SMALL) {
> result = malloc(size);
> if (!result)
> return CMD_RET_FAILURE;
> - ret = EFI_CALL(RT->get_variable(var_name16, &guid, NULL, &size,
> - result));
> + ret = efi_get_variable_int(var_name16, &guid, NULL, &size,
> + result, NULL);
> }
> if (ret != EFI_SUCCESS) {
> free(result);
> @@ -1062,11 +1064,11 @@ static int do_efi_boot_add(struct cmd_tbl *cmdtp, int flag,
> goto out;
> }
>
> - ret = EFI_CALL(efi_set_variable(var_name16, &guid,
> - EFI_VARIABLE_NON_VOLATILE |
> - EFI_VARIABLE_BOOTSERVICE_ACCESS |
> - EFI_VARIABLE_RUNTIME_ACCESS,
> - size, data));
> + ret = efi_set_variable_int(var_name16, &guid,
> + EFI_VARIABLE_NON_VOLATILE |
> + EFI_VARIABLE_BOOTSERVICE_ACCESS |
> + EFI_VARIABLE_RUNTIME_ACCESS,
> + size, data, false);
> if (ret != EFI_SUCCESS) {
> printf("Cannot set %ls\n", var_name16);
> r = CMD_RET_FAILURE;
> @@ -1117,7 +1119,8 @@ static int do_efi_boot_rm(struct cmd_tbl *cmdtp, int flag,
>
> efi_create_indexed_name(var_name16, sizeof(var_name16),
> "Boot", id);
> - ret = EFI_CALL(efi_set_variable(var_name16, &guid, 0, 0, NULL));
> + ret = efi_set_variable_int(var_name16, &guid, 0, 0, NULL,
> + false);
> if (ret) {
> printf("Cannot remove %ls\n", var_name16);
> return CMD_RET_FAILURE;
> @@ -1416,11 +1419,11 @@ static int do_efi_boot_next(struct cmd_tbl *cmdtp, int flag,
>
> guid = efi_global_variable_guid;
> size = sizeof(u16);
> - ret = EFI_CALL(efi_set_variable(L"BootNext", &guid,
> + ret = efi_set_variable_int(L"BootNext", &guid,
> EFI_VARIABLE_NON_VOLATILE |
> EFI_VARIABLE_BOOTSERVICE_ACCESS |
> EFI_VARIABLE_RUNTIME_ACCESS,
> - size, &bootnext));
> + size, &bootnext, false);
> if (ret != EFI_SUCCESS) {
> printf("Cannot set BootNext\n");
> r = CMD_RET_FAILURE;
> @@ -1477,11 +1480,11 @@ static int do_efi_boot_order(struct cmd_tbl *cmdtp, int flag,
> }
>
> guid = efi_global_variable_guid;
> - ret = EFI_CALL(efi_set_variable(L"BootOrder", &guid,
> + ret = efi_set_variable_int(L"BootOrder", &guid,
> EFI_VARIABLE_NON_VOLATILE |
> EFI_VARIABLE_BOOTSERVICE_ACCESS |
> EFI_VARIABLE_RUNTIME_ACCESS,
> - size, bootorder));
> + size, bootorder, true);
> if (ret != EFI_SUCCESS) {
> printf("Cannot set BootOrder\n");
> r = CMD_RET_FAILURE;
> --
> 2.30.2
>
Tested-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2021-05-24 13:55 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-24 9:56 [PATCH 0/4] efi_loader: simplify efidebug implementation Heinrich Schuchardt
2021-05-24 9:56 ` [PATCH 1/4] efi_loader: simplify show_efi_boot_opt_data() Heinrich Schuchardt
2021-05-24 13:51 ` Ilias Apalodimas
2021-05-24 9:56 ` [PATCH 2/4] efi_loader: simplify show_efi_boot_order() Heinrich Schuchardt
2021-05-24 13:52 ` Ilias Apalodimas
2021-05-24 9:56 ` [PATCH 3/4] efi_loader: use efi_create_indexed_name() Heinrich Schuchardt
2021-05-24 13:52 ` Ilias Apalodimas
2021-05-24 9:56 ` [PATCH 4/4] efi_loader: simplify accessing variables Heinrich Schuchardt
2021-05-24 13:55 ` Ilias Apalodimas
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.