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