blob: 030c0948185fb8280c3a4ffe14d54b9d6df5cd17 [file] [log] [blame]
Sherry Zhang0b9738a2021-01-07 14:26:01 +08001#######################
2Firmware Update Service
3#######################
4
5:Author: Sherry Zhang
6:Organization: Arm Limited
7:Contact: Sherry Zhang <Sherry.Zhang2@arm.com>
Sherry Zhang0b9738a2021-01-07 14:26:01 +08008
9.. contents:: Table of Contents
10
11***************************************
12Introduction of Firmware Update service
13***************************************
14The Firmware Update(FWU) service provides the functionality of updating firmware
15images. It provides a standard interface for updating firmware and it is
16platform independent. TF-M defines a shim layer to support cooperation between
17bootloader and FWU service.
18
19This partition supports the following features:
20
21- Query image information
22 Fetch information about the firmware images on the device. This covers the
23 images in the running area and also the staging area.
24- Store image
25 Write a candidate image to its staging area.
26- Validate image
27 Starts the validation of the image.
28- Trigger reboot
29 Trigger a reboot to restart the platform.
30
31**********
32Components
33**********
34The structure of the TF-M Firmware Update service is listed below:
35 +-----------------------------+---------------------------------------------------------------+----------------------------------------------------------------------------------+
36 | **Component name** | **Description** | **Location** |
37 +=============================+===============================================================+==================================================================================+
38 | SPE client API interface | This module exports the client API of PSA Firmware Update to | ``./secure_fw/partitions/firmware_update/tfm_fwu_secure_api.c`` |
39 | | the other services available in TF-M. | |
40 +-----------------------------+---------------------------------------------------------------+----------------------------------------------------------------------------------+
41 | NSPE client API interface | This module exports the client API of PSA Firmware Update to | ``./interface/src/tfm_firmware_update_func_api.c`` |
42 | | the NSPE(i.e. to the applications). | ``./interface/src/tfm_firmware_update_ipc_api.c`` |
43 +-----------------------------+---------------------------------------------------------------+----------------------------------------------------------------------------------+
44 | Manifest | The manifest file is a description of the service components | ``./secure_fw/partitions/firmware_update/tfm_firmware_update.yaml`` |
45 | | for both library mode and IPC mode. | |
46 +-----------------------------+---------------------------------------------------------------+----------------------------------------------------------------------------------+
47 | Secure functions and IPC | This module handles all the secure function requests in | ``./secure_fw/partitions/firmware_update/tfm_fwu_req_mngr.c`` |
48 | request handlers | library model and all the service requests in IPC model. | |
49 | | It maitains the image state context and calls the image ID | |
50 | | converter to achieve the firmware update functionalities. | |
51 +-----------------------------+---------------------------------------------------------------+----------------------------------------------------------------------------------+
52 | Image ID Converter | This module converts the image ID between psa_image_id_t, | ``./secure_fw/partitions/firmware_update/tfm_fwu_internal.c`` |
53 | | which is the image ID structure in user interfaces, and | |
54 | | bl_image_id_t which is the image ID structure in bootloader. | |
55 +-----------------------------+---------------------------------------------------------------+----------------------------------------------------------------------------------+
56 | Shim layer between FWU and | This module provides the APIs with the functionality of | ``./secure_fw/partitions/firmware_update/tfm_bootloader_fwu_abstraction.h`` |
57 | bootloader | operating the bootloader to cooperate with the Firmware Update| |
58 | | service | |
59 +-----------------------------+---------------------------------------------------------------+----------------------------------------------------------------------------------+
60 | Shim layer example based on | This module is the implementation of the shim layer between | ``./secure_fw/partitions/firmware_update/bootloader/mcuboot/tfm_mcuboot_fwu.c`` |
61 | MCUboot | FWU and bootloader based on MCUboot. | |
62 | | | |
63 +-----------------------------+---------------------------------------------------------------+----------------------------------------------------------------------------------+
64
65***********************
66Service API description
67***********************
David Hu050756f2021-04-13 17:53:01 +080068This service follows the PSA Firmware Update API spec of version 0.7 [1]_.
Sherry Zhang0b9738a2021-01-07 14:26:01 +080069It implements the mandatory interface functions listed in section 5.1 and the
70optional interface ``psa_fwu_accept()``. Please refer to Firmware Update spec
71for the detailed description.
72
73*************************************
74Shim Layer between FWU and bootloader
75*************************************
76The firmware update operations are achieved by calling the shim layer APIs
77between bootloader and FWU.
78
79Shim layer introduction
80=======================
81This shim layer provides the APIs with the functionality of operating the
82bootloader to cooperate with the Firmware Update service. This shim layer
83is decoupled from bootloader implementation. Users can specify a specific
84bootloader by setting ``TFM_FWU_BOOTLOADER_LIB`` build configuration and
85adding the specific build scripts into that file. By default, the MCUboot
86is chosen as the bootloader.
87
88Interfaces of the shim Layer
89============================
90
91fwu_bootloader_init(function)
92-----------------------------
93Prototype
94^^^^^^^^^
95.. code-block:: c
96
97 psa_status_t fwu_bootloader_init(void);
98
99Description
100^^^^^^^^^^^
101Bootloader related initialization for the firmware update, such as reading
102some necessary shared data from the memory if needed.
103
104Parameters
105^^^^^^^^^^
106 N/A
107
108fwu_bootloader_staging_area_init(function)
109------------------------------------------
David Hu050756f2021-04-13 17:53:01 +0800110**Prototype**
111
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800112.. code-block:: c
113
114 psa_status_t fwu_bootloader_staging_area_init(bl_image_id_t bootloader_image_id);
115
David Hu050756f2021-04-13 17:53:01 +0800116**Description**
117
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800118Prepare the staging area of the image with the given ID for image download.
119For example, initialize the staging area, open the flash area, and so on.
120The image will be written into the staging area later.
121
David Hu050756f2021-04-13 17:53:01 +0800122**Parameters**
123
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800124- ``bootloader_image_id``: The identifier of the target image in bootloader.
125
126fwu_bootloader_load_image(function)
127-----------------------------------
David Hu050756f2021-04-13 17:53:01 +0800128**Prototype**
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800129
130.. code-block:: c
131
132 psa_status_t fwu_bootloader_load_image(bl_image_id_t bootloader_image_id,
133 size_t image_offset,
134 const void *block,
135 size_t block_size);
136
David Hu050756f2021-04-13 17:53:01 +0800137**Description**
138
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800139Load the image to its staging area.
140
David Hu050756f2021-04-13 17:53:01 +0800141**Parameters**
142
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800143- ``bootloader_image_id``: The identifier of the target image in bootloader.
144- ``image_offset``: The offset of the image being passed into block, in bytes.
145- ``block``: A buffer containing a block of image data. This might be a complete image or a subset.
146- ``block_size``: Size of block.
147
148fwu_bootloader_install_image(function)
149---------------------------------------------
David Hu050756f2021-04-13 17:53:01 +0800150**Prototype**
151
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800152.. code-block:: c
153
154 psa_status_t fwu_bootloader_install_image(bl_image_id_t bootloader_image_id,
155 bl_image_id_t *dependency,
156 psa_image_version_t *dependency_version);
157
David Hu050756f2021-04-13 17:53:01 +0800158**Description**
159
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800160Check the authenticity and integrity of the image. If a reboot is required to
161complete the check, then mark this image as a candidate so that the next time
162bootloader runs it will take this image as a candidate one to bootup. Return
163the error code PSA_SUCCESS_REBOOT.
164
David Hu050756f2021-04-13 17:53:01 +0800165**Parameters**
166
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800167- ``bootloader_image_id``: The identifier of the target image in bootloader.
168- ``dependency``: Bootloader image ID of dependency if needed.
169- ``dependency_version``: Bootloader image version of dependency if needed.
170
171fwu_bootloader_mark_image_accepted(function)
172--------------------------------------------
David Hu050756f2021-04-13 17:53:01 +0800173**Prototype**
174
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800175.. code-block:: c
176
177 psa_status_t fwu_bootloader_mark_image_accepted(void);
178
David Hu050756f2021-04-13 17:53:01 +0800179**Description**
180
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800181Call this API to mark the running images as permanent/accepted to avoid
182revert when next time bootup. Usually, this API is called after the running
183images have been verified as valid.
184
David Hu050756f2021-04-13 17:53:01 +0800185**Parameters**
186
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800187 N/A
188
189fwu_bootloader_abort(function)
190------------------------------
David Hu050756f2021-04-13 17:53:01 +0800191**Prototype**
192
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800193.. code-block:: c
194
195 psa_status_t fwu_bootloader_abort(void);
196
David Hu050756f2021-04-13 17:53:01 +0800197**Description**
198
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800199Abort the current image download process.
200
David Hu050756f2021-04-13 17:53:01 +0800201**Parameters**
202
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800203 N/A
204
205fwu_bootloader_get_image_info(function)
206---------------------------------------
David Hu050756f2021-04-13 17:53:01 +0800207**Prototype**
208
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800209.. code-block:: c
210
211 psa_status_t fwu_bootloader_get_image_info(bl_image_id_t bootloader_image_id,
212 bool staging_area,
213 tfm_image_info_t *info);
214
David Hu050756f2021-04-13 17:53:01 +0800215**Description**
216
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800217Get the image information of the given bootloader_image_id in the staging area
218or the running area.
219
David Hu050756f2021-04-13 17:53:01 +0800220**Parameters**
221
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800222 - ``bootloader_image_id``: The identifier of the target image in bootloader.
223 - ``active_image``: Indicates image location.
224
225 - ``True``: the running image.
226 - ``False``: the image in the passive(or staging) slot.
227
228 - ``info``: Buffer containing the image information.
229
230******************************************
231Additional shared data between BL2 and SPE
232******************************************
233An additional TLV area "image version" is added into the shared memory between
234BL2 and TF-M. So that the firmware update partition can get the image version.
235Even though the image version information is also included in the ``BOOT RECORD``
236TLV area which is encoded by CBOR, adding a dedicated ``image version`` TLV area
237is preferred to avoid involving the CBOR encoder which can increase the code
238size. The FWU partition will read the shared data at the partition
239initialization.
240
241******************
242Image ID structure
243******************
244The structure of image ID is:
245 image_id[7:0]: slot.
246 image_id[15:8]: image type.
247 image_id[31:16]: specific image ID.
248
249Three image types are defined in this partition.
250- FWU_IMAGE_TYPE_NONSECURE: the non_secure image
251- FWU_IMAGE_TYPE_SECURE: the secure image
252- FWU_IMAGE_TYPE_FULL: the secure + non_secure image
253
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800254Macros **FWU_CALCULATE_IMAGE_ID**, **FWU_IMAGE_ID_GET_TYPE** and
255**FWU_IMAGE_ID_GET_SLOT** are dedicated to converting the image id, type, and
256slot. The service users can call these macros to get the image ID.
257
258.. Note::
259
260 The image ID structure, as well as the macros listed here, is TF-M specific implementation.
261
262***********************************
263Benefits Analysis on this Partition
264***********************************
265
266Implement the FWU functionality in the non-secure side
267======================================================
David Hu050756f2021-04-13 17:53:01 +0800268The APIs listed in PSA Firmware Update API spec [1]_ can also be implemented in
269the non-secure side. The library model implementation can be referred to for the
270non-secure side implementation.
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800271
272Pros and Cons for Implementing FWU APIs in Secure Side
273======================================================
274
275Pros
276----
277- It protects the image in the passive or staging area from being tampered with
278 by the NSPE. Otherwise, a malicious actor from NSPE can tamper the image
279 stored in the non-secure area to break image update.
280
281- It protects secure image information from disclosure. In some cases, the
282 non-secure side shall not be permitted to get secure image information.
283
284- It protects the active image from being manipulated by NSPE. Some bootloader
285 supports testing the image. After the image is successfully installed and
286 starts to run, the user should set the image as permanent image if the image
287 passes the test. To achieve this, the area of the active image needs to be
288 accessed. In this case, implementing FWU service in SPE can prevent NSPE
289 from manipulating the active image area.
290
291- On some devices, such as the Arm Musca-B1 board, the passive or staging area
292 is restricted as secure access only. In this case, the FWU partition should
293 be implemented in the secure side.
294
295Cons
296----
297- It increases the image size of the secure image.
298- It increases the execution latency and footprint. Compared to implementing
299 FWU in NSPE directly, calling the Firmware Update APIs which are implemented
300 in the secure side increases the execution latency and footprint.
301- It can increase the attack surface of the secure runtime.
302
303Users can decide whether to call the FWU service in TF-M directly or implement
304the Firmware Update APIs in the non-secure side based on the pros and cons
305analysis above.
306
David Hu050756f2021-04-13 17:53:01 +0800307*********
308Reference
309*********
310
311.. [1] `PSA Firwmare Update API <https://developer.arm.com/documentation/ihi0093/0000/>`_
312
313--------------
314
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800315*Copyright (c) 2021, Arm Limited. All rights reserved.*