From patchwork Fri Apr 26 00:44:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1091170 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="QbvFUXg/"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44qwMJ36Vkz9s00 for ; Fri, 26 Apr 2019 10:45:32 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 19110C21E0D; Fri, 26 Apr 2019 00:45:11 +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 BE8B0C21E35; Fri, 26 Apr 2019 00:45:09 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 6C58DC21DB5; Fri, 26 Apr 2019 00:45:02 +0000 (UTC) Received: from mail-yb1-f180.google.com (mail-yb1-f180.google.com [209.85.219.180]) by lists.denx.de (Postfix) with ESMTPS id C45B6C21E45 for ; Fri, 26 Apr 2019 00:44:57 +0000 (UTC) Received: by mail-yb1-f180.google.com with SMTP id e76so691420ybc.3 for ; Thu, 25 Apr 2019 17:44:57 -0700 (PDT) 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=YL0HW1e+s3jFtVLZdLYDlXpnHnzrJ0atH+L576jKbXc=; b=QbvFUXg/lY6X2SeEj0UZmT2KuhT/hkigThPQ3JhWFSA5JT84gE9mKiYtcRIhG+fM8E GRuQn9XDoamLdnZNO4UE2fyir15qImjGCtLvok8EgiNEKM6XBWGLB50HY0bpKHVTVY0H rseMuniiZ3tYU2m/6oTyZtlcTutRXq2lbrb1yBFWEfivg6fbK0tVXBaAKs3d78UqfyYf Bv8GwnOU7gf8k1Xi9XqyAkEgypHwYbXpEyutgzl/mNJwjeoqbZ6pwr/OT7su+/5v81Nu EmSbRgiXx+SF0bGtGedzvdMOBBZzVC0pgn9Iwf2irkGBLXDvp4ToSfcDgxMII1dFVS8T eJKQ== 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=YL0HW1e+s3jFtVLZdLYDlXpnHnzrJ0atH+L576jKbXc=; b=iEE9UQM8BJmTZ3i+hcJZ52PjQWw9UYhXuWVwfunelxAehyUO69moeAZhxOaRgcd7Ky HAjrp64x9Gpgtp19mlcYt9yjYl79wyBCjrjYDv11h3dbpSu0mgw1EJ+gXKZinZ2aFdhQ pqO2VqBcsmRcYQbB/26ujEiAvMvApU43sQ4dEG64nuPnfojn33bLQ2MOOz8aOE+tRCji WVgnNjVWWNQjK1/mkjgeKcRm8ibDVrKdugx6Po5HXPtaPNPbMuVDv0WkDe9jzPa4laAv N06Hn/V7CzkT9SOPPwib6J+LQiajvqWNPUZK4PjHQm4gD7lOM3oMoueCam7uu1ELt9K6 fqlw== X-Gm-Message-State: APjAAAWklq4MeeHzVqRRnHAqtSpUxNB9s7eWmycU8RkgCa0YicuEakSf plwC+iAfr2/URgfEjCkuRPvDqoZeUl4= X-Google-Smtp-Source: APXvYqz+1WV7IobOOXroUHYwdB2mlTtbzxh+3PD+F4/CAZD+f5BC2dDyk6Db5Suh4S73XtbQF4Xuxw== X-Received: by 2002:a25:2e4e:: with SMTP id b14mr35848763ybn.12.1556239496546; Thu, 25 Apr 2019 17:44:56 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id q11sm8405627ywg.53.2019.04.25.17.44.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Apr 2019 17:44:56 -0700 (PDT) From: AKASHI Takahiro To: xypron.glpk@gmx.de, agraf@csgraf.de Date: Fri, 26 Apr 2019 09:44:18 +0900 Message-Id: <20190426004418.31081-2-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190426004418.31081-1-takahiro.akashi@linaro.org> References: <20190426004418.31081-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH 1/1] cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName() 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 in do_efi_boot_dump(), we directly read EFI variables from related environment variables. To accommodate alternative storage backends, we should switch to using the UEFI API instead. Signed-off-by: AKASHI Takahiro Reviewed-by: Heinrich Schuchardt --- cmd/efidebug.c | 79 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 55 insertions(+), 24 deletions(-) diff --git a/cmd/efidebug.c b/cmd/efidebug.c index a40c4f4be286..efe4ea873eec 100644 --- a/cmd/efidebug.c +++ b/cmd/efidebug.c @@ -693,6 +693,17 @@ static void show_efi_boot_opt(int id) free(data); } +static int u16_tohex(u16 c) +{ + if (c >= '0' && c <= '9') + return c - '0'; + if (c >= 'A' && c <= 'F') + return c - 'A' + 10; + + /* not hexadecimal */ + return -1; +} + /** * show_efi_boot_dump() - dump all UEFI load options * @@ -709,38 +720,58 @@ static void show_efi_boot_opt(int id) static int do_efi_boot_dump(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { - char regex[256]; - char * const regexlist[] = {regex}; - char *variables = NULL, *boot, *value; - int len; - int id; + u16 *var_name16, *p; + efi_uintn_t buf_size, size; + efi_guid_t guid; + int id, i, digit; + efi_status_t ret; if (argc > 1) return CMD_RET_USAGE; - snprintf(regex, 256, "efi_.*-.*-.*-.*-.*_Boot[0-9A-F]+"); - - /* TODO: use GetNextVariableName? */ - len = hexport_r(&env_htab, '\n', H_MATCH_REGEX | H_MATCH_KEY, - &variables, 0, 1, regexlist); - - if (!len) - return CMD_RET_SUCCESS; - - if (len < 0) + buf_size = 128; + var_name16 = malloc(buf_size); + if (!var_name16) return CMD_RET_FAILURE; - boot = variables; - while (*boot) { - value = strstr(boot, "Boot") + 4; - id = (int)simple_strtoul(value, NULL, 16); - show_efi_boot_opt(id); - boot = strchr(boot, '\n'); - if (!*boot) + 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; - boot++; + 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; + } + + if (memcmp(var_name16, L"Boot", 8)) + continue; + + for (id = 0, i = 0; i < 4; i++) { + digit = u16_tohex(var_name16[4 + i]); + if (digit < 0) + break; + id = (id << 4) + digit; + } + if (i == 4 && !var_name16[8]) + show_efi_boot_opt(id); } - free(variables); + + free(var_name16); return CMD_RET_SUCCESS; }