blob: a10d7d3c04d02c6d89db522839c98c9d5bbc1c3c [file] [log] [blame]
Gyorgy Szingdb9783c2019-04-17 21:08:48 +02001##############################
2Trusted Firmware M secure boot
3##############################
4For secure devices it is security critical to enforce firmware authenticity to
5protect against execution of malicious software. This is implemented by building
6a trust chain where each step in the execution chain authenticates the next
7step before execution. The chain of trust in based on a "Root of Trust" which
8is implemented using asymmetric cryptography. The Root of Trust is a combination
9of an immutable bootloader and a public key (ROTPK).
10
11*******************************
12Second stage bootloader in TF-M
13*******************************
14To implement secure boot functionality an external project MCUBoot has been
15integrated to TF-M. For further information please refer to the
David Vincze8a2a4e22019-05-24 10:14:23 +020016`MCUBoot homepage <https://www.mcuboot.com/>`__. Original source-code is
17available at `GitHub <https://github.com/JuulLabs-OSS/mcuboot>`__. This document
18contains information about MCUBoot modifications and how MCUBoot has been
19integrated to TF-M.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020020
21Bootloader is started when CPU is released from reset. It runs in secure mode.
22It authenticates the firmware image by hash (SHA-256) and digital signature
David Vincze9c609012019-08-22 13:37:21 +020023(RSA-3072) validation. Public key, that the checks happens against, can be built
24into the bootloader image or can be provisioned to the SoC during manufacturing.
25Metadata of the image is delivered together with the image itself in a header
26and trailer section. In case of successful authentication, bootloader passes
27execution to the secure image. Execution never returns to bootloader until
28next reset.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020029
30A default RSA key pair is stored in the repository, public key is in ``keys.c``
Tamas Ban7801ed42019-05-20 13:21:53 +010031and private key is in ``root-rsa-3072.pem``.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020032
David Vincze8a2a4e22019-05-24 10:14:23 +020033.. Warning::
34 DO NOT use them in production code, they are exclusively for testing!
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020035
36Private key must be stored in a safe place outside of the repository.
37``Imgtool.py`` can be used to generate new key pairs.
38
David Vincze9c609012019-08-22 13:37:21 +020039The bootloader can handle the secure and non-secure images independently
40(multiple image boot) or together (single image boot). In case of multiple image
41boot they are signed independently with different keys and they can be updated
42separately. In case of single image boot the secure and non-secure image is
43handled as a single blob, therefore they must be contiguous in the device
44memory. In this case they are signed together and also they can be updated only
45together. In order to have the same artefacts at the end of the build regardless
46of how the images are handled (independently or together) the images are always
47concatenated. In case of single image boot they are concatenated first and then
48signed. In case of multiple image boot they are separately signed first and then
49concatenated. Preparation of payload is done by Python scripts:
50``bl2/ext/mcuboot/scripts/``. At the end of a successful build the signed TF-M
51payload can be found in: ``<build_dir>/install/outputs/fvp/tfm_sign.bin``
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020052
53*********************
54Integration with TF-M
55*********************
56MCUBoot assumes a predefined memory layout which is described below (applicable
David Vincze8bdfc2d2019-03-18 15:49:23 +010057for AN521). It is mandatory to define the primary slot and the secondary slot
David Vincze9c609012019-08-22 13:37:21 +020058partitions, but their size and location can be changed::
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020059
60 - 0x0000_0000 - 0x0007_FFFF: BL2 bootloader - MCUBoot
David Vincze8bdfc2d2019-03-18 15:49:23 +010061 - 0x0008_0000 - 0x000F_FFFF: Primary slot : Single binary blob:
62 Secure + Non-Secure image;
63 Primary memory partition
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020064 - 0x0008_0000 - 0x0008_03FF: Common image header
65 - 0x0008_0400 - 0x0008_xxxx: Secure image
66 - 0x0008_xxxx - 0x0010_03FF: Padding (with 0xFF)
67 - 0x0010_0400 - 0x0010_xxxx: Non-secure image
David Vincze9c609012019-08-22 13:37:21 +020068 - 0x0010_xxxx - 0x0010_xxxx: Hash value(SHA256), RSA signature and other
69 metadata of combined image
David Vincze8a2a4e22019-05-24 10:14:23 +020070
David Vincze8bdfc2d2019-03-18 15:49:23 +010071 - 0x0018_0000 - 0x0027_FFFF: Secondary slot : Secure + Non-Secure image;
72 Secondary memory partition, structured
73 identically to the primary slot
David Vincze9c609012019-08-22 13:37:21 +020074 - 0x0028_0000 - 0x0037_FFFF: Scratch area, only used during image
75 swapping
76
77Multiple image boot requires a slightly different layout::
78
79 - 0x0000_0000 - 0x0007_FFFF: BL2 bootloader - MCUBoot
80 - 0x0008_0000 - 0x000F_FFFF: Primary slot : Secure image
81 - 0x0008_0000 - 0x0008_03FF: Secure image header
82 - 0x0008_0400 - 0x000x_xxxx: Secure image
83 - 0x000x_xxxx - 0x000x_xxxx: Hash value(SHA256), RSA signature and other
84 metadata of secure image
85
86 - 0x0010_0000 - 0x0017_FFFF: Primary slot : Non-secure image
87 - 0x0010_0000 - 0x0010_03FF: Non-secure image header
88 - 0x0010_0400 - 0x001x_xxxx: Non-secure image
89 - 0x001x_xxxx - 0x001x_xxxx: Hash value(SHA256), RSA signature and other
90 metadata of non-secure image
91
92 - 0x0018_0000 - 0x001F_FFFF: Secondary slot : Secure image
93 - 0x0020_0000 - 0x0027_FFFF: Secondary slot : Non-secure image
94
95 - 0x0028_0000 - 0x002F_FFFF: Scratch area, only used during image
96 swapping, used for secure and non-secure
97 image as well
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020098
99**************************
100Firmware upgrade operation
101**************************
102MCUBoot handles only the firmware authenticity check after start-up and the
103firmware switch part of the firmware update process. Downloading the new version
David Vincze8a2a4e22019-05-24 10:14:23 +0200104of the firmware is out-of-scope for MCUBoot. MCUBoot supports three different
105ways to switch to the new firmware and it is assumed that firmware images are
106executed-in-place (XIP). The default behaviour is the overwrite-based image
David Vincze8bdfc2d2019-03-18 15:49:23 +0100107upgrade. In this case the active firmware is always executed from the primary
108slot and the secondary slot is a staging area for new images. Before executing
109the new firmware image, the content of the primary slot must be overwritten with
110the content of the secondary slot (the new firmware image). The second option is
111the image swapping strategy when the content of the two memory slots must be
112physically swapped. This needs the scratch area to be defined in the memory
113layout. The third option is the non-swapping version, which eliminates the
114complexity of image swapping and its administration. Active image can be
115executed from either memory slot, but new firmware must be linked to the address
116space of the proper (currently inactive) memory slot.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200117
David Vincze8a2a4e22019-05-24 10:14:23 +0200118Overwrite operation
Tamas Bane7efdc62019-06-05 13:14:52 +0100119===================
David Vincze8bdfc2d2019-03-18 15:49:23 +0100120Active image is stored in the primary slot, and this image is started always by
121the bootloader. Therefore images must be linked to the primary slot. If the
122bootloader finds a valid image in the secondary slot, which is marked for
123upgrade, then the content of the primary slot will be simply overwritten with
124the content of the secondary slot, before starting the new image from the
125primary slot. After the content of the primary slot has been successfully
126overwritten, the header and trailer of the new image in the secondary slot is
David Vincze9c609012019-08-22 13:37:21 +0200127erased to prevent the triggering of another unnecessary image upgrade after a
David Vincze8bdfc2d2019-03-18 15:49:23 +0100128restart. The overwrite operation is fail-safe and resistant to power-cut
129failures. For more details please refer to the MCUBoot
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200130`documentation <https://www.mcuboot.com/mcuboot/design.html>`__.
131
David Vincze8a2a4e22019-05-24 10:14:23 +0200132Swapping operation
133==================
134This operation can be set with the ``MCUBOOT_UPGRADE_STRATEGY`` compile time
135switch (see `Build time configuration`_). With swapping image upgrade strategy
David Vincze8bdfc2d2019-03-18 15:49:23 +0100136the active image is also stored in the primary slot and it will always be
137started by the bootloader. If the bootloader finds a valid image in the
138secondary slot, which is marked for upgrade, then contents of the primary slot
139and the secondary slot will be swapped, before starting the new image from the
140primary slot. Scratch area is used as a temporary storage place during image
141swapping. Update mark from the secondary slot is removed when the swapping is
David Vincze8a2a4e22019-05-24 10:14:23 +0200142successful. The boot loader can revert the swapping as a fall-back mechanism to
143recover the previous working firmware version after a faulty update. The swap
144operation is fail-safe and resistant to power-cut failures. For more details
145please refer to the MCUBoot
146`documentation <https://www.mcuboot.com/mcuboot/design.html>`__.
147
148.. Note::
149
150 After a successful image upgrade the firmware can mark itself as "OK" at
151 runtime by setting the image_ok flag in the flash. When this happens, the
152 swap is made "permanent" and MCUBoot will then still choose to run it
153 during the next boot. Currently TF-M does not set the image_ok flag,
154 therefore the bootloader will always perform a "revert" (swap the images
155 back) during the next boot.
156
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200157Non-swapping operation
158======================
David Vincze8a2a4e22019-05-24 10:14:23 +0200159This operation can be set with the ``MCUBOOT_UPGRADE_STRATEGY`` compile time
160switch (see `Build time configuration`_). When enabling non-swapping operation
161then the active image flag is moved between slots during firmware upgrade. If
162firmware is executed-in-place (XIP), then two firmware images must be generated.
David Vincze8bdfc2d2019-03-18 15:49:23 +0100163One of them is linked to be executed from the primary slot memory region and the
164other from the secondary slot. The firmware upgrade client, which downloads the
165new image, must be aware, which slot hosts the active firmware and which acts as
166a staging area and it is responsible for downloading the proper firmware image.
167At boot time MCUBoot inspects the version number in the image header and passes
168execution to the newer firmware version. New image must be marked for upgrade
169which is automatically done by Python scripts at compile time. Image
170verification is done the same way in all operational modes. If new image fails
171during authentication then MCUBoot erases the memory slot and starts the other
172image, after successful authentication.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200173
174At build time automatically two binaries are generated::
175
David Vincze8bdfc2d2019-03-18 15:49:23 +0100176 <build_dir>/install/outputs/fvp/tfm_s_ns_signed.bin : Image linked for the primary slot memory partition
David Vincze8a2a4e22019-05-24 10:14:23 +0200177
David Vincze8bdfc2d2019-03-18 15:49:23 +0100178 <build_dir>/install/outputs/fvp/tfm_s_ns_signed_1.bin : Image linked for the secondary slot memory partition
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200179
David Vincze9c609012019-08-22 13:37:21 +0200180.. Note::
181
182 Only single image boot is supported with non-swapping upgrade mode.
183
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200184RAM Loading firmware upgrade
185============================
David Vincze8a2a4e22019-05-24 10:14:23 +0200186Musca-A supports an image upgrade mode that is separate to the other (overwrite,
187swapping and non-swapping) modes. This is the ``RAM loading`` mode (please refer
188to the table below). Like the non-swapping mode, this selects the newest image
189by reading the image version numbers in the image headers, but instead of
190executing it in place, the newest image is copied to RAM for execution. The load
191address, the location in RAM where the image is copied to, is stored in the
192image header.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200193
David Vincze9c609012019-08-22 13:37:21 +0200194.. Note::
195
196 Only single image boot is supported with RAM loading upgrade mode.
197
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200198Summary of different modes for image upgrade
199============================================
200Different implementations of the image upgrade operation (whether through
David Vincze8a2a4e22019-05-24 10:14:23 +0200201overwriting, swapping, non-swapping or loading into RAM and executing from
202there) are supported by the platforms. The table below shows which of these
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200203modes are supported by which platforms:
204
David Vincze8a2a4e22019-05-24 10:14:23 +0200205+----------+-----------------+----------------------------------------------------------+
206| | Without BL2 [1]_| With BL2 [2]_ |
207+==========+=================+===============+==========+=============+=================+
208| | XIP | XIP | XIP | XIP | Not XIP |
209+----------+-----------------+---------------+----------+-------------+-----------------+
210| | | Overwrite [3]_| Swap [4]_| No-swap [5]_| RAM loading [6]_|
211+----------+-----------------+---------------+----------+-------------+-----------------+
212| AN521 | Yes | Yes | Yes | Yes | No |
213+----------+-----------------+---------------+----------+-------------+-----------------+
214| AN519 | Yes | Yes | Yes | Yes | No |
215+----------+-----------------+---------------+----------+-------------+-----------------+
216| Musca-A | No | No | No | No | Yes |
217+----------+-----------------+---------------+----------+-------------+-----------------+
218| Musca-B1 | Yes | No | No | Yes | No |
219+----------+-----------------+---------------+----------+-------------+-----------------+
Kevin Peng0a142112018-09-21 10:42:22 +0800220| AN524 | Yes | No | No | Yes | No |
221+----------+-----------------+---------------+----------+-------------+-----------------+
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200222
223.. [1] To disable BL2, please turn off the ``BL2`` compiler switch in the
David Vincze9c609012019-08-22 13:37:21 +0200224 build configuration file (``bl2/ext/mcuboot/MCUBootConfig.cmake``) or
225 in the command line
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200226
227.. [2] BL2 is enabled by default
228
David Vincze8a2a4e22019-05-24 10:14:23 +0200229.. [3] The image executes in-place (XIP) and is in Overwrite mode for image
230 update by default
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200231
David Vincze8a2a4e22019-05-24 10:14:23 +0200232.. [4] To enable XIP Swap mode, assign the "SWAP" string to the
David Vincze9c609012019-08-22 13:37:21 +0200233 ``MCUBOOT_UPGRADE_STRATEGY`` configuration variable in the build
David Vincze8a2a4e22019-05-24 10:14:23 +0200234 configuration file, or include this macro definition in the command line
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200235
David Vincze8a2a4e22019-05-24 10:14:23 +0200236.. [5] To enable XIP No-swap, assign the "NO_SWAP" string to the
David Vincze9c609012019-08-22 13:37:21 +0200237 ``MCUBOOT_UPGRADE_STRATEGY`` configuration variable in the build
David Vincze8a2a4e22019-05-24 10:14:23 +0200238 configuration file, or include this macro definition in the command line
239
240.. [6] To enable RAM loading, assign the "RAM_LOADING" string to the
David Vincze9c609012019-08-22 13:37:21 +0200241 ``MCUBOOT_UPGRADE_STRATEGY`` configuration variable in the build
David Vincze8a2a4e22019-05-24 10:14:23 +0200242 configuration file, or include this macro definition in the command line
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200243
David Vincze9c609012019-08-22 13:37:21 +0200244*******************
245Multiple image boot
246*******************
247It is possible to update the firmware images independently to support the
248scenario when secure and non-secure images are provided by different vendors.
249Multiple image boot is supported only together with the overwrite and swap
250firmware upgrade modes.
251
252It is possible to describe the dependencies of the images on each other in
253order to avoid a faulty upgrade when incompatible versions would be installed.
254These dependencies are part of the image manifest area.
255The dependencies are composed from two parts:
256
257 - **Image identifier:** The number of the image which the current image (whose
258 manifest area contains the dependency entry) depends on. The image identifier
259 starts from 0.
260
261 - **Minimum version:** The minimum version of other image must be present on
262 the device by the end of the upgrade (both images might be updated at the
263 same time).
264
265Dependencies can be added to the images at compile time with the following
266compile time switches:
267
268 - ``S_IMAGE_MIN_VER`` It is added to the non-secure image and specifies the
269 minimum required version of the secure image.
270 - ``NS_IMAGE_MIN_VER`` It is added to the secure image and specifies the
271 minimum required version of the non-secure image.
272
273Example of how to provide the secure image minimum version::
274
275 cmake -G"Unix Makefiles" -DTARGET_PLATFORM=AN521 -DCOMPILER=ARMCLANG -DS_IMAGE_MIN_VER=1.2.3+4 ../
276
Tamas Ban7801ed42019-05-20 13:21:53 +0100277********************
278Signature algorithms
279********************
280MbedTLS library is used to sign the images. The list of supported signing
281algorithms:
Tamas Bane7efdc62019-06-05 13:14:52 +0100282
283 - `RSA-2048`
284 - `RSA-3072`: default
285
David Vincze9c609012019-08-22 13:37:21 +0200286Example keys stored in:
287
288 - ``root-rsa-2048.pem`` : Used to sign single image (S+NS) or secure image
289 in case of multiple image boot
290 - ``root-rsa-2048_1.pem`` : Used to sign non-secure image in case of multiple
291 image boot
292 - ``root-rsa-3072.pem`` : Used to sign single image (S+NS) or secure image
293 in case of multiple image boot
294 - ``root-rsa-3072_1.pem`` : Used to sign non-secure image in case of multiple
295 image boot
Tamas Ban7801ed42019-05-20 13:21:53 +0100296
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200297************************
298Build time configuration
299************************
David Vincze9c609012019-08-22 13:37:21 +0200300MCUBoot related compile time switches can be set in the build configuration
301file::
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200302
David Vincze9c609012019-08-22 13:37:21 +0200303 bl2/ext/mcuboot/MCUBootConfig.cmake
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200304
305Compile time switches:
306
307- BL2 (default: True):
308 - **True:** TF-M built together with bootloader. MCUBoot is executed after
309 reset and it authenticates TF-M and starts secure code.
310 - **False:** TF-M built without bootloader. Secure image linked to the
311 beginning of the device memory and executed after reset. If it is false
David Vincze9c609012019-08-22 13:37:21 +0200312 then using any of the further compile time switches is invalid.
David Vincze8a2a4e22019-05-24 10:14:23 +0200313- MCUBOOT_UPGRADE_STRATEGY (default: "OVERWRITE_ONLY"):
314 - **"OVERWRITE_ONLY":** Default firmware upgrade operation with overwrite.
315 - **"SWAP":** Activate swapping firmware upgrade operation.
316 - **"NO_SWAP":** Activate non-swapping firmware upgrade operation.
317 - **"RAM_LOADING":** Activate RAM loading firmware upgrade operation, where
David Vincze9c609012019-08-22 13:37:21 +0200318 the latest image is copied to RAM and runs from there instead of being
David Vincze8a2a4e22019-05-24 10:14:23 +0200319 executed in-place.
Tamas Ban7801ed42019-05-20 13:21:53 +0100320- MCUBOOT_SIGNATURE_TYPE (default: RSA-3072):
David Vincze9c609012019-08-22 13:37:21 +0200321 - **RSA-3072:** Image is signed with RSA-3072 algorithm
322 - **RSA-2048:** Image is signed with RSA-2048 algorithm
323- MCUBOOT_IMAGE_NUMBER (default: 2):
324 - **1:** Single image boot, secure and non-secure images are signed and
325 updated together.
326 - **2:** Multiple image boot, secure and non-secure images are signed and
327 updatable independently.
328- MCUBOOT_HW_KEY (default: True):
329 - **True:** The hash of public key is provisioned to the SoC and the image
330 manifest contains the whole public key. MCUBoot validates the key before
331 using it for firmware authentication, it calculates the hash of public key
332 from the manifest and compare against the retrieved key-hash from the
333 hardware. This way MCUBoot is independent from the public key(s).
334 Key(s) can be provisioned any time and by different parties.
335 - **False:** The whole public key is embedded to the bootloader code and the
336 image manifest contains only the hash of the public key. MCUBoot validates
337 the key before using it for firmware authentication, it calculates the
338 hash of built-in public key and compare against the retrieved key-hash
339 from the image manifest. After this the bootloader can verify that the
340 image was signed with a private key that corresponds to the retrieved
341 key-hash (it can have more public keys embedded in and it may have to look
342 for the matching one). All the public key(s) must be known at MCUBoot
343 build time.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200344
345Image versioning
346================
David Vincze9c609012019-08-22 13:37:21 +0200347An image version number is written to its header by one of the Python scripts,
David Vincze8a2a4e22019-05-24 10:14:23 +0200348and this number is used by the bootloader when the non-swapping or RAM loading
David Vincze9c609012019-08-22 13:37:21 +0200349mode is enabled. It is also used in case of multiple image boot when the
350bootloader checks the image dependencies if any have been added to the images.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200351
David Vincze9c609012019-08-22 13:37:21 +0200352The version number of the image (single image boot) can manually be passed in
353through the command line in the cmake configuration step::
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200354
355 cmake -G"Unix Makefiles" -DTARGET_PLATFORM=AN521 -DCOMPILER=ARMCLANG -DIMAGE_VERSION=1.2.3+4 ../
356
357Alternatively, the version number can be less specific (e.g 1, 1.2, or 1.2.3),
358where the missing numbers are automatically set to zero. The image version
359number argument is optional, and if it is left out, then the version numbers of
360the image(s) being built in the same directory will automatically change. In
361this case, the last component (the build number) automatically increments from
362the previous one: 0.0.0+1 -> 0.0.0+2, for as many times as the build is re-ran,
363**until a number is explicitly provided**. If automatic versioning is in place
364and then an image version number is provided for the first time, the new number
365will take precedence and be used instead. All subsequent image versions are
366then set to the last number that has been specified, and the build number would
367stop incrementing. Any new version numbers that are provided will overwrite
368the previous one: 0.0.0+1 -> 0.0.0+2. Note: To re-apply automatic image
369versioning, please start a clean build without specifying the image version
David Vincze9c609012019-08-22 13:37:21 +0200370number at all. In case of multiple image boot there are separate compile time
371switches for both images to provide their version: ``IMAGE_VERSION_S`` and
372``IMAGE_VERSION_NS``. These must be used instead of ``IMAGE_VERSION``.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200373
David Vincze060968d2019-05-23 01:13:14 +0200374Security counter
375================
376Each signed image contains a security counter in its manifest. It is used by the
377bootloader and its aim is to have an independent (from the image version)
378counter to ensure rollback protection by comparing the new image's security
379counter against the original (currently active) image's security counter during
380the image upgrade process. It is added to the manifest (to the TLV area that is
David Vincze9c609012019-08-22 13:37:21 +0200381appended to the end of the image) by one of the Python scripts when signing the
David Vincze060968d2019-05-23 01:13:14 +0200382image. The value of the security counter is security critical data and it is in
David Vincze9c609012019-08-22 13:37:21 +0200383the integrity protected part of the image. The last valid security counter
384should always be stored in a non-volatile and trusted component of the device
385and its value should always be increased if a security flaw was fixed in the
386current image version. The value of the security counter (single image boot) can
387be specified at build time in the cmake configuration step::
David Vincze060968d2019-05-23 01:13:14 +0200388
389 cmake -G"Unix Makefiles" -DTARGET_PLATFORM=AN521 -DCOMPILER=ARMCLANG -DSECURITY_COUNTER=42 ../
390
391The security counter can be independent from the image version, but not
392necessarily. Alternatively, if it is not specified at build time with the
David Vincze9c609012019-08-22 13:37:21 +0200393``SECURITY_COUNTER`` option the Python script will automatically generate it
David Vincze060968d2019-05-23 01:13:14 +0200394from the image version number (not including the build number) and this value
David Vincze9c609012019-08-22 13:37:21 +0200395will be added to the signed image. In case of multiple image boot there are
396separate compile time switches for both images to provide their security counter
397value: ``SECURITY_COUNTER_S`` and ``SECURITY_COUNTER_NS``. These must be used
398instead of ``SECURITY_COUNTER``. If these are not defined then the security
399counter values will be derived from the corresponding image version similar to
400the single image boot.
401
402***************************
403Signing the images manually
404***************************
405Normally the build system handles the signing (computing hash over the image
406and security critical manifest data and then signing the hash) of the firmware
407images. However, the images also can be signed manually by using the ``imgtool``
408Python program which is located in the ``bl2/ext/mcuboot/scripts`` directory.
409Issue the ``python3 imgtool.py sign --help`` command in the directory for more
410information about the mandatory and optional arguments. The tool takes an image
411in binary or Intel Hex format and adds a header and trailer that MCUBoot is
412expecting. In case of single image boot after a successful build the
413``tfm_full.bin`` build artifact (contains the concatenated secure and non-secure
414images) must be passed to the script and in case of multiple image boot the
415``tfm_s.bin`` and ``tfm_ns.bin`` binaries can be passed to prepare the signed
416images.
417
418Signing the secure image manually in case of multiple image boot
419================================================================
420
421::
422
423 python3 bl2/ext/mcuboot/scripts/imgtool.py sign \
424 --layout <build_dir>/image_macros_preprocessed_s.c \
425 -k <tfm_dir>/bl2/ext/mcuboot/root-rsa-3072.pem \
426 --public-key-format full \
427 --align 1 \
428 -v 1.2.3+4 \
429 -d "(1,1.2.3+0)" \
430 -s 42 \
431 -H 0x400 \
432 <build_dir>/install/outputs/AN521/tfm_s.bin \
433 <build_dir>/tfm_s_signed.bin
David Vincze060968d2019-05-23 01:13:14 +0200434
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200435************************
436Testing firmware upgrade
437************************
438As downloading the new firmware image is out of scope for MCUBoot, the update
439process is started from a state where the original and the new image are already
440programmed to the appropriate memory slots. To generate the original and a new
441firmware package, TF-M is built twice with different build configurations.
442
David Vincze8a2a4e22019-05-24 10:14:23 +0200443Overwriting firmware upgrade
Tamas Bane7efdc62019-06-05 13:14:52 +0100444============================
David Vincze9c609012019-08-22 13:37:21 +0200445Run TF-M build twice with ``MCUBOOT_IMAGE_NUMBER`` set to "1" in both cases
446(single image boot), but with two different build configurations: default and
David Vincze8a2a4e22019-05-24 10:14:23 +0200447regression. Save the artifacts between builds, because second run can overwrite
David Vincze8bdfc2d2019-03-18 15:49:23 +0100448original binaries. Download default build to the primary slot and regression
449build to the secondary slot.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200450
451Executing firmware upgrade on FVP_MPS2_AEMv8M
452---------------------------------------------
453.. code-block:: bash
454
455 <DS5_PATH>/sw/models/bin/FVP_MPS2_AEMv8M \
456 --parameter fvp_mps2.platform_type=2 \
457 --parameter cpu0.baseline=0 \
458 --parameter cpu0.INITVTOR_S=0x10000000 \
459 --parameter cpu0.semihosting-enable=0 \
460 --parameter fvp_mps2.DISABLE_GATING=0 \
461 --parameter fvp_mps2.telnetterminal0.start_telnet=1 \
462 --parameter fvp_mps2.telnetterminal1.start_telnet=0 \
463 --parameter fvp_mps2.telnetterminal2.start_telnet=0 \
464 --parameter fvp_mps2.telnetterminal0.quiet=0 \
465 --parameter fvp_mps2.telnetterminal1.quiet=1 \
466 --parameter fvp_mps2.telnetterminal2.quiet=1 \
467 --application cpu0=<build_dir>/bl2/ext/mcuboot/mcuboot.axf \
468 --data cpu0=<default_build_dir>/install/outputs/fvp/tfm_s_ns_signed.bin@0x10080000 \
469 --data cpu0=<regresssion_build_dir>/install/outputs/fvp/tfm_s_ns_signed.bin@0x10180000
470
471Executing firmware upgrade on SSE 200 FPGA on MPS2 board
472--------------------------------------------------------
473
474::
475
476 TITLE: Versatile Express Images Configuration File
477 [IMAGES]
478 TOTALIMAGES: 3 ;Number of Images (Max: 32)
479 IMAGE0ADDRESS: 0x00000000
480 IMAGE0FILE: \Software\mcuboot.axf ; BL2 bootloader
481 IMAGE1ADDRESS: 0x10080000
David Vincze8a2a4e22019-05-24 10:14:23 +0200482 IMAGE1FILE: \Software\tfm_sig1.bin ; TF-M default test binary blob
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200483 IMAGE2ADDRESS: 0x10180000
484 IMAGE2FILE: \Software\tfm_sig2.bin ; TF-M regression test binary blob
485
David Vincze8a2a4e22019-05-24 10:14:23 +0200486The following message will be shown in case of successful firmware upgrade:
487
488::
489
490 [INF] Starting bootloader
491 [INF] Swap type: test
David Vincze8bdfc2d2019-03-18 15:49:23 +0100492 [INF] Image upgrade secondary slot -> primary slot
493 [INF] Erasing the primary slot
494 [INF] Copying the secondary slot to the primary slot: 0x100000 bytes
David Vincze8a2a4e22019-05-24 10:14:23 +0200495 [INF] Bootloader chainload address offset: 0x80000
496 [INF] Jumping to the first image slot
497 [Sec Thread] Secure image initializing!
498
499 #### Execute test suites for the Secure area ####
500 Running Test Suite PSA protected storage S interface tests (TFM_SST_TEST_2XXX)...
501 ...
502
David Vincze9c609012019-08-22 13:37:21 +0200503To update the secure and non-secure images separately (multiple image boot),
504set the ``MCUBOOT_IMAGE_NUMBER`` switch to "2" (this is the default
505configuration value) and follow the same instructions as in case of single image
506boot.
507
508Executing multiple firmware upgrades on SSE 200 FPGA on MPS2 board
509------------------------------------------------------------------
510
511::
512
513 TITLE: Versatile Express Images Configuration File
514 [IMAGES]
515 TOTALIMAGES: 4 ;Number of Images (Max: 32)
516 IMAGE0ADDRESS: 0x00000000
517 IMAGE0FILE: \Software\mcuboot.axf ; BL2 bootloader
518 IMAGE1ADDRESS: 0x10080000
519 IMAGE1FILE: \Software\tfm_sign.bin ; TF-M default test binary blob
520 IMAGE2ADDRESS: 0x10180000
521 IMAGE2FILE: \Software\tfm_ss1.bin ; TF-M regression test secure (signed) image
522 IMAGE3ADDRESS: 0x10200000
523 IMAGE3FILE: \Software\tfm_nss1.bin ; TF-M regression test non-secure (signed) image
524
525Note that both the concatenated binary blob (the images are signed separately
526and then concatenated) and the separate signed images can be downloaded to the
527device because on this platform (AN521) both the primary slots and the secondary
528slots are contiguous areas in the Flash (see `Integration with TF-M`_). The
529following message will be shown in case of successful firmware upgrades:
530
531::
532
533 [INF] Starting bootloader
534 [INF] Swap type: test
535 [INF] Swap type: test
536 [INF] Image upgrade secondary slot -> primary slot
537 [INF] Erasing the primary slot
538 [INF] Copying the secondary slot to the primary slot: 0x80000 bytes
539 [INF] Image upgrade secondary slot -> primary slot
540 [INF] Erasing the primary slot
541 [INF] Copying the secondary slot to the primary slot: 0x80000 bytes
542 [INF] Bootloader chainload address offset: 0x80000
543 [INF] Jumping to the first image slot
544 [Sec Thread] Secure image initializing!
545 TFM level is: 1
546 [Sec Thread] Jumping to non-secure code...
547
548 #### Execute test suites for the Secure area ####
549 Running Test Suite PSA protected storage S interface tests (TFM_SST_TEST_2XXX)...
550 ...
551
David Vincze8a2a4e22019-05-24 10:14:23 +0200552Swapping firmware upgrade
553=============================
554Follow the same instructions and platform related configurations as in case of
555overwriting build including these changes:
556
David Vincze9c609012019-08-22 13:37:21 +0200557- Set the ``MCUBOOT_UPGRADE_STRATEGY`` compile time switch to "SWAP"
558 before build.
559- Set the ``MCUBOOT_IMAGE_NUMBER`` compile time switch to "1" (single image
560 boot) or "2" (multiple image boot) before build.
David Vincze8a2a4e22019-05-24 10:14:23 +0200561
David Vincze9c609012019-08-22 13:37:21 +0200562During single image boot the following message will be shown in case of
563successful firmware upgrade, ``Swap type: test`` indicates that images were
564swapped:
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200565
566::
567
David Vincze8a2a4e22019-05-24 10:14:23 +0200568 [INF] Starting bootloader
569 [INF] Image 0: magic= good, copy_done=0x3, image_ok=0x3
570 [INF] Scratch: magic= bad, copy_done=0x0, image_ok=0x2
David Vincze8bdfc2d2019-03-18 15:49:23 +0100571 [INF] Boot source: primary slot
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200572 [INF] Swap type: test
573 [INF] Bootloader chainload address offset: 0x80000
574 [INF] Jumping to the first image slot
575 [Sec Thread] Secure image initializing!
576
David Vincze8a2a4e22019-05-24 10:14:23 +0200577 #### Execute test suites for the Secure area ####
578 Running Test Suite PSA protected storage S interface tests (TFM_SST_TEST_2XXX)...
579 ...
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200580
581Non-swapping firmware upgrade
582=============================
David Vincze9c609012019-08-22 13:37:21 +0200583Follow the same instructions and platform related configurations as in case of
584overwriting build including these changes:
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200585
David Vincze8a2a4e22019-05-24 10:14:23 +0200586- Set the ``MCUBOOT_UPGRADE_STRATEGY`` compile time switch to "NO_SWAP"
587 before build.
David Vincze9c609012019-08-22 13:37:21 +0200588- Make sure the image version number was increased between the two build runs
589 either by specifying it manually or by checking in the build log that it was
590 incremented automatically.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200591
592Executing firmware upgrade on FVP_MPS2_AEMv8M
593---------------------------------------------
594
595.. code-block:: bash
596
597 <DS5_PATH>/sw/models/bin/FVP_MPS2_AEMv8M \
598 --parameter fvp_mps2.platform_type=2 \
599 --parameter cpu0.baseline=0 \
600 --parameter cpu0.INITVTOR_S=0x10000000 \
601 --parameter cpu0.semihosting-enable=0 \
602 --parameter fvp_mps2.DISABLE_GATING=0 \
603 --parameter fvp_mps2.telnetterminal0.start_telnet=1 \
604 --parameter fvp_mps2.telnetterminal1.start_telnet=0 \
605 --parameter fvp_mps2.telnetterminal2.start_telnet=0 \
606 --parameter fvp_mps2.telnetterminal0.quiet=0 \
607 --parameter fvp_mps2.telnetterminal1.quiet=1 \
608 --parameter fvp_mps2.telnetterminal2.quiet=1 \
609 --application cpu0=<build_dir>/bl2/ext/mcuboot/mcuboot.axf \
Tamas Banbba85642019-06-06 09:31:59 +0100610 --data cpu0=<default_build_dir>/install/outputs/fvp/tfm_s_ns_signed.bin@0x10080000 \
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200611 --data cpu0=<regresssion_build_dir>/install/outputs/fvp/tfm_s_ns_signed_1.bin@0x10180000
612
613Executing firmware upgrade on SSE 200 FPGA on MPS2 board
614--------------------------------------------------------
615
616::
617
618 TITLE: Versatile Express Images Configuration File
619 [IMAGES]
620 TOTALIMAGES: 3 ;Number of Images (Max: 32)
621 IMAGE0ADDRESS: 0x00000000
622 IMAGE0FILE: \Software\mcuboot.axf ; BL2 bootloader
623 IMAGE1ADDRESS: 0x10080000
Tamas Banbba85642019-06-06 09:31:59 +0100624 IMAGE1FILE: \Software\tfm_sign.bin ; TF-M default test binary blob
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200625 IMAGE2ADDRESS: 0x10180000
626 IMAGE2FILE: \Software\tfm_sig1.bin ; TF-M regression test binary blob
627
628Executing firmware upgrade on Musca-B1 board
629--------------------------------------------
David Vincze9c609012019-08-22 13:37:21 +0200630After the two images have been built, they can be concatenated to create the
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200631combined image using ``srec_cat``:
632
633- Linux::
David Vincze8a2a4e22019-05-24 10:14:23 +0200634
Tamas Banbba85642019-06-06 09:31:59 +0100635 srec_cat bl2/ext/mcuboot/mcuboot.bin -Binary -offset 0xA000000 tfm_sign.bin -Binary -offset 0xA020000 tfm_sign_1.bin -Binary -offset 0xA0E0000 -o tfm.hex -Intel
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200636
637- Windows::
David Vincze8a2a4e22019-05-24 10:14:23 +0200638
Tamas Banbba85642019-06-06 09:31:59 +0100639 srec_cat.exe bl2\ext\mcuboot\mcuboot.bin -Binary -offset 0xA000000 tfm_sign.bin -Binary -offset 0xA020000 tfm_sign_1.bin -Binary -offset 0xA0E0000 -o tfm.hex -Intel
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200640
641The following message will be shown in case of successful firmware upgrade,
642notice that image with higher version number (``version=1.2.3.5``) is executed:
643
644::
645
646 [INF] Starting bootloader
David Vincze8a2a4e22019-05-24 10:14:23 +0200647 [INF] Image 0: version=1.2.3.4, magic= good, image_ok=0x3
648 [INF] Image 1: version=1.2.3.5, magic= good, image_ok=0x3
David Vincze8bdfc2d2019-03-18 15:49:23 +0100649 [INF] Booting image from the secondary slot
David Vincze8a2a4e22019-05-24 10:14:23 +0200650 [INF] Bootloader chainload address offset: 0xa0000
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200651 [INF] Jumping to the first image slot
652 [Sec Thread] Secure image initializing!
653
David Vincze8a2a4e22019-05-24 10:14:23 +0200654 #### Execute test suites for the Secure area ####
655 Running Test Suite PSA protected storage S interface tests (TFM_SST_TEST_2XXX)...
656 ...
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200657
Kevin Peng0a142112018-09-21 10:42:22 +0800658Executing firmware upgrade on CoreLink SSE-200 Subsystem for MPS3 (AN524)
659-------------------------------------------------------------------------
660
661::
662
663 TITLE: Arm MPS3 FPGA prototyping board Images Configuration File
664
665 [IMAGES]
666 TOTALIMAGES: 3 ;Number of Images (Max: 32)
667
668 IMAGE0UPDATE: AUTO ;Image Update:NONE/AUTO/FORCE
669 IMAGE0ADDRESS: 0x00000000
670 IMAGE0FILE: \SOFTWARE\mcuboot.bin ;BL2 bootloader
671 IMAGE1UPDATE: AUTO
672 IMAGE1ADDRESS: 0x00040000
673 IMAGE1FILE: \SOFTWARE\tfm_sig0.bin ;TF-M example application binary blob
674 IMAGE2UPDATE: AUTO
675 IMAGE2ADDRESS: 0x000C0000
676 IMAGE2FILE: \SOFTWARE\tfm_sig1.bin ;TF-M regression test binary blob
677
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200678RAM loading firmware upgrade
679============================
David Vincze8a2a4e22019-05-24 10:14:23 +0200680To enable RAM loading, please set ``MCUBOOT_UPGRADE_STRATEGY`` to "RAM_LOADING"
681(either in the configuration file or through the command line), and then specify
682a destination load address in RAM where the image can be copied to and executed
683from. The ``IMAGE_LOAD_ADDRESS`` macro must be specified in the target dependent
684files, for example with Musca-A, its ``flash_layout.h`` file in the ``platform``
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200685folder should include ``#define IMAGE_LOAD_ADDRESS #0x10020000``
686
David Vincze8a2a4e22019-05-24 10:14:23 +0200687Executing firmware upgrade on Musca-A board
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200688--------------------------------------------
689After two images have been built, they can be concatenated to create the
690combined image using ``srec_cat``:
691
David Vincze8a2a4e22019-05-24 10:14:23 +0200692- Linux::
693
694 srec_cat bl2/ext/mcuboot/mcuboot.bin -Binary -offset 0x200000 tfm_sign_old.bin -Binary -offset 0x220000 tfm_sign_new.bin -Binary -offset 0x320000 -o tfm.hex -Intel
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200695
696- Windows::
David Vincze8a2a4e22019-05-24 10:14:23 +0200697
David Vincze9c609012019-08-22 13:37:21 +0200698 srec_cat.exe bl2\ext\mcuboot\mcuboot.bin -Binary -offset 0x200000 tfm_sign_old.bin -Binary -offset 0x220000 tfm_sign_new.bin -Binary -offset 0x320000 -o tfm.hex -Intel
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200699
700The following message will be shown in case of successful firmware upgrade when,
701RAM loading is enabled, notice that image with higher version number
702(``version=0.0.0.2``) is executed:
703
704::
705
David Vincze8a2a4e22019-05-24 10:14:23 +0200706 [INF] Starting bootloader
707 [INF] Image 0: version=0.0.0.1, magic= good, image_ok=0x3
708 [INF] Image 1: version=0.0.0.2, magic= good, image_ok=0x3
David Vincze8bdfc2d2019-03-18 15:49:23 +0100709 [INF] Image has been copied from the secondary slot in flash to SRAM address 0x10020000
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200710 [INF] Booting image from SRAM at address 0x10020000
711 [INF] Bootloader chainload address offset: 0x20000
712 [INF] Jumping to the first image slot
713 [Sec Thread] Secure image initializing!
714
715--------------
716
717*Copyright (c) 2018-2019, Arm Limited. All rights reserved.*