[PATCH v6 4/8] efi_loader: get lowest supported version from device tree
Ilias Apalodimas
ilias.apalodimas at linaro.org
Mon May 22 23:33:50 CEST 2023
On Fri, May 19, 2023 at 07:32:10PM +0900, Masahisa Kojima wrote:
> This commit gets the lowest supported version from device tree,
> then fills the lowest supported version in FMP->GetImageInfo().
>
> Signed-off-by: Masahisa Kojima <masahisa.kojima at linaro.org>
> ---
> Changed in v6:
> - fw_version is removed from device tree
>
> .../firmware/firmware-version.txt | 22 ++++++++
> lib/efi_loader/efi_firmware.c | 50 ++++++++++++++++++-
> 2 files changed, 71 insertions(+), 1 deletion(-)
> create mode 100644 doc/device-tree-bindings/firmware/firmware-version.txt
>
> diff --git a/doc/device-tree-bindings/firmware/firmware-version.txt b/doc/device-tree-bindings/firmware/firmware-version.txt
> new file mode 100644
> index 0000000000..ee90ce3117
> --- /dev/null
> +++ b/doc/device-tree-bindings/firmware/firmware-version.txt
> @@ -0,0 +1,22 @@
> +firmware-version bindings
> +-------------------------------
> +
> +Required properties:
> +- image-type-id : guid for image blob type
> +- image-index : image index
> +- lowest-supported-version : lowest supported version
> +
> +Example:
> +
> + firmware-version {
> + image1 {
> + image-type-id = "09D7CF52-0720-4710-91D1-08469B7FE9C8";
> + image-index = <1>;
> + lowest-supported-version = <3>;
> + };
> + image2 {
> + image-type-id = "5A7021F5-FEF2-48B4-AABA-832E777418C0";
> + image-index = <2>;
> + lowest-supported-version = <7>;
> + };
> + };
> diff --git a/lib/efi_loader/efi_firmware.c b/lib/efi_loader/efi_firmware.c
> index 64ceefa212..00cf9a088a 100644
> --- a/lib/efi_loader/efi_firmware.c
> +++ b/lib/efi_loader/efi_firmware.c
> @@ -144,6 +144,51 @@ efi_status_t EFIAPI efi_firmware_set_package_info_unsupported(
> return EFI_EXIT(EFI_UNSUPPORTED);
> }
>
> +/**
> + * efi_firmware_get_lsv_from_dtb - get lowest supported version from dtb
> + * @image_index: Image index
> + * @image_type_id: Image type id
> + * @lsv: Pointer to store the lowest supported version
> + *
> + * Read the firmware version information from dtb.
> + */
> +static void efi_firmware_get_lsv_from_dtb(u8 image_index,
> + efi_guid_t *image_type_id, u32 *lsv)
> +{
> + const void *fdt = gd->fdt_blob;
> + const fdt32_t *val;
> + const char *guid_str;
> + int len, offset, index;
> + int parent;
> +
> + *lsv = 0;
> +
> + parent = fdt_subnode_offset(fdt, 0, "firmware-version");
> + if (parent < 0)
> + return;
> +
> + fdt_for_each_subnode(offset, fdt, parent) {
> + efi_guid_t guid;
> +
> + guid_str = fdt_getprop(fdt, offset, "image-type-id", &len);
> + if (!guid_str)
> + continue;
> + uuid_str_to_bin(guid_str, guid.b, UUID_STR_FORMAT_GUID);
> +
> + val = fdt_getprop(fdt, offset, "image-index", &len);
> + if (!val)
> + continue;
> + index = fdt32_to_cpu(*val);
> +
> + if (!guidcmp(&guid, image_type_id) && index == image_index) {
> + val = fdt_getprop(fdt, offset,
> + "lowest-supported-version", &len);
> + if (val)
> + *lsv = fdt32_to_cpu(*val);
> + }
> + }
> +}
> +
> /**
> * efi_firmware_fill_version_info - fill the version information
> * @image_info: Image information
> @@ -171,8 +216,11 @@ void efi_firmware_fill_version_info(struct efi_firmware_image_descriptor *image_
> else
> image_info->version = 0;
>
> + efi_firmware_get_lsv_from_dtb(fw_array->image_index,
> + &fw_array->image_type_id,
> + &image_info->lowest_supported_image_version);
> +
> image_info->version_name = NULL; /* not supported */
> - image_info->lowest_supported_image_version = 0;
> image_info->last_attempt_version = 0;
> image_info->last_attempt_status = LAST_ATTEMPT_STATUS_SUCCESS;
> }
> --
> 2.17.1
>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas at linaro.org>
More information about the U-Boot
mailing list