diff mbox series

[v4,2/5] efi_loader: versioning support in GetImageInfo

Message ID 20230323110906.23783-3-masahisa.kojima@linaro.org
State New
Headers show
Series FMP versioning support | expand

Commit Message

Masahisa Kojima March 23, 2023, 11:09 a.m. UTC
Current FMP->GetImageInfo() always return 0 for the firmware
version, user can not identify which firmware version is currently
running through the EFI interface.

This commit reads the "FmpStateXXXX" EFI variable, then fills the
firmware version, lowest supported version, last attempt version
and last attempt status in FMP->GetImageInfo().

Now FMP->GetImageInfo() and ESRT have the meaningful version number.

Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
---
No update since v1

 lib/efi_loader/efi_firmware.c | 30 ++++++++++++++++++++++++++----
 1 file changed, 26 insertions(+), 4 deletions(-)

Comments

Ilias Apalodimas March 28, 2023, 6:52 a.m. UTC | #1
On Thu, 23 Mar 2023 at 13:09, Masahisa Kojima
<masahisa.kojima@linaro.org> wrote:
>
> Current FMP->GetImageInfo() always return 0 for the firmware
> version, user can not identify which firmware version is currently
> running through the EFI interface.
>
> This commit reads the "FmpStateXXXX" EFI variable, then fills the
> firmware version, lowest supported version, last attempt version
> and last attempt status in FMP->GetImageInfo().
>
> Now FMP->GetImageInfo() and ESRT have the meaningful version number.
>
> Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
> ---
> No update since v1
>
>  lib/efi_loader/efi_firmware.c | 30 ++++++++++++++++++++++++++----
>  1 file changed, 26 insertions(+), 4 deletions(-)
>
> diff --git a/lib/efi_loader/efi_firmware.c b/lib/efi_loader/efi_firmware.c
> index fb5f7906d3..7536fcfa55 100644
> --- a/lib/efi_loader/efi_firmware.c
> +++ b/lib/efi_loader/efi_firmware.c
> @@ -190,13 +190,38 @@ static efi_status_t efi_fill_image_desc_array(
>         *package_version_name = NULL; /* not supported */
>
>         for (i = 0; i < num_image_type_guids; i++) {
> +               u16 varname[13]; /* u"FmpStateXXXX" */
> +               efi_status_t ret;
> +               efi_uintn_t size;
> +               struct fmp_state var_state = { 0 };
> +
>                 image_info[i].image_index = fw_array[i].image_index;
>                 image_info[i].image_type_id = fw_array[i].image_type_id;
>                 image_info[i].image_id = fw_array[i].image_index;
>
>                 image_info[i].image_id_name = fw_array[i].fw_name;
>
> -               image_info[i].version = 0; /* not supported */
> +               efi_create_indexed_name(varname, sizeof(varname), "FmpState",
> +                                       fw_array[i].image_index);
> +               size = sizeof(var_state);
> +               ret = efi_get_variable_int(varname, &fw_array[i].image_type_id,
> +                                          NULL, &size, &var_state, NULL);
> +               if (ret == EFI_SUCCESS) {
> +                       image_info[i].version = var_state.fw_version;
> +                       image_info[i].lowest_supported_image_version =
> +                               var_state.lowest_supported_version;
> +                       image_info[i].last_attempt_version =
> +                               var_state.last_attempt_version;
> +                       image_info[i].last_attempt_status =
> +                               var_state.last_attempt_status;
> +               } else {
> +                       image_info[i].version = 0;
> +                       image_info[i].lowest_supported_image_version = 0;
> +                       image_info[i].last_attempt_version = 0;
> +                       image_info[i].last_attempt_status =
> +                               LAST_ATTEMPT_STATUS_SUCCESS;
> +               }
> +
>                 image_info[i].version_name = NULL; /* not supported */
>                 image_info[i].size = 0;
>                 image_info[i].attributes_supported =
> @@ -210,9 +235,6 @@ static efi_status_t efi_fill_image_desc_array(
>                         image_info[0].attributes_setting |=
>                                 IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED;
>
> -               image_info[i].lowest_supported_image_version = 0;
> -               image_info[i].last_attempt_version = 0;
> -               image_info[i].last_attempt_status = LAST_ATTEMPT_STATUS_SUCCESS;
>                 image_info[i].hardware_instance = 1;
>                 image_info[i].dependencies = NULL;
>         }
> --
> 2.17.1
>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
diff mbox series

Patch

diff --git a/lib/efi_loader/efi_firmware.c b/lib/efi_loader/efi_firmware.c
index fb5f7906d3..7536fcfa55 100644
--- a/lib/efi_loader/efi_firmware.c
+++ b/lib/efi_loader/efi_firmware.c
@@ -190,13 +190,38 @@  static efi_status_t efi_fill_image_desc_array(
 	*package_version_name = NULL; /* not supported */
 
 	for (i = 0; i < num_image_type_guids; i++) {
+		u16 varname[13]; /* u"FmpStateXXXX" */
+		efi_status_t ret;
+		efi_uintn_t size;
+		struct fmp_state var_state = { 0 };
+
 		image_info[i].image_index = fw_array[i].image_index;
 		image_info[i].image_type_id = fw_array[i].image_type_id;
 		image_info[i].image_id = fw_array[i].image_index;
 
 		image_info[i].image_id_name = fw_array[i].fw_name;
 
-		image_info[i].version = 0; /* not supported */
+		efi_create_indexed_name(varname, sizeof(varname), "FmpState",
+					fw_array[i].image_index);
+		size = sizeof(var_state);
+		ret = efi_get_variable_int(varname, &fw_array[i].image_type_id,
+					   NULL, &size, &var_state, NULL);
+		if (ret == EFI_SUCCESS) {
+			image_info[i].version = var_state.fw_version;
+			image_info[i].lowest_supported_image_version =
+				var_state.lowest_supported_version;
+			image_info[i].last_attempt_version =
+				var_state.last_attempt_version;
+			image_info[i].last_attempt_status =
+				var_state.last_attempt_status;
+		} else {
+			image_info[i].version = 0;
+			image_info[i].lowest_supported_image_version = 0;
+			image_info[i].last_attempt_version = 0;
+			image_info[i].last_attempt_status =
+				LAST_ATTEMPT_STATUS_SUCCESS;
+		}
+
 		image_info[i].version_name = NULL; /* not supported */
 		image_info[i].size = 0;
 		image_info[i].attributes_supported =
@@ -210,9 +235,6 @@  static efi_status_t efi_fill_image_desc_array(
 			image_info[0].attributes_setting |=
 				IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED;
 
-		image_info[i].lowest_supported_image_version = 0;
-		image_info[i].last_attempt_version = 0;
-		image_info[i].last_attempt_status = LAST_ATTEMPT_STATUS_SUCCESS;
 		image_info[i].hardware_instance = 1;
 		image_info[i].dependencies = NULL;
 	}