| Message ID | 20260415183250.3031030-7-dario.binacchi@amarulasolutions.com |
|---|---|
| State | New |
| Headers | show |
| Series |
|
| Related | show |
Hi Dario, On 2026-04-15T18:31:27, Dario Binacchi <dario.binacchi@amarulasolutions.com> wrote: > fwu: add helper to get image GUID by type and bank index > > 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 <dario.binacchi@amarulasolutions.com> > > include/fwu.h | 11 +++++++++++ > lib/fwu_updates/fwu.c | 33 +++++++++++++++++++++++++++++++++ > 2 files changed, 44 insertions(+) > diff --git a/lib/fwu_updates/fwu.c b/lib/fwu_updates/fwu.c > @@ -243,6 +243,39 @@ int fwu_sync_mdata(struct fwu_mdata *mdata, int part) > +int fwu_mdata_get_image_guid(efi_guid_t *image_guid, > + const 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++) { Using data->num_images here is the proper approach for new code. Some existing functions still use CONFIG_FWU_NUM_IMAGES_PER_BANK in their loops but using the runtime value is more correct, especially since FWU v2 populates num_images from the metadata itself. Is there a unit test for this new function? Since you have added tests for the part command in patches 2, 3, and 5, it would be good to add coverage here as well, e.g. testing success, -EINVAL for invalid bank index, and -ENOENT for missing image type. Reviewed-by: Simon Glass <sjg@chromium.org> To unsubscribe from this group and stop receiving emails from it, send an email to linux-amarula+unsubscribe@amarulasolutions.com.
On Wed, 15 Apr 2026 at 21:33, Dario Binacchi <dario.binacchi@amarulasolutions.com> wrote: > > 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 <dario.binacchi@amarulasolutions.com> > > --- > > Changes in v3: > - Add kerneldoc comment for fwu_mdata_get_image_guid() above its > declaration in fwu.h. > > Changes in v2: > - Add kerneldoc comment for fwu_mdata_get_image_guid(). > - Pass efi_guid_t by pointer for consistency. > Acked-by: Ilias Apalodimas <ilias.apalodimas@linaro.org> > include/fwu.h | 11 +++++++++++ > lib/fwu_updates/fwu.c | 33 +++++++++++++++++++++++++++++++++ > 2 files changed, 44 insertions(+) > > diff --git a/include/fwu.h b/include/fwu.h > index 9cee8fb085cb..68a51fb4296b 100644 > --- a/include/fwu.h > +++ b/include/fwu.h > @@ -396,6 +396,17 @@ void fwu_populate_mdata_image_info(struct fwu_data *data); > */ > int fwu_get_mdata_size(uint32_t *mdata_size); > > +/** > + * fwu_mdata_get_image_guid() - Get image GUID for a type and bank > + * @image_guid: Pointer to be filled with the found image GUID > + * @image_type_guid: Pointer to the image type GUID to search for > + * @bank_index: Index of the bank > + * > + * Return: 0 if OK, -ve on error > + */ > +int fwu_mdata_get_image_guid(efi_guid_t *image_guid, > + const efi_guid_t *image_type_guid, u32 bank_index); > + > /** > * fwu_state_machine_updates() - Update FWU state of the platform > * @state: FWU bank state > diff --git a/lib/fwu_updates/fwu.c b/lib/fwu_updates/fwu.c > index 37c613014d18..e5e4907a2d43 100644 > --- a/lib/fwu_updates/fwu.c > +++ b/lib/fwu_updates/fwu.c > @@ -243,6 +243,39 @@ int fwu_sync_mdata(struct fwu_mdata *mdata, int part) > return 0; > } > > +/** > + * fwu_mdata_get_image_guid() - Get image GUID for a type and bank > + * @image_guid: Pointer to be filled with the found image GUID > + * @image_type_guid: Pointer to the image type GUID to search for > + * @bank_index: Index of the bank > + * > + * Return: 0 if OK, -ve on error > + */ > +int fwu_mdata_get_image_guid(efi_guid_t *image_guid, > + const 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 > To unsubscribe from this group and stop receiving emails from it, send an email to linux-amarula+unsubscribe@amarulasolutions.com.
diff --git a/include/fwu.h b/include/fwu.h index 9cee8fb085cb..68a51fb4296b 100644 --- a/include/fwu.h +++ b/include/fwu.h @@ -396,6 +396,17 @@ void fwu_populate_mdata_image_info(struct fwu_data *data); */ int fwu_get_mdata_size(uint32_t *mdata_size); +/** + * fwu_mdata_get_image_guid() - Get image GUID for a type and bank + * @image_guid: Pointer to be filled with the found image GUID + * @image_type_guid: Pointer to the image type GUID to search for + * @bank_index: Index of the bank + * + * Return: 0 if OK, -ve on error + */ +int fwu_mdata_get_image_guid(efi_guid_t *image_guid, + const efi_guid_t *image_type_guid, u32 bank_index); + /** * fwu_state_machine_updates() - Update FWU state of the platform * @state: FWU bank state diff --git a/lib/fwu_updates/fwu.c b/lib/fwu_updates/fwu.c index 37c613014d18..e5e4907a2d43 100644 --- a/lib/fwu_updates/fwu.c +++ b/lib/fwu_updates/fwu.c @@ -243,6 +243,39 @@ int fwu_sync_mdata(struct fwu_mdata *mdata, int part) return 0; } +/** + * fwu_mdata_get_image_guid() - Get image GUID for a type and bank + * @image_guid: Pointer to be filled with the found image GUID + * @image_type_guid: Pointer to the image type GUID to search for + * @bank_index: Index of the bank + * + * Return: 0 if OK, -ve on error + */ +int fwu_mdata_get_image_guid(efi_guid_t *image_guid, + const 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
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 <dario.binacchi@amarulasolutions.com> --- Changes in v3: - Add kerneldoc comment for fwu_mdata_get_image_guid() above its declaration in fwu.h. Changes in v2: - Add kerneldoc comment for fwu_mdata_get_image_guid(). - Pass efi_guid_t by pointer for consistency. include/fwu.h | 11 +++++++++++ lib/fwu_updates/fwu.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+)