Patrick Williams | 2194f50 | 2022-10-16 14:26:09 -0500 | [diff] [blame^] | 1 | From d8fca6ebd5917df9a12dbf1da6a97f99af06eee9 Mon Sep 17 00:00:00 2001 |
| 2 | From: Satish Kumar <satish.kumar01@arm.com> |
| 3 | Date: Fri, 19 Aug 2022 09:18:33 +0100 |
| 4 | Subject: [PATCH] arm/corstone1000: esrt support |
| 5 | |
| 6 | The implementation is platform specific and would require |
| 7 | change in future. |
| 8 | |
| 9 | The patch should not be upstreamed as it is to the u-boot. |
| 10 | Redesign of FMP protocol for ESRT and Capsule Update interface |
| 11 | is to be considered in the future. |
| 12 | |
| 13 | Signed-off-by: Satish Kumar <satish.kumar01@arm.com> |
| 14 | Upstream-Status: Inappropriate [Redesign of FMP protocol for ESRT and Capsule update interface is required] |
| 15 | --- |
| 16 | include/efi_api.h | 2 +- |
| 17 | lib/efi_loader/efi_firmware.c | 133 ++++++++++++++++++++++++++++++++++ |
| 18 | lib/efi_loader/efi_setup.c | 16 ++-- |
| 19 | 3 files changed, 142 insertions(+), 9 deletions(-) |
| 20 | |
| 21 | diff --git a/include/efi_api.h b/include/efi_api.h |
| 22 | index 83c01085fd..26899afd01 100644 |
| 23 | --- a/include/efi_api.h |
| 24 | +++ b/include/efi_api.h |
| 25 | @@ -2014,7 +2014,7 @@ struct efi_firmware_image_descriptor { |
| 26 | u32 last_attempt_status; |
| 27 | u64 hardware_instance; |
| 28 | efi_firmware_image_dep_t *dependencies; |
| 29 | -}; |
| 30 | +} __packed; |
| 31 | |
| 32 | struct efi_firmware_management_protocol { |
| 33 | efi_status_t (EFIAPI *get_image_info)( |
| 34 | diff --git a/lib/efi_loader/efi_firmware.c b/lib/efi_loader/efi_firmware.c |
| 35 | index 28d9a19edb..aa4af8036b 100644 |
| 36 | --- a/lib/efi_loader/efi_firmware.c |
| 37 | +++ b/lib/efi_loader/efi_firmware.c |
| 38 | @@ -14,6 +14,7 @@ |
| 39 | #include <signatures.h> |
| 40 | |
| 41 | #include <linux/list.h> |
| 42 | +#include <efi_variable.h> |
| 43 | |
| 44 | #define FMP_PAYLOAD_HDR_SIGNATURE SIGNATURE_32('M', 'S', 'S', '1') |
| 45 | |
| 46 | @@ -416,8 +417,140 @@ efi_status_t EFIAPI efi_firmware_fit_set_image( |
| 47 | return EFI_EXIT(EFI_SUCCESS); |
| 48 | } |
| 49 | |
| 50 | +#if CONFIG_IS_ENABLED(TARGET_CORSTONE1000) |
| 51 | + |
| 52 | +/** |
| 53 | + * efi_firmware_corstone1000_get_image_info - return information about the current |
| 54 | + firmware image |
| 55 | + * @this: Protocol instance |
| 56 | + * @image_info_size: Size of @image_info |
| 57 | + * @image_info: Image information |
| 58 | + * @descriptor_version: Pointer to version number |
| 59 | + * @descriptor_count: Pointer to number of descriptors |
| 60 | + * @descriptor_size: Pointer to descriptor size |
| 61 | + * package_version: Package version |
| 62 | + * package_version_name: Package version's name |
| 63 | + * |
| 64 | + * Return information bout the current firmware image in @image_info. |
| 65 | + * @image_info will consist of a number of descriptors. |
| 66 | + * Each descriptor will be created based on efi fetched variable. |
| 67 | + * |
| 68 | + * Return status code |
| 69 | + */ |
| 70 | +static |
| 71 | +efi_status_t EFIAPI efi_firmware_corstone1000_get_image_info( |
| 72 | + struct efi_firmware_management_protocol *this, |
| 73 | + efi_uintn_t *image_info_size, |
| 74 | + struct efi_firmware_image_descriptor *image_info, |
| 75 | + u32 *descriptor_version, |
| 76 | + u8 *descriptor_count, |
| 77 | + efi_uintn_t *descriptor_size, |
| 78 | + u32 *package_version, |
| 79 | + u16 **package_version_name) |
| 80 | +{ |
| 81 | + efi_uintn_t var_size; |
| 82 | + efi_status_t ret = EFI_SUCCESS; |
| 83 | + efi_uintn_t image_info_size_var = 0; |
| 84 | + efi_uintn_t image_info_name_size_var; |
| 85 | + efi_uintn_t image_info_version_size_var; |
| 86 | + u8 *runner = (u8 *)image_info; |
| 87 | + u16 fmp_image_name[14] = {'F', 'm', 'p', 'I', 'm', 'a', 'g', 'e', 'N', 'a', 'm', 'e', '1', '\0'}; |
| 88 | + u16 fmp_version_name[16] = {'F', 'm', 'p', 'V', 'e', 'r', 's', 'i', 'o', 'n', 'N', 'a', 'm', 'e', '1', '\0'}; |
| 89 | + |
| 90 | + EFI_ENTRY("%p %p %p %p %p %p %p %p\n", this, |
| 91 | + image_info_size, image_info, |
| 92 | + descriptor_version, descriptor_count, descriptor_size, |
| 93 | + package_version, package_version_name); |
| 94 | + |
| 95 | + if (!image_info_size) |
| 96 | + return EFI_EXIT(EFI_INVALID_PARAMETER); |
| 97 | + |
| 98 | + if (*image_info_size && |
| 99 | + (!image_info || !descriptor_version || !descriptor_count || |
| 100 | + !descriptor_size || !package_version || !package_version_name)) |
| 101 | + return EFI_EXIT(EFI_INVALID_PARAMETER); |
| 102 | + |
| 103 | + var_size = sizeof(*descriptor_version); |
| 104 | + ret = efi_get_variable(u"FmpDescriptorVersion", |
| 105 | + &efi_guid_firmware_management_protocol, NULL, |
| 106 | + &var_size, descriptor_version); |
| 107 | + if (ret != EFI_SUCCESS) |
| 108 | + return EFI_EXIT(ret); |
| 109 | + |
| 110 | + if (*descriptor_version != EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION) |
| 111 | + return EFI_EXIT(EFI_UNSUPPORTED); |
| 112 | + |
| 113 | + var_size = sizeof(image_info_size_var); |
| 114 | + ret = efi_get_variable(u"FmpImageInfoSize", |
| 115 | + &efi_guid_firmware_management_protocol, NULL, |
| 116 | + &var_size, &image_info_size_var); |
| 117 | + if (ret != EFI_SUCCESS) |
| 118 | + return EFI_EXIT(ret); |
| 119 | + |
| 120 | + if (*image_info_size < image_info_size_var) { |
| 121 | + *image_info_size = image_info_size_var; |
| 122 | + return EFI_EXIT(EFI_BUFFER_TOO_SMALL); |
| 123 | + } |
| 124 | + |
| 125 | + image_info_name_size_var = image_info_size_var; |
| 126 | + |
| 127 | + var_size = sizeof(*descriptor_count); |
| 128 | + ret = efi_get_variable(u"FmpDescriptorCount", |
| 129 | + &efi_guid_firmware_management_protocol, NULL, |
| 130 | + &var_size, descriptor_count); |
| 131 | + if (ret != EFI_SUCCESS) { |
| 132 | + return EFI_EXIT(ret); |
| 133 | + } |
| 134 | + |
| 135 | + ret = efi_get_variable(u"FmpImageInfo", |
| 136 | + &efi_guid_firmware_management_protocol, NULL, |
| 137 | + &image_info_size_var, image_info); |
| 138 | + if (ret != EFI_SUCCESS) |
| 139 | + return EFI_EXIT(ret); |
| 140 | + |
| 141 | + runner += image_info_size_var; |
| 142 | + |
| 143 | + image_info_name_size_var -= image_info_size_var; |
| 144 | + image_info_version_size_var = image_info_name_size_var; |
| 145 | + |
| 146 | + /* Consider changing the string modfication logic */ |
| 147 | + fmp_image_name[12] = '0' + (u16)image_info->image_id; |
| 148 | + ret = efi_get_variable(fmp_image_name, |
| 149 | + &efi_guid_firmware_management_protocol, NULL, |
| 150 | + &image_info_name_size_var, runner); |
| 151 | + if (ret != EFI_SUCCESS) |
| 152 | + return EFI_EXIT(ret); |
| 153 | + |
| 154 | + image_info_version_size_var -= image_info_name_size_var; |
| 155 | + image_info->image_id_name = runner; |
| 156 | + runner += image_info_name_size_var; |
| 157 | + |
| 158 | + /* Consider changing the string modfication logic */ |
| 159 | + fmp_version_name[14] = '0' + (u16)image_info->image_id; |
| 160 | + ret = efi_get_variable(fmp_version_name, |
| 161 | + &efi_guid_firmware_management_protocol, NULL, |
| 162 | + &image_info_version_size_var, runner); |
| 163 | + if (ret != EFI_SUCCESS) |
| 164 | + return EFI_EXIT(ret); |
| 165 | + |
| 166 | + image_info->version_name = runner; |
| 167 | + |
| 168 | + *image_info_size = image_info_size_var; |
| 169 | + |
| 170 | + *package_version = 0xffffffff; /* not supported */ |
| 171 | + *package_version_name = NULL; /* not supported */ |
| 172 | + |
| 173 | + return EFI_EXIT(ret); |
| 174 | +} |
| 175 | + |
| 176 | +#endif |
| 177 | + |
| 178 | const struct efi_firmware_management_protocol efi_fmp_fit = { |
| 179 | +#if CONFIG_IS_ENABLED(TARGET_CORSTONE1000) |
| 180 | + .get_image_info = efi_firmware_corstone1000_get_image_info, |
| 181 | +#else |
| 182 | .get_image_info = efi_firmware_get_image_info, |
| 183 | +#endif |
| 184 | .get_image = efi_firmware_get_image_unsupported, |
| 185 | .set_image = efi_firmware_fit_set_image, |
| 186 | .check_image = efi_firmware_check_image_unsupported, |
| 187 | diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c |
| 188 | index 6c9e14c37e..6ccda175ff 100644 |
| 189 | --- a/lib/efi_loader/efi_setup.c |
| 190 | +++ b/lib/efi_loader/efi_setup.c |
| 191 | @@ -168,13 +168,6 @@ static efi_status_t efi_init_capsule(void) |
| 192 | |
| 193 | #if IS_ENABLED(CONFIG_TARGET_CORSTONE1000) |
| 194 | int ffa_ret; |
| 195 | - |
| 196 | - ffa_ret = efi_corstone1000_uboot_efi_started_event(); |
| 197 | - if (ffa_ret) |
| 198 | - debug("[efi_boottime][ERROR]: Failure to notify SE Proxy FW update service\n"); |
| 199 | - else |
| 200 | - debug("[efi_boottime][INFO]: SE Proxy FW update service notified\n"); |
| 201 | - |
| 202 | ret = efi_corstone1000_alloc_capsule_shared_buf(); |
| 203 | if (ret != EFI_SUCCESS) { |
| 204 | printf("EFI: Corstone-1000: cannot allocate caspsule shared buffer\n"); |
| 205 | @@ -306,7 +299,14 @@ efi_status_t efi_init_obj_list(void) |
| 206 | if (ret != EFI_SUCCESS) |
| 207 | goto out; |
| 208 | } |
| 209 | - |
| 210 | +#if IS_ENABLED(CONFIG_TARGET_CORSTONE1000) |
| 211 | + int ffa_ret; |
| 212 | + ffa_ret = efi_corstone1000_uboot_efi_started_event(); |
| 213 | + if (ffa_ret) |
| 214 | + debug("[efi_boottime][ERROR]: Failure to notify SE Proxy FW update service\n"); |
| 215 | + else |
| 216 | + debug("[efi_boottime][INFO]: SE Proxy FW update service notified\n"); |
| 217 | +#endif |
| 218 | /* Initialize variable services */ |
| 219 | ret = efi_init_variables(); |
| 220 | if (ret != EFI_SUCCESS) |
| 221 | -- |
| 222 | 2.25.1 |
| 223 | |