Sherry Zhang | 07b4241 | 2021-01-07 14:19:41 +0800 | [diff] [blame] | 1 | /* |
Sherry Zhang | 73126e5 | 2022-02-15 14:27:49 +0800 | [diff] [blame] | 2 | * Copyright (c) 2021-2022, Arm Limited. All rights reserved. |
Sherry Zhang | 07b4241 | 2021-01-07 14:19:41 +0800 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
Sherry Zhang | 7146895 | 2022-10-19 14:09:05 +0800 | [diff] [blame] | 8 | /* PSA Firmware Update API v1.0 Beta */ |
| 9 | |
Sherry Zhang | 07b4241 | 2021-01-07 14:19:41 +0800 | [diff] [blame] | 10 | #ifndef PSA_UPDATE_H |
| 11 | #define PSA_UPDATE_H |
| 12 | |
| 13 | #include <stddef.h> |
| 14 | #include <stdint.h> |
| 15 | |
| 16 | #include "psa/error.h" |
Sherry Zhang | 7146895 | 2022-10-19 14:09:05 +0800 | [diff] [blame] | 17 | #ifdef FWU_DEVICE_CONFIG_FILE |
| 18 | #include FWU_DEVICE_CONFIG_FILE |
| 19 | #else |
Sherry Zhang | 73126e5 | 2022-02-15 14:27:49 +0800 | [diff] [blame] | 20 | #include "psa/fwu_config.h" |
Sherry Zhang | 7146895 | 2022-10-19 14:09:05 +0800 | [diff] [blame] | 21 | #endif |
Sherry Zhang | 07b4241 | 2021-01-07 14:19:41 +0800 | [diff] [blame] | 22 | #include "tfm_fwu_defs.h" |
| 23 | |
| 24 | #ifdef __cplusplus |
| 25 | extern "C" { |
| 26 | #endif |
| 27 | |
Sherry Zhang | 7146895 | 2022-10-19 14:09:05 +0800 | [diff] [blame] | 28 | /** |
| 29 | * @brief The major version of this implementation of the Firmware Update API. |
Sherry Zhang | 07b4241 | 2021-01-07 14:19:41 +0800 | [diff] [blame] | 30 | */ |
Sherry Zhang | 7146895 | 2022-10-19 14:09:05 +0800 | [diff] [blame] | 31 | #define PSA_FWU_API_VERSION_MAJOR 1 |
Sherry Zhang | 07b4241 | 2021-01-07 14:19:41 +0800 | [diff] [blame] | 32 | |
| 33 | /** |
Sherry Zhang | 7146895 | 2022-10-19 14:09:05 +0800 | [diff] [blame] | 34 | * @brief The minor version of this implementation of the Firmware Update API. |
Sherry Zhang | 07b4241 | 2021-01-07 14:19:41 +0800 | [diff] [blame] | 35 | */ |
Sherry Zhang | 7146895 | 2022-10-19 14:09:05 +0800 | [diff] [blame] | 36 | #define PSA_FWU_API_VERSION_MINOR 0 |
| 37 | |
| 38 | /** |
| 39 | * @brief A status code that indicates that the firmware of another component |
| 40 | * requires updating. |
| 41 | */ |
| 42 | #define PSA_ERROR_DEPENDENCY_NEEDED ((psa_status_t)-156) |
| 43 | |
| 44 | /** |
| 45 | * @brief A status code that indicates that the system is limiting i/o |
| 46 | * operations to avoid rapid flash exhaustion. |
| 47 | */ |
| 48 | #define PSA_ERROR_FLASH_ABUSE ((psa_status_t)-160) |
| 49 | |
| 50 | /** |
| 51 | * @brief A status code that indicates that the system does not have enough |
| 52 | * power to carry out the request. |
| 53 | */ |
| 54 | #define PSA_ERROR_INSUFFICIENT_POWER ((psa_status_t)-161) |
| 55 | |
| 56 | /** |
| 57 | * @brief The action was completed successfully and requires a system reboot to |
| 58 | * complete installation. |
| 59 | */ |
| 60 | #define PSA_SUCCESS_REBOOT ((psa_status_t)+1) |
| 61 | |
| 62 | /** |
| 63 | * @brief The action was completed successfully and requires a restart of the |
| 64 | * component to complete installation. |
| 65 | */ |
| 66 | #define PSA_SUCCESS_RESTART ((psa_status_t)+2) |
| 67 | |
| 68 | /** |
| 69 | * @brief Firmware component type identifier. |
| 70 | */ |
| 71 | typedef uint8_t psa_fwu_component_t; |
| 72 | |
| 73 | /** |
| 74 | * @brief Version information about a firmware image. |
| 75 | */ |
| 76 | typedef struct psa_fwu_image_version_t { |
| 77 | /* The major version of an image. */ |
| 78 | uint8_t major; |
| 79 | /* The minor version of an image. */ |
| 80 | uint8_t minor; |
| 81 | /* The revision or patch version of an image. */ |
| 82 | uint16_t patch; |
| 83 | /* The build number of an image. */ |
| 84 | uint32_t build; |
| 85 | } psa_fwu_image_version_t; |
| 86 | |
| 87 | /** |
| 88 | * @brief The READY state: the component is ready to start another update. |
| 89 | */ |
| 90 | #define PSA_FWU_READY 0u |
| 91 | |
| 92 | /** |
| 93 | * @brief The WRITING state: a new firmware image is being written to the |
| 94 | * firmware store. |
| 95 | */ |
| 96 | #define PSA_FWU_WRITING 1u |
| 97 | |
| 98 | /** |
| 99 | * @brief The CANDIDATE state: a new firmware image is ready for installation. |
| 100 | */ |
| 101 | #define PSA_FWU_CANDIDATE 2u |
| 102 | |
| 103 | /** |
| 104 | * @brief The STAGED state: a new firmware image is queued for installation. |
| 105 | */ |
| 106 | #define PSA_FWU_STAGED 3u |
| 107 | |
| 108 | /** |
| 109 | * @brief The FAILED state: a firmware update has been cancelled or has failed. |
| 110 | */ |
| 111 | #define PSA_FWU_FAILED 4u |
| 112 | |
| 113 | /** |
| 114 | * @brief The TRIAL state: a new firmware image requires testing prior to |
| 115 | * acceptance of the update. |
| 116 | */ |
| 117 | #define PSA_FWU_TRIAL 5u |
| 118 | |
| 119 | /** |
| 120 | * @brief The REJECTED state: a new firmware image has been rejected after |
| 121 | * testing. |
| 122 | */ |
| 123 | #define PSA_FWU_REJECTED 6u |
| 124 | |
| 125 | /** |
| 126 | * @brief The UPDATED state: a firmware update has been successful, and the new |
| 127 | * image is now active. |
| 128 | */ |
| 129 | #define PSA_FWU_UPDATED 7u |
| 130 | |
| 131 | /** |
| 132 | * @brief Flag to indicate whether the image data in the component staging area |
| 133 | * is discarded at system reset. |
| 134 | */ |
| 135 | #define PSA_FWU_FLAG_VOLATILE_STAGING 0x00000001u |
| 136 | |
| 137 | /** |
| 138 | * @brief Flag to indicate whether a firmware component expects encrypted images |
| 139 | * during an update. |
| 140 | */ |
| 141 | #define PSA_FWU_FLAG_ENCRYPTION 0x00000002u |
| 142 | |
| 143 | /** |
| 144 | * @brief The implementation-specific data in the component information |
| 145 | * structure. |
| 146 | */ |
| 147 | typedef struct { |
| 148 | /* The digest of second image when store state is CANDIDATE. */ |
| 149 | uint8_t candidate_digest[TFM_FWU_MAX_DIGEST_SIZE]; |
| 150 | } psa_fwu_impl_info_t; |
| 151 | |
| 152 | /** |
| 153 | * @brief Information about the firmware store for a firmware component. |
| 154 | */ |
| 155 | typedef struct psa_fwu_component_info_t { |
| 156 | /* State of the component. */ |
| 157 | uint8_t state; |
| 158 | /* Error for second image when store state is REJECTED or FAILED. */ |
| 159 | psa_status_t error; |
| 160 | /* Version of active image. */ |
| 161 | psa_fwu_image_version_t version; |
| 162 | /* Maximum image size in bytes. */ |
| 163 | uint32_t max_size; |
| 164 | /* Flags that describe extra information about the firmware component. */ |
| 165 | uint32_t flags; |
| 166 | /* Implementation-defined image location. */ |
| 167 | uint32_t location; |
| 168 | /* Reserved for implementation-specific usage. */ |
| 169 | psa_fwu_impl_info_t impl; |
| 170 | } psa_fwu_component_info_t; |
| 171 | |
| 172 | /** |
| 173 | * @brief Retrieve the firmware store information for a specific firmware |
| 174 | * component. |
| 175 | * |
| 176 | * @param component Firmware component for which information is requested. |
| 177 | * @param info Output parameter for component information. |
| 178 | * |
| 179 | * @return Result status. |
| 180 | */ |
| 181 | psa_status_t psa_fwu_query(psa_fwu_component_t component, |
| 182 | psa_fwu_component_info_t *info); |
| 183 | |
| 184 | /** |
| 185 | * @brief Begin a firmware update operation for a specific firmware component. |
| 186 | * |
| 187 | * @param component Identifier of the firmware component to be updated. |
| 188 | * @param manifest A pointer to a buffer containing a detached manifest for |
| 189 | * the update. |
| 190 | * @param manifest_size The size of the detached manifest. |
| 191 | * |
| 192 | * @return Result status. |
| 193 | */ |
| 194 | psa_status_t psa_fwu_start(psa_fwu_component_t component, |
| 195 | const void *manifest, |
| 196 | size_t manifest_size); |
| 197 | |
| 198 | /** |
| 199 | * @brief The maximum permitted size for block in psa_fwu_write(), in bytes. |
| 200 | */ |
| 201 | #define PSA_FWU_MAX_WRITE_SIZE TFM_CONFIG_FWU_MAX_WRITE_SIZE |
| 202 | |
| 203 | /** |
| 204 | * @brief Write a firmware image, or part of a firmware image, to its staging |
| 205 | * area. |
| 206 | * |
| 207 | * @param component Identifier of the firmware component being updated. |
| 208 | * @param image_offset The offset of the data block in the whole image. |
| 209 | * @param block A buffer containing a block of image data. |
| 210 | * @param block_size Size of block, in bytes. |
| 211 | * |
| 212 | * @return Result status. |
| 213 | */ |
| 214 | psa_status_t psa_fwu_write(psa_fwu_component_t component, |
| 215 | size_t image_offset, |
Sherry Zhang | 07b4241 | 2021-01-07 14:19:41 +0800 | [diff] [blame] | 216 | const void *block, |
| 217 | size_t block_size); |
| 218 | |
Sherry Zhang | 07b4241 | 2021-01-07 14:19:41 +0800 | [diff] [blame] | 219 | /** |
Sherry Zhang | 7146895 | 2022-10-19 14:09:05 +0800 | [diff] [blame] | 220 | * @brief Mark a firmware image in the staging area as ready for installation. |
Sherry Zhang | 07b4241 | 2021-01-07 14:19:41 +0800 | [diff] [blame] | 221 | * |
Sherry Zhang | 7146895 | 2022-10-19 14:09:05 +0800 | [diff] [blame] | 222 | * @param component Identifier of the firmware component to install. |
Sherry Zhang | 07b4241 | 2021-01-07 14:19:41 +0800 | [diff] [blame] | 223 | * |
Sherry Zhang | 7146895 | 2022-10-19 14:09:05 +0800 | [diff] [blame] | 224 | * @return Result status. |
Sherry Zhang | 07b4241 | 2021-01-07 14:19:41 +0800 | [diff] [blame] | 225 | */ |
Sherry Zhang | 7146895 | 2022-10-19 14:09:05 +0800 | [diff] [blame] | 226 | psa_status_t psa_fwu_finish(psa_fwu_component_t component); |
Sherry Zhang | 07b4241 | 2021-01-07 14:19:41 +0800 | [diff] [blame] | 227 | |
| 228 | /** |
Sherry Zhang | 7146895 | 2022-10-19 14:09:05 +0800 | [diff] [blame] | 229 | * @brief Abandon an update that is in WRITING or CANDIDATE state. |
Sherry Zhang | 07b4241 | 2021-01-07 14:19:41 +0800 | [diff] [blame] | 230 | * |
Sherry Zhang | 7146895 | 2022-10-19 14:09:05 +0800 | [diff] [blame] | 231 | * @param component Identifier of the firmware component to be cancelled. |
Sherry Zhang | 07b4241 | 2021-01-07 14:19:41 +0800 | [diff] [blame] | 232 | * |
Sherry Zhang | 7146895 | 2022-10-19 14:09:05 +0800 | [diff] [blame] | 233 | * @return Result status. |
Sherry Zhang | 07b4241 | 2021-01-07 14:19:41 +0800 | [diff] [blame] | 234 | */ |
Sherry Zhang | 7146895 | 2022-10-19 14:09:05 +0800 | [diff] [blame] | 235 | psa_status_t psa_fwu_cancel(psa_fwu_component_t component); |
Sherry Zhang | 07b4241 | 2021-01-07 14:19:41 +0800 | [diff] [blame] | 236 | |
| 237 | /** |
Sherry Zhang | 7146895 | 2022-10-19 14:09:05 +0800 | [diff] [blame] | 238 | * @brief Prepare the component for another update. |
Sherry Zhang | 07b4241 | 2021-01-07 14:19:41 +0800 | [diff] [blame] | 239 | * |
Sherry Zhang | 7146895 | 2022-10-19 14:09:05 +0800 | [diff] [blame] | 240 | * @param component Identifier of the firmware component to tidy up. |
Sherry Zhang | 07b4241 | 2021-01-07 14:19:41 +0800 | [diff] [blame] | 241 | * |
Sherry Zhang | 7146895 | 2022-10-19 14:09:05 +0800 | [diff] [blame] | 242 | * @return Result status. |
Sherry Zhang | 07b4241 | 2021-01-07 14:19:41 +0800 | [diff] [blame] | 243 | */ |
Sherry Zhang | 7146895 | 2022-10-19 14:09:05 +0800 | [diff] [blame] | 244 | psa_status_t psa_fwu_clean(psa_fwu_component_t component); |
Sherry Zhang | 07b4241 | 2021-01-07 14:19:41 +0800 | [diff] [blame] | 245 | |
| 246 | /** |
Sherry Zhang | 7146895 | 2022-10-19 14:09:05 +0800 | [diff] [blame] | 247 | * @brief Start the installation of all firmware images that have been prepared |
| 248 | * for update. |
Sherry Zhang | 07b4241 | 2021-01-07 14:19:41 +0800 | [diff] [blame] | 249 | * |
Sherry Zhang | 7146895 | 2022-10-19 14:09:05 +0800 | [diff] [blame] | 250 | * @return Result status. |
| 251 | */ |
| 252 | psa_status_t psa_fwu_install(void); |
| 253 | |
| 254 | /** |
| 255 | * @brief Requests the platform to reboot. |
Sherry Zhang | 07b4241 | 2021-01-07 14:19:41 +0800 | [diff] [blame] | 256 | * |
Sherry Zhang | 7146895 | 2022-10-19 14:09:05 +0800 | [diff] [blame] | 257 | * @return Result status. |
Sherry Zhang | 07b4241 | 2021-01-07 14:19:41 +0800 | [diff] [blame] | 258 | */ |
| 259 | psa_status_t psa_fwu_request_reboot(void); |
| 260 | |
| 261 | /** |
Sherry Zhang | 7146895 | 2022-10-19 14:09:05 +0800 | [diff] [blame] | 262 | * @brief Abandon an installation that is in STAGED or TRIAL state. |
Sherry Zhang | 07b4241 | 2021-01-07 14:19:41 +0800 | [diff] [blame] | 263 | * |
Sherry Zhang | 7146895 | 2022-10-19 14:09:05 +0800 | [diff] [blame] | 264 | * @param error An application-specific error code chosen by the application. |
Sherry Zhang | 2da977d | 2021-05-10 16:59:05 +0800 | [diff] [blame] | 265 | * |
Sherry Zhang | 7146895 | 2022-10-19 14:09:05 +0800 | [diff] [blame] | 266 | * @return Result status. |
Sherry Zhang | 07b4241 | 2021-01-07 14:19:41 +0800 | [diff] [blame] | 267 | */ |
Sherry Zhang | 7146895 | 2022-10-19 14:09:05 +0800 | [diff] [blame] | 268 | psa_status_t psa_fwu_reject(psa_status_t error); |
Sherry Zhang | 07b4241 | 2021-01-07 14:19:41 +0800 | [diff] [blame] | 269 | |
| 270 | /** |
Sherry Zhang | 7146895 | 2022-10-19 14:09:05 +0800 | [diff] [blame] | 271 | * @brief Accept a firmware update that is currently in TRIAL state. |
Sherry Zhang | 07b4241 | 2021-01-07 14:19:41 +0800 | [diff] [blame] | 272 | * |
Sherry Zhang | 7146895 | 2022-10-19 14:09:05 +0800 | [diff] [blame] | 273 | * @return Result status. |
Sherry Zhang | 07b4241 | 2021-01-07 14:19:41 +0800 | [diff] [blame] | 274 | */ |
Sherry Zhang | 7146895 | 2022-10-19 14:09:05 +0800 | [diff] [blame] | 275 | psa_status_t psa_fwu_accept(void); |
Sherry Zhang | 07b4241 | 2021-01-07 14:19:41 +0800 | [diff] [blame] | 276 | |
| 277 | #ifdef __cplusplus |
| 278 | } |
| 279 | #endif |
Sherry Zhang | 7146895 | 2022-10-19 14:09:05 +0800 | [diff] [blame] | 280 | |
Sherry Zhang | 07b4241 | 2021-01-07 14:19:41 +0800 | [diff] [blame] | 281 | #endif /* PSA_UPDATE_H */ |