-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
M2354: Support PSA Firmware Update #14972
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
# Rebuild TF-M and integrate with Mbed on M2354 | ||
# Rebuild TF-M and integrate with Mbed for M2354 | ||
|
||
This document guides how to rebuild TF-M and integrate with Mbed on M2354. | ||
This document guides how to rebuild TF-M and integrate with Mbed for M2354. | ||
|
||
### Downloading TF-M source | ||
|
||
The M2354 port in TF-M must patch to enable TF-M integration with Mbed. | ||
For TF-M 1.3/Mbed integration on M2354, the [mainstream TF-M](https://git.trustedfirmware.org/TF-M/trusted-firmware-m.git) is patched as follows: | ||
For TF-M 1.3/Mbed integration for M2354, the [mainstream TF-M](https://git.trustedfirmware.org/TF-M/trusted-firmware-m.git) is patched as follows: | ||
- Apply Mbed-enabled patch to `nuvoton/m2354` TF-M target. | ||
|
||
Run the following command to fetch and switch to the intended version: | ||
```sh | ||
git clone https://github.com/OpenNuvoton/trusted-firmware-m -b nuvoton_mbed_m2354_tfm-1.3 | ||
``` | ||
$ git clone https://github.com/OpenNuvoton/trusted-firmware-m -b nuvoton_mbed_m2354_tfm-1.3 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fork and branch doesn't seem to contain the Firmware Update changes in this PR? Do they come from somewhere else? We will upgrade TF-M in Mbed OS to v1.4.0 soon, so it would be good to have all patches on one branch, making it easy to rebase them to TF-M v1.4.0 when we need to. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah I can see your fork of mbed-os-tf-m-regression-tests points to your fork of trusted-firmware-m, which has branches for both TF-M v1.3 and v1.4 with all the Firmware Update patches. 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The OpenNuvoton TF-M fork is the officially public one for users who want to re-build TF-M for M2354. As this PR lands, the |
||
``` | ||
|
||
## Customizing TF-M | ||
|
@@ -36,6 +36,7 @@ In TF-M, by default, the M2354 hardware is partitioned as follows: | |
- **PDMA1**: Configured to nonsecure for Mbed asynchronous transfer. | ||
- **CRYPTO**: Configured to secure. Inaccessible to Mbed. | ||
- **TRNG**: Hardwired to secure. Accessible to Mbed indirectly through PSA Cryptography API. | ||
- **SDH**: Configured to secure to enable PSA Firmware Update. Inaccessible to Mbed. | ||
|
||
### Defining Flash for TF-M/Mbed | ||
|
||
|
@@ -75,14 +76,22 @@ To define memory spec of SRAM for TF-M/Mbed, search/change the line: | |
Navigate [TF-M](https://www.trustedfirmware.org/projects/tf-m/). | ||
Then go through **DOCS** → **Getting Started Guides** → **Software requirements** for TF-M build environment setup. | ||
|
||
**NOTE**: **GNU Arm Embedded Toolchain 9 2020-q2-update** and earlier built code **FAILS** to run with `-Os`. Avoid these toolchain versions. Check [their bug report](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95646). | ||
|
||
**NOTE**: **GNU Arm Embedded Toolchain 10-2020-q4-major** built code **FAILS** to run. Avoid this toolchain version. Check [its bug report](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99157). | ||
|
||
### Compile | ||
### Default relevant build configurations | ||
|
||
- Enabled BL2 (MCUboot) | ||
- Enabled multiple image boot | ||
- Enabled SDH (SD card) as update staging area for PSA Firmware Update | ||
|
||
### Compiling | ||
|
||
To compile TF-M on M2354, run: | ||
To compile TF-M for M2354, run: | ||
|
||
```sh | ||
cmake -S . \ | ||
``` | ||
$ cmake -S . \ | ||
-B cmake_build \ | ||
-DTFM_PLATFORM=nuvoton/m2354 \ | ||
-DTFM_TOOLCHAIN_FILE=toolchain_GNUARM.cmake \ | ||
|
@@ -93,8 +102,8 @@ cmake -S . \ | |
|
||
Then: | ||
|
||
```sh | ||
cmake --build cmake_build -- install | ||
``` | ||
$ cmake --build cmake_build -- install | ||
``` | ||
|
||
## Integrating with Mbed | ||
|
@@ -111,21 +120,41 @@ The following TF-M exported stuffs must update into Mbed: | |
|
||
- partition/: Flash layout for image signing and concatenating in post-build process | ||
|
||
**NOTE**: On import, `signing_layout_s_ns.o` is renamed to `signing_layout_preprocessed.h` for the following reasons: | ||
- Post-build script checks file name with `_s`/`_ns` to resolve `sw_type` as `SPE`/`NSPE` respectively. | ||
To recognize as `NSPE_SPE`, don't use `_s_ns`/`_ns_s` file name to avoid mis-recognized. | ||
- Use `.h` instead of `.c` as file extension name. | ||
This is to enable custom TF-M build where the locatioin of this directory can change elsewhere. | ||
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. | ||
**NOTE**: On import, `signing_layout_*.o` are renamed to `signing_layout_*.h`. | ||
This is to use `.h` instead of `.c`/`.o` as file extension name and avoid adding into compile/link list. | ||
|
||
**NOTE**: On import for single image boot, `signing_layout_s_ns.o` is renamed to `signing_layout_preprocessed.h`. | ||
Post-build script checks file name with `_s`/`_ns` to resolve `sw_type` as `SPE`/`NSPE` respectively. | ||
To recognize as `NSPE_SPE`, don't use `_s_ns`/`_ns_s` file name to avoid mis-recognized. | ||
|
||
- [signing_key/](signing_key/nuvoton_m2354-root-rsa-3072.md) | ||
|
||
Below summarizes the copy paths from TF-M into Mbed: | ||
Below summarize the copy paths from TF-M into Mbed: | ||
|
||
- trusted-firmware-m/cmake_build/bin/bl2.bin → bl2.bin | ||
- trusted-firmware-m/cmake_build/install/export/tfm/lib/s_veneers.o → s_veneers.o | ||
- trusted-firmware-m/cmake_build/bin/tfm_s.bin → tfm_s.bin | ||
- trusted-firmware-m/cmake_build/install/outputs/NUVOTON/M2354/bl2.bin → bl2.bin | ||
- trusted-firmware-m/cmake_build/install/outputs/NUVOTON/M2354/tfm_s.bin → tfm_s.bin | ||
- trusted-firmware-m/cmake_build/install/interface/lib/s_veneers.o → s_veneers.o | ||
- trusted-firmware-m/platform/ext/target/nuvoton/m2354/partition/flash_layout.h → partition/flash_layout.h | ||
- trusted-firmware-m/platform/ext/target/nuvoton/m2354/partition/region_defs.h → partition/region_defs.h | ||
- trusted-firmware-m/cmake_build/bl2/ext/mcuboot/CMakeFiles/signing_layout_s.dir/signing_layout_s_ns.o → partition/signing_layout_preprocessed.h | ||
- trusted-firmware-m/bl2/ext/mcuboot/root-RSA-3072.pem → signing_key/nuvoton_m2354-root-rsa-3072.pem | ||
- trusted-firmware-m/cmake_build/install/image_signing/layout_files/signing_layout_s.o → partition/signing_layout_s_preprocessed.h | ||
- trusted-firmware-m/cmake_build/install/image_signing/layout_files/signing_layout_ns.o → partition/signing_layout_ns_preprocessed.h | ||
- trusted-firmware-m/cmake_build/install/image_signing/keys/root-RSA-3072.pem → signing_key/nuvoton_m2354-root-rsa-3072.pem | ||
- trusted-firmware-m/cmake_build/install/image_signing/keys/root-RSA-3072_1.pem → signing_key/nuvoton_m2354-root-rsa-3072_1.pem | ||
|
||
**NOTE**: `trusted-firmware-m/cmake_build/install/image_signing/keys/root-RSA-3072.pem` can be missing due to TF-M build tool issue. | ||
Try to get it from `trusted-firmware-m/bl2/ext/mcuboot/root-RSA-3072.pem` instead if it is just the original source. | ||
|
||
## PSA Firmware Update | ||
|
||
### Requirement | ||
|
||
- SD card: Used for update staging area according to above TF-M build configurations. | ||
|
||
### Update binary files | ||
|
||
After finishing Mbed build, you will find the following files under build directory. | ||
They are to write to update staging area through PSA Firmware Update API for firmware upgrade. | ||
|
||
- `tfm_s_update.bin`: TF-M secure binary file for update separately when multiple image boot is enabled | ||
- `<application>_update.bin`: Mbed non-secure binary file for update separately when multiple image boot is enabled or | ||
combined TF-M secure+Mbed non-secure binary file for update together when single image boot is enabled |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it mean we support both single and multi image boots, and updating from SD card and flash? Have all of them been tested with Mbed OS? And how will users select which one to use (with both Mbed CLI 1 and 2)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both from SD and from flash are supported and they are both verified with Mbed OS. But due to limited flash size 1MiB on M2354, from flash is not practical. From SD is the default and for public. From flash is for internal development/test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In principle, we can keep only the default/supported cased here, rather than having code for all cases. But I get the idea of making it flexible for internal development, so I'm personally fine with this.