blob: ca543dc913a610ad48d461977728d99c4aea809b [file] [log] [blame]
Sherry Zhang0b9738a2021-01-07 14:26:01 +08001#######################
2Firmware Update Service
3#######################
4
5:Author: Sherry Zhang
6:Organization: Arm Limited
Sherry Zhang0b9738a2021-01-07 14:26:01 +08007
8.. contents:: Table of Contents
Anton Komlev3ae2ac32023-01-03 14:56:47 +00009 :depth: 3
Sherry Zhang0b9738a2021-01-07 14:26:01 +080010
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
Sherry Zhang71468952022-10-19 14:09:05 +080021- Query the firmware store information.
22- Image preparation: prepare a new firmware image in the component's firmware store.
23- Image installation: install prepared firmware images on all components that have been prepared for installation.
24- Image trial: manage a trial of new firmware images atomically on all components that are in TRIAL state.
25
26A typical flow through the component states is shown below [1]_.
27
Anton Komlevb3f64662023-01-28 11:53:05 +000028.. figure:: /design_docs/media/fwu-states.svg
Sherry Zhang71468952022-10-19 14:09:05 +080029 :scale: 65 %
30 :align: center
31 :name: The component state model transitions.
Sherry Zhang0b9738a2021-01-07 14:26:01 +080032
33**********
34Components
35**********
36The structure of the TF-M Firmware Update service is listed below:
Anton Komlev525ee342021-10-19 16:09:31 +010037 +-----------------------------+---------------------------------------------------------------+---------------------------------------------------------------------------------------+
38 | **Component name** | **Description** | **Location** |
39 +=============================+===============================================================+=======================================================================================+
Summer Qin2db78c82022-10-10 17:17:44 +080040 | Client API interface | This module exports the client API of PSA Firmware Update to | ``./interface/src/tfm_fwu_api.c`` |
41 | | the users. | |
Anton Komlev525ee342021-10-19 16:09:31 +010042 +-----------------------------+---------------------------------------------------------------+---------------------------------------------------------------------------------------+
Summer Qin2db78c82022-10-10 17:17:44 +080043 | Manifest | The manifest file is a description of the service components. | ``./secure_fw/partitions/firmware_update/tfm_firmware_update.yaml`` |
Anton Komlev525ee342021-10-19 16:09:31 +010044 +-----------------------------+---------------------------------------------------------------+---------------------------------------------------------------------------------------+
Sherry Zhang71468952022-10-19 14:09:05 +080045 | NSPE client API interface | This module exports the client API of PSA Firmware Update to | ``./interface/src/tfm_fwu_api.c`` |
46 | | the NSPE(i.e. to the applications). | |
47 +-----------------------------+---------------------------------------------------------------+---------------------------------------------------------------------------------------+
Summer Qin2db78c82022-10-10 17:17:44 +080048 | IPC request handlers | This module handles all the secure requests in IPC model. | ``./secure_fw/partitions/firmware_update/tfm_fwu_req_mngr.c`` |
Antonio de Angelis9d496a52025-01-07 21:18:00 +000049 | | It maintains the image state context and calls the image ID | |
Anton Komlev525ee342021-10-19 16:09:31 +010050 | | converter to achieve the firmware update functionalities. | |
51 +-----------------------------+---------------------------------------------------------------+---------------------------------------------------------------------------------------+
Anton Komlev525ee342021-10-19 16:09:31 +010052 | Shim layer between FWU and | This module provides the APIs with the functionality of | ``./secure_fw/partitions/firmware_update/bootloader/tfm_bootloader_fwu_abstraction.h``|
53 | bootloader | operating the bootloader to cooperate with the Firmware Update| |
54 | | service | |
55 +-----------------------------+---------------------------------------------------------------+---------------------------------------------------------------------------------------+
56 | 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`` |
57 | MCUboot | FWU and bootloader based on MCUboot. | |
58 | | | |
59 +-----------------------------+---------------------------------------------------------------+---------------------------------------------------------------------------------------+
Sherry Zhang0b9738a2021-01-07 14:26:01 +080060
61***********************
62Service API description
63***********************
Sherry Zhang71468952022-10-19 14:09:05 +080064This service follows the PSA Firmware Update API spec of version 1.0 [1]_. Please refer to
65Firmware Update spec for the detailed description.
Sherry Zhang0b9738a2021-01-07 14:26:01 +080066
67*************************************
68Shim Layer between FWU and bootloader
69*************************************
70The firmware update operations are achieved by calling the shim layer APIs
71between bootloader and FWU.
72
73Shim layer introduction
74=======================
75This shim layer provides the APIs with the functionality of operating the
76bootloader to cooperate with the Firmware Update service. This shim layer
77is decoupled from bootloader implementation. Users can specify a specific
78bootloader by setting ``TFM_FWU_BOOTLOADER_LIB`` build configuration and
79adding the specific build scripts into that file. By default, the MCUboot
80is chosen as the bootloader.
81
82Interfaces of the shim Layer
83============================
84
85fwu_bootloader_init(function)
86-----------------------------
87Prototype
88^^^^^^^^^
89.. code-block:: c
90
91 psa_status_t fwu_bootloader_init(void);
92
93Description
94^^^^^^^^^^^
Michel Jaouen0a06eb32022-04-22 14:38:06 +020095Bootloader related initialization for the firmware update. It reads
96some necessary shared data from the memory if needed. It initializes
97the flash drivers defined in FLASH_DRIVER_LIST. Platform can define
98FLASH_DRIVER_LIST in flash_layout.h to overload the default driver list.
Sherry Zhang0b9738a2021-01-07 14:26:01 +080099
100Parameters
101^^^^^^^^^^
102 N/A
103
104fwu_bootloader_staging_area_init(function)
105------------------------------------------
David Hu050756f2021-04-13 17:53:01 +0800106**Prototype**
107
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800108.. code-block:: c
109
Sherry Zhang71468952022-10-19 14:09:05 +0800110 psa_status_t fwu_bootloader_staging_area_init(psa_fwu_component_t component,
111 const void *manifest,
112 size_t manifest_size);
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800113
David Hu050756f2021-04-13 17:53:01 +0800114**Description**
115
Sherry Zhang71468952022-10-19 14:09:05 +0800116The component is in READY state. Prepare the staging area of the component for image download.
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800117For example, initialize the staging area, open the flash area, and so on.
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800118
David Hu050756f2021-04-13 17:53:01 +0800119**Parameters**
120
Sherry Zhang71468952022-10-19 14:09:05 +0800121- ``component``: The identifier of the target component in bootloader.
122- ``manifest``: A pointer to a buffer containing a detached manifest for the update.
123 If the manifest is bundled with the firmware image, manifest must be NULL.
124- ``manifest_size``: Size of the manifest buffer in bytes.
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800125
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
Sherry Zhang71468952022-10-19 14:09:05 +0800132 psa_status_t fwu_bootloader_load_image(psa_fwu_component_t component,
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800133 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 Zhang71468952022-10-19 14:09:05 +0800139Load the image into the target component.
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800140
David Hu050756f2021-04-13 17:53:01 +0800141**Parameters**
142
Sherry Zhang71468952022-10-19 14:09:05 +0800143- ``component``: The identifier of the target component in bootloader.
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800144- ``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
Sherry Zhang71468952022-10-19 14:09:05 +0800154 psa_status_t fwu_bootloader_install_image(psa_fwu_component_t *candidates,
155 uint8_t number);
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800156
David Hu050756f2021-04-13 17:53:01 +0800157**Description**
158
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800159Check the authenticity and integrity of the image. If a reboot is required to
160complete the check, then mark this image as a candidate so that the next time
Antonio de Angelis9d496a52025-01-07 21:18:00 +0000161bootloader runs it will take this image as a candidate one to boot-up. Return
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800162the error code PSA_SUCCESS_REBOOT.
163
David Hu050756f2021-04-13 17:53:01 +0800164**Parameters**
165
Sherry Zhang71468952022-10-19 14:09:05 +0800166- ``candidates``: A list of components in CANDIDATE state.
167- ``number``: Number of components in CANDIDATE state.
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800168
169fwu_bootloader_mark_image_accepted(function)
170--------------------------------------------
David Hu050756f2021-04-13 17:53:01 +0800171**Prototype**
172
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800173.. code-block:: c
174
Sherry Zhang71468952022-10-19 14:09:05 +0800175 psa_status_t fwu_bootloader_mark_image_accepted(const psa_fwu_component_t *trials,
176 uint8_t number);
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800177
David Hu050756f2021-04-13 17:53:01 +0800178**Description**
179
Sherry Zhang71468952022-10-19 14:09:05 +0800180Call this API to mark the TRIAL(running) image in component as confirmed to avoid
Antonio de Angelis9d496a52025-01-07 21:18:00 +0000181revert when next time boot-up. Usually, this API is called after the running
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800182images have been verified as valid.
183
David Hu050756f2021-04-13 17:53:01 +0800184**Parameters**
185
Sherry Zhang71468952022-10-19 14:09:05 +0800186- ``trials``: A list of components in TRIAL state.
187- ``number``: Number of components in TRIAL state.
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800188
Sherry Zhang71468952022-10-19 14:09:05 +0800189fwu_bootloader_reject_staged_image(function)
190--------------------------------------------
David Hu050756f2021-04-13 17:53:01 +0800191**Prototype**
192
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800193.. code-block:: c
194
Sherry Zhang71468952022-10-19 14:09:05 +0800195 psa_status_t fwu_bootloader_reject_staged_image(psa_fwu_component_t component);
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800196
David Hu050756f2021-04-13 17:53:01 +0800197**Description**
198
Sherry Zhang71468952022-10-19 14:09:05 +0800199The component is in STAGED state. Call this API to Uninstall the staged image in the
Antonio de Angelis9d496a52025-01-07 21:18:00 +0000200component so that this image will not be treated as a candidate next time boot-up.
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800201
David Hu050756f2021-04-13 17:53:01 +0800202**Parameters**
203
Sherry Zhang71468952022-10-19 14:09:05 +0800204- ``component``: The identifier of the target component in bootloader.
205
206fwu_bootloader_reject_trial_image(function)
207--------------------------------------------
208**Prototype**
209
210.. code-block:: c
211
212 psa_status_t fwu_bootloader_reject_trial_image(psa_fwu_component_t component);
213
214**Description**
215
216The component is in TRIAL state. Mark the running image in the component as rejected.
217
218**Parameters**
219
220- ``component``: The identifier of the target component in bootloader.
221
222fwu_bootloader_clean_component(function)
223----------------------------------------
224**Prototype**
225
226.. code-block:: c
227
228 psa_status_t fwu_bootloader_clean_component(psa_fwu_component_t component);
229
230**Description**
231
232The component is in FAILED or UPDATED state. Clean the staging area of the component.
233
234**Parameters**
235
236- ``component``: The identifier of the target component in bootloader.
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800237
238fwu_bootloader_get_image_info(function)
239---------------------------------------
David Hu050756f2021-04-13 17:53:01 +0800240**Prototype**
241
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800242.. code-block:: c
243
Sherry Zhang71468952022-10-19 14:09:05 +0800244 psa_status_t fwu_bootloader_get_image_info(psa_fwu_component_t component,
245 bool query_state,
246 bool query_impl_info,
247 psa_fwu_component_info_t *info);
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800248
David Hu050756f2021-04-13 17:53:01 +0800249**Description**
250
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800251Get the image information of the given bootloader_image_id in the staging area
252or the running area.
253
David Hu050756f2021-04-13 17:53:01 +0800254**Parameters**
255
Sherry Zhang71468952022-10-19 14:09:05 +0800256 - ``component``: The identifier of the target component in bootloader.
257 - ``query_state``: Whether query the 'state' field of psa_fwu_component_info_t.
258 - ``query_impl_info``: Whether Query 'impl' field of psa_fwu_component_info_t.
259 - ``info``: Buffer containing return the component information.
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800260
261******************************************
262Additional shared data between BL2 and SPE
263******************************************
264An additional TLV area "image version" is added into the shared memory between
265BL2 and TF-M. So that the firmware update partition can get the image version.
266Even though the image version information is also included in the ``BOOT RECORD``
267TLV area which is encoded by CBOR, adding a dedicated ``image version`` TLV area
268is preferred to avoid involving the CBOR encoder which can increase the code
269size. The FWU partition will read the shared data at the partition
270initialization.
271
Sherry Zhang71468952022-10-19 14:09:05 +0800272*********************************************
273Build configurations related to FWU partition
274*********************************************
275- ``TFM_PARTITION_FIRMWARE_UPDATE`` Controls whether FWU partition is enabled or not.
276- ``TFM_FWU_BOOTLOADER_LIB`` Bootloader configure file for FWU partition.
277- ``TFM_CONFIG_FWU_MAX_WRITE_SIZE`` The maximum permitted size for block in psa_fwu_write, in bytes.
278- ``TFM_FWU_BUF_SIZE`` Size of the FWU internal data transfer buffer (defaults to
279 TFM_CONFIG_FWU_MAX_WRITE_SIZE if not set).
280- ``FWU_STACK_SIZE`` The stack size of FWU Partition.
281- ``FWU_DEVICE_CONFIG_FILE`` The device configuration file for FWU partition. The default value is
282 the configuration file generated for MCUboot. The following macros should be defined in the
283 configuration file:
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800284
Sherry Zhang71468952022-10-19 14:09:05 +0800285 - ``FWU_COMPONENT_NUMBER`` The number of components on the device.
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800286
Sherry Zhang71468952022-10-19 14:09:05 +0800287 .. Note::
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800288
Sherry Zhang71468952022-10-19 14:09:05 +0800289 In this design, component ID ranges from 0 to ``FWU_COMPONENT_NUMBER`` - 1.
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800290
Sherry Zhang71468952022-10-19 14:09:05 +0800291 - ``FWU_SUPPORT_TRIAL_STATE`` Whether TRIAL component state is supported.
292- ``TEST_NS_FWU`` FWU nonsecure tests switch.
293- ``TEST_S_FWU`` FWU secure tests switch.
294
295 .. Note::
296
297 The running image which supports revert mechanism should be confirmed before initiating a
298 firmware update process. For example, if the running image is built with
299 ``-DMCUBOOT_UPGRADE_STRATEGY=SWAP_USING_MOVE``, the image should be confirmed either by
300 adding ``-DMCUBOOT_CONFIRM_IMAGE=ON`` build option or by calling ``psa_fwu_accept()`` API
301 before initiating a firmware update process. Otherwise, ``PSA_ERROR_BAD_STATE`` will be
302 returned by ``psa_fwu_start()``.
303
304*************************************
305Limitations of current implementation
306*************************************
307Currently, the MCUboot based implementation does not record image update results like failure or
308success. And FWU partition does not detect failure errors in bootloader installation. If an image
309installation fails in the bootloader and the old image still runs after reboot, ``PSA_FWU_READY``
310state will be returned by ``psa_fwu_query()`` after reboot.
311
312Currently, image download recovery after a reboot is not supported. If a reboot happens in image
313preparation, the downloaded image data will be ignored after the reboot.
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800314
315***********************************
316Benefits Analysis on this Partition
317***********************************
318
319Implement the FWU functionality in the non-secure side
320======================================================
David Hu050756f2021-04-13 17:53:01 +0800321The APIs listed in PSA Firmware Update API spec [1]_ can also be implemented in
Summer Qin2db78c82022-10-10 17:17:44 +0800322the non-secure side.
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800323
Sherry Zhang71468952022-10-19 14:09:05 +0800324Pros and Cons for implementing FWU APIs in secure side
Sherry Zhang0b9738a2021-01-07 14:26:01 +0800325======================================================
326
327Pros
328----
329- It protects the image in the passive or staging area from being tampered with
330 by the NSPE. Otherwise, a malicious actor from NSPE can tamper the image
331 stored in the non-secure area to break image update.
332
333- It protects secure image information from disclosure. In some cases, the
334 non-secure side shall not be permitted to get secure image information.
335
336- It protects the active image from being manipulated by NSPE. Some bootloader
337 supports testing the image. After the image is successfully installed and
338 starts to run, the user should set the image as permanent image if the image
339 passes the test. To achieve this, the area of the active image needs to be
340 accessed. In this case, implementing FWU service in SPE can prevent NSPE
341 from manipulating the active image area.
342
343- On some devices, such as the Arm Musca-B1 board, the passive or staging area
344 is restricted as secure access only. In this case, the FWU partition should
345 be implemented in the secure side.
346
347Cons
348----
349- It increases the image size of the secure image.
350- It increases the execution latency and footprint. Compared to implementing
351 FWU in NSPE directly, calling the Firmware Update APIs which are implemented
352 in the secure side increases the execution latency and footprint.
353- It can increase the attack surface of the secure runtime.
354
355Users can decide whether to call the FWU service in TF-M directly or implement
356the Firmware Update APIs in the non-secure side based on the pros and cons
357analysis above.
358
David Hu050756f2021-04-13 17:53:01 +0800359*********
360Reference
361*********
362
Antonio de Angelis9d496a52025-01-07 21:18:00 +0000363.. [1] `PSA Firmware Update API <https://arm-software.github.io/psa-api/fwu/1.0/>`_
David Hu050756f2021-04-13 17:53:01 +0800364
365--------------
366
Summer Qin2db78c82022-10-10 17:17:44 +0800367*Copyright (c) 2021-2022, Arm Limited. All rights reserved.*