[PATCH 4/6] fwu: check all images for transitioning out of Trial State

Michal Simek michal.simek at amd.com
Wed Sep 4 14:36:51 CEST 2024



On 8/30/24 13:40, Sughosh Ganu wrote:
> The platform transitions out of Trial State into the Regular State
> only when all the images in the update bank have been accepted. Check
> for this condition before transitioning out of Trial State.
> 
> Signed-off-by: Sughosh Ganu <sughosh.ganu at linaro.org>
> ---
>   include/fwu.h            | 11 +++++++++++
>   lib/fwu_updates/fwu.c    | 25 +++++++++++++++++++++++++
>   lib/fwu_updates/fwu_v1.c |  9 ++++++---
>   lib/fwu_updates/fwu_v2.c |  3 +++
>   4 files changed, 45 insertions(+), 3 deletions(-)
> 
> diff --git a/include/fwu.h b/include/fwu.h
> index 77ec65e618..70a5166f5e 100644
> --- a/include/fwu.h
> +++ b/include/fwu.h
> @@ -417,4 +417,15 @@ int fwu_state_machine_updates(bool trial_state, uint32_t update_index);
>    */
>   int fwu_init(void);
>   
> +/**
> + * fwu_bank_accepted() - Has the bank been accepted
> + * @data: Version agnostic FWU metadata information
> + * @bank: Update bank to check
> + *
> + * Check in the given bank if all the images have been accepted.
> + *
> + * Return: true if all images accepted, false otherwise
> + */
> +bool fwu_bank_accepted(struct fwu_data *data, uint32_t bank);
> +
>   #endif /* _FWU_H_ */
> diff --git a/lib/fwu_updates/fwu.c b/lib/fwu_updates/fwu.c
> index c7fc8987be..a94a769a2b 100644
> --- a/lib/fwu_updates/fwu.c
> +++ b/lib/fwu_updates/fwu.c
> @@ -28,6 +28,31 @@ enum {
>   	IMAGE_ACCEPT_CLEAR,
>   };
>   
> +/**
> + * fwu_bank_accepted() - Has the bank been accepted
> + * @data: Version agnostic FWU metadata information
> + * @bank: Update bank to check
> + *
> + * Check in the given bank if all the images have been accepted.
> + *
> + * Return: true if all images accepted, false otherwise
> + */
> +bool fwu_bank_accepted(struct fwu_data *data, uint32_t bank)
> +{
> +	u32 i;
> +	struct fwu_image_entry *img_entry;
> +	struct fwu_image_bank_info *img_bank_info;
> +
> +	img_entry = &data->fwu_images[0];
> +	for (i = 0; i < CONFIG_FWU_NUM_IMAGES_PER_BANK; i++) {
> +		img_bank_info = &img_entry[i].img_bank_info[bank];
> +		if (!img_bank_info->accepted)
> +			return false;
> +	}
> +
> +	return true;
> +}
> +
>   static int trial_counter_update(u16 *trial_state_ctr)
>   {
>   	bool delete;
> diff --git a/lib/fwu_updates/fwu_v1.c b/lib/fwu_updates/fwu_v1.c
> index 023e43728d..c311a8857a 100644
> --- a/lib/fwu_updates/fwu_v1.c
> +++ b/lib/fwu_updates/fwu_v1.c
> @@ -52,11 +52,14 @@ static void fwu_data_init(void)
>   	memcpy(dst_img_info, src_img_info, image_info_size);
>   }
>   
> -static int fwu_trial_state_update(bool trial_state)
> +static int fwu_trial_state_update(bool trial_state, uint32_t bank)
>   {
>   	int ret;
>   	struct fwu_data *data = fwu_get_data();
>   
> +	if (!trial_state && !fwu_bank_accepted(data, bank))
> +		return 0;
> +
>   	if (trial_state) {
>   		ret = fwu_trial_state_ctr_start();
>   		if (ret)
> @@ -112,9 +115,9 @@ void fwu_populate_mdata_image_info(struct fwu_data *data)
>    * Return: 0 if OK, -ve on error
>    */
>   int fwu_state_machine_updates(bool trial_state,
> -			      __maybe_unused uint32_t update_index)
> +			      uint32_t update_index)
>   {
> -	return fwu_trial_state_update(trial_state);
> +	return fwu_trial_state_update(trial_state, update_index);
>   }
>   
>   /**
> diff --git a/lib/fwu_updates/fwu_v2.c b/lib/fwu_updates/fwu_v2.c
> index 69306282aa..9c696952ed 100644
> --- a/lib/fwu_updates/fwu_v2.c
> +++ b/lib/fwu_updates/fwu_v2.c
> @@ -88,6 +88,9 @@ static int fwu_bank_state_update(bool trial_state, uint32_t bank)
>   	struct fwu_data *data = fwu_get_data();
>   	struct fwu_mdata *mdata = data->fwu_mdata;
>   
> +	if (!trial_state && !fwu_bank_accepted(data, bank))
> +		return 0;
> +
>   	mdata->bank_state[bank] = data->bank_state[bank] = trial_state ?
>   		FWU_BANK_VALID : FWU_BANK_ACCEPTED;
>   

Tested-by: Michal Simek <michal.simek at amd.com>

Thanks,
Michal


More information about the U-Boot mailing list