Introduce fwu_mdata_get_image_guid() to retrieve a specific image GUID from the FWU metadata based on the bank index and image type GUID.
This allows identifying the correct partition in multi-bank (A/B) scenarios, ensuring the correct image is targeted depending on the current bank. Signed-off-by: Dario Binacchi <[email protected]> --- include/fwu.h | 3 +++ lib/fwu_updates/fwu.c | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/include/fwu.h b/include/fwu.h index e7bd1d492af1..47242629e404 100644 --- a/include/fwu.h +++ b/include/fwu.h @@ -394,6 +394,9 @@ void fwu_populate_mdata_image_info(struct fwu_data *data); */ int fwu_get_mdata_size(uint32_t *mdata_size); +int fwu_mdata_get_image_guid(efi_guid_t *image_guid, efi_guid_t image_type_guid, + u32 bank_index); + /** * fwu_state_machine_updates() - Update FWU state of the platform * @trial_state: Is platform transitioning into Trial State diff --git a/lib/fwu_updates/fwu.c b/lib/fwu_updates/fwu.c index 0f5ef2ba5153..a2857d369b92 100644 --- a/lib/fwu_updates/fwu.c +++ b/lib/fwu_updates/fwu.c @@ -243,6 +243,30 @@ int fwu_sync_mdata(struct fwu_mdata *mdata, int part) return 0; } +int fwu_mdata_get_image_guid(efi_guid_t *image_guid, efi_guid_t image_type_guid, + u32 bank_index) +{ + struct fwu_data *data = &g_fwu_data; + struct fwu_image_entry *image; + int i; + + if (bank_index >= data->num_banks) + return -EINVAL; + + for (i = 0; i < data->num_images; i++) { + image = &data->fwu_images[i]; + + if (!guidcmp(&image_type_guid, &image->image_type_guid)) { + struct fwu_image_bank_info *bank; + + bank = &image->img_bank_info[bank_index]; + guidcpy(image_guid, &bank->image_guid); + return 0; + } + } + + return -ENOENT; +} /** * fwu_mdata_copies_allocate() - Allocate memory for metadata * @mdata_size: Size of the metadata structure -- 2.43.0

