From patchwork Mon Nov 28 12:45:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 628985 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2912974pvb; Mon, 28 Nov 2022 04:45:54 -0800 (PST) X-Google-Smtp-Source: AA0mqf5betU+MiK02vRX2qpE6M+ztyjUjWNN9/04egZ1D6crkZOxPmLuvCCOViUmC89F7lv69Ws8 X-Received: by 2002:a02:9149:0:b0:375:9c59:7856 with SMTP id b9-20020a029149000000b003759c597856mr23444033jag.240.1669639553778; Mon, 28 Nov 2022 04:45:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669639553; cv=none; d=google.com; s=arc-20160816; b=kPcQsPy02Kd5Dsphp/FzaF2wfm/tSko1CdZfYzgui9+0upshMsOzxGcR0kfZ6e4VIe 890xYCyPHVNTJ1h2SjnH0f5unQyOOvlH2Atn1ox0uz12Kc1KB5ROCvycWovCFmQKXiqZ 133oEPqd0Xcy5G77B9BthmIrpiQEuAqIUJKFahA7MnxRxnD5aEOKnWlapK/w7sWBackg YIuTz2mTDQTBSYb6zPb4lkmKOwls1W7TL+br+ycqsBrCko1ayy1i2tCsKjWgOfzA8CD5 E+OTT3fHtjj2MpdX54FV0oqc6sMDbZTrB8AJBos+JIQAg07LUfvlxEfwWXouTbpCt1Wg 6dvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=46oMHSDkat/aWjP/ELVjgbt8f6SIWI33I0ShpHcJ3lU=; b=BZUa1ShNO9PKrjzce4vZ/bpnqjzts7CiFypP3o6wwdb4AuKNJs6AFjh5HEhxuTBIP4 dBDcpp8hjKH27f8WNCJzQMfWq9E8B9Z11PlqPndSIX0G2pK3ZSjl3LJOAdxUkQq8tDjT XySGN3K4/xYyzzEJMahASSD1rumpco0/y9t9ozva5p5uNDoOQzFsnw7NdMIYhDnDoPd6 /q0+7Za+3B62HUFa2RaW0uCImWzfHyBzvmjQrubaLoX5fPhzKLiFhFeIcxarcpAw72DV /SzDTOQISBBSVI+rsae2vNkRRJ3KsLCpfuJECPvR866ac2FX9BtMZM1GkdUpZGkjV+oR AFKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=a+qKT5B8; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id l12-20020a0566022dcc00b006b3ad8240a7si10467155iow.69.2022.11.28.04.45.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Nov 2022 04:45:53 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=a+qKT5B8; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 312E885277; Mon, 28 Nov 2022 13:45:36 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="a+qKT5B8"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id AE65F85240; Mon, 28 Nov 2022 13:45:14 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id E77CA8524F for ; Mon, 28 Nov 2022 13:45:10 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-pg1-x531.google.com with SMTP id 6so9797462pgm.6 for ; Mon, 28 Nov 2022 04:45:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=46oMHSDkat/aWjP/ELVjgbt8f6SIWI33I0ShpHcJ3lU=; b=a+qKT5B88UnO5qTkct3QnmEqcBBHbV3/a+yIOzhQQeYpDADjfaarCRHDx5TrTHUPt6 SXrtMvfAFLvWo2sgLQAFsYnH7tY34lawPbqa/SJDcz4Pa7C1yX0mZADiL49Sl5ZjHvde 8Kr3LBfr+aqCEz7p2j8Zf2h1313+ey+pt7Z7nCoCTlXrGC0wRKGmYcnPjQ7wIOm/Lais 2Phz4qKuqMqVlcdlzLwNUxOBXSm8Bv7vkVsvKZsfX9PRfcoV7+IwB8G/hQsMfsEdAgK3 eFD8ZSSyZ3t6qYstkg9PbGHcbJ0iHOaGWGn7nVQCYfdGcfjzW3TI0vfkUIYUVJAJEcI3 bjVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=46oMHSDkat/aWjP/ELVjgbt8f6SIWI33I0ShpHcJ3lU=; b=XAsVLvzquPwlBgpgokDgn9RInM4DUyefpo0EtLmQaWZ453nEZwOd/praK532XXiw0E ibKVONhYzADHS2i6OkNEyhsFbfzNsGgEnMTU1ogZr3woNlLuQeDWHjqVuLRlWv46nN97 B+nn10MpIbJ81ZcAtbLvssB32g9Olwbyu/afD3dkIpDPrGIDELDgGsBr43iIrjTTGMO3 sQ7c39mLckLg9LtTn6x4FI+ZaelmRNBUGy+vhyT/6zo65Z2lNdbS/rO2TBBnLRnHIbOO jjVsypUjd88OmBi1wh/pF6FTVdA1G/CyUBWAxrGHtmJR7xqPDundoNstXmq+XLeFDwWv fiQg== X-Gm-Message-State: ANoB5pl2hq5Fq4iYo9ciqNfGt4aqwlW6XvmLZyvxAI0XCXRPRpjd6qsk qFKsp4yhtF7/G1xaWjHgmchWarOAXlzVFQ== X-Received: by 2002:a62:3306:0:b0:56b:8181:fe3e with SMTP id z6-20020a623306000000b0056b8181fe3emr53537583pfz.57.1669639508698; Mon, 28 Nov 2022 04:45:08 -0800 (PST) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id w27-20020a63475b000000b0047681fa88d1sm3925303pgk.53.2022.11.28.04.45.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Nov 2022 04:45:07 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Jerome Forissier , Masahisa Kojima Subject: [PATCH v2 3/5] efi_loader: utility function to check the variable name is "Boot####" Date: Mon, 28 Nov 2022 21:45:07 +0900 Message-Id: <20221128124509.6939-4-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221128124509.6939-1-masahisa.kojima@linaro.org> References: <20221128124509.6939-1-masahisa.kojima@linaro.org> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean Some commands need to enumerate the existing UEFI load option variable("Boot####"). This commit transfers some code from cmd/efidebug.c to lib/efi_loder/, then exposes u16_tohex() and efi_varname_is_load_option() function to check whether the UEFI variable name is "Boot####". Signed-off-by: Masahisa Kojima Reviewed-by: Ilias Apalodimas --- Newly created in v2 cmd/efidebug.c | 23 +---------------------- include/efi_loader.h | 2 ++ lib/efi_loader/efi_helper.c | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 22 deletions(-) diff --git a/cmd/efidebug.c b/cmd/efidebug.c index ef239bb34b..ceb3aa5cee 100644 --- a/cmd/efidebug.c +++ b/cmd/efidebug.c @@ -1010,17 +1010,6 @@ static void show_efi_boot_opt(u16 *varname16) } } -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 * @@ -1041,7 +1030,6 @@ static int do_efi_boot_dump(struct cmd_tbl *cmdtp, int flag, 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) @@ -1074,16 +1062,7 @@ static int do_efi_boot_dump(struct cmd_tbl *cmdtp, int flag, return CMD_RET_FAILURE; } - if (memcmp(var_name16, u"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]) + if (efi_varname_is_load_option(var_name16, NULL)) show_efi_boot_opt(var_name16); } diff --git a/include/efi_loader.h b/include/efi_loader.h index 0c6c95ba46..b1ded811e7 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -707,6 +707,8 @@ int algo_to_len(const char *algo); int efi_link_dev(efi_handle_t handle, struct udevice *dev); int efi_unlink_dev(efi_handle_t handle); +int u16_tohex(u16 c); +bool efi_varname_is_load_option(u16 *var_name16, int *index); /** * efi_size_in_pages() - convert size in bytes to size in pages diff --git a/lib/efi_loader/efi_helper.c b/lib/efi_loader/efi_helper.c index c71e87d118..8a7afcc381 100644 --- a/lib/efi_loader/efi_helper.c +++ b/lib/efi_loader/efi_helper.c @@ -190,3 +190,36 @@ int efi_unlink_dev(efi_handle_t handle) return 0; } + +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; +} + +bool efi_varname_is_load_option(u16 *var_name16, int *index) +{ + int id, i, digit; + + if (memcmp(var_name16, u"Boot", 8)) + return false; + + 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]) { + if (index) + *index = id; + return true; + } + + return false; +}