From patchwork Fri Feb 22 08:10:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1046630 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="x2nb4xRT"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 445PBW5mGkz9s70 for ; Fri, 22 Feb 2019 19:09:23 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 70517C21F45; Fri, 22 Feb 2019 08:09:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id A5FA0C21F1A; Fri, 22 Feb 2019 08:09:13 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 16D7FC21E47; Fri, 22 Feb 2019 08:09:07 +0000 (UTC) Received: from mail-yw1-f65.google.com (mail-yw1-f65.google.com [209.85.161.65]) by lists.denx.de (Postfix) with ESMTPS id BC496C21EB1 for ; Fri, 22 Feb 2019 08:09:01 +0000 (UTC) Received: by mail-yw1-f65.google.com with SMTP id n12so496990ywn.13 for ; Fri, 22 Feb 2019 00:09:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=C2pYstzit0+yKpP06bISNhlyZioKCj7JPxc02+WGWFc=; b=x2nb4xRTaGjTOlNgDJUQthPuzGjjUlcBP+46TUcn5JbMyywQp/p3upr6GKoV5jSeSq mXFmb/0hhNbb7+oQEWY5Liw0ff8phjAoFqYsam8eo1nuhFUQPHbXty1GkNtaEQSbwiox Zl1vcrHCjAoYGIqq6tVfTfapF+fv2TFjtR6+tR7mmF3JlJ5PsvFzMKhC8NV0pO3z9d3n l6Ao+lPTqvSq5fXkV3jwTOec5qQfYwu9id6yp/OEsfCAVuBW20Zmq4P9Wzbmg6NX//J2 MgBLHETVBuDLyNdVR0JncD0VwFS/POlEDFT9tYVTKmN3hsNqushqOIaJOyP5V6jD74eA ABug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=C2pYstzit0+yKpP06bISNhlyZioKCj7JPxc02+WGWFc=; b=oVgnck73gaQesgIvbt92xQZJnnHl3IxGqvNuqonJbESUijneUl2Wxx5p3FydQvuLOS DknLYnqMbZVRNJOnvu2kQ2dtwUfHghrclXbQiAhappiwOK1G17gh7CGBaXb+5CoydIns 2P3vAiKhhQ59J7u4cYXsZQDSYPv38v9cIcK8iXVc3VJG/RGl2O0db3XnVgxDvlfWXn9k pYuHVxDrdsUfKcpfClWAI6rfuBDdeoQI6B6SYkVggUJAoh9EnpJ5oy09imG+9qEMEpff XshY5SmRCCuBVmakzSMazWeBbsVWhI+h/jeMXi7QQlKhQkn3sY37aS5GvJ9q5vBnor7K CzIw== X-Gm-Message-State: AHQUAubjUjPsWF+i6WA9360PKGoxQ6sQInwItCBA9G1lXCZyBsl9ETLN //+CTh7zsisGzRUd97PASDWx4w== X-Google-Smtp-Source: AHgI3IYnnhMyqVo3bN7nzo2tJEvLbU7Nm1xeDxV9rqki9tksG0tvqL07lE41ZYc0Jkx5Dxnlz0SU8w== X-Received: by 2002:a0d:c242:: with SMTP id e63mr2210268ywd.10.1550822940430; Fri, 22 Feb 2019 00:09:00 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id 205sm281381ywf.35.2019.02.22.00.08.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Feb 2019 00:08:59 -0800 (PST) From: AKASHI Takahiro To: trini@konsulko.com, agraf@suse.de, xypron.glpk@gmx.de Date: Fri, 22 Feb 2019 17:10:07 +0900 Message-Id: <20190222081014.2117-2-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190222081014.2117-1-takahiro.akashi@linaro.org> References: <20190222081014.2117-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH v8 1/8] cmd: env: add "-e" option for handling UEFI variables X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" "env [print|set] -e" allows for handling uefi variables without knowing details about mapping to corresponding u-boot variables. Signed-off-by: AKASHI Takahiro --- MAINTAINERS | 1 + cmd/Kconfig | 10 ++ cmd/Makefile | 1 + cmd/nvedit.c | 28 +++- cmd/nvedit_efi.c | 399 ++++++++++++++++++++++++++++++++++++++++++++++ include/command.h | 8 + 6 files changed, 446 insertions(+), 1 deletion(-) create mode 100644 cmd/nvedit_efi.c diff --git a/MAINTAINERS b/MAINTAINERS index f1f8818d6ba8..0cce9db2660e 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -471,6 +471,7 @@ F: lib/efi*/ F: test/py/tests/test_efi* F: test/unicode_ut.c F: cmd/bootefi.c +F: cmd/nvedit_efi.c F: tools/file2include.c FPGA diff --git a/cmd/Kconfig b/cmd/Kconfig index 3ea42e425611..ddcdee44538d 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -420,6 +420,16 @@ config CMD_ENV_FLAGS be deleted. This command shows the variables that have special flags. +config CMD_NVEDIT_EFI + bool "env [set|print] -e - set/print UEFI variables" + depends on EFI_LOADER + default y + imply HEXDUMP + help + UEFI variables are encoded as some form of U-Boot variables. + If enabled, we are allowed to set/print UEFI variables using + "env" command with "-e" option without knowing details. + endmenu menu "Memory commands" diff --git a/cmd/Makefile b/cmd/Makefile index a127a995394f..b9ee51869d48 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -98,6 +98,7 @@ obj-$(CONFIG_CMD_MTD) += mtd.o obj-$(CONFIG_CMD_MTDPARTS) += mtdparts.o obj-$(CONFIG_CMD_NAND) += nand.o obj-$(CONFIG_CMD_NET) += net.o +obj-$(CONFIG_CMD_NVEDIT_EFI) += nvedit_efi.o obj-$(CONFIG_CMD_ONENAND) += onenand.o obj-$(CONFIG_CMD_OSD) += osd.o obj-$(CONFIG_CMD_PART) += part.o diff --git a/cmd/nvedit.c b/cmd/nvedit.c index ebaa16b75459..f798e5137d26 100644 --- a/cmd/nvedit.c +++ b/cmd/nvedit.c @@ -119,6 +119,11 @@ static int do_env_print(cmd_tbl_t *cmdtp, int flag, int argc, int rcode = 0; int env_flag = H_HIDE_DOT; +#if defined(CONFIG_CMD_NVEDIT_EFI) + if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'e') + return do_env_print_efi(cmdtp, flag, --argc, ++argv); +#endif + if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'a') { argc--; argv++; @@ -216,6 +221,12 @@ static int _do_env_set(int flag, int argc, char * const argv[], int env_flag) ENTRY e, *ep; debug("Initial value for argc=%d\n", argc); + +#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_CMD_NVEDIT_EFI) + if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'e') + return do_env_set_efi(NULL, flag, --argc, ++argv); +#endif + while (argc > 1 && **(argv + 1) == '-') { char *arg = *++argv; @@ -1263,11 +1274,17 @@ static char env_help_text[] = "env import [-d] [-t [-r] | -b | -c] addr [size] [var ...] - import environment\n" #endif "env print [-a | name ...] - print environment\n" +#if defined(CONFIG_CMD_NVEDIT_EFI) + "env print -e [name ...] - print UEFI environment\n" +#endif #if defined(CONFIG_CMD_RUN) "env run var [...] - run commands in an environment variable\n" #endif #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE) "env save - save environment\n" +#endif +#if defined(CONFIG_CMD_NVEDIT_EFI) + "env set -e name [arg ...] - set UEFI variable; unset if 'arg' not specified\n" #endif "env set [-f] name [arg ...]\n"; #endif @@ -1295,6 +1312,10 @@ U_BOOT_CMD_COMPLETE( printenv, CONFIG_SYS_MAXARGS, 1, do_env_print, "print environment variables", "[-a]\n - print [all] values of all environment variables\n" +#if defined(CONFIG_CMD_NVEDIT_EFI) + "printenv -e [name ...]\n" + " - print UEFI variable 'name' or all the variables\n" +#endif "printenv name ...\n" " - print value of environment variable 'name'", var_complete @@ -1322,7 +1343,12 @@ U_BOOT_CMD_COMPLETE( U_BOOT_CMD_COMPLETE( setenv, CONFIG_SYS_MAXARGS, 0, do_env_set, "set environment variables", - "[-f] name value ...\n" +#if defined(CONFIG_CMD_NVEDIT_EFI) + "-e name [value ...]\n" + " - set UEFI variable 'name' to 'value' ...'\n" + " - delete UEFI variable 'name' if 'value' not specified\n" +#endif + "setenv [-f] name value ...\n" " - [forcibly] set environment variable 'name' to 'value ...'\n" "setenv [-f] name\n" " - [forcibly] delete environment variable 'name'", diff --git a/cmd/nvedit_efi.c b/cmd/nvedit_efi.c new file mode 100644 index 000000000000..ca32566a6153 --- /dev/null +++ b/cmd/nvedit_efi.c @@ -0,0 +1,399 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Integrate UEFI variables to u-boot env interface + * + * Copyright (c) 2018 AKASHI Takahiro, Linaro Limited + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * 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"}, +}; + +/** + * efi_dump_single_var() - show information about a UEFI variable + * + * @name: Name of the variable + * @guid: Vendor GUID + * + * Show information encoded in one UEFI variable + */ +static void efi_dump_single_var(u16 *name, efi_guid_t *guid) +{ + u32 attributes; + u8 *data; + efi_uintn_t size; + int count, i; + efi_status_t ret; + + data = NULL; + size = 0; + ret = EFI_CALL(efi_get_variable(name, guid, &attributes, &size, data)); + if (ret == EFI_BUFFER_TOO_SMALL) { + data = malloc(size); + if (!data) + goto out; + + ret = EFI_CALL(efi_get_variable(name, guid, &attributes, &size, + data)); + } + if (ret == EFI_NOT_FOUND) { + printf("Error: \"%ls\" not defined\n", name); + goto out; + } + if (ret != EFI_SUCCESS) + goto out; + + printf("%ls:", name); + for (count = 0, i = 0; i < ARRAY_SIZE(efi_var_attrs); i++) + if (attributes & efi_var_attrs[i].mask) { + if (count) + putc('|'); + else + putc(' '); + count++; + puts(efi_var_attrs[i].text); + } + printf(", DataSize = 0x%zx\n", size); + print_hex_dump(" ", DUMP_PREFIX_OFFSET, 16, 1, data, size, true); + + return; +out: + free(data); +} + +/** + * efi_dump_vars() - show information about named UEFI variables + * + * @argc: Number of arguments (variables) + * @argv: Argument (variable name) array + * Return: CMD_RET_SUCCESS on success, or CMD_RET_RET_FAILURE + * + * Show information encoded in named UEFI variables + */ +static int efi_dump_vars(int argc, char * const argv[]) +{ + u16 *var_name16, *p; + efi_uintn_t buf_size, size; + + buf_size = 128; + var_name16 = malloc(buf_size); + if (!var_name16) + return CMD_RET_FAILURE; + + for (; argc > 0; argc--, argv++) { + size = (utf8_utf16_strlen(argv[0]) + 1) * sizeof(u16); + if (buf_size < size) { + buf_size = size; + p = realloc(var_name16, buf_size); + if (!p) { + free(var_name16); + return CMD_RET_FAILURE; + } + var_name16 = p; + } + + p = var_name16; + utf8_utf16_strcpy(&p, argv[0]); + + efi_dump_single_var(var_name16, + (efi_guid_t *)&efi_global_variable_guid); + } + + free(var_name16); + + return CMD_RET_SUCCESS; +} + +/** + * efi_dump_vars() - show information about all the UEFI variables + * + * Return: CMD_RET_SUCCESS on success, or CMD_RET_RET_FAILURE + * + * Show information encoded in all the UEFI variables + */ +static int efi_dump_var_all(void) +{ + u16 *var_name16, *p; + efi_uintn_t buf_size, size; + efi_guid_t guid; + efi_status_t ret; + + 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; + } + + efi_dump_single_var(var_name16, &guid); + } + + free(var_name16); + + 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: + * => env print -e [var [...]] + * If one or more variable names are specified, show information + * named UEFI variables, otherwise show all the UEFI variables. + */ +int do_env_print_efi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + 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; + } + + if (argc > 1) + /* show specified UEFI variables */ + return efi_dump_vars(--argc, ++argv); + + /* enumerate and show all UEFI variables */ + return efi_dump_var_all(); +} + +/** + * 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 + */ +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; + + if (hex2bin((u8 *)tmp_buf, data, len) < 0) + return -1; + + 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; +} + +/** + * do_env_print_efi() - set UEFI variable + * + * @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: + * => env set -e var [value ...]] + * Encode values specified and set given UEFI variable. + * If no value is specified, delete the variable. + */ +int do_env_set_efi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + char *var_name, *value = NULL; + efi_uintn_t size = 0; + u16 *var_name16 = NULL, *p; + size_t len; + efi_guid_t guid; + 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; + } + + var_name = argv[1]; + if (argc == 2) { + /* delete */ + value = NULL; + size = 0; + } else { /* set */ + argc -= 2; + argv += 2; + + for ( ; argc > 0; argc--, argv++) + if (append_value(&value, &size, argv[0]) < 0) { + ret = CMD_RET_FAILURE; + goto out; + } + } + + len = utf8_utf16_strnlen(var_name, strlen(var_name)); + var_name16 = malloc((len + 1) * 2); + if (!var_name16) { + ret = CMD_RET_FAILURE; + goto out; + } + p = var_name16; + 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, + size, value)); + ret = (ret == EFI_SUCCESS ? CMD_RET_SUCCESS : CMD_RET_FAILURE); +out: + free(value); + free(var_name16); + + return ret; +} diff --git a/include/command.h b/include/command.h index 461b17447c0d..2e24e8ad3eef 100644 --- a/include/command.h +++ b/include/command.h @@ -139,6 +139,14 @@ extern int do_poweroff(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[] extern unsigned long do_go_exec(ulong (*entry)(int, char * const []), int argc, char * const argv[]); + +#if defined(CONFIG_CMD_NVEDIT_EFI) +extern int do_env_print_efi(cmd_tbl_t *cmdtp, int flag, int argc, + char * const argv[]); +extern int do_env_set_efi(cmd_tbl_t *cmdtp, int flag, int argc, + char * const argv[]); +#endif + /* * Error codes that commands return to cmd_process(). We use the standard 0 * and 1 for success and failure, but add one more case - failure with a From patchwork Fri Feb 22 08:10:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1046634 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="bLxR6vy5"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 445PFV09sgz9s70 for ; Fri, 22 Feb 2019 19:11:57 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 92FFEC21ECC; Fri, 22 Feb 2019 08:10:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id A38BEC21F3D; Fri, 22 Feb 2019 08:09:25 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id F1E17C21F13; Fri, 22 Feb 2019 08:09:09 +0000 (UTC) Received: from mail-yw1-f66.google.com (mail-yw1-f66.google.com [209.85.161.66]) by lists.denx.de (Postfix) with ESMTPS id BC794C21EDC for ; Fri, 22 Feb 2019 08:09:03 +0000 (UTC) Received: by mail-yw1-f66.google.com with SMTP id k14so519138ywe.4 for ; Fri, 22 Feb 2019 00:09:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Rg+YW5ShBH20BKLF8c/gosolaShy9PEu7fGBdA7wzgs=; b=bLxR6vy57xoTIYpp1ufaNRzgLSpMj7rU8PUpizKjiJrMWJ3s43zMKiZhkiW1ckfzy3 wF8APZEEdXZojhUQXUf4jDfu9rEgMZ/N6iIJTTKumFh6fgSsJe4Xxqz58DO/48YeHZdL ALUj/vKxT5+2Un81TO/4JpmdZXo0x5/aKwF9hw7a6Il6R4JmctEJTr4T1whBL/eBJwcB 7xnwBdzbnjbQN3EdDnllO47y6Omb7mOO753+Qd69ztGQ/KqniBaRdJ98ciG7EAyfXRM6 3KFqGqVl8gpYl7dJVtirrPFlcB3QSy3eORlR7YTDLFs+5cLe+Yp4bG4DpoJBmLk6lbI3 n/KQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Rg+YW5ShBH20BKLF8c/gosolaShy9PEu7fGBdA7wzgs=; b=MB9C3g9iX2d7o4HGW0u+aGeHlTVVJpXXTfKDVOXLDYOb5iWL7mqivMSvyCpcciAXgk yE8gqd1xZL3GFF1/t9rByVmMPQLgdDHxzmoXEx3kPvrpHtoF94T0vl8KFu7FZhwNrg+D 1JJkQ+nC6aFzFepQf77meFDCUuN89jVbQCeUt7qHWHBxim4FvAHLmsoQt3v6Dl2p3+jU yt+8MU2FpR3DKEF/4KliLi4LRG2+ouiIYVT6XBtNRnZ9r9gUxcCJyHg28rd82Q9hzPAv oQzMoScsPei8a3cR7l2Mud/SQo2Ky0UYvpEYQdKX3zVaCbEwzWuVySPn6QxRp3pn5VJk IfwA== X-Gm-Message-State: AHQUAuYgvoBpYVpMkfj518f5079KTA46dsDhhO+Q7lKAJxeHt/bWksn/ t77Gu8GC/DGGZuAVEfGn/qCdtg== X-Google-Smtp-Source: AHgI3IYFoLGsWFOpXc7cH+il04njyX3f/pX0Em8Tu20RicgK1Afi6ZQO5JgkHDi3f18UwHGEQ5NHSA== X-Received: by 2002:a81:63d4:: with SMTP id x203mr2138134ywb.82.1550822942738; Fri, 22 Feb 2019 00:09:02 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id l6sm252950ywm.43.2019.02.22.00.09.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Feb 2019 00:09:02 -0800 (PST) From: AKASHI Takahiro To: trini@konsulko.com, agraf@suse.de, xypron.glpk@gmx.de Date: Fri, 22 Feb 2019 17:10:08 +0900 Message-Id: <20190222081014.2117-3-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190222081014.2117-1-takahiro.akashi@linaro.org> References: <20190222081014.2117-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH v8 2/8] efi_loader: define load option attributes X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" See UEFI specification v2.7a, section 3.1.3, "Load Option Processing." Signed-off-by: AKASHI Takahiro --- include/efi_api.h | 9 +++++++++ lib/efi_loader/efi_bootmgr.c | 4 ---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/include/efi_api.h b/include/efi_api.h index 45ca05e8ac69..ccf608653d4a 100644 --- a/include/efi_api.h +++ b/include/efi_api.h @@ -1438,4 +1438,13 @@ struct efi_unicode_collation_protocol { char *supported_languages; }; +/* Boot manager load options */ +#define LOAD_OPTION_ACTIVE 0x00000001 +#define LOAD_OPTION_FORCE_RECONNECT 0x00000002 +#define LOAD_OPTION_HIDDEN 0x00000008 +/* All values 0x00000200-0x00001F00 are reserved */ +#define LOAD_OPTION_CATEGORY 0x00001F00 +#define LOAD_OPTION_CATEGORY_BOOT 0x00000000 +#define LOAD_OPTION_CATEGORY_APP 0x00000100 + #endif diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c index 196116b54729..8bb84f888c12 100644 --- a/lib/efi_loader/efi_bootmgr.c +++ b/lib/efi_loader/efi_bootmgr.c @@ -14,10 +14,6 @@ static const struct efi_boot_services *bs; static const struct efi_runtime_services *rs; -#define LOAD_OPTION_ACTIVE 0x00000001 -#define LOAD_OPTION_FORCE_RECONNECT 0x00000002 -#define LOAD_OPTION_HIDDEN 0x00000008 - /* * bootmgr implements the logic of trying to find a payload to boot * based on the BootOrder + BootXXXX variables, and then loading it. From patchwork Fri Feb 22 08:10:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1046633 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="N7MZBC4W"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 445PDG5vMBz9s70 for ; Fri, 22 Feb 2019 19:10:54 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 6C8E9C21E2C; Fri, 22 Feb 2019 08:10:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 201E5C21E8A; Fri, 22 Feb 2019 08:09:21 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id A4037C21F31; Fri, 22 Feb 2019 08:09:11 +0000 (UTC) Received: from mail-yb1-f193.google.com (mail-yb1-f193.google.com [209.85.219.193]) by lists.denx.de (Postfix) with ESMTPS id C3BC4C21F4A for ; Fri, 22 Feb 2019 08:09:06 +0000 (UTC) Received: by mail-yb1-f193.google.com with SMTP id e14so513125ybf.10 for ; Fri, 22 Feb 2019 00:09:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8SJakw7dtoyOGOORdbaCYvrTeJdvP6DRhmcpJQFV9/c=; b=N7MZBC4WMW38Jnc+eVr6MtNBMeg/0q6Y7i+7MQdMDjeDw/Z4ZmOu1A+71flIn6TOdM qPSTtrDhi816QLE46Mwg8N5kDvcTm0HpO6NQMtBWy4yTS5GeYTVwGb92OoVE4KkOZeZ7 nJ6BzVRHYmqRzRyGipMALvowkIxIN3KFkv9AgZ0TlCExqOy9+klZJyCZmqfdVZDMpSb5 P0Sb34qnPahNIz/Sggd7GrPJpOWbUEk7i0uO1arjo/2yOBbtU58v45qjzlGEOgtCP9XW t/miNUQg0Ils09WxSa5Jqaacj6HYTj6lKLsmOHusCbVyptQ8rF9YbpaDEjQHeqNM2N2v Y7ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8SJakw7dtoyOGOORdbaCYvrTeJdvP6DRhmcpJQFV9/c=; b=X029G1mIOJcJXC0zqO/EpejSQMbzsSGJWLWkY8LJhree5n2x4oIlh6Ikum/D5Vq03P EHUM3nEIWzsuR0hkVQBnFSNE4ZblEKxfN2c5BXMbtiRHIigz8N2IOu8Ysws4NYL1w7Kw 4s+mlYqhfMUC/4ZC7dU5XRa5EFTGGJqZHHwKfOvqjSHWbQM1jZ+V4QhITQmTTTyLY1AQ XDWWX/vJMYqFGW3WetlBPDI+SFRfS0s4GsRmaWpy4TFnms7kJCvgmupu6Z+vTcAF0VUk Y5RbNBkY/cSlLPufvS4s9I8LaMiUwfG5qonAw7ysJyP58NN7BRQugHJpYqhdbwtGHLOo aAAA== X-Gm-Message-State: AHQUAuZF2Lji+BLSM/7tplFHbFsKAyYWFaaIJpw13ONmAc6agO99CAfN emOJhtvkxfnb0BtdSh/2zVAsNQ== X-Google-Smtp-Source: AHgI3IZmB2w8T+FH1Ijg0tWnqKoEyy09ZRWQ7syJry6OTrLaCGaaR0Z+HJ3FTtURilBEOLQ4BFRAuQ== X-Received: by 2002:a25:854b:: with SMTP id f11mr2213014ybn.497.1550822945376; Fri, 22 Feb 2019 00:09:05 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id l6sm252972ywm.43.2019.02.22.00.09.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Feb 2019 00:09:04 -0800 (PST) From: AKASHI Takahiro To: trini@konsulko.com, agraf@suse.de, xypron.glpk@gmx.de Date: Fri, 22 Feb 2019 17:10:09 +0900 Message-Id: <20190222081014.2117-4-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190222081014.2117-1-takahiro.akashi@linaro.org> References: <20190222081014.2117-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH v8 3/8] cmd: add efidebug command X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Currently, there is no easy way to add or modify UEFI variables. In particular, bootmgr supports BootOrder/BootXXXX variables, it is quite hard to define them as u-boot variables because they are represented in a complicated and encoded format. The new command, efidebug, helps address these issues and give us more friendly interfaces: * efidebug boot add: add BootXXXX variable * efidebug boot rm: remove BootXXXX variable * efidebug boot dump: display all BootXXXX variables * efidebug boot next: set BootNext variable * efidebug boot order: set/display a boot order (BootOrder) Signed-off-by: AKASHI Takahiro Reviewed-by: Heinrich Schuchardt --- MAINTAINERS | 1 + cmd/Kconfig | 10 + cmd/Makefile | 1 + cmd/efidebug.c | 578 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 590 insertions(+) create mode 100644 cmd/efidebug.c diff --git a/MAINTAINERS b/MAINTAINERS index 0cce9db2660e..4fabb75eda37 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -471,6 +471,7 @@ F: lib/efi*/ F: test/py/tests/test_efi* F: test/unicode_ut.c F: cmd/bootefi.c +F: cmd/efidebug.c F: cmd/nvedit_efi.c F: tools/file2include.c diff --git a/cmd/Kconfig b/cmd/Kconfig index ddcdee44538d..88b086b074be 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -1407,6 +1407,16 @@ config CMD_DISPLAY displayed on a simple board-specific display. Implement display_putc() to use it. +config CMD_EFIDEBUG + bool "efidebug - display/configure UEFI environment" + depends on EFI_LOADER + default n + help + Enable the 'efidebug' command which provides a subset of UEFI + shell utility with simplified functionality. It will be useful + particularly for managing boot parameters as well as examining + various EFI status for debugging. + config CMD_LED bool "led" default y if LED diff --git a/cmd/Makefile b/cmd/Makefile index b9ee51869d48..acb85f49fba8 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -51,6 +51,7 @@ obj-$(CONFIG_CMD_ECHO) += echo.o obj-$(CONFIG_ENV_IS_IN_EEPROM) += eeprom.o obj-$(CONFIG_CMD_EEPROM) += eeprom.o obj-$(CONFIG_EFI_STUB) += efi.o +obj-$(CONFIG_CMD_EFIDEBUG) += efidebug.o obj-$(CONFIG_CMD_ELF) += elf.o obj-$(CONFIG_HUSH_PARSER) += exit.o obj-$(CONFIG_CMD_EXT4) += ext4.o diff --git a/cmd/efidebug.c b/cmd/efidebug.c new file mode 100644 index 000000000000..ef3a66e393f0 --- /dev/null +++ b/cmd/efidebug.c @@ -0,0 +1,578 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * UEFI Shell-like command + * + * Copyright (c) 2018 AKASHI Takahiro, Linaro Limited + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/** + * do_efi_boot_add() - set UEFI load option + * + * @cmdtp: Command table + * @flag: Command flag + * @argc: Number of arguments + * @argv: Argument array + * Return: CMD_RET_SUCCESS on success, + * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure + * + * Implement efidebug "boot add" sub-command. + * Create or change UEFI load option. + * - boot add