[PATCH v5 03/11] efi: add a helper to generate dynamic UUIDs

Ilias Apalodimas ilias.apalodimas at linaro.org
Thu Jul 25 13:57:47 CEST 2024


Hi Caleb,


> +/**
> + * efi_capsule_update_info_gen_ids - generate GUIDs for the images
> + *
> + * Generate the image_type_id for each image in the update_info.images array
> + * using the first compatible from the device tree and a salt
> + * UUID defined at build time.
> + *
> + * Returns:            status code
> + */
> +static efi_status_t efi_capsule_update_info_gen_ids(void)

I think efi_gen_capsule_guids() is a better name

> +{
> +       int ret, i;
> +       struct uuid namespace;
> +       const char *compatible; /* Full array including null bytes */
> +       struct efi_fw_image *fw_array;
> +
> +       fw_array = update_info.images;
> +       /* Check if we need to run (there are images and we didn't already generate their IDs) */
> +       if (!update_info.num_images ||
> +           memchr_inv(&fw_array[0].image_type_id, 0, sizeof(fw_array[0].image_type_id)))
> +               return EFI_SUCCESS;
> +
> +       ret = uuid_str_to_bin(CONFIG_EFI_CAPSULE_NAMESPACE_GUID,
> +                       (unsigned char *)&namespace, UUID_STR_FORMAT_GUID);
> +       if (ret) {
> +               log_debug("%s: EFI_CAPSULE_NAMESPACE_GUID is invalid: %d\n", __func__, ret);
> +               return EFI_UNSUPPORTED;

EFI_INVALID_PARAMETER is a better return code for this and the check
that follows

> +       }
> +
> +       compatible = ofnode_read_string(ofnode_root(), "compatible");
> +       if (!compatible) {
> +               log_debug("%s: model or compatible not defined\n", __func__);
> +               return EFI_UNSUPPORTED;
> +       }
> +
> +       for (i = 0; i < update_info.num_images; i++) {
> +               gen_v5_guid(&namespace,
> +                           &fw_array[i].image_type_id,
> +                           compatible, strlen(compatible),
> +                           fw_array[i].fw_name, u16_strlen(fw_array[i].fw_name) * sizeof(uint16_t),
> +                           NULL);
> +
> +               log_debug("Image %ls UUID %pUl\n", fw_array[i].fw_name,
> +                         &fw_array[i].image_type_id);
> +       }
> +
> +       return EFI_SUCCESS;
> +}
> +
>  /**
>   * efi_fill_image_desc_array - populate image descriptor array
>   * @image_info_size:           Size of @image_info
>   * @image_info:                        Image information
> @@ -282,8 +331,11 @@ static efi_status_t efi_fill_image_desc_array(
>                 return EFI_BUFFER_TOO_SMALL;
>         }
>         *image_info_size = total_size;
>
> +       if (efi_capsule_update_info_gen_ids() != EFI_SUCCESS)
> +               return EFI_UNSUPPORTED;

When you make the changes above do
ret = efi_gen_capsule_guids()
if (ret != EFI_SUCESS)
    return ret;

> +
>         fw_array = update_info.images;
>         *descriptor_count = update_info.num_images;
>         *descriptor_version = EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION;
>         *descriptor_size = sizeof(*image_info);
>
> --
> 2.45.2
>

Other than that, this patch looks ok

Cheers
/Ilias


More information about the U-Boot mailing list