[PATCH 13/25] efi_loader: fwu_arm_psa: Add set_image and get_image_info support

Heinrich Schuchardt xypron.glpk at gmx.de
Fri Jul 4 13:21:50 CEST 2025


On 02.07.25 17:25, abdellatif.elkhlifi at arm.com wrote:
> From: Abdellatif El Khlifi <abdellatif.elkhlifi at arm.com>
> 
> Implement set_image and get_image_info through RAW functions
> 
> The implementation is done using efi_firmware_raw_set_image()
> and efi_firmware_get_image_info()
> 
> Signed-off-by: Abdellatif El Khlifi <abdellatif.elkhlifi at arm.com>
> Signed-off-by: Davidson kumaresan <davidson.kumaresan at arm.com>
> Cc: Heinrich Schuchardt <xypron.glpk at gmx.de>
> Cc: Sughosh Ganu <sughosh.ganu at linaro.org>
> Cc: Tom Rini <trini at konsulko.com>
> Cc: Ilias Apalodimas <ilias.apalodimas at linaro.org>
> Cc: Simon Glass <sjg at chromium.org>
> Cc: Michal Simek <michal.simek at amd.com>
> Cc: Marek Vasut <marek.vasut+renesas at mailbox.org>
> Cc: Casey Connolly <casey.connolly at linaro.org>
> Cc: Adriano Cordova <adrianox at gmail.com>
> ---
>   lib/efi_loader/efi_firmware.c | 97 ++++++++++++++++++++++-------------
>   1 file changed, 60 insertions(+), 37 deletions(-)
> 
> diff --git a/lib/efi_loader/efi_firmware.c b/lib/efi_loader/efi_firmware.c
> index 75501e21557..dad80beb23e 100644
> --- a/lib/efi_loader/efi_firmware.c
> +++ b/lib/efi_loader/efi_firmware.c
> @@ -4,6 +4,12 @@
>    *
>    *  Copyright (c) 2020 Linaro Limited
>    *			Author: AKASHI Takahiro
> + *
> + * Copyright 2025 Arm Limited and/or its affiliates <open-source-office at arm.com>
> + *
> + * Authors:
> + *   Abdellatif El Khlifi <abdellatif.elkhlifi at arm.com>
> + *   Davidson kumaresan <davidson.kumaresan at arm.com>
>    */
>   
>   #define LOG_CATEGORY LOGC_EFI
> @@ -14,6 +20,7 @@
>   #include <efi_variable.h>
>   #include <env.h>
>   #include <fwu.h>
> +#include <fwu_arm_psa.h>
>   #include <image.h>
>   #include <signatures.h>
>   
> @@ -601,10 +608,21 @@ efi_status_t EFIAPI efi_firmware_get_image_info(
>   	     !descriptor_size || !package_version || !package_version_name))
>   		return EFI_EXIT(EFI_INVALID_PARAMETER);
>   
> -	ret = efi_fill_image_desc_array(image_info_size, image_info,
> -					descriptor_version, descriptor_count,
> -					descriptor_size, package_version,
> -					package_version_name);
> +	if (IS_ENABLED(CONFIG_FWU_ARM_PSA)) {
> +		ret = fwu_arm_psa_get_image_info(image_info_size, image_info,
> +						 descriptor_version,
> +						 descriptor_count,
> +						 descriptor_size,
> +						 package_version,
> +						 package_version_name);
> +	} else {
> +		ret = efi_fill_image_desc_array(image_info_size, image_info,
> +						descriptor_version,
> +						descriptor_count,
> +						descriptor_size,
> +						package_version,
> +						package_version_name);
> +	}
>   
>   	return EFI_EXIT(ret);
>   }
> @@ -749,48 +767,53 @@ efi_status_t EFIAPI efi_firmware_raw_set_image(
>   	if (status != EFI_SUCCESS)
>   		return EFI_EXIT(status);
>   
> -	/*
> -	 * dfu_alt_num is assigned from 0 while image_index starts from 1.
> -	 * dfu_alt_num is calculated by (image_index - 1) when multi bank update
> -	 * is not used.
> -	 */
> -	dfu_alt_num = image_index - 1;
> -	if (IS_ENABLED(CONFIG_FWU_MULTI_BANK_UPDATE)) {
> +	if (IS_ENABLED(CONFIG_FWU_ARM_PSA)) {
> +		if (fwu_update_image(image, image_index, image_size))
> +			return EFI_EXIT(EFI_DEVICE_ERROR);
> +	} else {
>   		/*
> -		 * Based on the value of update bank, derive the
> -		 * image index value.
> +		 * dfu_alt_num is assigned from 0 while image_index starts from 1.
> +		 * dfu_alt_num is calculated by (image_index - 1) when multi bank update
> +		 * is not used.
>   		 */
> -		ret = fwu_get_dfu_alt_num(image_index, &dfu_alt_num);
> -		if (ret) {
> -			log_debug("Unable to get FWU image_index\n");
> -			return EFI_EXIT(EFI_DEVICE_ERROR);
> +		dfu_alt_num = image_index - 1;
> +		if (IS_ENABLED(CONFIG_FWU_MULTI_BANK_UPDATE)) {
> +			/*
> +			 * Based on the value of update bank, derive the
> +			 * image index value.
> +			 */
> +			ret = fwu_get_dfu_alt_num(image_index, &dfu_alt_num);
> +			if (ret) {
> +				log_debug("Unable to get FWU image_index\n");
> +				return EFI_EXIT(EFI_DEVICE_ERROR);
> +			}

This part looks like at two different changes mixed in a single patch:

* Add support for FWU_ARM_PSA
* Reading fwu_get_dfu_alt_num() even if neither of FWU_ARM_PSA and 
FWU_MULTI_BANK_UPDATE is selected.

Please, separate the changes and describe the changes in the respective 
commit messages.

Best regards

Heinrich

>   		}
> -	}
>   
> -	orig_dfu_env = env_get("dfu_alt_info");
> -	if (orig_dfu_env) {
> -		orig_dfu_env = strdup(orig_dfu_env);
> -		if (!orig_dfu_env) {
> -			log_err("strdup() failed!\n");
> -			return EFI_EXIT(EFI_OUT_OF_RESOURCES);
> +		orig_dfu_env = env_get("dfu_alt_info");
> +		if (orig_dfu_env) {
> +			orig_dfu_env = strdup(orig_dfu_env);
> +			if (!orig_dfu_env) {
> +				log_err("strdup() failed!\n");
> +				return EFI_EXIT(EFI_OUT_OF_RESOURCES);
> +			}
> +		}
> +		if (env_set("dfu_alt_info", update_info.dfu_string)) {
> +			log_err("Unable to set env variable \"dfu_alt_info\"!\n");
> +			free(orig_dfu_env);
> +			return EFI_EXIT(EFI_DEVICE_ERROR);
>   		}
> -	}
> -	if (env_set("dfu_alt_info", update_info.dfu_string)) {
> -		log_err("Unable to set env variable \"dfu_alt_info\"!\n");
> -		free(orig_dfu_env);
> -		return EFI_EXIT(EFI_DEVICE_ERROR);
> -	}
>   
> -	ret = dfu_write_by_alt(dfu_alt_num, (void *)image, image_size,
> -			       NULL, NULL);
> +		ret = dfu_write_by_alt(dfu_alt_num, (void *)image, image_size,
> +				       NULL, NULL);
>   
> -	if (env_set("dfu_alt_info", orig_dfu_env))
> -		log_warning("Unable to restore env variable \"dfu_alt_info\".  Further DFU operations may fail!\n");
> +		if (env_set("dfu_alt_info", orig_dfu_env))
> +			log_warning("Unable to restore env variable \"dfu_alt_info\".  Further DFU operations may fail!\n");
>   
> -	free(orig_dfu_env);
> +		free(orig_dfu_env);
>   
> -	if (ret)
> -		return EFI_EXIT(EFI_DEVICE_ERROR);
> +		if (ret)
> +			return EFI_EXIT(EFI_DEVICE_ERROR);
> +	}
>   
>   	efi_firmware_set_fmp_state_var(&state, image_index);
>   



More information about the U-Boot mailing list