public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Ilias Apalodimas <ilias.apalodimas@linaro.org>
To: Masahisa Kojima <masahisa.kojima@linaro.org>
Cc: u-boot@lists.denx.de, Heinrich Schuchardt <xypron.glpk@gmx.de>,
	Jerome Forissier <jerome.forissier@linaro.org>
Subject: Re: [PATCH v2 3/5] efi_loader: utility function to check the variable name is "Boot####"
Date: Tue, 29 Nov 2022 09:33:46 +0200	[thread overview]
Message-ID: <Y4W12ivLOlCR8oez@hera> (raw)
In-Reply-To: <20221128124509.6939-4-masahisa.kojima@linaro.org>

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 <masahisa.kojima@linaro.org>
> ---
> 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 <ilias.apalodimas@linaro.org>


  reply	other threads:[~2022-11-29  7:33 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-28 12:45 [PATCH v2 0/5] miscellaneous fixes of eficonfig Masahisa Kojima
2022-11-28 12:45 ` [PATCH v2 1/5] eficonfig: fix going one directory up issue Masahisa Kojima
2022-11-29  7:14   ` Ilias Apalodimas
2022-11-28 12:45 ` [PATCH v2 2/5] eficonfig: use u16_strsize() to get u16 string buffer size Masahisa Kojima
2022-11-29  7:14   ` Ilias Apalodimas
2022-11-28 12:45 ` [PATCH v2 3/5] efi_loader: utility function to check the variable name is "Boot####" Masahisa Kojima
2022-11-29  7:33   ` Ilias Apalodimas [this message]
2022-11-29  9:57     ` Masahisa Kojima
2022-11-28 12:45 ` [PATCH v2 4/5] eficonfig: use efi_get_next_variable_name_int() Masahisa Kojima
2022-11-28 12:45 ` [PATCH v2 5/5] doc:eficonfig: add description for UEFI Secure Boot Configuration Masahisa Kojima

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y4W12ivLOlCR8oez@hera \
    --to=ilias.apalodimas@linaro.org \
    --cc=jerome.forissier@linaro.org \
    --cc=masahisa.kojima@linaro.org \
    --cc=u-boot@lists.denx.de \
    --cc=xypron.glpk@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox