AKASHI Takahiro | f4818e6 | 2020-11-30 18:12:12 +0900 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * EFI Firmware management protocol |
| 4 | * |
| 5 | * Copyright (c) 2020 Linaro Limited |
| 6 | * Author: AKASHI Takahiro |
| 7 | */ |
| 8 | |
| 9 | #include <common.h> |
| 10 | #include <charset.h> |
| 11 | #include <dfu.h> |
| 12 | #include <efi_loader.h> |
| 13 | #include <image.h> |
Sughosh Ganu | 7221c6e | 2020-12-30 19:27:05 +0530 | [diff] [blame] | 14 | #include <signatures.h> |
| 15 | |
AKASHI Takahiro | f4818e6 | 2020-11-30 18:12:12 +0900 | [diff] [blame] | 16 | #include <linux/list.h> |
| 17 | |
Sughosh Ganu | 7221c6e | 2020-12-30 19:27:05 +0530 | [diff] [blame] | 18 | #define FMP_PAYLOAD_HDR_SIGNATURE SIGNATURE_32('M', 'S', 'S', '1') |
| 19 | |
| 20 | /** |
| 21 | * struct fmp_payload_header - EDK2 header for the FMP payload |
| 22 | * |
| 23 | * This structure describes the header which is preprended to the |
| 24 | * FMP payload by the edk2 capsule generation scripts. |
| 25 | * |
| 26 | * @signature: Header signature used to identify the header |
| 27 | * @header_size: Size of the structure |
| 28 | * @fw_version: Firmware versions used |
| 29 | * @lowest_supported_version: Lowest supported version |
| 30 | */ |
| 31 | struct fmp_payload_header { |
| 32 | u32 signature; |
| 33 | u32 header_size; |
| 34 | u32 fw_version; |
| 35 | u32 lowest_supported_version; |
| 36 | }; |
| 37 | |
Sughosh Ganu | a1d9f67 | 2022-04-15 11:29:37 +0530 | [diff] [blame] | 38 | __weak void set_dfu_alt_info(char *interface, char *devstr) |
| 39 | { |
| 40 | env_set("dfu_alt_info", update_info.dfu_string); |
| 41 | } |
| 42 | |
AKASHI Takahiro | 7ff3f3c | 2020-11-17 09:28:00 +0900 | [diff] [blame] | 43 | /* Place holder; not supported */ |
| 44 | static |
| 45 | efi_status_t EFIAPI efi_firmware_get_image_unsupported( |
| 46 | struct efi_firmware_management_protocol *this, |
| 47 | u8 image_index, |
| 48 | void *image, |
| 49 | efi_uintn_t *image_size) |
| 50 | { |
| 51 | EFI_ENTRY("%p %d %p %p\n", this, image_index, image, image_size); |
| 52 | |
| 53 | return EFI_EXIT(EFI_UNSUPPORTED); |
| 54 | } |
| 55 | |
| 56 | /* Place holder; not supported */ |
| 57 | static |
| 58 | efi_status_t EFIAPI efi_firmware_check_image_unsupported( |
| 59 | struct efi_firmware_management_protocol *this, |
| 60 | u8 image_index, |
| 61 | const void *image, |
| 62 | efi_uintn_t *image_size, |
| 63 | u32 *image_updatable) |
| 64 | { |
| 65 | EFI_ENTRY("%p %d %p %p %p\n", this, image_index, image, image_size, |
| 66 | image_updatable); |
| 67 | |
| 68 | return EFI_EXIT(EFI_UNSUPPORTED); |
| 69 | } |
| 70 | |
| 71 | /* Place holder; not supported */ |
| 72 | static |
| 73 | efi_status_t EFIAPI efi_firmware_get_package_info_unsupported( |
| 74 | struct efi_firmware_management_protocol *this, |
| 75 | u32 *package_version, |
| 76 | u16 **package_version_name, |
| 77 | u32 *package_version_name_maxlen, |
| 78 | u64 *attributes_supported, |
| 79 | u64 *attributes_setting) |
| 80 | { |
| 81 | EFI_ENTRY("%p %p %p %p %p %p\n", this, package_version, |
| 82 | package_version_name, package_version_name_maxlen, |
| 83 | attributes_supported, attributes_setting); |
| 84 | |
| 85 | return EFI_EXIT(EFI_UNSUPPORTED); |
| 86 | } |
| 87 | |
| 88 | /* Place holder; not supported */ |
| 89 | static |
| 90 | efi_status_t EFIAPI efi_firmware_set_package_info_unsupported( |
| 91 | struct efi_firmware_management_protocol *this, |
| 92 | const void *image, |
| 93 | efi_uintn_t *image_size, |
| 94 | const void *vendor_code, |
| 95 | u32 package_version, |
| 96 | const u16 *package_version_name) |
| 97 | { |
| 98 | EFI_ENTRY("%p %p %p %p %x %p\n", this, image, image_size, vendor_code, |
| 99 | package_version, package_version_name); |
| 100 | |
| 101 | return EFI_EXIT(EFI_UNSUPPORTED); |
| 102 | } |
AKASHI Takahiro | f4818e6 | 2020-11-30 18:12:12 +0900 | [diff] [blame] | 103 | |
| 104 | /** |
Sughosh Ganu | 2a9fd7d | 2022-04-15 11:29:35 +0530 | [diff] [blame] | 105 | * efi_fill_image_desc_array - populate image descriptor array |
AKASHI Takahiro | f4818e6 | 2020-11-30 18:12:12 +0900 | [diff] [blame] | 106 | * @image_info_size: Size of @image_info |
| 107 | * @image_info: Image information |
| 108 | * @descriptor_version: Pointer to version number |
Sughosh Ganu | 2a9fd7d | 2022-04-15 11:29:35 +0530 | [diff] [blame] | 109 | * @descriptor_count: Image count |
AKASHI Takahiro | f4818e6 | 2020-11-30 18:12:12 +0900 | [diff] [blame] | 110 | * @descriptor_size: Pointer to descriptor size |
Sughosh Ganu | 2a9fd7d | 2022-04-15 11:29:35 +0530 | [diff] [blame] | 111 | * @package_version: Package version |
| 112 | * @package_version_name: Package version's name |
AKASHI Takahiro | f4818e6 | 2020-11-30 18:12:12 +0900 | [diff] [blame] | 113 | * |
Sughosh Ganu | 2a9fd7d | 2022-04-15 11:29:35 +0530 | [diff] [blame] | 114 | * Return information about the current firmware image in @image_info. |
AKASHI Takahiro | f4818e6 | 2020-11-30 18:12:12 +0900 | [diff] [blame] | 115 | * @image_info will consist of a number of descriptors. |
Sughosh Ganu | 2a9fd7d | 2022-04-15 11:29:35 +0530 | [diff] [blame] | 116 | * Each descriptor will be created based on efi_fw_image array. |
AKASHI Takahiro | f4818e6 | 2020-11-30 18:12:12 +0900 | [diff] [blame] | 117 | * |
| 118 | * Return status code |
| 119 | */ |
Sughosh Ganu | 2a9fd7d | 2022-04-15 11:29:35 +0530 | [diff] [blame] | 120 | static efi_status_t efi_fill_image_desc_array( |
AKASHI Takahiro | f4818e6 | 2020-11-30 18:12:12 +0900 | [diff] [blame] | 121 | efi_uintn_t *image_info_size, |
| 122 | struct efi_firmware_image_descriptor *image_info, |
| 123 | u32 *descriptor_version, |
| 124 | u8 *descriptor_count, |
| 125 | efi_uintn_t *descriptor_size, |
| 126 | u32 *package_version, |
Sughosh Ganu | 2a9fd7d | 2022-04-15 11:29:35 +0530 | [diff] [blame] | 127 | u16 **package_version_name) |
AKASHI Takahiro | f4818e6 | 2020-11-30 18:12:12 +0900 | [diff] [blame] | 128 | { |
Sughosh Ganu | 2a9fd7d | 2022-04-15 11:29:35 +0530 | [diff] [blame] | 129 | size_t total_size; |
| 130 | struct efi_fw_image *fw_array; |
| 131 | int i; |
AKASHI Takahiro | f4818e6 | 2020-11-30 18:12:12 +0900 | [diff] [blame] | 132 | |
Sughosh Ganu | 2a9fd7d | 2022-04-15 11:29:35 +0530 | [diff] [blame] | 133 | total_size = sizeof(*image_info) * num_image_type_guids; |
AKASHI Takahiro | f4818e6 | 2020-11-30 18:12:12 +0900 | [diff] [blame] | 134 | |
AKASHI Takahiro | f4818e6 | 2020-11-30 18:12:12 +0900 | [diff] [blame] | 135 | if (*image_info_size < total_size) { |
| 136 | *image_info_size = total_size; |
AKASHI Takahiro | f4818e6 | 2020-11-30 18:12:12 +0900 | [diff] [blame] | 137 | |
| 138 | return EFI_BUFFER_TOO_SMALL; |
| 139 | } |
| 140 | *image_info_size = total_size; |
| 141 | |
Sughosh Ganu | c212fc7 | 2022-05-31 12:45:33 +0530 | [diff] [blame] | 142 | fw_array = update_info.images; |
| 143 | *descriptor_count = num_image_type_guids; |
AKASHI Takahiro | f4818e6 | 2020-11-30 18:12:12 +0900 | [diff] [blame] | 144 | *descriptor_version = EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION; |
AKASHI Takahiro | f4818e6 | 2020-11-30 18:12:12 +0900 | [diff] [blame] | 145 | *descriptor_size = sizeof(*image_info); |
| 146 | *package_version = 0xffffffff; /* not supported */ |
| 147 | *package_version_name = NULL; /* not supported */ |
| 148 | |
Sughosh Ganu | 2a9fd7d | 2022-04-15 11:29:35 +0530 | [diff] [blame] | 149 | for (i = 0; i < num_image_type_guids; i++) { |
| 150 | image_info[i].image_index = fw_array[i].image_index; |
| 151 | image_info[i].image_type_id = fw_array[i].image_type_id; |
| 152 | image_info[i].image_id = fw_array[i].image_index; |
AKASHI Takahiro | f4818e6 | 2020-11-30 18:12:12 +0900 | [diff] [blame] | 153 | |
Sughosh Ganu | 2a9fd7d | 2022-04-15 11:29:35 +0530 | [diff] [blame] | 154 | image_info[i].image_id_name = fw_array[i].fw_name; |
AKASHI Takahiro | f4818e6 | 2020-11-30 18:12:12 +0900 | [diff] [blame] | 155 | |
| 156 | image_info[i].version = 0; /* not supported */ |
| 157 | image_info[i].version_name = NULL; /* not supported */ |
| 158 | image_info[i].size = 0; |
| 159 | image_info[i].attributes_supported = |
Sughosh Ganu | c9a821b | 2020-12-30 19:27:10 +0530 | [diff] [blame] | 160 | IMAGE_ATTRIBUTE_IMAGE_UPDATABLE | |
| 161 | IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED; |
AKASHI Takahiro | f4818e6 | 2020-11-30 18:12:12 +0900 | [diff] [blame] | 162 | image_info[i].attributes_setting = |
| 163 | IMAGE_ATTRIBUTE_IMAGE_UPDATABLE; |
Sughosh Ganu | c9a821b | 2020-12-30 19:27:10 +0530 | [diff] [blame] | 164 | |
| 165 | /* Check if the capsule authentication is enabled */ |
Sughosh Ganu | d1bd849 | 2021-04-12 20:35:23 +0530 | [diff] [blame] | 166 | if (IS_ENABLED(CONFIG_EFI_CAPSULE_AUTHENTICATE)) |
Sughosh Ganu | c9a821b | 2020-12-30 19:27:10 +0530 | [diff] [blame] | 167 | image_info[0].attributes_setting |= |
| 168 | IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED; |
| 169 | |
AKASHI Takahiro | f4818e6 | 2020-11-30 18:12:12 +0900 | [diff] [blame] | 170 | image_info[i].lowest_supported_image_version = 0; |
| 171 | image_info[i].last_attempt_version = 0; |
| 172 | image_info[i].last_attempt_status = LAST_ATTEMPT_STATUS_SUCCESS; |
| 173 | image_info[i].hardware_instance = 1; |
| 174 | image_info[i].dependencies = NULL; |
AKASHI Takahiro | f4818e6 | 2020-11-30 18:12:12 +0900 | [diff] [blame] | 175 | } |
| 176 | |
AKASHI Takahiro | f4818e6 | 2020-11-30 18:12:12 +0900 | [diff] [blame] | 177 | return EFI_SUCCESS; |
| 178 | } |
| 179 | |
Vincent Stehlé | 6a4625e | 2022-05-31 09:55:34 +0200 | [diff] [blame] | 180 | /** |
| 181 | * efi_firmware_capsule_authenticate - authenticate the capsule if enabled |
| 182 | * @p_image: Pointer to new image |
| 183 | * @p_image_size: Pointer to size of new image |
| 184 | * |
| 185 | * Authenticate the capsule if authentication is enabled. |
| 186 | * The image pointer and the image size are updated in case of success. |
| 187 | * |
| 188 | * Return: status code |
| 189 | */ |
| 190 | static |
| 191 | efi_status_t efi_firmware_capsule_authenticate(const void **p_image, |
| 192 | efi_uintn_t *p_image_size) |
| 193 | { |
| 194 | const void *image = *p_image; |
| 195 | efi_uintn_t image_size = *p_image_size; |
| 196 | u32 fmp_hdr_signature; |
| 197 | struct fmp_payload_header *header; |
| 198 | void *capsule_payload; |
| 199 | efi_status_t status; |
| 200 | efi_uintn_t capsule_payload_size; |
| 201 | |
| 202 | if (IS_ENABLED(CONFIG_EFI_CAPSULE_AUTHENTICATE)) { |
| 203 | capsule_payload = NULL; |
| 204 | capsule_payload_size = 0; |
| 205 | status = efi_capsule_authenticate(image, image_size, |
| 206 | &capsule_payload, |
| 207 | &capsule_payload_size); |
| 208 | |
| 209 | if (status == EFI_SECURITY_VIOLATION) { |
| 210 | printf("Capsule authentication check failed. Aborting update\n"); |
| 211 | return status; |
| 212 | } else if (status != EFI_SUCCESS) { |
| 213 | return status; |
| 214 | } |
| 215 | |
| 216 | debug("Capsule authentication successful\n"); |
| 217 | image = capsule_payload; |
| 218 | image_size = capsule_payload_size; |
| 219 | } else { |
| 220 | debug("Capsule authentication disabled. "); |
| 221 | debug("Updating capsule without authenticating.\n"); |
| 222 | } |
| 223 | |
| 224 | fmp_hdr_signature = FMP_PAYLOAD_HDR_SIGNATURE; |
| 225 | header = (void *)image; |
| 226 | |
| 227 | if (!memcmp(&header->signature, &fmp_hdr_signature, |
| 228 | sizeof(fmp_hdr_signature))) { |
| 229 | /* |
| 230 | * When building the capsule with the scripts in |
| 231 | * edk2, a FMP header is inserted above the capsule |
| 232 | * payload. Compensate for this header to get the |
| 233 | * actual payload that is to be updated. |
| 234 | */ |
| 235 | image += header->header_size; |
| 236 | image_size -= header->header_size; |
| 237 | } |
| 238 | |
| 239 | *p_image = image; |
| 240 | *p_image_size = image_size; |
| 241 | return EFI_SUCCESS; |
| 242 | } |
| 243 | |
AKASHI Takahiro | f4818e6 | 2020-11-30 18:12:12 +0900 | [diff] [blame] | 244 | /** |
Sughosh Ganu | 4ed7261 | 2022-06-01 23:30:41 +0530 | [diff] [blame] | 245 | * efi_firmware_get_image_info - return information about the current |
AKASHI Takahiro | f4818e6 | 2020-11-30 18:12:12 +0900 | [diff] [blame] | 246 | * firmware image |
| 247 | * @this: Protocol instance |
| 248 | * @image_info_size: Size of @image_info |
| 249 | * @image_info: Image information |
| 250 | * @descriptor_version: Pointer to version number |
| 251 | * @descriptor_count: Pointer to number of descriptors |
| 252 | * @descriptor_size: Pointer to descriptor size |
Vincent Stehlé | 0f3c922 | 2022-05-25 11:20:22 +0200 | [diff] [blame] | 253 | * @package_version: Package version |
| 254 | * @package_version_name: Package version's name |
AKASHI Takahiro | f4818e6 | 2020-11-30 18:12:12 +0900 | [diff] [blame] | 255 | * |
| 256 | * Return information bout the current firmware image in @image_info. |
| 257 | * @image_info will consist of a number of descriptors. |
| 258 | * Each descriptor will be created based on "dfu_alt_info" variable. |
| 259 | * |
| 260 | * Return status code |
| 261 | */ |
| 262 | static |
Sughosh Ganu | 4ed7261 | 2022-06-01 23:30:41 +0530 | [diff] [blame] | 263 | efi_status_t EFIAPI efi_firmware_get_image_info( |
AKASHI Takahiro | f4818e6 | 2020-11-30 18:12:12 +0900 | [diff] [blame] | 264 | struct efi_firmware_management_protocol *this, |
| 265 | efi_uintn_t *image_info_size, |
| 266 | struct efi_firmware_image_descriptor *image_info, |
| 267 | u32 *descriptor_version, |
| 268 | u8 *descriptor_count, |
| 269 | efi_uintn_t *descriptor_size, |
| 270 | u32 *package_version, |
| 271 | u16 **package_version_name) |
| 272 | { |
| 273 | efi_status_t ret; |
| 274 | |
| 275 | EFI_ENTRY("%p %p %p %p %p %p %p %p\n", this, |
| 276 | image_info_size, image_info, |
| 277 | descriptor_version, descriptor_count, descriptor_size, |
| 278 | package_version, package_version_name); |
| 279 | |
| 280 | if (!image_info_size) |
| 281 | return EFI_EXIT(EFI_INVALID_PARAMETER); |
| 282 | |
| 283 | if (*image_info_size && |
| 284 | (!image_info || !descriptor_version || !descriptor_count || |
| 285 | !descriptor_size || !package_version || !package_version_name)) |
| 286 | return EFI_EXIT(EFI_INVALID_PARAMETER); |
| 287 | |
Sughosh Ganu | 2a9fd7d | 2022-04-15 11:29:35 +0530 | [diff] [blame] | 288 | ret = efi_fill_image_desc_array(image_info_size, image_info, |
| 289 | descriptor_version, descriptor_count, |
| 290 | descriptor_size, package_version, |
| 291 | package_version_name); |
AKASHI Takahiro | f4818e6 | 2020-11-30 18:12:12 +0900 | [diff] [blame] | 292 | |
| 293 | return EFI_EXIT(ret); |
| 294 | } |
| 295 | |
Sughosh Ganu | 4ed7261 | 2022-06-01 23:30:41 +0530 | [diff] [blame] | 296 | #ifdef CONFIG_EFI_CAPSULE_FIRMWARE_FIT |
| 297 | /* |
| 298 | * This FIRMWARE_MANAGEMENT_PROTOCOL driver provides a firmware update |
| 299 | * method with existing FIT image format, and handles |
| 300 | * - multiple regions of firmware via DFU |
| 301 | * but doesn't support |
| 302 | * - versioning of firmware image |
| 303 | * - package information |
| 304 | */ |
| 305 | |
AKASHI Takahiro | f4818e6 | 2020-11-30 18:12:12 +0900 | [diff] [blame] | 306 | /** |
| 307 | * efi_firmware_fit_set_image - update the firmware image |
| 308 | * @this: Protocol instance |
| 309 | * @image_index: Image index number |
| 310 | * @image: New image |
| 311 | * @image_size: Size of new image |
| 312 | * @vendor_code: Vendor-specific update policy |
| 313 | * @progress: Function to report the progress of update |
| 314 | * @abort_reason: Pointer to string of abort reason |
| 315 | * |
| 316 | * Update the firmware to new image, using dfu. The new image should |
| 317 | * have FIT image format commonly used in U-Boot. |
| 318 | * @vendor_code, @progress and @abort_reason are not supported. |
| 319 | * |
| 320 | * Return: status code |
| 321 | */ |
| 322 | static |
| 323 | efi_status_t EFIAPI efi_firmware_fit_set_image( |
| 324 | struct efi_firmware_management_protocol *this, |
| 325 | u8 image_index, |
| 326 | const void *image, |
| 327 | efi_uintn_t image_size, |
| 328 | const void *vendor_code, |
| 329 | efi_status_t (*progress)(efi_uintn_t completion), |
| 330 | u16 **abort_reason) |
| 331 | { |
Vincent Stehlé | 6a4625e | 2022-05-31 09:55:34 +0200 | [diff] [blame] | 332 | efi_status_t status; |
| 333 | |
Heinrich Schuchardt | 94f09e0 | 2022-02-03 20:13:17 +0100 | [diff] [blame] | 334 | EFI_ENTRY("%p %d %p %zu %p %p %p\n", this, image_index, image, |
AKASHI Takahiro | f4818e6 | 2020-11-30 18:12:12 +0900 | [diff] [blame] | 335 | image_size, vendor_code, progress, abort_reason); |
| 336 | |
| 337 | if (!image || image_index != 1) |
| 338 | return EFI_EXIT(EFI_INVALID_PARAMETER); |
| 339 | |
Vincent Stehlé | 6a4625e | 2022-05-31 09:55:34 +0200 | [diff] [blame] | 340 | status = efi_firmware_capsule_authenticate(&image, &image_size); |
| 341 | if (status != EFI_SUCCESS) |
| 342 | return EFI_EXIT(status); |
| 343 | |
AKASHI Takahiro | f4818e6 | 2020-11-30 18:12:12 +0900 | [diff] [blame] | 344 | if (fit_update(image)) |
| 345 | return EFI_EXIT(EFI_DEVICE_ERROR); |
| 346 | |
| 347 | return EFI_EXIT(EFI_SUCCESS); |
| 348 | } |
| 349 | |
AKASHI Takahiro | 7ff3f3c | 2020-11-17 09:28:00 +0900 | [diff] [blame] | 350 | const struct efi_firmware_management_protocol efi_fmp_fit = { |
Sughosh Ganu | 4ed7261 | 2022-06-01 23:30:41 +0530 | [diff] [blame] | 351 | .get_image_info = efi_firmware_get_image_info, |
AKASHI Takahiro | 7ff3f3c | 2020-11-17 09:28:00 +0900 | [diff] [blame] | 352 | .get_image = efi_firmware_get_image_unsupported, |
| 353 | .set_image = efi_firmware_fit_set_image, |
| 354 | .check_image = efi_firmware_check_image_unsupported, |
| 355 | .get_package_info = efi_firmware_get_package_info_unsupported, |
| 356 | .set_package_info = efi_firmware_set_package_info_unsupported, |
| 357 | }; |
| 358 | #endif /* CONFIG_EFI_CAPSULE_FIRMWARE_FIT */ |
AKASHI Takahiro | f4818e6 | 2020-11-30 18:12:12 +0900 | [diff] [blame] | 359 | |
AKASHI Takahiro | 7ff3f3c | 2020-11-17 09:28:00 +0900 | [diff] [blame] | 360 | #ifdef CONFIG_EFI_CAPSULE_FIRMWARE_RAW |
| 361 | /* |
| 362 | * This FIRMWARE_MANAGEMENT_PROTOCOL driver provides a firmware update |
| 363 | * method with raw data. |
| 364 | */ |
AKASHI Takahiro | f4818e6 | 2020-11-30 18:12:12 +0900 | [diff] [blame] | 365 | |
AKASHI Takahiro | 7ff3f3c | 2020-11-17 09:28:00 +0900 | [diff] [blame] | 366 | /** |
AKASHI Takahiro | 7ff3f3c | 2020-11-17 09:28:00 +0900 | [diff] [blame] | 367 | * efi_firmware_raw_set_image - update the firmware image |
| 368 | * @this: Protocol instance |
| 369 | * @image_index: Image index number |
| 370 | * @image: New image |
| 371 | * @image_size: Size of new image |
| 372 | * @vendor_code: Vendor-specific update policy |
| 373 | * @progress: Function to report the progress of update |
| 374 | * @abort_reason: Pointer to string of abort reason |
| 375 | * |
| 376 | * Update the firmware to new image, using dfu. The new image should |
| 377 | * be a single raw image. |
| 378 | * @vendor_code, @progress and @abort_reason are not supported. |
| 379 | * |
| 380 | * Return: status code |
| 381 | */ |
AKASHI Takahiro | f4818e6 | 2020-11-30 18:12:12 +0900 | [diff] [blame] | 382 | static |
AKASHI Takahiro | 7ff3f3c | 2020-11-17 09:28:00 +0900 | [diff] [blame] | 383 | efi_status_t EFIAPI efi_firmware_raw_set_image( |
AKASHI Takahiro | f4818e6 | 2020-11-30 18:12:12 +0900 | [diff] [blame] | 384 | struct efi_firmware_management_protocol *this, |
AKASHI Takahiro | 7ff3f3c | 2020-11-17 09:28:00 +0900 | [diff] [blame] | 385 | u8 image_index, |
AKASHI Takahiro | f4818e6 | 2020-11-30 18:12:12 +0900 | [diff] [blame] | 386 | const void *image, |
AKASHI Takahiro | 7ff3f3c | 2020-11-17 09:28:00 +0900 | [diff] [blame] | 387 | efi_uintn_t image_size, |
AKASHI Takahiro | f4818e6 | 2020-11-30 18:12:12 +0900 | [diff] [blame] | 388 | const void *vendor_code, |
AKASHI Takahiro | 7ff3f3c | 2020-11-17 09:28:00 +0900 | [diff] [blame] | 389 | efi_status_t (*progress)(efi_uintn_t completion), |
| 390 | u16 **abort_reason) |
AKASHI Takahiro | f4818e6 | 2020-11-30 18:12:12 +0900 | [diff] [blame] | 391 | { |
Sughosh Ganu | c9a821b | 2020-12-30 19:27:10 +0530 | [diff] [blame] | 392 | efi_status_t status; |
Sughosh Ganu | 7221c6e | 2020-12-30 19:27:05 +0530 | [diff] [blame] | 393 | |
Heinrich Schuchardt | 94f09e0 | 2022-02-03 20:13:17 +0100 | [diff] [blame] | 394 | EFI_ENTRY("%p %d %p %zu %p %p %p\n", this, image_index, image, |
AKASHI Takahiro | 7ff3f3c | 2020-11-17 09:28:00 +0900 | [diff] [blame] | 395 | image_size, vendor_code, progress, abort_reason); |
AKASHI Takahiro | f4818e6 | 2020-11-30 18:12:12 +0900 | [diff] [blame] | 396 | |
AKASHI Takahiro | 7ff3f3c | 2020-11-17 09:28:00 +0900 | [diff] [blame] | 397 | if (!image) |
| 398 | return EFI_EXIT(EFI_INVALID_PARAMETER); |
| 399 | |
Vincent Stehlé | 6a4625e | 2022-05-31 09:55:34 +0200 | [diff] [blame] | 400 | status = efi_firmware_capsule_authenticate(&image, &image_size); |
| 401 | if (status != EFI_SUCCESS) |
| 402 | return EFI_EXIT(status); |
Sughosh Ganu | 7221c6e | 2020-12-30 19:27:05 +0530 | [diff] [blame] | 403 | |
AKASHI Takahiro | 7ff3f3c | 2020-11-17 09:28:00 +0900 | [diff] [blame] | 404 | if (dfu_write_by_alt(image_index - 1, (void *)image, image_size, |
| 405 | NULL, NULL)) |
| 406 | return EFI_EXIT(EFI_DEVICE_ERROR); |
| 407 | |
| 408 | return EFI_EXIT(EFI_SUCCESS); |
AKASHI Takahiro | f4818e6 | 2020-11-30 18:12:12 +0900 | [diff] [blame] | 409 | } |
| 410 | |
AKASHI Takahiro | 7ff3f3c | 2020-11-17 09:28:00 +0900 | [diff] [blame] | 411 | const struct efi_firmware_management_protocol efi_fmp_raw = { |
Sughosh Ganu | 4ed7261 | 2022-06-01 23:30:41 +0530 | [diff] [blame] | 412 | .get_image_info = efi_firmware_get_image_info, |
AKASHI Takahiro | f4818e6 | 2020-11-30 18:12:12 +0900 | [diff] [blame] | 413 | .get_image = efi_firmware_get_image_unsupported, |
AKASHI Takahiro | 7ff3f3c | 2020-11-17 09:28:00 +0900 | [diff] [blame] | 414 | .set_image = efi_firmware_raw_set_image, |
AKASHI Takahiro | f4818e6 | 2020-11-30 18:12:12 +0900 | [diff] [blame] | 415 | .check_image = efi_firmware_check_image_unsupported, |
| 416 | .get_package_info = efi_firmware_get_package_info_unsupported, |
| 417 | .set_package_info = efi_firmware_set_package_info_unsupported, |
| 418 | }; |
AKASHI Takahiro | 7ff3f3c | 2020-11-17 09:28:00 +0900 | [diff] [blame] | 419 | #endif /* CONFIG_EFI_CAPSULE_FIRMWARE_RAW */ |