Skip to content

[qcom-next] efi_loader: capsule: report spec-compliant ImageIndex for dynamic fw_images[] - #131

Open
balajiselvanathan wants to merge 4 commits into
qualcomm-linux:qcom-nextfrom
balajiselvanathan:capsule-seq-image-index
Open

[qcom-next] efi_loader: capsule: report spec-compliant ImageIndex for dynamic fw_images[]#131
balajiselvanathan wants to merge 4 commits into
qualcomm-linux:qcom-nextfrom
balajiselvanathan:capsule-seq-image-index

Conversation

@balajiselvanathan

Copy link
Copy Markdown

Platforms that build their fw_images[] array at runtime from the partition
table (Qualcomm Snapdragon) assign each descriptor a fixed, per-component
image_index. A board only carries a subset of components, so those indices
can fall outside 1 <= ImageIndex <= DescriptorCount — the range UEFI 2.9A
§23.1 requires GetImageInfo to report.

This series makes such platforms assign image_index sequentially and resolves
capsule payloads by image type GUID instead of by index, so the reported
descriptor array and the ESRT stay in range. Platforms with a static 1:1
fw_images[] are unaffected.

This reverts commit c699c6d.

With OSIndications now set from Kernel, OsIndications is taken into
account during capsule update in U-Boot.
Comment thread doc/develop/uefi/uefi.rst
Such platforms set num_images and dfu_alt_num_valid = true. When
dfu_alt_num_valid is false (the default) behaviour is unchanged: the capsule's
UpdateImageIndex is used as-is and dfu_alt_num is ignored.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if validated and tested code should be changed to handle snapdragon not aligning with the expectation. If GUID overrides the index for flashing, why cant Qualcomm use an index that is inline with EFI expectation?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if validated and tested code should be changed to handle snapdragon not aligning with the expectation. If GUID overrides the index for flashing, why cant Qualcomm use an index that is inline with EFI expectation?

Hi, index varies across boards, depending the on the partitions present on a given board.
Hence, we cant use index for identifying dfu string (and so we relyon GUID).
Also, testing for capsule update is yet to start, hence, doing the change now, so testing can validate these changes also.

Comment thread doc/develop/uefi/uefi.rst Outdated
Comment thread doc/develop/uefi/uefi.rst Outdated

struct efi_capsule_update_info {
const char *dfu_string;
int num_images;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drop

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed.

Comment thread lib/efi_loader/efi_capsule.c Outdated
Comment on lines +520 to +532
/**
* efi_capsule_resolve_image_index - map a capsule to its platform image index
* @image_type: Image type GUID from the capsule (UpdateImageTypeId)
* @capsule_index: Image index from the capsule (UpdateImageIndex)
*
* Return the image_index to use for efi_fmp_find() and set_image(). The weak
* default trusts the capsule's own UpdateImageIndex, so behaviour is unchanged
* for platforms with a static 1:1 fw_images[]. A platform whose fw_images[] is
* built dynamically (so the capsule's UpdateImageIndex cannot be relied on)
* overrides this to resolve @image_type to its own image_index.
*
* Return: the image_index to use for efi_fmp_find() and set_image()
*/

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The info in the include/efi_loader.h for the prototype is better. This can be dropped.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropped.

Comment thread lib/efi_loader/efi_capsule.c Outdated
Comment on lines +520 to +532
/**
* efi_capsule_resolve_image_index - map a capsule to its platform image index
* @image_type: Image type GUID from the capsule (UpdateImageTypeId)
* @capsule_index: Image index from the capsule (UpdateImageIndex)
*
* Return the image_index to use for efi_fmp_find() and set_image(). The weak
* default trusts the capsule's own UpdateImageIndex, so behaviour is unchanged
* for platforms with a static 1:1 fw_images[]. A platform whose fw_images[] is
* built dynamically (so the capsule's UpdateImageIndex cannot be relied on)
* overrides this to resolve @image_type to its own image_index.
*
* Return: the image_index to use for efi_fmp_find() and set_image()
*/

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop. Comments in the header is enough and it is better

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropped.

Comment thread doc/develop/uefi/uefi.rst Outdated

struct efi_capsule_update_info {
const char *dfu_string;
int num_images;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropped.

Platforms that build their fw_images[] array dynamically from the
partition table (e.g. Qualcomm Snapdragon) assign each descriptor a
fixed, per-component image_index. Because a given board only carries a
subset of components, those values can fall outside the range
1 <= ImageIndex <= DescriptorCount that UEFI 2.9A section 23.1 requires
GetImageInfo to report. Such a platform must instead assign image_index
sequentially (1..num_images), after which the capsule's UpdateImageIndex
can no longer be trusted to select the right image.

Add a __weak efi_capsule_resolve_image_index() that maps a capsule to
the image_index used for efi_fmp_find() and set_image(). The default
returns the capsule's UpdateImageIndex unchanged, so platforms with a
static 1:1 fw_images[] are byte-for-byte unchanged. A platform with a
dynamically built fw_images[] overrides it to resolve the payload by
image_type_id (GUID) to its own sequential image_index; the generic code
carries no platform-specific policy.

Signed-off-by: Balaji Selvanathan <balaji.selvanathan@oss.qualcomm.com>
Build on the generic weak hook and make Snapdragon's dynamically built
fw_images[] spec-compliant: image_index is assigned sequentially (i + 1)
in qcom_build_fw_images(), so GetImageInfo reports ImageIndex values in
1..DescriptorCount as required by UEFI 2.9A section 23.1.

Once image_index is sequential it depends on which components a board
carries, so it can no longer match the capsule's frozen UpdateImageIndex.
Override efi_capsule_resolve_image_index() to map an incoming payload to
its image_index by image_type_id (GUID); the generic capsule flow uses
that resolved index for both efi_fmp_find() and set_image(). No flag on
the shared struct is needed - platforms that don't override keep the weak
default and are unaffected.

Signed-off-by: Balaji Selvanathan <balaji.selvanathan@oss.qualcomm.com>
Add the multiimgqti component (partition multiimgqti_a/_b, image type
GUID 846c6f05-eb46-4c0a-a1a3-3648ef3f9d0e) to qcom_image_map[] so boards
that carry it can capsule-update it. It is appended with a new authoring
index (17) so the frozen indices of already-authored capsules are
preserved.

Drop the apdp component from the map. Removing a row leaves a gap in the
authoring-index sequence (15); this is harmless because the index is only
compared by value (rule-1 dedup) and is never used as an array subscript,
and the runtime fw_images[].image_index is assigned sequentially
regardless.

Signed-off-by: Balaji Selvanathan <balaji.selvanathan@oss.qualcomm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants