Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame^] | 1 | From 9d70628b7dc1dbc3c1ac7f4f3c0f6aa6b237510d Mon Sep 17 00:00:00 2001 |
| 2 | From: Satish Kumar <satish.kumar01@arm.com> |
| 3 | Date: Wed, 6 Jul 2022 11:19:39 +0100 |
| 4 | Subject: [PATCH 5/6] corstone1000: support for UEFI FMP image Information |
| 5 | |
| 6 | The commit provides the support for UEFI FMP (Firmware Management |
| 7 | Protocol) SET and GET Image info APIs. |
| 8 | |
| 9 | The APIs to SET and GET image info is implemented. In current design, |
| 10 | SET is called by secure encalve and GET is called by the host. |
| 11 | |
| 12 | FMP image information is initialized on every boot and retained |
| 13 | in SRAM. The updatable values of the FMP are stored in private |
| 14 | metadata section of the flash. |
| 15 | |
| 16 | Change-Id: Iaf0b4a13a9c24f05e4a32509e61a8b96ee8e9e4b |
| 17 | Signed-off-by: Satish Kumar <satish.kumar01@arm.com> |
| 18 | Upstream-Status: Accepted [TF-Mv1.7.0] |
| 19 | --- |
| 20 | .../target/arm/corstone1000/CMakeLists.txt | 2 + |
| 21 | .../ext/target/arm/corstone1000/config.cmake | 8 +- |
| 22 | .../corstone1000/fw_update_agent/fwu_agent.c | 61 ++++- |
| 23 | .../corstone1000/fw_update_agent/fwu_agent.h | 3 + |
| 24 | .../corstone1000/fw_update_agent/uefi_fmp.c | 240 ++++++++++++++++++ |
| 25 | .../corstone1000/fw_update_agent/uefi_fmp.h | 56 ++++ |
| 26 | .../include/corstone1000_ioctl_requests.h | 14 +- |
| 27 | .../services/src/tfm_platform_system.c | 9 + |
| 28 | 8 files changed, 374 insertions(+), 19 deletions(-) |
| 29 | create mode 100644 platform/ext/target/arm/corstone1000/fw_update_agent/uefi_fmp.c |
| 30 | create mode 100644 platform/ext/target/arm/corstone1000/fw_update_agent/uefi_fmp.h |
| 31 | |
| 32 | diff --git a/platform/ext/target/arm/corstone1000/CMakeLists.txt b/platform/ext/target/arm/corstone1000/CMakeLists.txt |
| 33 | index 81522c7cf0..3602312a3a 100644 |
| 34 | --- a/platform/ext/target/arm/corstone1000/CMakeLists.txt |
| 35 | +++ b/platform/ext/target/arm/corstone1000/CMakeLists.txt |
| 36 | @@ -76,6 +76,8 @@ target_sources(platform_s |
| 37 | fw_update_agent/uefi_capsule_parser.c |
| 38 | fw_update_agent/fwu_agent.c |
| 39 | $<$<BOOL:${TFM_S_REG_TEST}>:${CMAKE_CURRENT_SOURCE_DIR}/target_cfg.c> |
| 40 | + fw_update_agent/uefi_fmp.c |
| 41 | + $<$<NOT:$<BOOL:${PLATFORM_DEFAULT_OTP}>>:${PLATFORM_DIR}/ext/accelerator/cc312/otp_cc312.c> |
| 42 | ) |
| 43 | |
| 44 | if (PLATFORM_IS_FVP) |
| 45 | diff --git a/platform/ext/target/arm/corstone1000/config.cmake b/platform/ext/target/arm/corstone1000/config.cmake |
| 46 | index a6a1a33c42..ab0fe17ba8 100644 |
| 47 | --- a/platform/ext/target/arm/corstone1000/config.cmake |
| 48 | +++ b/platform/ext/target/arm/corstone1000/config.cmake |
| 49 | @@ -50,7 +50,9 @@ else() |
| 50 | set(PLATFORM_PSA_ADAC_SECURE_DEBUG FALSE CACHE BOOL "Whether to use psa-adac secure debug.") |
| 51 | endif() |
| 52 | |
| 53 | -set(DEFAULT_MCUBOOT_SECURITY_COUNTERS OFF CACHE BOOL "Whether to use the default security counter configuration defined by TF-M project") |
| 54 | +set(DEFAULT_MCUBOOT_SECURITY_COUNTERS OFF CACHE BOOL "Whether to use the default security counter configuration defined by TF-M project") |
| 55 | |
| 56 | -set(PS_ENCRYPTION OFF CACHE BOOL "Enable encryption for Protected Storage partition") |
| 57 | -set(PS_ROLLBACK_PROTECTION OFF CACHE BOOL "Enable rollback protection for Protected Storage partition") |
| 58 | +set(PS_ENCRYPTION OFF CACHE BOOL "Enable encryption for Protected Storage partition") |
| 59 | +set(PS_ROLLBACK_PROTECTION OFF CACHE BOOL "Enable rollback protection for Protected Storage partition") |
| 60 | + |
| 61 | +set(PLATFORM_SERVICE_OUTPUT_BUFFER_SIZE 256 CACHE STRING "Size of output buffer in platform service.") |
| 62 | diff --git a/platform/ext/target/arm/corstone1000/fw_update_agent/fwu_agent.c b/platform/ext/target/arm/corstone1000/fw_update_agent/fwu_agent.c |
| 63 | index 3abb5dd0dc..72a5fc9c1d 100644 |
| 64 | --- a/platform/ext/target/arm/corstone1000/fw_update_agent/fwu_agent.c |
| 65 | +++ b/platform/ext/target/arm/corstone1000/fw_update_agent/fwu_agent.c |
| 66 | @@ -18,6 +18,7 @@ |
| 67 | #include "platform_description.h" |
| 68 | #include "tfm_plat_nv_counters.h" |
| 69 | #include "tfm_plat_defs.h" |
| 70 | +#include "uefi_fmp.h" |
| 71 | |
| 72 | /* Properties of image in a bank */ |
| 73 | struct fwu_image_properties { |
| 74 | @@ -84,6 +85,11 @@ struct fwu_private_metadata { |
| 75 | /* staged nv_counter: temprary location before written to the otp */ |
| 76 | uint32_t nv_counter[NR_OF_IMAGES_IN_FW_BANK]; |
| 77 | |
| 78 | + /* FMP information */ |
| 79 | + uint32_t fmp_version; |
| 80 | + uint32_t fmp_last_attempt_version; |
| 81 | + uint32_t fmp_last_attempt_status; |
| 82 | + |
| 83 | } __packed; |
| 84 | |
| 85 | #define MAX_BOOT_ATTEMPTS_PER_BANK 3 |
| 86 | @@ -278,7 +284,7 @@ enum fwu_agent_error_t fwu_metadata_provision(void) |
| 87 | { |
| 88 | enum fwu_agent_error_t ret; |
| 89 | struct fwu_private_metadata priv_metadata; |
| 90 | - uint32_t image_version = 0; |
| 91 | + uint32_t image_version = FWU_IMAGE_INITIAL_VERSION; |
| 92 | |
| 93 | FWU_LOG_MSG("%s: enter\n\r", __func__); |
| 94 | |
| 95 | @@ -302,8 +308,8 @@ enum fwu_agent_error_t fwu_metadata_provision(void) |
| 96 | memset(&_metadata, 0, sizeof(struct fwu_metadata)); |
| 97 | |
| 98 | _metadata.version = 1; |
| 99 | - _metadata.active_index = 0; |
| 100 | - _metadata.previous_active_index = 1; |
| 101 | + _metadata.active_index = BANK_0; |
| 102 | + _metadata.previous_active_index = BANK_1; |
| 103 | |
| 104 | /* bank 0 is the place where images are located at the |
| 105 | * start of device lifecycle */ |
| 106 | @@ -339,6 +345,10 @@ enum fwu_agent_error_t fwu_metadata_provision(void) |
| 107 | priv_metadata.boot_index = BANK_0; |
| 108 | priv_metadata.boot_attempted = 0; |
| 109 | |
| 110 | + priv_metadata.fmp_version = FWU_IMAGE_INITIAL_VERSION; |
| 111 | + priv_metadata.fmp_last_attempt_version = FWU_IMAGE_INITIAL_VERSION; |
| 112 | + priv_metadata.fmp_last_attempt_status = LAST_ATTEMPT_STATUS_SUCCESS; |
| 113 | + |
| 114 | ret = private_metadata_write(&priv_metadata); |
| 115 | if (ret) { |
| 116 | return ret; |
| 117 | @@ -540,9 +550,25 @@ enum fwu_agent_error_t corstone1000_fwu_flash_image(void) |
| 118 | &image_bank_offset); |
| 119 | switch(image_index) { |
| 120 | case IMAGE_ALL: |
| 121 | + |
| 122 | ret = flash_full_capsule(&_metadata, capsule_info.image[i], |
| 123 | capsule_info.size[i], |
| 124 | capsule_info.version[i]); |
| 125 | + |
| 126 | + if (ret != FWU_AGENT_SUCCESS) { |
| 127 | + |
| 128 | + priv_metadata.fmp_last_attempt_version = capsule_info.version[i]; |
| 129 | + priv_metadata.fmp_last_attempt_status = LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL; |
| 130 | + |
| 131 | + private_metadata_write(&priv_metadata); |
| 132 | + |
| 133 | + fmp_set_image_info(&full_capsule_image_guid, |
| 134 | + priv_metadata.fmp_version, |
| 135 | + priv_metadata.fmp_last_attempt_version, |
| 136 | + priv_metadata.fmp_last_attempt_status); |
| 137 | + } |
| 138 | + |
| 139 | + |
| 140 | break; |
| 141 | default: |
| 142 | FWU_LOG_MSG("%s: sent image not recognized\n\r", __func__); |
| 143 | @@ -866,17 +892,42 @@ enum fwu_agent_error_t corstone1000_fwu_host_ack(void) |
| 144 | |
| 145 | current_state = get_fwu_agent_state(&_metadata, &priv_metadata); |
| 146 | if (current_state == FWU_AGENT_STATE_REGULAR) { |
| 147 | + |
| 148 | ret = FWU_AGENT_SUCCESS; /* nothing to be done */ |
| 149 | + |
| 150 | + fmp_set_image_info(&full_capsule_image_guid, |
| 151 | + priv_metadata.fmp_version, |
| 152 | + priv_metadata.fmp_last_attempt_version, |
| 153 | + priv_metadata.fmp_last_attempt_status); |
| 154 | + |
| 155 | goto out; |
| 156 | + |
| 157 | } else if (current_state != FWU_AGENT_STATE_TRIAL) { |
| 158 | FWU_ASSERT(0); |
| 159 | } |
| 160 | |
| 161 | if (_metadata.active_index != priv_metadata.boot_index) { |
| 162 | + |
| 163 | /* firmware update failed, revert back to previous bank */ |
| 164 | + |
| 165 | + priv_metadata.fmp_last_attempt_version = |
| 166 | + _metadata.img_entry[IMAGE_0].img_props[_metadata.active_index].version; |
| 167 | + |
| 168 | + priv_metadata.fmp_last_attempt_status = LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL; |
| 169 | + |
| 170 | ret = fwu_select_previous(&_metadata, &priv_metadata); |
| 171 | + |
| 172 | } else { |
| 173 | + |
| 174 | /* firmware update successful */ |
| 175 | + |
| 176 | + priv_metadata.fmp_version = |
| 177 | + _metadata.img_entry[IMAGE_0].img_props[_metadata.active_index].version; |
| 178 | + priv_metadata.fmp_last_attempt_version = |
| 179 | + _metadata.img_entry[IMAGE_0].img_props[_metadata.active_index].version; |
| 180 | + |
| 181 | + priv_metadata.fmp_last_attempt_status = LAST_ATTEMPT_STATUS_SUCCESS; |
| 182 | + |
| 183 | ret = fwu_accept_image(&full_capsule_image_guid, &_metadata, |
| 184 | &priv_metadata); |
| 185 | if (!ret) { |
| 186 | @@ -886,6 +937,10 @@ enum fwu_agent_error_t corstone1000_fwu_host_ack(void) |
| 187 | |
| 188 | if (ret == FWU_AGENT_SUCCESS) { |
| 189 | disable_host_ack_timer(); |
| 190 | + fmp_set_image_info(&full_capsule_image_guid, |
| 191 | + priv_metadata.fmp_version, |
| 192 | + priv_metadata.fmp_last_attempt_version, |
| 193 | + priv_metadata.fmp_last_attempt_status); |
| 194 | } |
| 195 | |
| 196 | out: |
| 197 | diff --git a/platform/ext/target/arm/corstone1000/fw_update_agent/fwu_agent.h b/platform/ext/target/arm/corstone1000/fw_update_agent/fwu_agent.h |
| 198 | index 57b07e8d2c..aa18179024 100644 |
| 199 | --- a/platform/ext/target/arm/corstone1000/fw_update_agent/fwu_agent.h |
| 200 | +++ b/platform/ext/target/arm/corstone1000/fw_update_agent/fwu_agent.h |
| 201 | @@ -30,6 +30,9 @@ enum fwu_agent_error_t { |
| 202 | } \ |
| 203 | |
| 204 | |
| 205 | +/* Version used for the very first image of the device. */ |
| 206 | +#define FWU_IMAGE_INITIAL_VERSION 0 |
| 207 | + |
| 208 | enum fwu_agent_error_t fwu_metadata_provision(void); |
| 209 | enum fwu_agent_error_t fwu_metadata_init(void); |
| 210 | |
| 211 | diff --git a/platform/ext/target/arm/corstone1000/fw_update_agent/uefi_fmp.c b/platform/ext/target/arm/corstone1000/fw_update_agent/uefi_fmp.c |
| 212 | new file mode 100644 |
| 213 | index 0000000000..ce576e1794 |
| 214 | --- /dev/null |
| 215 | +++ b/platform/ext/target/arm/corstone1000/fw_update_agent/uefi_fmp.c |
| 216 | @@ -0,0 +1,240 @@ |
| 217 | +/* |
| 218 | + * Copyright (c) 2022, Arm Limited. All rights reserved. |
| 219 | + * |
| 220 | + * SPDX-License-Identifier: BSD-3-Clause |
| 221 | + * |
| 222 | + */ |
| 223 | + |
| 224 | +#include <string.h> |
| 225 | +#include <stdbool.h> |
| 226 | +#include "cmsis.h" |
| 227 | +#include "uefi_fmp.h" |
| 228 | + |
| 229 | +/* The count will increase when partial update is supported. |
| 230 | + * At present, only full WIC is considered as updatable image. |
| 231 | + */ |
| 232 | +#define NUMBER_OF_FMP_IMAGES 1 |
| 233 | +#define NO_OF_FMP_VARIABLES_PER_IMAGE 6 |
| 234 | + |
| 235 | +#define UEFI_ARCHITECTURE_64 |
| 236 | + |
| 237 | +#ifdef UEFI_ARCHITECTURE_64 |
| 238 | +typedef uint64_t uefi_ptr_t; |
| 239 | +typedef uint64_t efi_uintn_t; |
| 240 | +#else |
| 241 | +typedef uint32_t uefi_ptr_t; |
| 242 | +typedef uint32_t efi_uintn_t; |
| 243 | +#endif |
| 244 | + |
| 245 | +/* Below macro definations and struct declarations taken from UEFI spec 2.9 */ |
| 246 | + |
| 247 | +/* |
| 248 | + * Image Attribute Definitions |
| 249 | + */ |
| 250 | +#define IMAGE_ATTRIBUTE_IMAGE_UPDATABLE 0x00000001 |
| 251 | +#define IMAGE_ATTRIBUTE_RESET_REQUIRED 0x00000002 |
| 252 | +#define IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED 0x00000004 |
| 253 | +#define IMAGE_ATTRIBUTE_IN_USE 0x00000008 |
| 254 | +#define IMAGE_ATTRIBUTE_UEFI_IMAGE 0x00000010 |
| 255 | +#define IMAGE_ATTRIBUTE_DEPENDENCY 0x00000020 |
| 256 | + |
| 257 | +typedef uint32_t DescriptorVersion_t; |
| 258 | +typedef uint32_t DescriptorSize_t; |
| 259 | +typedef uint8_t DescriptorCount_t; |
| 260 | + |
| 261 | +typedef __PACKED_STRUCT { |
| 262 | + uint8_t ImageIndex; |
| 263 | + struct efi_guid ImageTypeId; |
| 264 | + uint64_t ImageId; |
| 265 | + uefi_ptr_t PtrImageIdName; |
| 266 | + uint32_t Version; |
| 267 | + uefi_ptr_t PtrVersionName; |
| 268 | + efi_uintn_t Size; |
| 269 | + uint64_t AttributesSupported; |
| 270 | + uint64_t AttributesSetting; |
| 271 | + uint64_t Compatibilities; |
| 272 | + /* Introduced with DescriptorVersion 2+ */ |
| 273 | + uint32_t LowestSupportedImageVersion; |
| 274 | + /* Introduced with DescriptorVersion 3+ */ |
| 275 | + uint32_t LastAttemptVersion; |
| 276 | + uint32_t LastAttemptStatus; |
| 277 | + uint64_t HardwareInstance; |
| 278 | + /* Introduced with DescriptorVersion 4+ */ |
| 279 | + uefi_ptr_t PtrDependencies; |
| 280 | +} EFI_FIRMWARE_IMAGE_DESCRIPTOR; |
| 281 | + |
| 282 | +typedef __PACKED_STRUCT { |
| 283 | + DescriptorVersion_t DescriptorVersion; |
| 284 | + DescriptorSize_t DescriptorsSize; |
| 285 | + DescriptorCount_t DescriptorCount; |
| 286 | + EFI_FIRMWARE_IMAGE_DESCRIPTOR ImageDescriptor; |
| 287 | + uint16_t *ImageName; |
| 288 | + uint32_t ImageNameSize; |
| 289 | + uint16_t *ImageVersionName; |
| 290 | + uint32_t ImageVersionNameSize; |
| 291 | +} EFI_FIRMWARE_MANAGEMENT_PROTOCOL_IMAGE_INFO; |
| 292 | + |
| 293 | + |
| 294 | +static uint16_t corstone_image_name0[] = { 'C', 'O', 'R', 'S', 'T', 'O', 'N', 'E', '1', '0', '0', '0', '_', 'W', 'I', 'C', '\0' }; |
| 295 | +static uint16_t corstone_version_name0[] = { 'C', 'O', 'R', 'S', 'T', 'O', 'N', 'E', '1', '0', '0', '0', '_', 'B', 'E', 'S', 'T', '\0'}; |
| 296 | + |
| 297 | +static EFI_FIRMWARE_MANAGEMENT_PROTOCOL_IMAGE_INFO fmp_info[NUMBER_OF_FMP_IMAGES]; |
| 298 | + |
| 299 | +extern struct efi_guid full_capsule_image_guid; |
| 300 | + |
| 301 | +static bool is_fmp_info_initialized = false; |
| 302 | + |
| 303 | +static void init_fmp_info(void) |
| 304 | +{ |
| 305 | + memset(fmp_info, 0, |
| 306 | + sizeof(EFI_FIRMWARE_MANAGEMENT_PROTOCOL_IMAGE_INFO) * NUMBER_OF_FMP_IMAGES); |
| 307 | + |
| 308 | + /* Fill information for the WIC. |
| 309 | + * Add further details when partial image is supported. |
| 310 | + */ |
| 311 | + |
| 312 | + fmp_info[0].DescriptorVersion = 4; |
| 313 | + fmp_info[0].DescriptorCount = NUMBER_OF_FMP_IMAGES; |
| 314 | + fmp_info[0].DescriptorsSize = |
| 315 | + sizeof(EFI_FIRMWARE_IMAGE_DESCRIPTOR) + |
| 316 | + sizeof(corstone_image_name0) + sizeof(corstone_version_name0); |
| 317 | + |
| 318 | + fmp_info[0].ImageDescriptor.ImageIndex = 1; |
| 319 | + |
| 320 | + memcpy(&fmp_info[0].ImageDescriptor.ImageTypeId, &full_capsule_image_guid, |
| 321 | + sizeof(struct efi_guid)); |
| 322 | + |
| 323 | + fmp_info[0].ImageDescriptor.ImageId = 1; |
| 324 | + fmp_info[0].ImageDescriptor.Version = FWU_IMAGE_INITIAL_VERSION; |
| 325 | + fmp_info[0].ImageDescriptor.AttributesSupported = 1; |
| 326 | + fmp_info[0].ImageDescriptor.AttributesSetting = ( |
| 327 | + IMAGE_ATTRIBUTE_IMAGE_UPDATABLE | IMAGE_ATTRIBUTE_RESET_REQUIRED); |
| 328 | + fmp_info[0].ImageDescriptor.LowestSupportedImageVersion = |
| 329 | + FWU_IMAGE_INITIAL_VERSION; |
| 330 | + fmp_info[0].ImageDescriptor.LastAttemptVersion = FWU_IMAGE_INITIAL_VERSION; |
| 331 | + fmp_info[0].ImageDescriptor.LastAttemptStatus = LAST_ATTEMPT_STATUS_SUCCESS; |
| 332 | + |
| 333 | + fmp_info[0].ImageName = corstone_image_name0; |
| 334 | + fmp_info[0].ImageNameSize = sizeof(corstone_image_name0); |
| 335 | + fmp_info[0].ImageVersionName = corstone_version_name0; |
| 336 | + fmp_info[0].ImageVersionNameSize = sizeof(corstone_version_name0); |
| 337 | + |
| 338 | + is_fmp_info_initialized = true; |
| 339 | + |
| 340 | + return; |
| 341 | +} |
| 342 | + |
| 343 | +enum fwu_agent_error_t fmp_set_image_info(struct efi_guid *guid, |
| 344 | + uint32_t current_version, uint32_t attempt_version, |
| 345 | + uint32_t last_attempt_status) |
| 346 | +{ |
| 347 | + enum fwu_agent_error_t status = FWU_AGENT_ERROR; |
| 348 | + |
| 349 | + FWU_LOG_MSG("%s:%d Enter\n\r", __func__, __LINE__); |
| 350 | + |
| 351 | + if (is_fmp_info_initialized == false) { |
| 352 | + init_fmp_info(); |
| 353 | + } |
| 354 | + |
| 355 | + for (int i = 0; i < NUMBER_OF_FMP_IMAGES; i++) { |
| 356 | + if ((memcmp(guid, &fmp_info[i].ImageDescriptor.ImageTypeId, |
| 357 | + sizeof(struct efi_guid))) == 0) |
| 358 | + { |
| 359 | + FWU_LOG_MSG("FMP image update: image id = %u\n\r", |
| 360 | + fmp_info[i].ImageDescriptor.ImageId); |
| 361 | + fmp_info[i].ImageDescriptor.Version = current_version; |
| 362 | + fmp_info[i].ImageDescriptor.LastAttemptVersion = attempt_version; |
| 363 | + fmp_info[i].ImageDescriptor.LastAttemptStatus = last_attempt_status; |
| 364 | + FWU_LOG_MSG("FMP image update: status = %u" |
| 365 | + "version=%u last_attempt_version=%u.\n\r", |
| 366 | + last_attempt_status, current_version, |
| 367 | + attempt_version); |
| 368 | + status = FWU_AGENT_SUCCESS; |
| 369 | + break; |
| 370 | + } |
| 371 | + } |
| 372 | + |
| 373 | + FWU_LOG_MSG("%s:%d Exit.\n\r", __func__, __LINE__); |
| 374 | + return status; |
| 375 | +} |
| 376 | + |
| 377 | + |
| 378 | +#define NO_OF_FMP_VARIABLES (NUMBER_OF_FMP_IMAGES * NO_OF_FMP_VARIABLES_PER_IMAGE) |
| 379 | + |
| 380 | +static enum fwu_agent_error_t pack_image_info(void *buffer, uint32_t size) |
| 381 | +{ |
| 382 | + typedef __PACKED_STRUCT { |
| 383 | + uint32_t variable_count; |
| 384 | + uint32_t variable_size[NO_OF_FMP_VARIABLES]; |
| 385 | + uint8_t variable[]; |
| 386 | + } packed_buffer_t; |
| 387 | + |
| 388 | + packed_buffer_t *packed_buffer = buffer; |
| 389 | + int runner = 0; |
| 390 | + int index = 0; |
| 391 | + int current_size = sizeof(packed_buffer_t); |
| 392 | + int size_requirement_1 = 0; |
| 393 | + int size_requirement_2 = 0; |
| 394 | + |
| 395 | + if (size < current_size) { |
| 396 | + FWU_LOG_MSG("%s:%d Buffer too small.\n\r", __func__, __LINE__); |
| 397 | + return FWU_AGENT_ERROR; |
| 398 | + } |
| 399 | + |
| 400 | + packed_buffer->variable_count = NO_OF_FMP_VARIABLES; |
| 401 | + |
| 402 | + for (int i = 0; i < NUMBER_OF_FMP_IMAGES; i++) { |
| 403 | + |
| 404 | + packed_buffer->variable_size[index++] = sizeof(DescriptorVersion_t); |
| 405 | + packed_buffer->variable_size[index++] = sizeof(DescriptorSize_t); |
| 406 | + packed_buffer->variable_size[index++] = sizeof(DescriptorCount_t); |
| 407 | + packed_buffer->variable_size[index++] = sizeof(EFI_FIRMWARE_IMAGE_DESCRIPTOR); |
| 408 | + packed_buffer->variable_size[index++] = fmp_info[i].ImageNameSize; |
| 409 | + packed_buffer->variable_size[index++] = fmp_info[i].ImageVersionNameSize; |
| 410 | + |
| 411 | + size_requirement_1 = sizeof(DescriptorVersion_t) + sizeof(DescriptorSize_t) + |
| 412 | + sizeof(DescriptorCount_t) + sizeof(EFI_FIRMWARE_IMAGE_DESCRIPTOR); |
| 413 | + |
| 414 | + size_requirement_2 = fmp_info[i].ImageNameSize + fmp_info[i].ImageVersionNameSize; |
| 415 | + |
| 416 | + current_size += size_requirement_1 + size_requirement_2; |
| 417 | + |
| 418 | + if (size < current_size) { |
| 419 | + FWU_LOG_MSG("%s:%d Buffer too small.\n\r", __func__, __LINE__); |
| 420 | + return FWU_AGENT_ERROR; |
| 421 | + } |
| 422 | + |
| 423 | + FWU_LOG_MSG("%s:%d ImageInfo size = %u, ImageName size = %u, " |
| 424 | + "ImageVersionName size = %u\n\r", __func__, __LINE__, |
| 425 | + sizeof(EFI_FIRMWARE_IMAGE_DESCRIPTOR), fmp_info[i].ImageNameSize, |
| 426 | + fmp_info[i].ImageVersionNameSize); |
| 427 | + |
| 428 | + memcpy(&packed_buffer->variable[runner], &fmp_info[i], size_requirement_1); |
| 429 | + runner += size_requirement_1; |
| 430 | + |
| 431 | + memcpy(&packed_buffer->variable[runner], fmp_info[i].ImageName, |
| 432 | + fmp_info[i].ImageNameSize); |
| 433 | + runner += fmp_info[i].ImageNameSize; |
| 434 | + |
| 435 | + memcpy(&packed_buffer->variable[runner], fmp_info[i].ImageVersionName, |
| 436 | + fmp_info[i].ImageVersionNameSize); |
| 437 | + runner += fmp_info[i].ImageVersionNameSize; |
| 438 | + |
| 439 | + } |
| 440 | + |
| 441 | + return FWU_AGENT_SUCCESS; |
| 442 | +} |
| 443 | + |
| 444 | +enum fwu_agent_error_t fmp_get_image_info(void *buffer, uint32_t size) |
| 445 | +{ |
| 446 | + enum fwu_agent_error_t status; |
| 447 | + |
| 448 | + FWU_LOG_MSG("%s:%d Enter\n\r", __func__, __LINE__); |
| 449 | + |
| 450 | + status = pack_image_info(buffer, size); |
| 451 | + |
| 452 | + FWU_LOG_MSG("%s:%d Exit\n\r", __func__, __LINE__); |
| 453 | + |
| 454 | + return status; |
| 455 | +} |
| 456 | + |
| 457 | diff --git a/platform/ext/target/arm/corstone1000/fw_update_agent/uefi_fmp.h b/platform/ext/target/arm/corstone1000/fw_update_agent/uefi_fmp.h |
| 458 | new file mode 100644 |
| 459 | index 0000000000..d876bd7cff |
| 460 | --- /dev/null |
| 461 | +++ b/platform/ext/target/arm/corstone1000/fw_update_agent/uefi_fmp.h |
| 462 | @@ -0,0 +1,56 @@ |
| 463 | +/* |
| 464 | + * Copyright (c) 2022, Arm Limited. All rights reserved. |
| 465 | + * |
| 466 | + * SPDX-License-Identifier: BSD-3-Clause |
| 467 | + * |
| 468 | + */ |
| 469 | + |
| 470 | +#ifndef UEFI_FMP_H |
| 471 | +#define UEFI_FMP_H |
| 472 | + |
| 473 | + |
| 474 | +#include <stdint.h> |
| 475 | +#include "fwu_agent.h" |
| 476 | +#include "../fip_parser/external/uuid.h" |
| 477 | + |
| 478 | +/* |
| 479 | + * Last Attempt Status Value |
| 480 | + */ |
| 481 | + |
| 482 | +#define LAST_ATTEMPT_STATUS_SUCCESS 0x00000000 |
| 483 | +#define LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL 0x00000001 |
| 484 | +#define LAST_ATTEMPT_STATUS_ERROR_INSUFFICIENT_RESOURCES 0x00000002 |
| 485 | +#define LAST_ATTEMPT_STATUS_ERROR_INCORRECT_VERSION 0x00000003 |
| 486 | +#define LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT 0x00000004 |
| 487 | +#define LAST_ATTEMPT_STATUS_ERROR_AUTH_ERROR 0x00000005 |
| 488 | +#define LAST_ATTEMPT_STATUS_ERROR_PWR_EVT_AC 0x00000006 |
| 489 | +#define LAST_ATTEMPT_STATUS_ERROR_PWR_EVT_BATT 0x00000007 |
| 490 | +#define LAST_ATTEMPT_STATUS_ERROR_UNSATISFIED_DEPENDENCIES 0x00000008 |
| 491 | +/* The LastAttemptStatus values of 0x1000 - 0x4000 are reserved for vendor usage. */ |
| 492 | +#define LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL_VENDOR_RANGE_MIN 0x00001000 |
| 493 | +#define LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL_VENDOR_RANGE_MAX 0x00004000 |
| 494 | + |
| 495 | + |
| 496 | + |
| 497 | +/* |
| 498 | + * Updates FMP information for the image matched by guid. |
| 499 | + * |
| 500 | + * guid : guid of the image |
| 501 | + * current_version: current versions for the image |
| 502 | + * attempt_version: attempted versions for the image |
| 503 | + * |
| 504 | + */ |
| 505 | +enum fwu_agent_error_t fmp_set_image_info(struct efi_guid *guid, |
| 506 | + uint32_t current_version, uint32_t attempt_version, |
| 507 | + uint32_t last_attempt_status); |
| 508 | + |
| 509 | +/* |
| 510 | + * Return fmp image information for all the updable images. |
| 511 | + * |
| 512 | + * buffer : pointer to the out buffer |
| 513 | + * size : size of the buffer |
| 514 | + * |
| 515 | + */ |
| 516 | +enum fwu_agent_error_t fmp_get_image_info(void *buffer, uint32_t size); |
| 517 | + |
| 518 | +#endif /* UEFI_FMP_H */ |
| 519 | diff --git a/platform/ext/target/arm/corstone1000/services/include/corstone1000_ioctl_requests.h b/platform/ext/target/arm/corstone1000/services/include/corstone1000_ioctl_requests.h |
| 520 | index 8ac67346b6..c5f3537e9d 100644 |
| 521 | --- a/platform/ext/target/arm/corstone1000/services/include/corstone1000_ioctl_requests.h |
| 522 | +++ b/platform/ext/target/arm/corstone1000/services/include/corstone1000_ioctl_requests.h |
| 523 | @@ -14,19 +14,7 @@ |
| 524 | enum corstone1000_ioctl_id_t { |
| 525 | IOCTL_CORSTONE1000_FWU_FLASH_IMAGES = 0, |
| 526 | IOCTL_CORSTONE1000_FWU_HOST_ACK, |
| 527 | + IOCTL_CORSTONE1000_FMP_GET_IMAGE_INFO, |
| 528 | }; |
| 529 | |
| 530 | - |
| 531 | -typedef struct corstone1000_ioctl_in_params { |
| 532 | - |
| 533 | - uint32_t ioctl_id; |
| 534 | - |
| 535 | -} corstone1000_ioctl_in_params_t; |
| 536 | - |
| 537 | -typedef struct corstone1000_ioctl_out_params { |
| 538 | - |
| 539 | - int32_t result; |
| 540 | - |
| 541 | -} corstone1000_ioctl_out_params_t; |
| 542 | - |
| 543 | #endif /* CORSTONE1000_IOCTL_REQUESTS_H */ |
| 544 | diff --git a/platform/ext/target/arm/corstone1000/services/src/tfm_platform_system.c b/platform/ext/target/arm/corstone1000/services/src/tfm_platform_system.c |
| 545 | index 5b3f3e14a2..41305ed966 100644 |
| 546 | --- a/platform/ext/target/arm/corstone1000/services/src/tfm_platform_system.c |
| 547 | +++ b/platform/ext/target/arm/corstone1000/services/src/tfm_platform_system.c |
| 548 | @@ -9,6 +9,7 @@ |
| 549 | #include "platform_description.h" |
| 550 | #include "corstone1000_ioctl_requests.h" |
| 551 | #include "fwu_agent.h" |
| 552 | +#include "uefi_fmp.h" |
| 553 | |
| 554 | void tfm_platform_hal_system_reset(void) |
| 555 | { |
| 556 | @@ -36,6 +37,14 @@ enum tfm_platform_err_t tfm_platform_hal_ioctl(tfm_platform_ioctl_req_t request, |
| 557 | corstone1000_fwu_host_ack(); |
| 558 | break; |
| 559 | |
| 560 | + case IOCTL_CORSTONE1000_FMP_GET_IMAGE_INFO: |
| 561 | + if (out_vec == NULL) { |
| 562 | + ret = TFM_PLATFORM_ERR_INVALID_PARAM; |
| 563 | + break; |
| 564 | + } |
| 565 | + fmp_get_image_info(out_vec[0].base, out_vec[0].len); |
| 566 | + break; |
| 567 | + |
| 568 | default: |
| 569 | ret = TFM_PLATFORM_ERR_NOT_SUPPORTED; |
| 570 | break; |
| 571 | -- |
| 572 | 2.25.1 |
| 573 | |