Hi Etienne,

On Thu, Feb 16, 2023 at 06:21:41PM +0100, Etienne Carriere wrote:
> Adds CONFIG_EFI_CAPSULE_MAX to configure the max index value used in
> EFI capsule reports. The config default value is 65535 as the index max
> value used before this change. Platforms with limited storage capacity
> can set a lower configuration value to prevent storage capacity
> overflow or even waste of storage space.
>
> Signed-off-by: Etienne Carriere <etienne.carri...@linaro.org>
> ---
> Changes since v1
> - Changed CONFIG_EFI_CAPSULE_MAX default value from 65535 to 15.
> ---
>  lib/efi_loader/Kconfig       |  8 ++++++
>  lib/efi_loader/efi_capsule.c | 48 +++++++++++++++++++++++++-----------
>  lib/efi_loader/efi_setup.c   |  7 +++++-
>  3 files changed, 48 insertions(+), 15 deletions(-)
>
> diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
> index c56904afc2..727241dc9c 100644
> --- a/lib/efi_loader/Kconfig
> +++ b/lib/efi_loader/Kconfig
> @@ -226,6 +226,14 @@ config EFI_CAPSULE_AUTHENTICATE
>         Select this option if you want to enable capsule
>         authentication
>
> +config EFI_CAPSULE_MAX
> +     int "Max value for capsule index"
> +     default 15
> +     range 0 65535
> +     help
> +       Select the max capsule index value used for capsule report
> +       variables. This value is used to create CapsuleMax variable.
> +
>  config EFI_DEVICE_PATH_TO_TEXT
>       bool "Device path to text protocol"
>       default y
> diff --git a/lib/efi_loader/efi_capsule.c b/lib/efi_loader/efi_capsule.c
> index 0997cd248f..d5d3ede7ae 100644
> --- a/lib/efi_loader/efi_capsule.c
> +++ b/lib/efi_loader/efi_capsule.c
> @@ -45,17 +45,7 @@ const efi_guid_t fwu_guid_os_request_fw_accept =
>  static struct efi_file_handle *bootdev_root;
>  #endif
>
> -/**
> - * get_last_capsule - get the last capsule index
> - *
> - * Retrieve the index of the capsule invoked last time from "CapsuleLast"
> - * variable.
> - *
> - * Return:
> - * * > 0     - the last capsule index invoked
> - * * 0xffff  - on error, or no capsule invoked yet
> - */
> -static __maybe_unused unsigned int get_last_capsule(void)
> +static __maybe_unused unsigned int get_capsule_index(const u16 
> *variable_name)
>  {
>       u16 value16[11]; /* "CapsuleXXXX": non-null-terminated */
>       char value[5];
> @@ -65,7 +55,7 @@ static __maybe_unused unsigned int get_last_capsule(void)
>       int i;
>
>       size = sizeof(value16);
> -     ret = efi_get_variable_int(u"CapsuleLast", &efi_guid_capsule_report,
> +     ret = efi_get_variable_int(variable_name, &efi_guid_capsule_report,
>                                  NULL, &size, value16, NULL);

Variable name is now an argument, but the value16 size remains an array of
11 u16's.  We should test that before calling efi_get_variable_int()
although the code currently just uses 'CapsuleLast' and 'CapsuleMax'.

>       if (ret != EFI_SUCCESS || size != 22 ||
>           u16_strncmp(value16, u"Capsule", 7))
> @@ -84,6 +74,35 @@ err:
>       return index;
>  }
>

[...]

Cheers
/Ilias

Reply via email to