Skip to content

Commit 98f5a99

Browse files
committed
M2354: Refine TF-M/Mbed integration readme
1 parent 9fee7d9 commit 98f5a99

File tree

1 file changed

+94
-38
lines changed
  • targets/TARGET_NUVOTON/TARGET_M2354/TARGET_TFM/TARGET_NU_M2354/COMPONENT_TFM_S_FW

1 file changed

+94
-38
lines changed
Lines changed: 94 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,27 @@
1-
# TF-M exported stuff for Mbed integration
1+
# Rebuild TF-M and integrate with Mbed on M2354
22

3-
This directory contains TF-M exported stuff to integrate with Mbed.
3+
This document guides how to rebuild TF-M and integrate with Mbed on M2354.
44

5-
## TF-M exported stuff
5+
### Downloading TF-M source
66

7-
- bl2.bin: [MCUboot](https://github.com/mcu-tools/mcuboot) bootloader binary
8-
9-
- tfm_s.bin: TF-M secure binary
10-
11-
- s_veneers.o: TF-M secure gateway library
12-
13-
- partition/: Flash layout for image signing and concatenating in post-build process
14-
15-
**NOTE**: On import, `signing_layout_s_ns.o` is renamed to `signing_layout_preprocessed.h` for the following reasons:
16-
- Post-build script checks file name with `_s`/`_ns` to resolve `sw_type` as `SPE`/`NSPE` respectively.
17-
To recognize as `NSPE_SPE`, don't use `_s_ns`/`_ns_s` file name to avoid mis-recognized.
18-
- Use `.h` instead of `.c` as file extension name.
19-
This is to enable custom TF-M build where the locatioin of this directory can change elsewhere.
20-
In Greentea build process, `.c` file isn't but`.h` file is copied into `BUILD` directory, so that post-build script can still access the file.
21-
22-
- [signing_key/](signing_key/nuvoton_m2354-root-rsa-3072.md)
7+
The M2354 port in TF-M must patch to enable TF-M integration with Mbed.
8+
For TF-M 1.2/Mbed integration on M2354, the [mainstream TF-M](https://git.trustedfirmware.org/TF-M/trusted-firmware-m.git) is patched as follows:
9+
- Apply Mbed-enabled patch to `nuvoton/m2354` TF-M target.
10+
- Backport to base on [ARMmbed TF-M mbed-tfm-1.2](https://github.com/ARMmbed/trusted-firmware-m/tree/mbed-tfm-1.2).
2311

24-
### Copy path summary
12+
Run the following command to fetch and switch to the intended version:
13+
```sh
14+
git clone https://github.com/OpenNuvoton/trusted-firmware-m -b nuvoton_mbed_m2354_tfm-1.2
15+
```
2516

26-
This section summarizes the copy paths from TF-M to Mbed.
17+
## Customizing TF-M
2718

28-
- trusted-firmware-m/cmake_build/bin/bl2.bin → bl2.bin
29-
- trusted-firmware-m/cmake_build/install/export/tfm/lib/s_veneers.o → s_veneers.o
30-
- trusted-firmware-m/cmake_build/bin/tfm_s.bin → tfm_s.bin
31-
- trusted-firmware-m/platform/ext/target/nuvoton/m2354/partition/flash_layout.h → partition/flash_layout.h
32-
- trusted-firmware-m/cmake_build/bl2/ext/mcuboot/CMakeFiles/signing_layout_s.dir/signing_layout_s_ns.o → partition/signing_layout_preprocessed.h
33-
- trusted-firmware-m/bl2/ext/mcuboot/root-RSA-3072.pem → signing_key/nuvoton_m2354-root-rsa-3072.pem
19+
TF-M is out of scope of Mbed.
20+
We only provide limited support for customizing M2354 port in TF-M.
3421

35-
## Partitioning the hardware
22+
### Default hardware partition
3623

37-
In TF-M, the hardware is partitioned as follows:
24+
In TF-M, by default, the M2354 hardware is partitioned as follows:
3825

3926
- Flash (1024KiB in total): 448KiB for secure and 576KiB for nonsecure.
4027
- SRAM (256KiB in total): 80KiB for secure and 176KiB for nonsecure.
@@ -49,18 +36,54 @@ In TF-M, the hardware is partitioned as follows:
4936
- **PDMA0**: Hardwired to secure. Inaccessible to Mbed.
5037
- **PDMA1**: Configured to nonsecure for Mbed asynchronous transfer.
5138
- **CRYPTO**: Configured to secure. Inaccessible to Mbed.
52-
- **TRNG**: Hardwired to secure. Accessible to Mbed through secure gateway.
39+
- **TRNG**: Hardwired to secure. Accessible to Mbed indirectly through PSA Cryptography API.
5340

54-
## Building TF-M
41+
### Defining Flash for TF-M/Mbed
5542

56-
For Mbed/TF-M 1.2 integration, the mainstream TF-M is patched as follows:
57-
- Apply Mbed-enabled patch to `nuvoton/m2354` TF-M target.
58-
- Backport to base on [ARMmbed TF-M mbed-tfm-1.2](https://github.com/ARMmbed/trusted-firmware-m/tree/mbed-tfm-1.2).
43+
To define memory spec of Flash for TF-M/Mbed, search/change the line:
44+
45+
**trusted-firmware-m/platform/ext/target/nuvoton/m2354/partition/flash_layout.h**:
46+
```C
47+
/* Max Flash size for TF-M + bootloader information */
48+
#define FLASH_S_PARTITION_SIZE (0x50000)
49+
/* Max Flash size for Mbed + bootloader information */
50+
#define FLASH_NS_PARTITION_SIZE (0x90000)
51+
```
52+
53+
M2354 has 1024KiB Flash in total, among which 128KiB have been allocated for bootloader code and ITS/PS storage.
54+
896KiB are left for `FLASH_S_PARTITION_SIZE` and `FLASH_NS_PARTITION_SIZE`.
55+
56+
**NOTE**: `FLASH_S_PARTITION_SIZE` and `FLASH_NS_PARTITION_SIZE` must be sector size (2KiB)-aligned.
57+
58+
### Defining SRAM for TF-M/Mbed
59+
60+
To define memory spec of SRAM for TF-M/Mbed, search/change the line:
61+
62+
**trusted-firmware-m/platform/ext/target/nuvoton/m2354/partition/region_defs.h**:
63+
```C
64+
/* Max SRAM size for TF-M */
65+
#define S_DATA_SIZE (80 * 1024)
66+
/* Max SRAM size for Mbed = Total - Max SRAM size for TF-M */
67+
#define NS_DATA_SIZE (TOTAL_RAM_SIZE - S_DATA_SIZE)
68+
```
69+
70+
**NOTE**: `S_DATA_SIZE` and `NS_DATA_SIZE` must be 16KiB-aligned required by M2354 Security Configuration Unit (SCU).
71+
72+
## Rebuilding TF-M
73+
74+
### Environment
75+
76+
Navigate [TF-M](https://www.trustedfirmware.org/projects/tf-m/).
77+
Then go through **DOCS****Getting Started Guides****Software requirements** for TF-M build environment setup.
5978

60-
To re-build TF-M, run:
79+
**NOTE**: For unknown reason, **GNU Arm Embedded Toolchain 10-2020-q4-major** built code **FAILS** to run. Avoid this toolchain version.
80+
81+
### Compile
82+
83+
To compile TF-M on M2354, run:
6184

6285
```sh
63-
$ cmake -S . \
86+
cmake -S . \
6487
-B cmake_build \
6588
-DTFM_PLATFORM=nuvoton/m2354 \
6689
-DTFM_TOOLCHAIN_FILE=toolchain_GNUARM.cmake \
@@ -69,8 +92,41 @@ $ cmake -S . \
6992
-G"Unix Makefiles"
7093
```
7194

95+
Then:
96+
7297
```sh
73-
$ cmake --build cmake_build -- install
98+
cmake --build cmake_build -- install
7499
```
75100

76-
**NOTE**: This patch has not been public yet.
101+
## Integrating with Mbed
102+
103+
### Updating TF-M exported stuff
104+
105+
The following TF-M exported stuffs must update into Mbed:
106+
107+
- bl2.bin: [MCUboot](https://github.com/mcu-tools/mcuboot) bootloader binary
108+
109+
- tfm_s.bin: TF-M secure binary
110+
111+
- s_veneers.o: TF-M secure gateway library
112+
113+
- partition/: Flash layout for image signing and concatenating in post-build process
114+
115+
**NOTE**: On import, `signing_layout_s_ns.o` is renamed to `signing_layout_preprocessed.h` for the following reasons:
116+
- Post-build script checks file name with `_s`/`_ns` to resolve `sw_type` as `SPE`/`NSPE` respectively.
117+
To recognize as `NSPE_SPE`, don't use `_s_ns`/`_ns_s` file name to avoid mis-recognized.
118+
- Use `.h` instead of `.c` as file extension name.
119+
This is to enable custom TF-M build where the locatioin of this directory can change elsewhere.
120+
In Greentea build process, `.c` file isn't but`.h` file is copied into `BUILD` directory, so that post-build script can still access the file.
121+
122+
- [signing_key/](signing_key/nuvoton_m2354-root-rsa-3072.md)
123+
124+
Below summarizes the copy paths from TF-M into Mbed:
125+
126+
- trusted-firmware-m/cmake_build/bin/bl2.bin → bl2.bin
127+
- trusted-firmware-m/cmake_build/install/export/tfm/lib/s_veneers.o → s_veneers.o
128+
- trusted-firmware-m/cmake_build/bin/tfm_s.bin → tfm_s.bin
129+
- trusted-firmware-m/platform/ext/target/nuvoton/m2354/partition/flash_layout.h → partition/flash_layout.h
130+
- trusted-firmware-m/platform/ext/target/nuvoton/m2354/partition/region_defs.h → partition/region_defs.h
131+
- trusted-firmware-m/cmake_build/bl2/ext/mcuboot/CMakeFiles/signing_layout_s.dir/signing_layout_s_ns.o → partition/signing_layout_preprocessed.h
132+
- trusted-firmware-m/bl2/ext/mcuboot/root-RSA-3072.pem → signing_key/nuvoton_m2354-root-rsa-3072.pem

0 commit comments

Comments
 (0)