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