Sughosh Ganu | b08b857 | 2022-10-21 18:16:08 +0530 | [diff] [blame] | 1 | .. SPDX-License-Identifier: GPL-2.0+ |
| 2 | .. Copyright (c) 2022 Linaro Limited |
| 3 | |
| 4 | FWU Multi Bank Updates in U-Boot |
| 5 | ================================ |
| 6 | |
| 7 | The FWU Multi Bank Update feature implements the firmware update |
| 8 | mechanism described in the PSA Firmware Update for A-profile Arm |
| 9 | Architecture specification [1]. Certain aspects of the Dependable |
| 10 | Boot specification [2] are also implemented. The feature provides a |
| 11 | mechanism to have multiple banks of updatable firmware images and for |
| 12 | updating the firmware images on the non-booted bank. On a successful |
| 13 | update, the platform boots from the updated bank on subsequent |
| 14 | boot. The UEFI capsule-on-disk update feature is used for performing |
| 15 | the actual updates of the updatable firmware images. |
| 16 | |
| 17 | The bookkeeping of the updatable images is done through a structure |
| 18 | called metadata. Currently, the FWU metadata supports identification |
| 19 | of images based on image GUIDs stored on a GPT partitioned storage |
| 20 | media. There are plans to extend the metadata structure for non GPT |
| 21 | partitioned devices as well. |
| 22 | |
| 23 | Accessing the FWU metadata is done through generic API's which are |
| 24 | defined in a driver which complies with the U-Boot's driver model. A |
| 25 | new uclass UCLASS_FWU_MDATA has been added for accessing the FWU |
| 26 | metadata. Individual drivers can be added based on the type of storage |
| 27 | media, and its partitioning method. Details of the storage device |
| 28 | containing the FWU metadata partitions are specified through a U-Boot |
| 29 | specific device tree property `fwu-mdata-store`. Please refer to |
Vincent Stehlé | ecf2151 | 2023-02-20 15:37:29 +0100 | [diff] [blame] | 30 | U-Boot :download:`fwu-mdata-gpt.yaml |
| 31 | </device-tree-bindings/firmware/fwu-mdata-gpt.yaml>` |
Sughosh Ganu | b08b857 | 2022-10-21 18:16:08 +0530 | [diff] [blame] | 32 | for the device tree bindings. |
| 33 | |
| 34 | Enabling the FWU Multi Bank Update feature |
| 35 | ------------------------------------------ |
| 36 | |
| 37 | The feature can be enabled by specifying the following configs:: |
| 38 | |
| 39 | CONFIG_EFI_CAPSULE_ON_DISK=y |
| 40 | CONFIG_EFI_CAPSULE_FIRMWARE_MANAGEMENT=y |
| 41 | CONFIG_EFI_CAPSULE_FIRMWARE_RAW=y |
| 42 | |
| 43 | CONFIG_FWU_MULTI_BANK_UPDATE=y |
| 44 | CONFIG_FWU_MDATA=y |
| 45 | CONFIG_FWU_MDATA_GPT_BLK=y |
| 46 | CONFIG_FWU_NUM_BANKS=<val> |
| 47 | CONFIG_FWU_NUM_IMAGES_PER_BANK=<val> |
| 48 | |
Sughosh Ganu | 4e6f8d8 | 2024-03-22 16:27:31 +0530 | [diff] [blame] | 49 | CONFIG_FWU_MDATA_V1=y or CONFIG_FWU_MDATA_V2=y |
| 50 | |
Sughosh Ganu | b08b857 | 2022-10-21 18:16:08 +0530 | [diff] [blame] | 51 | in the .config file |
| 52 | |
| 53 | By enabling the CONFIG_CMD_FWU_METADATA config option, the |
| 54 | fwu_mdata_read command can be used to check the current state of the |
| 55 | FWU metadata structure. |
| 56 | |
| 57 | The first group of configuration settings enable the UEFI |
| 58 | capsule-on-disk update functionality. The second group of configs |
| 59 | enable the FWU Multi Bank Update functionality. Please refer to the |
| 60 | section :ref:`uefi_capsule_update_ref` for more details on generation |
| 61 | of the UEFI capsule. |
| 62 | |
Sughosh Ganu | 4e6f8d8 | 2024-03-22 16:27:31 +0530 | [diff] [blame] | 63 | FWU Metadata |
| 64 | ------------ |
| 65 | |
| 66 | U-Boot supports both versions(1 and 2) of the FWU metadata defined in |
| 67 | the two revisions of the specification. Support can be enabled for |
| 68 | either of the two versions through a config flag. The mkfwumdata tool |
| 69 | can generate metadata for both the supported versions. |
| 70 | |
Sughosh Ganu | b08b857 | 2022-10-21 18:16:08 +0530 | [diff] [blame] | 71 | Setting up the device for GPT partitioned storage |
| 72 | ------------------------------------------------- |
| 73 | |
| 74 | Before enabling the functionality in U-Boot, a GPT partitioned storage |
| 75 | device is required. Assuming a GPT partitioned storage device, the |
| 76 | storage media needs to be partitioned with the correct number of |
| 77 | partitions, given the number of banks and number of images per bank |
| 78 | that the platform is going to support. Each updatable firmware image |
| 79 | will be stored on a separate partition. In addition, the two copies |
| 80 | of the FWU metadata will be stored on two separate partitions. These |
| 81 | partitions need to be created at the time of the platform's |
| 82 | provisioning. |
| 83 | |
| 84 | As an example, a platform supporting two banks with each bank |
| 85 | containing three images would need to have 2 * 3 = 6 partitions plus |
| 86 | the two metadata partitions, or 8 partitions. In addition the storage |
| 87 | media can have additional partitions of non-updatable images, like the |
| 88 | EFI System Partition(ESP), a partition for the root file system |
| 89 | etc. An example list of images on the storage medium would be |
| 90 | |
| 91 | * FWU metadata 1 |
| 92 | * U-Boot 1 |
| 93 | * OP-TEE 1 |
| 94 | * FWU metadata 2 |
| 95 | * OP-TEE 2 |
| 96 | * U-Boot 2 |
| 97 | * ESP |
| 98 | * rootfs |
| 99 | |
| 100 | When generating the partitions, a few aspects need to be taken care |
| 101 | of. Each GPT partition entry in the GPT header has two GUIDs:: |
| 102 | |
| 103 | * PartitionTypeGUID |
| 104 | * UniquePartitionGUID |
| 105 | |
| 106 | The PartitionTypeGUID value should correspond to the |
Sughosh Ganu | 4e6f8d8 | 2024-03-22 16:27:31 +0530 | [diff] [blame] | 107 | ``image_type_guid`` field of the FWU metadata. This field is used to |
Sughosh Ganu | b08b857 | 2022-10-21 18:16:08 +0530 | [diff] [blame] | 108 | identify a given type of updatable firmware image, e.g. U-Boot, |
| 109 | OP-TEE, FIP etc. This GUID should also be used for specifying the |
| 110 | `--guid` parameter when generating the capsule. |
| 111 | |
Sughosh Ganu | 4e6f8d8 | 2024-03-22 16:27:31 +0530 | [diff] [blame] | 112 | The UniquePartitionGUID value should correspond to the ``image_guid`` |
Sughosh Ganu | b08b857 | 2022-10-21 18:16:08 +0530 | [diff] [blame] | 113 | field in the FWU metadata. This GUID is used to identify images of a |
| 114 | given image type in different banks. |
| 115 | |
| 116 | The FWU specification defines the GUID value to be used for the |
| 117 | metadata partitions. This would be the PartitionTypeGUID for the |
| 118 | metadata partitions. Similarly, the UEFI specification defines the ESP |
| 119 | GUID to be be used. |
| 120 | |
Sughosh Ganu | 4e6f8d8 | 2024-03-22 16:27:31 +0530 | [diff] [blame] | 121 | When generating the metadata, the ``image_type_guid`` and the |
| 122 | ``image_guid`` values should match the *PartitionTypeGUID* and the |
Sughosh Ganu | b08b857 | 2022-10-21 18:16:08 +0530 | [diff] [blame] | 123 | *UniquePartitionGUID* values respectively. |
| 124 | |
| 125 | Performing the Update |
| 126 | --------------------- |
| 127 | |
| 128 | Once the storage media has been partitioned and populated with the |
| 129 | metadata partitions, the UEFI capsule-on-disk update functionality can |
| 130 | be used for performing the update. Refer to the section |
| 131 | :ref:`uefi_capsule_update_ref` for details on how the update can be |
| 132 | invoked. |
| 133 | |
| 134 | On a successful update, the FWU metadata gets updated to reflect the |
| 135 | bank from which the platform would be booting on subsequent boot. |
| 136 | |
| 137 | Based on the value of bit15 of the Flags member of the capsule header, |
| 138 | the updated images would either be accepted by the U-Boot's UEFI |
| 139 | implementation, or by the Operating System. If the Operating System is |
| 140 | accepting the firmware images, it does so by generating an empty |
| 141 | *accept* capsule. The Operating System can also reject the updated |
| 142 | firmware by generating a *revert* capsule. The empty capsule can be |
| 143 | applied by using the exact same procedure used for performing the |
| 144 | capsule-on-disk update. |
| 145 | |
| 146 | The task of accepting the different firmware images, post an update |
| 147 | may be done by multiple, separate components in the Operating |
| 148 | System. To help identify the firmware image that is being accepted, |
| 149 | the accept capsule passes the image GUID of the firmware image being |
| 150 | accepted. The relevant code in U-Boot then sets the Accept bit of the |
| 151 | corresponding firmware image for which the accept capsule was |
| 152 | found. Only when all the firmware components in a bank have been |
| 153 | accepted does the platform transition from trial state to regular |
| 154 | state. |
| 155 | |
| 156 | The revert capsule on the other hand does not pass any image GUID, |
| 157 | since reverting any image of the bank has the same result of the |
| 158 | platform booting from the other bank on subsequent boot. |
| 159 | |
| 160 | In the scenario that bit15 of the Flags member of the capsule header |
| 161 | has not been set, the images being updated are accepted by the |
| 162 | U-Boot's UEFI firmware implementation by default, on successful |
| 163 | update of the image. |
| 164 | |
| 165 | Generating an empty capsule |
| 166 | --------------------------- |
| 167 | |
| 168 | The empty capsule can be generated using the mkeficapsule utility. To |
| 169 | build the tool, enable:: |
| 170 | |
| 171 | CONFIG_TOOLS_MKEFICAPSULE=y |
| 172 | |
| 173 | Run the following commands to generate the accept/revert capsules:: |
| 174 | |
| 175 | .. code-block:: bash |
| 176 | |
| 177 | $ ./tools/mkeficapsule \ |
| 178 | [--fw-accept --guid <image guid>] | \ |
| 179 | [--fw-revert] \ |
| 180 | <capsule_file_name> |
| 181 | |
| 182 | Some examples of using the mkeficapsule tool for generation of the |
| 183 | empty capsule would be:: |
| 184 | |
| 185 | .. code-block:: bash |
| 186 | |
| 187 | $ ./tools/mkeficapsule --fw-accept --guid <image guid> \ |
| 188 | <accept_capsule_name> |
| 189 | $ ./tools/mkeficapsule --fw-revert <revert_capsule_name> |
| 190 | |
| 191 | Links |
| 192 | ----- |
| 193 | |
Sughosh Ganu | 4e6f8d8 | 2024-03-22 16:27:31 +0530 | [diff] [blame] | 194 | * [1] https://developer.arm.com/documentation/den0118/ - FWU Specification |
Sughosh Ganu | b08b857 | 2022-10-21 18:16:08 +0530 | [diff] [blame] | 195 | * [2] https://git.codelinaro.org/linaro/dependable-boot/mbfw/uploads/6f7ddfe3be24e18d4319e108a758d02e/mbfw.pdf - Dependable Boot Specification |