From patchwork Fri Dec 2 04:59:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 630193 Delivered-To: patch@linaro.org Received: by 2002:a17:906:9c8c:b0:7c0:a5ce:226a with SMTP id fj12csp903488ejc; Thu, 1 Dec 2022 21:00:48 -0800 (PST) X-Google-Smtp-Source: AA0mqf6U5lBZ3itS3VjFDuht8TSh6gmf+eJrZDD4sYLMafGzQ8x6AEPa/WtAHS/VmyugEkGB2atg X-Received: by 2002:a02:c897:0:b0:374:100a:b0c7 with SMTP id m23-20020a02c897000000b00374100ab0c7mr24196784jao.185.1669957248670; Thu, 01 Dec 2022 21:00:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669957248; cv=none; d=google.com; s=arc-20160816; b=VXQ99ReeGyptTAmxytqJJLwb7DKbYY1ykkX28BJ3MEt2x9tG0hWnI99xOpKvZBlHcw Fbpls8EExmHk+x2tFDIMgYKPDp+Ib1YZtpRoT+CuxAiAhP0Otvn8t65hitLOVaBbbnIC JOR4whqF2XBU+iMDwWK+hT7O/JmZ8iCVqn/yxhmSgqJAhmRnCmrMxqPEL0Cr68a4yNDq y4Yfs/3LlQJ4ln9f9TQfRHSf5JDuC9zKOFC2yMa4U4STV7qvF1Dk7bH+NiH0XbacDa29 cnGQesr7jCVKoRGrSkriJrrLoOwoON2tke7h3YDdRFLzZIekhdWufBCFiIW7az/lacAh cJVw== 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=DWpIc09y3cY4o59Y13swgpi3Gjilon5p2T/Sn6ZbRw0=; b=FiAl7tY/Hb3lgDCqREOxAqVRIh2LswrWoEU1Hn9TyH5fEPj8tbFgmLJjYYasvsV5Wl OhNaTQM5vT6csnXfUkG+RoOyp+WYx4kNaYtqkkzDiuNtlyTLQo0ReXI6IiPsOM8VMShS /4SlB3BJbY3Wa68j66u4ozU79S44HJmtPF0LitiDgcDfYM9bc8DSQsQMuh3twaQPchVV s0LGAHLimv81/JOonH6jQZVNTTnEeacZkXW+cFXXM4kIPhEA2R6vtDhmkTnNU7I5itNP x1ECAnkLMBugQrpjw7e2uwStwYbws/qI4x7mLyNcOI0ln9e6D3QtLn7Ie6jZ+nl/hHo9 g/Yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wO8HHRw5; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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. [85.214.62.61]) by mx.google.com with ESMTPS id b9-20020a92ce09000000b002f8140b4ff3si3730571ilo.103.2022.12.01.21.00.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Dec 2022 21:00:48 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wO8HHRw5; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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 42BCE85445; Fri, 2 Dec 2022 06:00:31 +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="wO8HHRw5"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2C00F8544C; Fri, 2 Dec 2022 06:00:10 +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-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) (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 8A2F78544A for ; Fri, 2 Dec 2022 05:59:57 +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-pf1-x434.google.com with SMTP id r7so3864574pfl.11 for ; Thu, 01 Dec 2022 20:59:57 -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=DWpIc09y3cY4o59Y13swgpi3Gjilon5p2T/Sn6ZbRw0=; b=wO8HHRw5IdVNn2YiCvBFFb6Utpm0FY3OyXpTt96e3nYnW1mXPvvsUskBuOtSTFsmeG I0hd5mUsXDS23SXNXwNSqdygMpmHcjyCYNF9OObq6ZScYqQhvBDYWFDWK0oSO/ISbQQK BmyG8U+Mm7xV18D6NCHDAB6HOuIq+5hGiisBquaMFmkQxUwSvnu8wddkDkP7CDyTvpFo irfn3/VxWtYhkLo+GhYKEgMXKd+Fejpmj+Om2wzpxIBntU1HMjwyl74E7nIF1eAWGmnj 8BErpBlMCFNGc7nCRJxDJBuRAZEf/0Kvq3H21lh6KdAghU1oeMrAfthIU1WsIt4cQBGx SFzg== 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=DWpIc09y3cY4o59Y13swgpi3Gjilon5p2T/Sn6ZbRw0=; b=gWjeQsN4sr46PdcZcA/gzJbC+997QZdNCc1jvFqzkX+vkJB1qy2BuzRneFMCEPYf0d 6WLEJMm0FRsWQD/zXQrwGGEzgV2PBjUXxyaYJxUyt5fcLSL/LXGHp5TW3flw1dqhpcPA PpzFH6pfnAGV2v+9zXjxP8+QLkKXItBhS0xNkb6JJg1wH4HKzyoxXDZakV/wIJimcoQ4 B8uZMyGdUTffi6RBEAIF+9KDq3hqZBDmmNsAMr+kG/1d2wD08y6mwY33JKbxypMl0eR6 p98o1OOkpsyNq+/CNoa1cXKxQNAf2dcxMMBlefFrIty6DyXEAP2cCOdE+hO0HTb+r+OQ FAVQ== X-Gm-Message-State: ANoB5pnglfOyibNu8mDz09zLPsnG6oXUBmX4AAqLkKsd/cu/wrPoxfFf nkhz9k3fdqu7DsnT2AXuXBmUFTYED6tBDe00 X-Received: by 2002:a62:1c95:0:b0:571:baf8:8945 with SMTP id c143-20020a621c95000000b00571baf88945mr50434964pfc.83.1669957195254; Thu, 01 Dec 2022 20:59:55 -0800 (PST) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id z27-20020aa7949b000000b00575fbe1cf31sm3234456pfk.67.2022.12.01.20.59.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Dec 2022 20:59:54 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Jerome Forissier , Masahisa Kojima Subject: [PATCH v3 3/5] efi_loader: utility function to check the variable name is "Boot####" Date: Fri, 2 Dec 2022 13:59:35 +0900 Message-Id: <20221202045937.7846-4-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221202045937.7846-1-masahisa.kojima@linaro.org> References: <20221202045937.7846-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 efi_varname_is_load_option() function to check whether the UEFI variable name is "Boot####". Signed-off-by: Masahisa Kojima Reviewed-by: Ilias Apalodimas --- v2->v3: - add static qualifier to u16_tohex() Newly created in v2 cmd/efidebug.c | 23 +---------------------- include/efi_loader.h | 1 + lib/efi_loader/efi_helper.c | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 35 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..0899e293e5 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -707,6 +707,7 @@ 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); +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..788cb9faec 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; } + +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; +} + +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; +}