Julian Hall | 7af7f90 | 2023-02-16 11:07:32 +0000 | [diff] [blame] | 1 | Overview |
| 2 | -------- |
| 3 | The ability to update device firmware and related resources is a key requirement for |
| 4 | maintaining security over a device's lifetime. Keeping firmware up-to-date with security |
| 5 | fixes and feature enhancements is important for defending against emerging threats. |
| 6 | Because firmware forms the security foundation of a device, it is important to apply |
| 7 | updates in a timely manner to minimize risks exposed by firmware vulnerabilities. Any |
| 8 | remote firmware update mechanism carries a risk of failure. As firmware is critical to |
| 9 | the operation of a device, failures during the update process that lead to corrupted |
| 10 | firmware have the potential to be highly disruptive. Any update mechanism intended |
| 11 | for use with a large population of devices must offer robustness guarantees sufficient |
| 12 | to keep the risk of failure at an acceptable level. |
| 13 | |
| 14 | Firmware update support within the Trusted Services project consists of a set of reusable |
| 15 | firmware components that can be deployed within different execution environments to enable |
| 16 | platform integrators to create firmware update solutions, tailored for their platform. |
| 17 | The components are intended to be integrated into platform firmware and will be used in |
| 18 | conjunction with a third-party update client, such as mender, swupd or fwupd, to create |
| 19 | an end-to-end solution. The features supported aim to meet requirements for robustness |
| 20 | and security. These include: |
| 21 | |
| 22 | - Banked A/B robust update support |
| 23 | - Transactional multi-component updates with ACID (Atomicity, Consistency, Isolation, |
| 24 | Durability) guarantees |
| 25 | - Partial updates where not all components are updated |
| 26 | - Trial of an update with bootloader or client initiated rollback |
| 27 | - Anti-rollback counter management |
| 28 | - Standardized signaling to bootloader via the FWU Metadata structure |
| 29 | - Flexible installer framework to support different image types |
| 30 | - Image directory for advertising updatable components |
| 31 | - Compatible with UEFI FMP capsule update model and ESRT |
| 32 | |
| 33 | To support test and development and to provide a useful reference, the Trusted Services |
| 34 | project maintains a reference integration with the following characteristics: |
| 35 | |
| 36 | - Dual flash system where firmware is loaded from a dedicated secure world flash device. |
| 37 | - Secure flash is formatted with UEFI MBR/GPT with separate partitions for FWU metadata |
| 38 | and firmware banks. |
| 39 | - TF-A is used as the bootloader with separate firmware components packaged in a FIP |
| 40 | image. |
| 41 | - The Update Agent runs within a secure partition and exposes an FF-A based ABI that |
Gyorgy Szing | 0accdf7 | 2023-04-13 01:55:22 +0200 | [diff] [blame] | 42 | conforms to the `Arm FWU-A specification`_. |
| 43 | - Test and development on supported :ref:`Target Platforms`. |
Julian Hall | 7af7f90 | 2023-02-16 11:07:32 +0000 | [diff] [blame] | 44 | |
| 45 | Source Code Location |
| 46 | -------------------- |
| 47 | Within the Trusted Services project, source code related to FWU can be found under the |
| 48 | following subdirectories (relative to the project root). |
| 49 | |
| 50 | .. list-table:: |
| 51 | :header-rows: 1 |
| 52 | |
| 53 | * - Directory |
| 54 | - Contains |
| 55 | * - components/service/fwu |
| 56 | - Service components for implementing the FWU service provider. |
| 57 | * - protocols/service/fwu |
| 58 | - Public service access protocol (ABI) definition. |
Gyorgy Szing | 0accdf7 | 2023-04-13 01:55:22 +0200 | [diff] [blame] | 59 | * - components/media/volume |
Julian Hall | 7af7f90 | 2023-02-16 11:07:32 +0000 | [diff] [blame] | 60 | - Storage volume access. |
| 61 | |
| 62 | Testing is covered in more detail in a later section. However, if you want a simple way |
| 63 | of building and testing FWU components, the component-test deployment may be built for a |
| 64 | native PC environment. The built executable includes an extensive set of FWU related tests |
| 65 | that exercise the core Update Agent in various configurations. To build and run these tests |
Gyorgy Szing | 0accdf7 | 2023-04-13 01:55:22 +0200 | [diff] [blame] | 66 | on a Linux PC, use the following (from TS root directory): |
Julian Hall | 7af7f90 | 2023-02-16 11:07:32 +0000 | [diff] [blame] | 67 | |
Gyorgy Szing | 0accdf7 | 2023-04-13 01:55:22 +0200 | [diff] [blame] | 68 | .. code-block:: bash |
Julian Hall | 7af7f90 | 2023-02-16 11:07:32 +0000 | [diff] [blame] | 69 | |
Gyorgy Szing | 0accdf7 | 2023-04-13 01:55:22 +0200 | [diff] [blame] | 70 | mkdir -p ~/compt-linux-pc |
| 71 | cmake -S deployments/component-test/linux-pc -B ~/compt-linux-pc |
| 72 | cmake --build ~/compt-linux-pc |
| 73 | ~/compt-linux-pc/component-test -v -g Fwu |
Julian Hall | 7af7f90 | 2023-02-16 11:07:32 +0000 | [diff] [blame] | 74 | |
Gyorgy Szing | 0accdf7 | 2023-04-13 01:55:22 +0200 | [diff] [blame] | 75 | Output will look like this:: |
| 76 | |
| 77 | TEST(FwuCopyInstallerTests, installAndCopy) - 1 ms |
| 78 | TEST(FwuRawInstallerTests, normalInstallFlow) - 1 ms |
| 79 | TEST(FwuMetadataManagerTests, checkAndRepairInaccessibleStorage) - 0 ms |
| 80 | TEST(FwuMetadataManagerTests, checkAndRepairAccessibleStorage) - 1 ms |
| 81 | TEST(FwuRollbackTests, bootloaderFallback) - 0 ms |
| 82 | TEST(FwuRollbackTests, selectPreviousAfterActivation) - 0 ms |
| 83 | TEST(FwuRollbackTests, selectPreviousPriorToActivation) - 0 ms |
| 84 | TEST(FwuPowerFailureTests, powerFailureDuringTrial) - 0 ms |
| 85 | TEST(FwuPowerFailureTests, powerFailureDuringStaging) - 0 ms |
| 86 | TEST(FwuUpdateScenarioTests, partialFirmwareUpdateFlow) - 0 ms |
| 87 | TEST(FwuUpdateScenarioTests, wholeFirmwareUpdateFlow) - 0 ms |
| 88 | TEST(FwuInvalidBehaviourTests, invalidOperationsInTrial) - 0 ms |
| 89 | TEST(FwuInvalidBehaviourTests, invalidOperationsInStaging) - 0 ms |
| 90 | TEST(FwuInvalidBehaviourTests, invalidOperationsInRegular) - 0 ms |
| 91 | TEST(FwuImageDirectoryTests, zeroFwLocations) - 0 ms |
| 92 | TEST(FwuImageDirectoryTests, multipleFwLocations) - 0 ms |
| 93 | TEST(FwuImageDirectoryTests, singleFwLocation) - 1 ms |
| 94 | TEST(FwuImageDirectoryTests, streamRecycling) - 0 ms |
| 95 | TEST(FwuImageDirectoryTests, streamedReads) - 0 ms |
| 96 | |
| 97 | OK (234 tests, 19 ran, 3452 checks, 0 ignored, 215 filtered out, 5 ms) |
Julian Hall | 7af7f90 | 2023-02-16 11:07:32 +0000 | [diff] [blame] | 98 | |
| 99 | Concepts and Assumptions |
| 100 | ------------------------ |
| 101 | Before describing details of the design, some important concepts and assumptions are |
| 102 | introduced in this section. |
| 103 | |
| 104 | Update Packaging |
| 105 | '''''''''''''''' |
| 106 | A set of firmware images that forms an update will be packaged in some way to enable |
| 107 | it to be delivered to a device for installation. No particular packaging method is assumed |
| 108 | by the FWU Update Agent. Any unpacking will be performed before individual images are |
| 109 | presented to the FWU service for installation. The only assumption that the Update Agent |
| 110 | relies on is that each image is identified by an image type UUID/GUID. The UEFI specification |
| 111 | defines the FMP Capsule format that acts as a container for a set of arbitrary images. The |
| 112 | reference integration maintained by the Trusted Services project uses UEFI FMP capsules |
| 113 | but the FWU service can be used with any packaging method. |
| 114 | |
| 115 | Transactional Updates |
| 116 | ''''''''''''''''''''' |
| 117 | A firmware update package may contain multiple images that all need to be installed as a |
| 118 | set in order to successfully update a device's firmware. To avoid the hazard of booting |
| 119 | a device using partially installed firmware, the FWU-A specification supports transactional |
| 120 | updates where as set of separate image install operations are grouped together to form a |
| 121 | single update transaction. The FWU-A specification defines a behavioral model where images |
Gyorgy Szing | 0accdf7 | 2023-04-13 01:55:22 +0200 | [diff] [blame] | 122 | are installed during the *STAGING* state. Entry to the *STAGING* state is triggered by the |
| 123 | client making the ``fwu_begin_staging`` ABI call. This is followed a set of one or more install |
Julian Hall | 7af7f90 | 2023-02-16 11:07:32 +0000 | [diff] [blame] | 124 | operations where images are written to the Update Agent. After committing the final image |
Gyorgy Szing | 0accdf7 | 2023-04-13 01:55:22 +0200 | [diff] [blame] | 125 | in the set, the client marks the end of the transaction by calling ``fwu_end_staging``. |
Julian Hall | 7af7f90 | 2023-02-16 11:07:32 +0000 | [diff] [blame] | 126 | |
| 127 | Banked Firmware Store |
| 128 | ''''''''''''''''''''' |
| 129 | To offer the guarantee that device firmware is never left in an unbootable state, a valid |
| 130 | version of firmware is always held in flash. Flash storage is organized into A and B banks |
| 131 | where one bank holds a valid set of images while updates are installed in the other bank. |
| 132 | The bootloader is capable of booting from either bank, as instructed by the FWU metadata |
| 133 | written by the Update Agent. Where firmware storage is distributed across multiple locations, |
| 134 | A and B volumes must exist for each location. |
| 135 | |
| 136 | Update Agent |
| 137 | '''''''''''' |
| 138 | The Update Agent is a logical component defined in the FWU-A specification reference model. |
| 139 | The Update Agent handles requests from a client to install a set of images in preparation |
| 140 | for activating the updated firmware. In the TS project, the role of the Update Agent is |
| 141 | reflected by a firmware component with the same name. |
| 142 | |
| 143 | Firmware Directory |
| 144 | '''''''''''''''''' |
| 145 | The FWU-A specification defines a stream endpoint that can be read by a client to obtain a |
| 146 | listing of updatable firmware components. In the TS implementation, this is backed by the |
| 147 | Firmware Directory component that is populated with information about the booted firmware. |
| 148 | |
| 149 | Storage Volumes |
| 150 | '''''''''''''''' |
| 151 | All NV storage accessed by the Update Agent is represented by a set of volume objects. A |
| 152 | volume presents a unit of storage as a seekable file with support for conventional file IO |
| 153 | operations. The volume provides a uniform interface for all storage operations performed by |
Gyorgy Szing | 0accdf7 | 2023-04-13 01:55:22 +0200 | [diff] [blame] | 154 | the Update Agent. The volume uses and extends the *io_dev* driver model from the TF-A project. |
Julian Hall | 7af7f90 | 2023-02-16 11:07:32 +0000 | [diff] [blame] | 155 | Concrete volume objects can access different types of storage such as: |
| 156 | |
| 157 | - A raw flash device |
| 158 | - A disk partition |
Gyorgy Szing | 0accdf7 | 2023-04-13 01:55:22 +0200 | [diff] [blame] | 159 | - Storage managed by a subsystem |
Julian Hall | 7af7f90 | 2023-02-16 11:07:32 +0000 | [diff] [blame] | 160 | |
| 161 | Installers |
| 162 | '''''''''' |
| 163 | Trusted Services FWU support provides a framework for updating arbitrary firmware images. |
| 164 | From the framework's perspective, an image is just a binary blob, identified by an image |
| 165 | type UUID. To allow for image format specific installation, a common installer interface is |
| 166 | defined to allow for alternative concrete installers. Installers can update the entire |
| 167 | contents of a volume or modify parts of a volume. Where a volume holds a container such |
| 168 | as a FIP, a specialized installer with knowledge of the container format can provide finer |
| 169 | grain updates of the container contents. An installer implements an enumerate method to |
| 170 | return information about images that it can handle. The Firmware Directory is formed by |
| 171 | aggregating the information returned by each installer's enumerate method. |
| 172 | |
| 173 | Firmware Locations |
| 174 | '''''''''''''''''' |
| 175 | The Update Agent can manage firmware distributed across multiple locations e.g. different |
| 176 | flash partitions, different flash devices or different subsystems. The concept of a firmware |
| 177 | location is used in the TS implementation to provide a generalized model for handling |
| 178 | distributed firmware. Each location is assigned an integer ID that is used to bind together: |
| 179 | |
| 180 | - A pair of storage volumes (for A + B banks) |
| 181 | - A set of one or more installers. The set of installers configured for the location |
| 182 | determines which image types are updatable for the location. |
| 183 | |
| 184 | Installers are categorized as one of the following types: |
| 185 | |
| 186 | - **Whole volume installer** - updates the entire contents of a volume. The whole volume |
| 187 | contents is presented as an entry in the firmware directory. |
| 188 | - **Sub-volume installer** - updates components contained within a volume. Each image |
| 189 | contained within the active volume is presented as an entry in the firmware directory. |
| 190 | - **Whole volume copy installer** - copies entire volume contents from one volume to |
| 191 | another. Contributes no entries to the firmware directory. |
| 192 | |
| 193 | A platform integrator is responsible for selecting which installers are configured for a |
| 194 | location. Each location must be assigned at least one installer. Any combination of different |
| 195 | types of installer could make sense in a platform configuration. Here are some example |
| 196 | configurations: |
| 197 | |
| 198 | .. list-table:: |
| 199 | :header-rows: 1 |
| 200 | |
| 201 | * - Location configuration |
| 202 | - Update capability for location |
| 203 | * - *WholeVolumeInstaller* |
| 204 | - A single entry appears in the firmware directory for the location that corresponds to |
| 205 | the entire volume contents. An incoming update package must include an image that |
| 206 | corresponds to the directory entry. |
| 207 | * - *WholeVolumeInstaller + SubVolumeInstaller* |
| 208 | - Firmware directory entries appear for the whole volume and for each updatable component |
| 209 | contained within the volume. An incoming update package must include either one or more |
| 210 | sub-volume images or a whole volume image for this location. |
| 211 | * - *WholeVolumeInstaller + SubVolumeInstaller + WholeVolumeCopyInstaller* |
| 212 | - Firmware directory entries appear for the whole volume and for each updatable component |
| 213 | contained within the volume. If no image for this location is included in an incoming |
| 214 | update package, the currently active volume contents is copied to the update volume. |
| 215 | * - *WholeVolumeCopyInstaller* |
| 216 | - This configuration can be used if it is necessary to prevent updates for a location. |
| 217 | For any update transaction, the currently active volume contents will always be copied |
| 218 | to the update volume for this location. |
| 219 | |
| 220 | Design Description |
| 221 | ------------------ |
| 222 | FWU components within the TS project are designed for reuse in alternative deployments. The |
| 223 | project currently maintains two FWU deployments, both sharing many common components: |
| 224 | |
| 225 | - **fwu/config/default-sp** - the Update Agent runs within a secure partition. The client |
Gyorgy Szing | 0accdf7 | 2023-04-13 01:55:22 +0200 | [diff] [blame] | 226 | invokes ABI operations via FF-A based RPC. Updates are applied to a dedicated SWd flash device. |
| 227 | - **fwu-tool/linux-pc** - the Update Agent runs within a command-line application. |
Julian Hall | 7af7f90 | 2023-02-16 11:07:32 +0000 | [diff] [blame] | 228 | Updates are applied to a disk image file residing in the host filesystem. |
| 229 | |
| 230 | There is clear separation between different classes of component making component-level reuse |
| 231 | straight-forward. The following diagram illustrates the main FWU components. The direction of |
| 232 | the arrows linking components shows the direction of a dependency between associated |
| 233 | components (i.e. A→B means that A depends on B). |
| 234 | |
Gyorgy Szing | 0accdf7 | 2023-04-13 01:55:22 +0200 | [diff] [blame] | 235 | .. image:: ../image/update-agent-components.svg |
Julian Hall | 7af7f90 | 2023-02-16 11:07:32 +0000 | [diff] [blame] | 236 | |
| 237 | Core Components |
| 238 | '''''''''''''''' |
| 239 | Any FWU deployment that supports a banked firmware store is expected to use the core set of |
| 240 | FWU components. Core components are partitioned between: |
| 241 | |
| 242 | - **Generic Update Agent** - manages update transactions and streams used for transferring |
| 243 | image data. Also owns the FW Directory. |
| 244 | - **Banked FW Store** - manages banked access to storage and communication with the bootloader |
| 245 | via FWU metadata. |
| 246 | |
| 247 | Generic Update Agent Model |
| 248 | """""""""""""""""""""""""" |
| 249 | The following class diagram models the generic Update Agent: |
| 250 | |
Gyorgy Szing | 0accdf7 | 2023-04-13 01:55:22 +0200 | [diff] [blame] | 251 | .. uml:: ../uml/UpdateAgentClassDiagram.puml |
Julian Hall | 7af7f90 | 2023-02-16 11:07:32 +0000 | [diff] [blame] | 252 | |
| 253 | Classes in the model perform the following roles: |
| 254 | |
| 255 | .. list-table:: |
| 256 | :header-rows: 1 |
| 257 | |
| 258 | * - Class |
| 259 | - Description |
| 260 | - Source files |
| 261 | * - *update_agent* |
| 262 | - Coordinates update transactions from start to finish. Implements the FWU state machine that |
| 263 | enforces correct behaviour during an update. Provides functions that form the public interface |
| 264 | for an instance of the Update Agent. |
| 265 | - components/service/fwu/agent/update_agent.h, components/service/fwu/agent/update_agent.c |
| 266 | * - *stream_manager* |
| 267 | - Manages a pool of stream objects for client initiated stream read and write operations. Streams |
| 268 | are used for writing image data and reading FWU objects such as the image directory. |
| 269 | - components/service/fwu/agent/stream_manager.h, components/service/fwu/agent/stream_manager.c |
| 270 | * - *fw_directory* |
| 271 | - Holds information about the currently active firmware. The contents of the fw_directory is |
| 272 | updated by a fw_inspector at boot time. Forms the source of the information returned to a |
| 273 | client that reads the image directory object. |
| 274 | - components/service/fwu/agent/fw_directory.h, components/service/fwu/agent/fw_directory.c |
| 275 | * - *img_dir_serializer* |
| 276 | - Serializes information about currently active firmware in-line with the FWU-A specification. |
| 277 | - components/service/fwu/agent/img_dir_serializer.h, components/service/fwu/agent/img_dir_serializer.c |
| 278 | * - *fw_inspector* |
| 279 | - Called by the update_agent to inspect firmware and update the contents of the fw_directory to |
| 280 | provide a fresh view of active firmware. To allow for alternative inspection strategies, the |
| 281 | concrete fw_inspector to use is determined by deployment specific configuration code and passed |
| 282 | to the update_agent at initialization. The direct_fw_inspector is a concrete fw_inspector that |
| 283 | relies on direct access to the set of installers registered as part of the Update Agent configuration. |
| 284 | - components/service/fwu/inspector/fw_inspector.h, components/service/fwu/inspector/direct/direct_fw_inspector.h, |
| 285 | components/service/fwu/inspector/direct/direct_fw_inspector.c |
| 286 | |
| 287 | Banked FW Store Model |
| 288 | """""""""""""""""""""" |
| 289 | The update_agent interacts with the fw_store via a common interface. No details about the nature of the fw_store |
| 290 | are exposed to the update_agent. The following class diagram models a particular realization of the fw_store |
| 291 | interface that implements the A/B bank scheme: |
| 292 | |
Gyorgy Szing | 0accdf7 | 2023-04-13 01:55:22 +0200 | [diff] [blame] | 293 | .. uml:: ../uml/FwStoreClassDiagram.puml |
Julian Hall | 7af7f90 | 2023-02-16 11:07:32 +0000 | [diff] [blame] | 294 | |
| 295 | Classes in the model perform the following roles: |
| 296 | |
| 297 | .. list-table:: |
| 298 | :header-rows: 1 |
| 299 | |
| 300 | * - Class |
| 301 | - Description |
| 302 | - Source files |
| 303 | * - *fw_store* |
| 304 | - Manages updates to banked storage volumes. |
| 305 | - components/service/fwu/fw_store/fw_store.h, |
| 306 | components/service/fwu/fw_store/banked/banked_fw_store.h, |
| 307 | components/service/fwu/fw_store/banked/banked_fw_store.c |
| 308 | * - *bank_tracker* |
| 309 | - Tracks usage and accepted state of firmware banks. |
| 310 | - components/service/fwu/fw_store/banked/bank_tracker.h, |
| 311 | components/service/fwu/fw_store/banked/bank_tracker.c |
| 312 | * - *metadata_manager* |
| 313 | - Manages storage and updates to the FWU metadata used for signaling to the bootloader. Responsible for |
| 314 | detecting and repairing corrupted metadata. |
| 315 | - components/service/fwu/fw_store/banked/metadata_manager.h, |
| 316 | components/service/fwu/fw_store/banked/metadata_manager.c |
| 317 | * - *metadata_serializer* |
| 318 | - Serializes update bank state in a standard format for compatibility with the boot loader. To ensure |
| 319 | version compatibility through fw updates, alternative realizations of the metadata_serializer may be |
| 320 | selected at runtime. Currently support for V1 and V2 formats (as defined by the FWU-A specification). |
| 321 | - components/service/fwu/fw_store/banked/metadata_serializer/metadata_serializer.h |
| 322 | * - *installer* |
| 323 | - Base class for installers. Defines a common interface for installing images associated with a location. |
| 324 | - components/service/fwu/installer/installer.h, |
| 325 | components/service/fwu/installer/installer.c |
| 326 | * - *installer_index* |
| 327 | - Holds pointers to the set of concrete installers registered during platform configuration. |
| 328 | - components/service/fwu/installer/installer_index.h, |
| 329 | components/service/fwu/installer/installer_index.c |
| 330 | * - *volume* |
| 331 | - Presents a unit of storage is a seekable file. Supports byte-orient read and writes operation |
| 332 | to storage. All NV storage is accessed by the Update Agent using volumes. The set of volume objects |
| 333 | needed for a deployment are created as part of platform specific initialisation. |
| 334 | - components/media/volume/volume.h, |
| 335 | components/media/volume/volume.c |
| 336 | * - *volume_index* |
| 337 | - Holds pointers to the set of concrete volumes registered during platform configuration. |
| 338 | - components/media/volume/index/volume_index.h, |
| 339 | components/media/volume/index/volume_index.c |
| 340 | |
| 341 | Service Interface |
| 342 | '''''''''''''''''' |
| 343 | For deployments where the Update Agent needs to be remotely callable, the fwu_provider implements an |
| 344 | RPC interface that accepts call requests, de-serializes call parameters and calls the corresponding |
| 345 | interface functions provided by the update_agent. In the reference deployment, where the Update |
| 346 | Agent runs within an SP, the fwu_provider receives call requests, made via FF-A, and returns responses |
| 347 | to the remote client. The fwu_provider may be used with any RPC layer where remote calling is required. |
| 348 | |
| 349 | Platform Configuration |
| 350 | ---------------------- |
| 351 | A platform specific configuration tells the Update Agent about storage for firmware and defines the |
| 352 | policy for the way the firmware can be update. Configuration steps result in the creation of: |
| 353 | |
| 354 | - A set of concrete installer objects registered with the installer_index. This defines the |
| 355 | type of images that can be updated. |
| 356 | - A set of concrete volume objects registered with the volume_index. This defines where images |
| 357 | can be installed. |
| 358 | |
| 359 | Each installer is assigned a location ID to bind the installer to a particular firmware location. |
| 360 | Location IDs are integer values defined by the configuration code. For example, where firmware |
Gyorgy Szing | e6b3846 | 2024-10-24 17:36:45 +0200 | [diff] [blame] | 361 | consists of AP firmware, SCP firmware and RSE firmware, location IDs could be assigned as follows: |
Julian Hall | 7af7f90 | 2023-02-16 11:07:32 +0000 | [diff] [blame] | 362 | |
| 363 | .. list-table:: |
| 364 | :header-rows: 1 |
| 365 | |
| 366 | * - Location |
| 367 | - ID |
| 368 | * - AP firmware |
| 369 | - 0 |
| 370 | * - SCP firmware |
| 371 | - 1 |
Gyorgy Szing | e6b3846 | 2024-10-24 17:36:45 +0200 | [diff] [blame] | 372 | * - RSE firmware |
Julian Hall | 7af7f90 | 2023-02-16 11:07:32 +0000 | [diff] [blame] | 373 | - 2 |
| 374 | |
| 375 | When volume objects are added to the volume index, each one is assigned a volume ID which is |
| 376 | formed by combining the corresponding location ID with the bank index to which the volume |
| 377 | provides access to. |
| 378 | |
| 379 | The types of installer and volume needed will depend on factors such as: |
| 380 | |
| 381 | - How NV storage is accessed by the Update Agent. |
| 382 | - The type of images that need to be installed. |
| 383 | - How flash storage is partitioned e.g. is GPT used or some other partition description method. |
| 384 | |
| 385 | Source files related to FWU configuration: |
| 386 | |
| 387 | .. list-table:: |
| 388 | :header-rows: 1 |
| 389 | |
| 390 | * - Directory |
| 391 | - Contains |
| 392 | * - components/service/fwu/config |
| 393 | - Configuration strategies for provisioning installers and volumes |
| 394 | * - components/service/fwu/installer/factory |
| 395 | - Factories for constructing different types of installer |
| 396 | * - components/media/volume/factory |
| 397 | - Factories for constructing different types of volume |
| 398 | |
| 399 | Update Agent Configuration using GPT |
| 400 | '''''''''''''''''''''''''''''''''''' |
| 401 | The TS FWU service implementation includes a GPT based configurator that automatically discovers |
| 402 | the set of installers and volumes to construct, based on the contents of the GPT that describes |
| 403 | the flash layout. The following diagram illustrates a typical flash partition layout. Note that |
| 404 | not all partitions contain firmware. |
| 405 | |
Gyorgy Szing | 0accdf7 | 2023-04-13 01:55:22 +0200 | [diff] [blame] | 406 | .. image:: ../image/gpt-based-flash-layout.svg |
Julian Hall | 7af7f90 | 2023-02-16 11:07:32 +0000 | [diff] [blame] | 407 | |
| 408 | A deployment of the Update Agent is built with an installer factory that has the capability to |
| 409 | construct a set of installers that are suitable for a family of platforms where common image |
| 410 | types and update policy applies. An installer factory is capable of constructing a concrete set |
| 411 | of installers for installing images into a particular set of partitions, identified by partition |
| 412 | type GUID. A platform may not incorporate the complete set of partition types. The default |
| 413 | installer factory (under components/service/fwu/installer/factory/default) includes rules for |
| 414 | constructing installers for: |
| 415 | |
| 416 | - **AP Firmware** - where application firmware is contained within a FIP |
| 417 | - **SCP Firmware** - binary boot image for SCP |
Gyorgy Szing | e6b3846 | 2024-10-24 17:36:45 +0200 | [diff] [blame] | 418 | - **RSE Firmware** - binary boot image for RSE |
Julian Hall | 7af7f90 | 2023-02-16 11:07:32 +0000 | [diff] [blame] | 419 | |
| 420 | The GPT based configurator relies on access to the GPT partition table. During initialization |
| 421 | of the Update Agent, the configurator iterates over each partition entry. If no installers are |
| 422 | registered for the partition, the partition type GUID is offered to the installer factory. If |
| 423 | at least one installer is constructed, a volume object is constructed to provide access to the |
| 424 | partition. This partition will hold one of the banked copies of the image identified by the |
| 425 | partition type GUID. If one or more installers have already been constructed for the partition |
| 426 | type GUID, an additional volume object is constructed to provide access to the second |
| 427 | banked partition. |
| 428 | |
| 429 | The designation of bank index to partition is determined from the PartitionName field in the |
| 430 | partition entry. The first UTF-16 character (0 or 1) is interpreted as the bank index assigned |
| 431 | to the partition. Different conventions are possible if an alternative configurator is used. |
| 432 | |
| 433 | FWU Command Line Application |
| 434 | ---------------------------- |
Gyorgy Szing | 0accdf7 | 2023-04-13 01:55:22 +0200 | [diff] [blame] | 435 | The *fwu-tool* deployment integrates the Update Agent within a command-line application that can be |
| 436 | run on a Linux PC. Instead of updating images stored in flash, the application operates on a GPT |
| 437 | formatted disk image file residing in the host machine's filesystem. (Refer to :ref:`UEFI disk image |
| 438 | creation instructions` to see how a disk image can be created.) The core components of the |
| 439 | application are identical to those used in embedded deployments. To build and run the fwu |
| 440 | application, use the following commands from the root of the checked-out TS project: |
Julian Hall | 7af7f90 | 2023-02-16 11:07:32 +0000 | [diff] [blame] | 441 | |
Gyorgy Szing | 0accdf7 | 2023-04-13 01:55:22 +0200 | [diff] [blame] | 442 | .. code-block:: bash |
Julian Hall | 7af7f90 | 2023-02-16 11:07:32 +0000 | [diff] [blame] | 443 | |
Gyorgy Szing | 0accdf7 | 2023-04-13 01:55:22 +0200 | [diff] [blame] | 444 | mkdir -p ~/fwu-tool |
| 445 | cmake -S deployments/fwu-tool/linux-pc -B ~/fwu-tool |
| 446 | cmake --build ~/fwu-tool |
Julian Hall | 7af7f90 | 2023-02-16 11:07:32 +0000 | [diff] [blame] | 447 | |
Gyorgy Szing | 0accdf7 | 2023-04-13 01:55:22 +0200 | [diff] [blame] | 448 | ~/fwu-tool/fwu-tool -h |
| 449 | Usage: fwu disk-filename [-dir -meta] [-boot-index number -meta-ver number] [-img filename -img-type uuid] |
Julian Hall | 7af7f90 | 2023-02-16 11:07:32 +0000 | [diff] [blame] | 450 | |
Gyorgy Szing | 0accdf7 | 2023-04-13 01:55:22 +0200 | [diff] [blame] | 451 | disk-filename Disk image file to update |
| 452 | -dir Print image directory |
| 453 | -meta Print FWU metadata |
| 454 | -boot-index Override default boot index [0..n] |
| 455 | -meta-ver Specify FWU metadata to use |
| 456 | -img File containing image update |
| 457 | -img-type Canonical UUID of image to update |
Julian Hall | 7af7f90 | 2023-02-16 11:07:32 +0000 | [diff] [blame] | 458 | |
Gyorgy Szing | 0accdf7 | 2023-04-13 01:55:22 +0200 | [diff] [blame] | 459 | Some sample disk image files can be found under ``components/media/disk/disk_images`` |
| 460 | |
| 461 | The sample disk image file *multi_location_fw.img* includes a GPT with entries for the firmware |
Julian Hall | 7af7f90 | 2023-02-16 11:07:32 +0000 | [diff] [blame] | 462 | and metadata partitions illustrated in the diagram above. Note that the sample disk image |
| 463 | does not contain valid FWU metadata within the primary and backup metadata partitions. This |
| 464 | condition is detected by the Update Agent which writes valid metadata that reflects the contents |
| 465 | of the disk image file. Subsequent invocations of the app will use the valid metadata previously |
| 466 | written to the disk image. |
| 467 | |
| 468 | The app can of course be used with flash image files created by a firmware build system. |
| 469 | The command-line interface currently restricts updates to consist of just a single image, |
| 470 | identified by an image type UUID. Extending the command-line interface to support multi-image |
| 471 | update transactions is possible by for example adding the capability to process an FMP capsule |
| 472 | file containing multiple images. |
| 473 | |
| 474 | Testing the Update Agent |
| 475 | ------------------------ |
| 476 | FWU components are tested in both native PC and embedded environments. PC based tests use the |
Gyorgy Szing | 0accdf7 | 2023-04-13 01:55:22 +0200 | [diff] [blame] | 477 | *fwu_dut* C++ class to simulate the role of the bootloader and to allow device reboot scenarios |
Julian Hall | 7af7f90 | 2023-02-16 11:07:32 +0000 | [diff] [blame] | 478 | to be recreated. The simulated device-under-test maintains NV storage state through reboots |
| 479 | to mimic real device behaviour. Test components that support PC based testing are summarized |
| 480 | in the following table: |
| 481 | |
| 482 | .. list-table:: |
| 483 | :header-rows: 1 |
| 484 | |
| 485 | * - Component |
| 486 | - Description |
| 487 | - Project Directory |
| 488 | * - *fwu_dut* |
| 489 | - Base class to represent a device-under-test (DUT). Presents an interface used by test |
| 490 | cases that allows for test-case reuse with different fwu_dut specializations. |
| 491 | - components/service/fwu/test/fwu_dut |
| 492 | * - *sim_fwu_dut* |
| 493 | - A specialization of the fwu_dut class that adds bootloader simulation and various |
| 494 | other test support capabilities. |
| 495 | - components/service/fwu/test/fwu_dut/sim |
| 496 | * - *proxy_fwu_dut* |
| 497 | - A specialization of the fwu_dut class that acts as a proxy for the fwu_dut that |
| 498 | actually hosts the Update Agent. |
| 499 | - components/service/fwu/test/fwu_dut/proxy |
| 500 | * - *fwu_client* |
| 501 | - Presents FWU methods (begin_staging, end_staging etc.) for use by test cases. |
| 502 | - components/service/fwu/test/fwu_client |
| 503 | * - *direct_fwu_client* |
| 504 | - An fwu_client that calls Update Agent interface functions directly. |
| 505 | - components/service/fwu/test/fwu_client/direct |
| 506 | * - *remote_fwu_client* |
| 507 | - An fwu_client that makes RPC call requests to invoke Update Agent operations. Call |
| 508 | parameters are serialized using the FWU access protocol. |
| 509 | - components/service/fwu/test/fwu_client/remote |
| 510 | * - *image_directory_checker* |
| 511 | - A test support class that fetches the serialized image directory and provides |
| 512 | methods for checking the fetched content. |
| 513 | - components/service/fwu/test/image_directory_checker |
| 514 | * - *metadata_checker* |
| 515 | - Provides methods to check that the fetched FWU metadata reflects the state expected |
| 516 | by test cases. Decouples test code from the underlying metadata format. Support |
| 517 | for V1 and V2 metadata is provided. |
| 518 | - components/service/fwu/test/metadata_checker |
| 519 | * - *metadata_fetcher* |
| 520 | - Provides an interface for fetching the metadata associated with the DUT. Depending |
| 521 | on the deployment, different strategies for fetching the metadata are needed. |
| 522 | - components/service/fwu/test/metadata_fetcher |
| 523 | |
| 524 | An extensive set of test suites uses the test framework components listed above to test |
Gyorgy Szing | 0accdf7 | 2023-04-13 01:55:22 +0200 | [diff] [blame] | 525 | various update scenarios. The following test suites live under ``components/service/fwu/test/ref_scenarios`` |
Julian Hall | 7af7f90 | 2023-02-16 11:07:32 +0000 | [diff] [blame] | 526 | |
| 527 | .. list-table:: |
| 528 | :header-rows: 1 |
| 529 | |
| 530 | * - Test Suite |
| 531 | - Description |
| 532 | * - *image_directory_tests* |
| 533 | - Tests reading of the image directory via the Update Agent stream interface. |
| 534 | * - *invalid_behaviour_tests* |
| 535 | - Tests to check that invalid requests are rejected with the expected error codes. |
| 536 | * - *oversize_image_tests* |
| 537 | - Tests to check defenses against attempts to install images that are too big for |
| 538 | the available storage. |
| 539 | * - *power_failure_tests* |
| 540 | - Tests recreate power-failure scenarios at various points during an update transaction. |
| 541 | Tests check that a viable set of firmware is always available. |
| 542 | * - *rollback_tests* |
| 543 | - Tests recreate bootloader initiated and update client requested rollback scenarios. |
| 544 | * - *update_scenario_tests* |
| 545 | - Various normal update scenarios with a well-behaved client. |
| 546 | |
| 547 | The test suites list above are included in the following TS test deployments: |
| 548 | |
Gyorgy Szing | 0accdf7 | 2023-04-13 01:55:22 +0200 | [diff] [blame] | 549 | - **component-test** - runs tests in a native PC environment using a *direct_fwu_client*. |
| 550 | - **ts-service-test** - runs tests in a native PC environment using a *remote_fwu_client*. |
Julian Hall | 7af7f90 | 2023-02-16 11:07:32 +0000 | [diff] [blame] | 551 | |
| 552 | Reference Integration Test Environment |
| 553 | -------------------------------------- |
| 554 | The following diagram provides an overview of the planned reference integration and test |
| 555 | environment used for testing on FVP. |
| 556 | |
Gyorgy Szing | 0accdf7 | 2023-04-13 01:55:22 +0200 | [diff] [blame] | 557 | .. image:: ../image/fwu-reference-integration.svg |
Julian Hall | 7af7f90 | 2023-02-16 11:07:32 +0000 | [diff] [blame] | 558 | |
| 559 | -------------- |
| 560 | |
Gyorgy Szing | 0accdf7 | 2023-04-13 01:55:22 +0200 | [diff] [blame] | 561 | _`Arm FWU-A specification`: https://developer.arm.com/documentation/den0118 |
| 562 | |
Julian Hall | 7af7f90 | 2023-02-16 11:07:32 +0000 | [diff] [blame] | 563 | *Copyright (c) 2023, Arm Limited and Contributors. All rights reserved.* |
| 564 | |
| 565 | SPDX-License-Identifier: BSD-3-Clause |