You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This document describes the process of adding new PSA targets to Mbed OS, focusing on target configurations, build and validation. Mbed OS relies on [TF-M](https://git.trustedfirmware.org/trusted-firmware-m.git/tree/) for its implementation of PSA, so the PSA target you are adding to Mbed OS **must** already be supported by TF-M.
3
+
This document describes the process of adding new PSA targets to Mbed OS, focusing on target configurations, build and validation.
4
4
5
5
Before reading this document, please read [porting a custom board](../porting/porting-a-custom-board.html) and [porting targets](../porting/porting-the-hal-apis.html), which provide step-by-step instructions to porting a new target to Mbed OS.
6
6
@@ -16,7 +16,7 @@ Before reading this document, please read [porting a custom board](../porting/po
16
16
To help create PSA targets, we have added a few generic targets to `targets/targets.json`:
17
17
18
18
*`PSA_Target`: Root level PSA target.
19
-
*`PSA_V7_M`: Single v7-M generic PSA target, which doesn't employ hardware isolation between the NSPE and the SPE. PSA secure service emulation enables PSA API compatibility.
19
+
*`PSA_V7_M`: Single-core v7-M generic PSA target, which doesn't employ hardware isolation between the NSPE and the SPE, so TF-M is not supported. PSA secure service emulation enables PSA API compatibility.
20
20
*`PSA_DUAL_CORE`: Dual-core generic PSA target. A dual-core PSA target has at least two cores that are either Armv7-M or Armv6-M. One core will be used for the SPE and another for the NSPE. Hardware isolation between the cores enables PSA compliance. On dual-core targets, TF-M
21
21
runs on the SPE and provides PSA services, and Mbed OS runs on the NSPE.
22
22
*`PSA_V8_M`: Armv8-M generic PSA target, which employs hardware to isolate the NSPE from the SPE. TF-M runs on the SPE and provides PSA services, and Mbed OS runs on the NSPE.
@@ -39,20 +39,10 @@ Example of a single-core Armv7-M PSA target's inheritance:
39
39
}
40
40
```
41
41
42
-
### Naming convention for dual-core and Armv8-M targets
43
-
44
-
As explained above, dual-core and Armv8-M PSA targets require only an NSPE target name. For Armv8-M non-PSA targets, you can define both SPE and NSPE target names.
45
-
46
-
The naming convention is:
47
-
48
-
-`TargetName`: PSA non-secure target (NSPE).
49
-
-`TargetName_NPSA_S`: Non-PSA secure target.
50
-
-`TargetName_NPSA`: Non-PSA non-secure target.
51
-
52
-
### Adding single-core PSA targets
42
+
### Adding single-core (non-TF-M) PSA targets
53
43
54
44
Mbed OS's PSA service emulation provides PSA compatibility for single-core PSA
55
-
targets.
45
+
targets which do not support TF-M.
56
46
57
47
The following example shows a PSA-enabled single-core target, `K64F`:
58
48
@@ -173,16 +163,20 @@ In this case, you must add the following additional attributes:
173
163
]
174
164
```
175
165
176
-
### Adding dual-core PSA targets
166
+
### Adding TF-M (dual-core or Armv8-M) PSA targets
177
167
178
-
A target can be categorized as a dual-core target if it has at least two cores that are either Armv7-M or Armv6-M. On dual-core PSA targets, TF-M runs on the SPE and provides PSA services.
168
+
An Mbed OS (NSPE) target that supports TF-M must contain the following attributes (in addition to other target attributes defined in [porting a custom board](../porting/porting-a-custom-board.html)and [porting targets](../porting/porting-the-hal-apis.html)):
179
169
180
-
An Mbed OS (NSPE) target must contain the following attributes (in addition to other target attributes defined in [porting a custom board](../porting/porting-a-custom-board.html) and [porting targets](../porting/porting-the-hal-apis.html)):
181
-
182
-
*`inherits`: PSA generic target `PSA_DUAL_CORE`, unless the target has to inherit
170
+
*`inherits`: PSA generic target `PSA_DUAL_CORE` or `PSA_V8_M`, unless the target has to inherit
183
171
from one of its family targets.
172
+
*`extra_labels`: `TARGET_`[label] paths to enable.
173
+
*`TFM_LATEST`: If the current version of TF-M (that Mbed OS is integrated with) is supported by the target. The current version is indicated in [mbed-os-tf-m-regression-tests](https://github.com/ARMmbed/mbed-os-tf-m-regression-tests).
174
+
*`TFM_V`[major]`_`[minor]: If a legacy release of TF-M is supported by the target.
175
+
*`macros_add`: C/C++ macros that are globally set during compilation.
176
+
*`BL2`: If the TF-M bootloader is supported by the target.
177
+
*`MCUBOOT_IMAGE_NUMBER=2`: If the secure and non-secure images are in two separate bootloader slots.
184
178
*`tfm_target_name`: Target name in TF-M.
185
-
*`tfm_bootloader_supported`: If TF-M bootloader is supported by the target.
179
+
*`tfm_bootloader_supported`: If the TF-M bootloader is supported by the target.
@@ -193,129 +187,36 @@ An Mbed OS (NSPE) target must contain the following attributes (in addition to o
193
187
The supported values are `ARMCLANG` and `GNUARM`.
194
188
*`tfm_delivery_dir`: The directory to which TF-M binaries will be copied.
195
189
*`TFM_OUTPUT_EXT`: Optional attribute that indicates the output extension of the TF-M secure binary.
190
+
*`post_binary_hook`:
191
+
*`function`: The target's post binary hook ([class].[method]) in `tools/targets/__init__.py` for image signing, required if the TF-M bootloader support is supported.
192
+
*`secure_image_filename`: The file name of the TF-M secure binary, to be signed by the post binary hook.
196
193
197
-
The following example shows a PSA enabled dual-core target, `PSoC64`:
194
+
**Note**: When `inherits` is used, some of attributes are set by the PSA generic target.
Please note the config options `macros_add`, `extra_labels_add` and `device_has_remove`. To add or remove `macros`, `extra_labels` or target capabilities, a PSA target definition must use
258
-
[macros/extra_labels/device_has]`_add` or [macros/extra_labels/device_has]`_remove` (not `macros`, `extra_labels` or `device_has`).
259
-
260
-
To add or remove a feature, use `feature_`[add/remove].
261
-
262
-
By default, a TF-M build generates a `bin` file. If the target requires a `hex` file, you need to add the attribute `"TFM_OUTPUT_EXT": "hex"` to the target definition. The build script will convert `bin` to `hex`, then copy the `hex` to `tfm_delivery_dir`.
263
-
264
-
This dual-core PSA target doesn't inherit from `PSA_DUAL_CORE` because it has to inherit from one of its family targets. Hence, we have added additional attributes:
196
+
The following example shows a PSA-enabled Armv8-M PSA target, `ARM_MUSCA_S1`:
265
197
266
198
```json
267
-
"features_add": [
268
-
"PSA"
269
-
],
270
-
"extra_labels_add": [
271
-
"TFM",
272
-
"TFM_DUALCPU"
273
-
]
274
-
```
275
-
276
-
If a dual-core PSA target can inherit from `PSA_DUAL_CORE`, then there is no need to add these additional attributes.
277
-
278
-
### Adding Armv8-M PSA targets
279
-
280
-
An Mbed OS (NSPE) target must contain the following attributes (in addition to other target attributes defined in [porting a custom board](../porting/porting-a-custom-board.html)
281
-
and [porting targets](../porting/porting-the-hal-apis.html)):
282
-
283
-
*`inherits`: PSA generic target `PSA_V8_M`, unless the target has to inherit from
284
-
one of its family targets.
285
-
*`tfm_target_name`: Target name in TF-M.
286
-
*`tfm_bootloader_supported`: If TF-M bootloader is supported by the target.
Please note the config options `macros_add`, `extra_labels_add` and `device_has_remove`. To add or remove `macros`, `extra_labels` or target capabilities, a PSA target definition must use
352
-
[macros/extra_labels/device_has]`_add` or [macros/extra_labels/device_has]`_remove` (not `macros`, `extra_labels` or `device_has`).
353
-
354
-
To add or remove a feature, use `feature_`[add/remove].
256
+
Please note the config options `features_add`, `macros_add`, `extra_labels_add` and `device_has_add`. To add or remove `features`, `macros`, `extra_labels` or target capabilities, a PSA target definition must use
257
+
[features/macros/extra_labels/device_has]`_add` or [features/macros/extra_labels/device_has]`_remove` (not `features`, `macros`, `extra_labels` or `device_has`).
355
258
356
259
By default, a TF-M build generates a `bin` file. If the target requires a `hex` file, you need to add the attribute `"TFM_OUTPUT_EXT": "hex"` to the target definition. The build script will convert `bin` to `hex`, then copy the `hex` to `tfm_delivery_dir`. You must also update `secure_image_filename` to match the new file extension.
357
260
358
-
If an Armv8-M PSA target cannot inherit from `PSA_V8_M` because it has to inherit from one of its family targets, you must add the following attributes:
261
+
If a PSA target cannot inherit from `PSA_V8_M`or `PSA_DUAL_CORE`because it has to inherit from one of its family targets, you must declare PSA and TF-M attributes manually. For example,
359
262
360
263
```json
361
264
"features_add": [
362
265
"PSA"
363
266
],
364
267
"extra_labels_add": [
365
268
"TFM",
269
+
"TFM_LATEST",
366
270
"TFM_V8M"
367
271
]
368
272
```
369
-
370
-
## Enabling PSA at application level
371
-
372
-
Having an entropy source is crucial for Mbed TLS and PSA. The [entropy source porting document](../porting/entropy-sources.html) discusses why and how to add an entropy source.
373
-
374
-
If your target doesn't have a True Random Number Generator (TRNG), configure it as a non-PSA target in `targets/targets.json`. In this scenario, if an application wants to use the target as a PSA target, then it is the application's responsibility to provide an entropy source and mark that target as a PSA target at the application level. To enable PSA for a target from an application, use the config option [target_overrides](../reference/configuration.html).
375
-
376
-
An example of `mbed_app.json`:
377
-
378
-
```json
379
-
"target_overrides": {
380
-
"K64F": {
381
-
"inherits": ["PSA_V7_M"]
382
-
}
383
-
}
384
-
```
273
+
(Please adjust the TF-M version and target architecture accordingly.)
385
274
386
275
## Build and validation
387
276
388
-
The Python script `build_tfm.py` automates building TF-M and copying the TF-M binary to the location defined by the target attribute `tfm_delivery_dir`. Another Python script, `build_psa_compliance.py`, automates
389
-
building PSA API compliance tests.
390
-
391
-
The [mbed-os-tf-m-regression-tests repository](https://github.com/ARMmbed/mbed-os-tf-m-regression-tests) contains build scripts, TF-M regression tests and PSA API compliance tests.
392
-
393
-
### Building TF-M and running regression tests
394
-
395
-
To build TF-M and regression tests:
396
-
397
-
1. Clone the [mbed-os-tf-m-regression-tests](https://github.com/ARMmbed/mbed-os-tf-m-regression-tests) repository.
398
-
1. Update `mbed-os.lib` to the copy of Mbed OS that contains new target support, including the `targets.json` changes described in this document.
The command builds a TF-M binary the service necessary to run regression tests.
412
-
413
-
<span class="notes">**Note:** Use this `ConfigRegressionIPC.cmake` only to run regression tests. The secure binary copied to Mbed OS (when you are ready to merge your new target) must be generated using the config option `ConfigCoreIPC.cmake`.</span>
414
-
415
-
1. Ensure the TF-M binary was copied to the location defined by the target attribute `tfm_delivery_dir`. If no binary was created or copied, please raise an [issue on the Mbed OS repository](https://github.com/ARMmbed/mbed-os).
416
-
417
-
1. To build Mbed OS and run regression tests, run:
418
-
419
-
```
420
-
mbed compile -m <new target> -t <toolchain>
421
-
```
422
-
1. Flash the regression tests binary to the target and ensure all regression tests pass.
423
-
424
-
### Building TF-M and running PSA compliance tests
425
-
426
-
To build TF-M and compliance tests:
427
-
428
-
1. Switch to the `mbed-os-tf-m-regression-tests` directory.
The command builds TF-M including PSA API compliance tests.
447
-
1. To build Mbed OS and run PSA API compliance tests, run:
448
-
449
-
```
450
-
mbed compile -m <new target> -t <toolchain>
451
-
```
452
-
1. Flash the PSA API compliance tests binary to the target and ensure all PSA API compliance tests pass.
453
-
454
-
<span class="notes">**Note:** Any PSA API compliance tests that fail in the TF-M example application will fail in Mbed OS as well.</span>
277
+
The [mbed-os-tf-m-regression-tests repository](https://github.com/ARMmbed/mbed-os-tf-m-regression-tests) contains build scripts, TF-M regression tests and PSA API compliance tests. Please follow instructions there to build and validate your TF-M target.
455
278
456
279
### Building TF-M and creating an Mbed OS pull request
457
280
@@ -466,7 +289,7 @@ To build TF-M and create an Mbed OS pull request:
The command builds TF-M with the config `ConfigCoreIPC.cmake`, copies the TF-M binary to the location defined by the target attribute `tfm_delivery_dir`, and commits the changes to Mbed OS.
292
+
The command builds TF-M with the config `CoreIPC`, copies the TF-M binary to the location defined by the target attribute `tfm_delivery_dir`, and commits the changes to Mbed OS.
470
293
471
294
<span class="tips">**Tip:** When you run the Python script `build_tfm.py` without any options, TF-M is built for all supported targets and the secure binary (TF-M) for each target is copied to the location defined by the target attribute `tfm_delivery_dir`. When you use the `--commit` option, a new Mbed OS commit is created with the new or modified TF-M binaries and `features/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/VERSION.txt`.</span>
0 commit comments