blob: 85778413f028aba33fb664c6c7caf87b4e30b444 [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>
8:Status: Draft
9
10.. contents:: Table of Contents
11
12***************************************
13Introduction of Firmware Update service
14***************************************
15The Firmware Update(FWU) service provides the functionality of updating firmware
16images. It provides a standard interface for updating firmware and it is
17platform independent. TF-M defines a shim layer to support cooperation between
18bootloader and FWU service.
19
20This partition supports the following features:
21
22- Query image information
23 Fetch information about the firmware images on the device. This covers the
24 images in the running area and also the staging area.
25- Store image
26 Write a candidate image to its staging area.
27- Validate image
28 Starts the validation of the image.
29- Trigger reboot
30 Trigger a reboot to restart the platform.
31
32**********
33Components
34**********
35The structure of the TF-M Firmware Update service is listed below:
36 +-----------------------------+---------------------------------------------------------------+----------------------------------------------------------------------------------+
37 | **Component name** | **Description** | **Location** |
38 +=============================+===============================================================+==================================================================================+
39 | 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`` |
40 | | the other services available in TF-M. | |
41 +-----------------------------+---------------------------------------------------------------+----------------------------------------------------------------------------------+
42 | NSPE client API interface | This module exports the client API of PSA Firmware Update to | ``./interface/src/tfm_firmware_update_func_api.c`` |
43 | | the NSPE(i.e. to the applications). | ``./interface/src/tfm_firmware_update_ipc_api.c`` |
44 +-----------------------------+---------------------------------------------------------------+----------------------------------------------------------------------------------+
45 | Manifest | The manifest file is a description of the service components | ``./secure_fw/partitions/firmware_update/tfm_firmware_update.yaml`` |
46 | | for both library mode and IPC mode. | |
47 +-----------------------------+---------------------------------------------------------------+----------------------------------------------------------------------------------+
48 | Secure functions and IPC | This module handles all the secure function requests in | ``./secure_fw/partitions/firmware_update/tfm_fwu_req_mngr.c`` |
49 | request handlers | library model and all the service requests in IPC model. | |
50 | | It maitains the image state context and calls the image ID | |
51 | | converter to achieve the firmware update functionalities. | |
52 +-----------------------------+---------------------------------------------------------------+----------------------------------------------------------------------------------+
53 | Image ID Converter | This module converts the image ID between psa_image_id_t, | ``./secure_fw/partitions/firmware_update/tfm_fwu_internal.c`` |
54 | | which is the image ID structure in user interfaces, and | |
55 | | bl_image_id_t which is the image ID structure in bootloader. | |
56 +-----------------------------+---------------------------------------------------------------+----------------------------------------------------------------------------------+
57 | Shim layer between FWU and | This module provides the APIs with the functionality of | ``./secure_fw/partitions/firmware_update/tfm_bootloader_fwu_abstraction.h`` |
58 | bootloader | operating the bootloader to cooperate with the Firmware Update| |
59 | | service | |
60 +-----------------------------+---------------------------------------------------------------+----------------------------------------------------------------------------------+
61 | 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`` |
62 | MCUboot | FWU and bootloader based on MCUboot. | |
63 | | | |
64 +-----------------------------+---------------------------------------------------------------+----------------------------------------------------------------------------------+
65
66***********************
67Service API description
68***********************
David Hu050756f2021-04-13 17:53:01 +080069This service follows the PSA Firmware Update API spec of version 0.7 [1]_.
Sherry Zhang0b9738a2021-01-07 14:26:01 +080070It implements the mandatory interface functions listed in section 5.1 and the
71optional interface ``psa_fwu_accept()``. Please refer to Firmware Update spec
72for the detailed description.
73
74*************************************
75Shim Layer between FWU and bootloader
76*************************************
77The firmware update operations are achieved by calling the shim layer APIs
78between bootloader and FWU.
79
80Shim layer introduction
81=======================
82This shim layer provides the APIs with the functionality of operating the
83bootloader to cooperate with the Firmware Update service. This shim layer
84is decoupled from bootloader implementation. Users can specify a specific
85bootloader by setting ``TFM_FWU_BOOTLOADER_LIB`` build configuration and
86adding the specific build scripts into that file. By default, the MCUboot
87is chosen as the bootloader.
88
89Interfaces of the shim Layer
90============================
91
92fwu_bootloader_init(function)
93-----------------------------
94Prototype
95^^^^^^^^^
96.. code-block:: c
97
98 psa_status_t fwu_bootloader_init(void);
99
100Description
101^^^^^^^^^^^
102Bootloader related initialization for the firmware update, such as reading
103some necessary shared data from the memory if needed.
104
105Parameters
106^^^^^^^^^^
107 N/A
108
109fwu_bootloader_staging_area_init(function)
110------------------------------------------
David Hu050756f2021-04-13 17:53:01 +0800111**Prototype**
112
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800113.. code-block:: c
114
115 psa_status_t fwu_bootloader_staging_area_init(bl_image_id_t bootloader_image_id);
116
David Hu050756f2021-04-13 17:53:01 +0800117**Description**
118
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800119Prepare the staging area of the image with the given ID for image download.
120For example, initialize the staging area, open the flash area, and so on.
121The image will be written into the staging area later.
122
David Hu050756f2021-04-13 17:53:01 +0800123**Parameters**
124
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800125- ``bootloader_image_id``: The identifier of the target image in bootloader.
126
127fwu_bootloader_load_image(function)
128-----------------------------------
David Hu050756f2021-04-13 17:53:01 +0800129**Prototype**
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800130
131.. code-block:: c
132
133 psa_status_t fwu_bootloader_load_image(bl_image_id_t bootloader_image_id,
134 size_t image_offset,
135 const void *block,
136 size_t block_size);
137
David Hu050756f2021-04-13 17:53:01 +0800138**Description**
139
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800140Load the image to its staging area.
141
David Hu050756f2021-04-13 17:53:01 +0800142**Parameters**
143
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800144- ``bootloader_image_id``: The identifier of the target image in bootloader.
145- ``image_offset``: The offset of the image being passed into block, in bytes.
146- ``block``: A buffer containing a block of image data. This might be a complete image or a subset.
147- ``block_size``: Size of block.
148
149fwu_bootloader_install_image(function)
150---------------------------------------------
David Hu050756f2021-04-13 17:53:01 +0800151**Prototype**
152
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800153.. code-block:: c
154
155 psa_status_t fwu_bootloader_install_image(bl_image_id_t bootloader_image_id,
156 bl_image_id_t *dependency,
157 psa_image_version_t *dependency_version);
158
David Hu050756f2021-04-13 17:53:01 +0800159**Description**
160
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800161Check the authenticity and integrity of the image. If a reboot is required to
162complete the check, then mark this image as a candidate so that the next time
163bootloader runs it will take this image as a candidate one to bootup. Return
164the error code PSA_SUCCESS_REBOOT.
165
David Hu050756f2021-04-13 17:53:01 +0800166**Parameters**
167
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800168- ``bootloader_image_id``: The identifier of the target image in bootloader.
169- ``dependency``: Bootloader image ID of dependency if needed.
170- ``dependency_version``: Bootloader image version of dependency if needed.
171
172fwu_bootloader_mark_image_accepted(function)
173--------------------------------------------
David Hu050756f2021-04-13 17:53:01 +0800174**Prototype**
175
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800176.. code-block:: c
177
178 psa_status_t fwu_bootloader_mark_image_accepted(void);
179
David Hu050756f2021-04-13 17:53:01 +0800180**Description**
181
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800182Call this API to mark the running images as permanent/accepted to avoid
183revert when next time bootup. Usually, this API is called after the running
184images have been verified as valid.
185
David Hu050756f2021-04-13 17:53:01 +0800186**Parameters**
187
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800188 N/A
189
190fwu_bootloader_abort(function)
191------------------------------
David Hu050756f2021-04-13 17:53:01 +0800192**Prototype**
193
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800194.. code-block:: c
195
196 psa_status_t fwu_bootloader_abort(void);
197
David Hu050756f2021-04-13 17:53:01 +0800198**Description**
199
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800200Abort the current image download process.
201
David Hu050756f2021-04-13 17:53:01 +0800202**Parameters**
203
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800204 N/A
205
206fwu_bootloader_get_image_info(function)
207---------------------------------------
David Hu050756f2021-04-13 17:53:01 +0800208**Prototype**
209
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800210.. code-block:: c
211
212 psa_status_t fwu_bootloader_get_image_info(bl_image_id_t bootloader_image_id,
213 bool staging_area,
214 tfm_image_info_t *info);
215
David Hu050756f2021-04-13 17:53:01 +0800216**Description**
217
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800218Get the image information of the given bootloader_image_id in the staging area
219or the running area.
220
David Hu050756f2021-04-13 17:53:01 +0800221**Parameters**
222
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800223 - ``bootloader_image_id``: The identifier of the target image in bootloader.
224 - ``active_image``: Indicates image location.
225
226 - ``True``: the running image.
227 - ``False``: the image in the passive(or staging) slot.
228
229 - ``info``: Buffer containing the image information.
230
231******************************************
232Additional shared data between BL2 and SPE
233******************************************
234An additional TLV area "image version" is added into the shared memory between
235BL2 and TF-M. So that the firmware update partition can get the image version.
236Even though the image version information is also included in the ``BOOT RECORD``
237TLV area which is encoded by CBOR, adding a dedicated ``image version`` TLV area
238is preferred to avoid involving the CBOR encoder which can increase the code
239size. The FWU partition will read the shared data at the partition
240initialization.
241
242******************
243Image ID structure
244******************
245The structure of image ID is:
246 image_id[7:0]: slot.
247 image_id[15:8]: image type.
248 image_id[31:16]: specific image ID.
249
250Three image types are defined in this partition.
251- FWU_IMAGE_TYPE_NONSECURE: the non_secure image
252- FWU_IMAGE_TYPE_SECURE: the secure image
253- FWU_IMAGE_TYPE_FULL: the secure + non_secure image
254
255.. Note::
256
257 Currently, images update with dependency is not supported by FWU in multiple image boot.
258
259Macros **FWU_CALCULATE_IMAGE_ID**, **FWU_IMAGE_ID_GET_TYPE** and
260**FWU_IMAGE_ID_GET_SLOT** are dedicated to converting the image id, type, and
261slot. The service users can call these macros to get the image ID.
262
263.. Note::
264
265 The image ID structure, as well as the macros listed here, is TF-M specific implementation.
266
267***********************************
268Benefits Analysis on this Partition
269***********************************
270
271Implement the FWU functionality in the non-secure side
272======================================================
David Hu050756f2021-04-13 17:53:01 +0800273The APIs listed in PSA Firmware Update API spec [1]_ can also be implemented in
274the non-secure side. The library model implementation can be referred to for the
275non-secure side implementation.
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800276
277Pros and Cons for Implementing FWU APIs in Secure Side
278======================================================
279
280Pros
281----
282- It protects the image in the passive or staging area from being tampered with
283 by the NSPE. Otherwise, a malicious actor from NSPE can tamper the image
284 stored in the non-secure area to break image update.
285
286- It protects secure image information from disclosure. In some cases, the
287 non-secure side shall not be permitted to get secure image information.
288
289- It protects the active image from being manipulated by NSPE. Some bootloader
290 supports testing the image. After the image is successfully installed and
291 starts to run, the user should set the image as permanent image if the image
292 passes the test. To achieve this, the area of the active image needs to be
293 accessed. In this case, implementing FWU service in SPE can prevent NSPE
294 from manipulating the active image area.
295
296- On some devices, such as the Arm Musca-B1 board, the passive or staging area
297 is restricted as secure access only. In this case, the FWU partition should
298 be implemented in the secure side.
299
300Cons
301----
302- It increases the image size of the secure image.
303- It increases the execution latency and footprint. Compared to implementing
304 FWU in NSPE directly, calling the Firmware Update APIs which are implemented
305 in the secure side increases the execution latency and footprint.
306- It can increase the attack surface of the secure runtime.
307
308Users can decide whether to call the FWU service in TF-M directly or implement
309the Firmware Update APIs in the non-secure side based on the pros and cons
310analysis above.
311
David Hu050756f2021-04-13 17:53:01 +0800312*********
313Reference
314*********
315
316.. [1] `PSA Firwmare Update API <https://developer.arm.com/documentation/ihi0093/0000/>`_
317
318--------------
319
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800320*Copyright (c) 2021, Arm Limited. All rights reserved.*