From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C88C6C433FE for ; Tue, 29 Nov 2022 07:33:56 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9CDEC852DA; Tue, 29 Nov 2022 08:33:54 +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="ijtwNy3E"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 401FE85318; Tue, 29 Nov 2022 08:33:53 +0100 (CET) Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) (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 0F597851F5 for ; Tue, 29 Nov 2022 08:33:51 +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=ilias.apalodimas@linaro.org Received: by mail-ej1-x62b.google.com with SMTP id n20so31718148ejh.0 for ; Mon, 28 Nov 2022 23:33:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=WiEFqGVGoonQc8DBANEsGoTIl6gM6SWF9MN9MWdsTYQ=; b=ijtwNy3EbZQ1oIv9ejWREdi1b9VXVoHo9wksUSsjcJq5S4mYGkPrIieNKxkvurXq4n eU2Ijl6JpvsEiRlxZb0Bzqp3jZCkVLgE/+kw2MdlDy5fH9WYT9nEBTJGbzTVKIkuuGur GGo1goe7WMWwOl/p9I4ETO1n9mHV917ub7yujx9FRxJILSjevE5Nlvy6CgDtxS2/+Veb HtDSx59ezgNxSIFkgPOTBJdjMjXmUKwtJVtrXCzQI4xY5zwCE44DxOyJr2TYLu8ydPkG d7dSos+rh1k73vW0/09itmY4OATn/dLHes5cn/550Qmqe0+cNWcG+zi4auM+1uxY47Oq PO/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=WiEFqGVGoonQc8DBANEsGoTIl6gM6SWF9MN9MWdsTYQ=; b=2zSV+85nscNOiKojzYjYMOyJ5+beQNeZEaees4ri1NLgrJD576iKPq4PjqQx4RIF4p 7AN1FDwmS2PtFaNFPNuDy0nSbvnGvSHlIhVWxv3gcEw+OOQk7Blh3gOF92oKUdGY9ETf hSUAddmbglBo7XMQNDVvRz5GMvjN9Vj/AEauUDUGYEtwGFbw9nNbJclrgYIftnIDSEyX G2QB/C173FIU4YYZ3MViXRHbmzyZ/CYWikMw75M+CZv+Hd6NkQH791Q6Bft1xTi7xbvM pGzQvaetDtCTeXo0Ht5EYThIk20PGJkZygSy6LiQnItjeVq3WhJQAU2RYkjlTEc8/e/c iz7g== X-Gm-Message-State: ANoB5plyqktiSKq/sdv77XfXs2ee/Sh/k4QMVCGQ0hY3Uns/w3ZJy1gi QV+vkNzmJfdpTkaHfNDijK/nVDhPDXGK8Q== X-Google-Smtp-Source: AA0mqf5lscm6rXHrfkdMT+TYJUXBd8GEjUIiAXao6xoc9prWaGyy8Xqa+P8AJSh3kEXkJBePqToUDQ== X-Received: by 2002:a17:906:547:b0:7ad:9028:4b17 with SMTP id k7-20020a170906054700b007ad90284b17mr46918820eja.366.1669707230634; Mon, 28 Nov 2022 23:33:50 -0800 (PST) Received: from hera (ppp078087234022.access.hol.gr. [78.87.234.22]) by smtp.gmail.com with ESMTPSA id bh16-20020a170906a0d000b007adaca75bd0sm5852921ejb.179.2022.11.28.23.33.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Nov 2022 23:33:48 -0800 (PST) Date: Tue, 29 Nov 2022 09:33:46 +0200 From: Ilias Apalodimas To: Masahisa Kojima Cc: u-boot@lists.denx.de, Heinrich Schuchardt , Jerome Forissier Subject: Re: [PATCH v2 3/5] efi_loader: utility function to check the variable name is "Boot####" Message-ID: References: <20221128124509.6939-1-masahisa.kojima@linaro.org> <20221128124509.6939-4-masahisa.kojima@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221128124509.6939-4-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 On Mon, Nov 28, 2022 at 09:45:07PM +0900, Masahisa Kojima wrote: > 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 > --- > 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) This needs static > +{ > + 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; > +} > -- > 2.17.1 > With that Reviewed-by: Ilias Apalodimas