Skip to content

Commit 5cc9950

Browse files
committed
Initial wolfHSM support for simulator and AURIX TC3xx
1 parent b333317 commit 5cc9950

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+4272
-2155
lines changed

.github/workflows/test-configs.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,3 +433,9 @@ jobs:
433433
arch: aarch64
434434
config-file: ./config/examples/zynqmp.config
435435
make-args: CROSS_COMPILE=aarch64-linux-gnu-
436+
437+
sim_wolfhsm_test:
438+
uses: ./.github/workflows/test-build.yml
439+
with:
440+
arch: host
441+
config-file: ./config/examples/sim-wolfHSM.config
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: wolfHSM simulator test
2+
3+
on:
4+
push:
5+
branches: [ 'master', 'main', 'release/**' ]
6+
pull_request:
7+
branches: [ '*' ]
8+
workflow_dispatch:
9+
10+
jobs:
11+
wolfhsm_simulator_test:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
with:
16+
submodules: true
17+
18+
- name: Workaround for sources.list
19+
run: sudo sed -i 's|http://azure.archive.ubuntu.com/ubuntu/|http://mirror.arizona.edu/ubuntu/|g' /etc/apt/sources.list
20+
21+
- name: Update repository
22+
run: sudo apt-get update
23+
24+
- name: make clean
25+
run: |
26+
make distclean
27+
28+
- name: Select config (wolfHSM simulator)
29+
run: |
30+
cp config/examples/sim-wolfHSM.config .config
31+
32+
- name: Build tools
33+
run: |
34+
make -C tools/keytools && make -C tools/bin-assemble
35+
36+
- name: Build wolfboot.elf
37+
run: |
38+
make clean && make test-sim-internal-flash-with-update
39+
40+
# checkout and build wolfHSM examples repo
41+
- name: Checkout wolfHSM-examples
42+
uses: actions/checkout@v3
43+
with:
44+
repository: wolfssl/wolfHSM-examples
45+
path: wolfHSM-examples
46+
47+
- name: Build example POSIX TCP server
48+
run: cd wolfHSM-examples/posix/tcp/wh_server_tcp && make WOLFSSL_DIR=../../../../lib/wolfssl WOLFHSM_DIR=../../../../lib/wolfHSM
49+
50+
# Start the server in the background
51+
- name: Run POSIX TCP server
52+
run: |
53+
cd wolfHSM-examples/posix/tcp/wh_server_tcp
54+
./Build/wh_server_tcp.elf --client 12 --id 255 --key ../../../../wolfboot_signing_private_key_pub.der &
55+
TCP_SERVER_PID=$!
56+
echo "TCP_SERVER_PID=$TCP_SERVER_PID" >> $GITHUB_ENV
57+
58+
# Run the sunny day update test against the server
59+
- name: Run sunny day update test
60+
run: |
61+
tools/scripts/sim-sunnyday-update.sh
62+
63+
# Kill the server if it is still running
64+
- name: Kill POSIX TCP server
65+
run: |
66+
kill $TCP_SERVER_PID

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ IDE/AURIX/SDK/*
209209
!IDE/AURIX/SDK/placeholder.txt
210210
IDE/AURIX/Configurations/*
211211
!IDE/AURIX/Configurations/placeholder.txt
212+
IDE/AURIX/wolfHSM-infineon-tc3xx/*
213+
!IDE/AURIX/wolfHSM-infineon-tc3xx/placeholder.txt
212214

213215
tpm_seal_key.key
214216

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@
77
[submodule "lib/wolfPKCS11"]
88
path = lib/wolfPKCS11
99
url = https://github.com/wolfSSL/wolfPKCS11.git
10+
[submodule "lib/wolfHSM"]
11+
path = lib/wolfHSM
12+
url = https://github.com/wolfssl/wolfhsm.git

IDE/AURIX/README.md

Lines changed: 103 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,32 @@
1-
# Overview
1+
# WolfBoot on Infineon AURIX TC3xx
22

33
This example demonstrates using wolfBoot on the Infineon AURIX TC3xx family of microcontrollers. The example is based on the TC375 Lite-Kit V2, but should be easily adaptable to other TC3xx devices. This README assumes basic familiarity with the TC375 SoC, the AURIX IDE, and Lauterbach Trace32 debugger.
44

5+
## Overview
6+
7+
- [WolfBoot on Infineon AURIX TC3xx](#wolfboot-on-infineon-aurix-tc3xx)
8+
- [Overview](#overview)
9+
- [Important notes](#important-notes)
10+
- [Flash Partitioning](#flash-partitioning)
11+
- [Building and running the wolfBoot demo](#building-and-running-the-wolfboot-demo)
12+
- [Prerequisites](#prerequisites)
13+
- [Clone wolfBoot](#clone-wolfboot)
14+
- [Build wolfBoot keytools and generate keys](#build-wolfboot-keytools-and-generate-keys)
15+
- [Install the Infineon TC3xx SDK into the wolfBoot project](#install-the-infineon-tc3xx-sdk-into-the-wolfboot-project)
16+
- [Build wolfBoot](#build-wolfboot)
17+
- [Connect the Lauterbach to the TC375 Device in TRACE32](#connect-the-lauterbach-to-the-tc375-device-in-trace32)
18+
- [Update the start address in UCBs using TRACE32](#update-the-start-address-in-ucbs-using-trace32)
19+
- [Load and run the wolfBoot demo in TRACE32](#load-and-run-the-wolfboot-demo-in-trace32)
20+
- [wolfHSM Compatibility](#wolfhsm-compatibility)
21+
- [Building wolfBoot with wolfHSM](#building-wolfboot-with-wolfhsm)
22+
- [Troubleshooting](#troubleshooting)
23+
- [WSL "bad interpreter" error](#wsl-bad-interpreter-error)
24+
525
The example contains two projects: `wolfBoot-tc3xx` and `test-app`. The `wolfBoot-tc3xx` project contains the wolfBoot bootloader, and the `test-app` project contains a simple firmware application that will be loaded and executed by wolfBoot. The `test-app` project is a simple blinky application that blinks LED2 on the TC375 Lite-Kit V2 once per second when running the base image, and rapidly (~3x/sec) when running the update image. The test app determines if it is a base or update image by inspecting the firmware version (obtained through the wolfBoot API). The firmware version is set in the image header by the wolfBoot keytools when signing the test app binaries. The same test app binary is used for both the base and update images, with the only difference being the firmware version set by the keytools.
626

727
## Important notes
828

9-
- In the TC375 UCBs, BMDHx.STAD must point to the wolfBoot entrypoint `0xA000_0000`. This is the default value of the TC375 and so need not be changed unless it has already been modified or you wish to rearrange the memory map.
29+
- In the TC375 UCBs, BMDHx.STAD must point to the wolfBoot entrypoint `0xA00A_0000`. You can modify this in the `UCB` section of the TRACE32 IDE as described in the steps later in this document. Please refer to the TRACE32 manual and the TC37xx user manual for more information on the UCBs.
1030
- Because TC3xx PFLASH ECC prevents reading from erased flash, the `EXT_FLASH` option is used to redirect flash reads to the `ext_flash_read()` HAL API, where the flash pages requested to be read can be blank-checked by hardware before reading.
1131
- TC3xx PFLASH is write-once (`NVM_FLASH_WRITEONCE`), however wolfBoot `NVM_FLASH_WRITEONCE` does not support `EXT_FLASH`. Therefore the write-once functionality is re-implemented in the `HAL` layer.
1232
- This demo app is only compatible with the GCC toolchain build configurations shipped with the AURIX IDE. The TASKING compiler build configurations are not yet supported.
@@ -18,20 +38,22 @@ The TC3xx AURIX port of wolfBoot places all images in PFLASH, and uses both PFLA
1838
```
1939
+==========+
2040
| PFLASH0 |
21-
+==========+ <-- 0x8000_0000
22-
| wolfBoot | 128K
23-
+----------+ <-- 0x8002_0000
24-
| SWAP | 16K
25-
+----------+ <-- 0x8002_4000
26-
| Unused | ~2.86M
41+
+----------+ <-- 0x8000_0000
42+
| Unused | 640K
43+
+==========+ <-- 0x800A_0000
44+
| wolfBoot | 172K
45+
+----------+ <-- 0x8002_B000
46+
| Unused | ~2.8M
2747
+----------+ <-- 0x8030_0000
2848
2949
+==========+
3050
| PFLASH1 |
3151
+==========+ <-- 0x8030_0000
32-
| BOOT | 1.5M
33-
+----------+ <-- 0x8048_0000
34-
| UPDATE | 1.5M
52+
| BOOT | 1.5M (0x17E000)
53+
+----------+ <-- 0x8047_E000
54+
| UPDATE | 1.5M (0x17E000)
55+
+----------+ <-- 0x805F_C000
56+
| SWAP | 16K (0x4000)
3557
+----------+ <-- 0x8060_0000
3658
```
3759

@@ -54,20 +76,19 @@ Please refer to the [wolfBoot](wolfBoot-tc3xx/Lcf_Gnu_Tricore_Tc.lsl) and [test-
5476

5577
1. Open a WSL2 terminal and navigate to the top level `wolfBoot` directory
5678
2. Compile the keytools by running `make keytools`
57-
3. Use the helper script to generate a new signing key pair using RSA 4096
79+
3. Use the helper script to generate a new signing key pair using ECC 256
5880
1. Navigate to `wolfBoot/tools/scripts/tc3xx`
5981
2. Run `./gen-tc3xx-keys.sh`. This generates the signing private key `wolfBoot/priv.der` and adds the public key to the wolfBoot keystore (see [keygen](https://github.com/wolfSSL/wolfBoot/blob/aurix-tc3xx-support/docs/Signing.md) for more information). If you already have generated a key, you will be prompted to overwrite it.
6082

6183
```
6284
$ ./gen-tc3xx-keys.sh
6385
+ cd ../../../
64-
+ ./tools/keytools/keygen -g priv.der --rsa4096
65-
Keytype: RSA4096
66-
Generating key (type: RSA4096)
67-
RSA public key len: 550 bytes
86+
+ tools/keytools/keygen --ecc256 -g priv.der
87+
Keytype: ECC256
88+
Generating key (type: ECC256)
6889
Associated key file: priv.der
6990
Partition ids mask: ffffffff
70-
Key type : RSA4096
91+
Key type : ECC256
7192
Public key slot: 0
7293
Done.
7394
```
@@ -125,45 +146,62 @@ wolfBoot/IDE/AURIX/Configurations/
125146

126147
```
127148
$ ./gen-tc3xx-signed-test-apps-release.sh
128-
+ ../../keytools/sign --rsa4096 --sha256 '../../../IDE/AURIX/test-app/TriCore Release (GCC)/test-app.bin' ../../../priv.der 1
149+
+ ../../keytools/sign --ecc256 --sha256 '../../../IDE/AURIX/test-app/TriCore Release (GCC)/test-app.bin' ../../../priv.der 1
129150
wolfBoot KeyTools (Compiled C version)
130-
wolfBoot version 2010000
151+
wolfBoot version 2020000
131152
Update type: Firmware
132153
Input image: ../../../IDE/AURIX/test-app/TriCore Release (GCC)/test-app.bin
133-
Selected cipher: RSA4096
154+
Selected cipher: ECC256
134155
Selected hash : SHA256
135156
Public key: ../../../priv.der
136157
Output image: ../../../IDE/AURIX/test-app/TriCore Release (GCC)/test-app_v1_signed.bin
137158
Target partition id : 1
138-
Found RSA512 key
139-
image header size calculated at runtime (1024 bytes)
159+
image header size calculated at runtime (256 bytes)
140160
Calculating SHA256 digest...
141161
Signing the digest...
142162
Output image(s) successfully created.
143-
+ ../../keytools/sign --rsa4096 --sha256 '../../../IDE/AURIX/test-app/TriCore Release (GCC)/test-app.bin' ../../../priv.der 2
163+
+ ../../keytools/sign --ecc256 --sha256 '../../../IDE/AURIX/test-app/TriCore Release (GCC)/test-app.bin' ../../../priv.der 2
144164
wolfBoot KeyTools (Compiled C version)
145-
wolfBoot version 2010000
165+
wolfBoot version 2020000
146166
Update type: Firmware
147167
Input image: ../../../IDE/AURIX/test-app/TriCore Release (GCC)/test-app.bin
148-
Selected cipher: RSA4096
168+
Selected cipher: ECC256
149169
Selected hash : SHA256
150170
Public key: ../../../priv.der
151171
Output image: ../../../IDE/AURIX/test-app/TriCore Release (GCC)/test-app_v2_signed.bin
152172
Target partition id : 1
153-
Found RSA512 key
154-
image header size calculated at runtime (1024 bytes)
173+
image header size calculated at runtime (256 bytes)
155174
Calculating SHA256 digest...
156175
Signing the digest...
157176
Output image(s) successfully created.
158177
```
159178

160-
### Load and run the wolfBoot demo
179+
### Connect the Lauterbach to the TC375 Device in TRACE32
180+
181+
1. Ensure the Lauterbach probe is connected to the debug port of the tc375 LiteKit
182+
2. Open Trace32 Power View for Tricore
183+
3. Open the SYStem menu and click "DETECT" to detect the tc375 device. Click "CONTINUE" in the pop-up window, and then choose "Set TC375xx" when the device is detected
184+
185+
### Update the start address in UCBs using TRACE32
186+
187+
The default Boot Mode Header (BMHD) start address on a new TC375 `0xA0000000` but the wolfBoot application has a start address of `0xA00A0000`. We must therefore update the BMHD UCBs with the correct entry point such that it can boot wolfBoot out of reset.
188+
189+
1. Select the TC37x dropdown menu and click UCBs
190+
2. Expand `BMHD0_COPY`
191+
3. Click "Edit"
192+
4. Set the `STAD` to `0xA00A0000`
193+
5. Click "Update" to recompute the CRC
194+
6. Click "Check" to verify the new CRC
195+
7. Click "Write" to update the UCB in flash
196+
8. Perform the same operations (2-7) on the `BMHD0_ORIG` UCB
161197

162-
1. Load wolfBoot and the firmware application images to the tc3xx device using Trace32 and a Lauterbach probe
163-
1. Ensure the Lauterbach probe is connected to the debug port of the tc375 LiteKit
164-
2. Open Trace32 Power View for Tricore
165-
3. Open the SYStem menu and click "DETECT" to detect the tc375 device. Click "CONTINUE" in the pop-up window, and then choose "Set TC375xx" when the device is detected
166-
4. Click "File" -> "ChangeDir and Run Script" and choose the `wolfBoot/tools/scripts/tc3xx/wolfBoot-loadAll-$BUILD.cmm` script, where $BUILD should be either "debug" or "release" depending on your build type in (4) and (6).
198+
The device is now configured to boot from `0xA00A0000` out of reset.
199+
200+
### Load and run the wolfBoot demo in TRACE32
201+
202+
We can now load wolfBoot and the firmware application images to the tc3xx device using Trace32 and a Lauterbach probe
203+
204+
1. Click "File" -> "ChangeDir and Run Script" and choose the `wolfBoot/tools/scripts/tc3xx/wolfBoot-loadAll-$BUILD.cmm` script, where $BUILD should be either "debug" or "release" depending on your build type in (4) and (6).
167205

168206
wolfBoot and the demo applications are now loaded into flash, and core0 will be halted at the wolfBoot entry point (`core0_main()`).
169207

@@ -173,15 +211,45 @@ wolfBoot and the demo applications are now loaded into flash, and core0 will be
173211

174212
To rerun the demo, simply rerun the loader script in Trace32 and repeat the above steps
175213

214+
## wolfHSM Compatibility
215+
216+
wolfBoot has full support for wolfHSM on the AURIX TC3xx platform. The wolfBoot application functions as the HSM client, and all cryptographic operations required to verify application images are offloaded to the HSM. When used in tandem with wolfHSM, wolfBoot can be configured to use keys stored on the HSM for cryptographic operations, or to store keys in the default keystore and send them on-demand to the HSM for usage. The former option is the default configuration, and is recommended for most use cases, as key material will never leave the secure boundary of the HSM. The latter option is useful for development and testing, before keys have been preloaded onto the HSM.
217+
218+
Note that information regarding the AURIX TC3xx HSM core is restricted by NDA with Infineon. Source code for the wolfHSM TC3xx platform port is therefore not publicly available and cannot be included for distribution in wolfBoot. Instructions to build wolfBoot with wolfHSM compatibility are provided here, but the wolfHSM TC3xx port must be obtained separately from wolfSSL. To obtain the wolfHSM TC3xx port, please contact wolfSSL at [[email protected]](mailto:[email protected]).
219+
220+
### Building wolfBoot with wolfHSM
221+
222+
Steps to build wolfBoot on TC3xx with wolfHSM are largely similar to the non-HSM case, with a few key differences.
223+
224+
1. Obtain the wolfHSM release for the AURIX TC3xx from wolfSSL
225+
2. Extract the contents of the `infineon/tc3xx` directory from the wolfHSM TC3xx release you obtained from wolfSSL into the [wolfBoot/IDE/AURIX/wolfHSM-infineon-tc3xx](./wolfHSM-infineon-tc3xx/) directory. The contents of this directory should now be:
226+
227+
```
228+
IDE/AURIX/wolfHSM-infineon-tc3xx/
229+
├── README.md
230+
├── T32
231+
├── placeholder.txt
232+
├── port
233+
├── tchsm-client
234+
├── tchsm-server
235+
├── wolfHSM
236+
└── wolfssl
237+
```
238+
239+
3. Build the wolfHSM server application and load it onto the HSM core, following the instructions provided in the release you obtained from wolfSSL. You do not need to build or load the demo client application, as wolfBoot will act as the client.
240+
4. Follow all of the steps in [Building and Running the wolfBoot Demo](#building-and-running-the-wolfboot-demo) for the non-HSM enabled case, but with the following key differences:
241+
1. The [wolfBoot-tc3xx-wolfHSM](./wolfBoot-tc3xx-wolfHSM/) AURIX Studio project should be used instead of `wolfBoot-tc3xx`
242+
2. Use the `wolfBoot-wolfHSM-loadAll-XXX.cmm` lauterbach scripts instead of `wolfBoot-loadAll-XXX.cmm` to load the wolfBoot and test-app images in the TRACE32 GUI
243+
5. If using the default build options in [wolfBoot-tc3xx-wolfHSM](./wolfBoot-tc3xx-wolfHSM/), wolfBoot will expect the public key for image verification to be stored at a specific keyId for the wolfBoot client ID. You can use [whnvmtool](https://github.com/wolfSSL/wolfHSM/tree/main/tools/whnvmtool) to generate a loadable NVM image that contains the required keys. [wolfBoot-wolfHSM-keys.nvminit](../../tools/scripts/tc3xx/wolfBoot-wolfHSM-keys.nvminit) provides an example `whnvmtool` config file that will include the generated key in the NVM image, which can then be loaded to the device via a flash programming tool. See the `whnvmtool` documentation and the documentation included in your wolfHSM AURIX release for more details. Note: if you want to use the standard wolfBoot keystore functionality in conjunction with wolfHSM for testing purposes (doesn't require pre-loading keys on the HSM) you can configure wolfBoot to send the keys to the HSM on-the-fly as ephemeral keys. To do this, ensure `WOLFBOOT_USE_WOLFHSM_PUBKEY_ID` is **NOT** defined, and remove the `--nolocalkeys` argument when invoking `keygen` in the `./gen-tc3xx-keys.sh` script.
176244

177245
## Troubleshooting
178246

179-
### WSL "bad interpreter" error
247+
### WSL "bad interpreter" error
180248

181249
When running a shell script in WSL, you may see the following error:
182250

183251
```
184-
$ ./gen-tc3xx-target.sh:
252+
$ ./gen-tc3xx-target.sh:
185253
/bin/bash^M: bad interpreter: No such file or directory
186254
```
187255

IDE/AURIX/test-app/.settings/language.settings.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
2222
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
2323
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
24-
<provider class="com.infineon.aurix.buildsystem.managed.gcc.AURIXGCC11BuiltinSpecsDetector" console="false" env-hash="20899676975013635" id="com.infineon.aurix.buildsystem.managed.CrossGCC11BuiltinSpecsDetector" keep-relative-paths="false" name="AURIXCrossGCC11compilerSpecsDetector" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
24+
<provider class="com.infineon.aurix.buildsystem.managed.gcc.AURIXGCC11BuiltinSpecsDetector" console="false" env-hash="478447636549809998" id="com.infineon.aurix.buildsystem.managed.CrossGCC11BuiltinSpecsDetector" keep-relative-paths="false" name="AURIXCrossGCC11compilerSpecsDetector" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
2525
<language-scope id="org.eclipse.cdt.core.gcc"/>
2626
<language-scope id="org.eclipse.cdt.core.g++"/>
2727
</provider>
@@ -32,7 +32,7 @@
3232
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
3333
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
3434
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
35-
<provider class="com.infineon.aurix.buildsystem.managed.gcc.AURIXGCC11BuiltinSpecsDetector" console="false" env-hash="20899676975013635" id="com.infineon.aurix.buildsystem.managed.CrossGCC11BuiltinSpecsDetector" keep-relative-paths="false" name="AURIXCrossGCC11compilerSpecsDetector" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
35+
<provider class="com.infineon.aurix.buildsystem.managed.gcc.AURIXGCC11BuiltinSpecsDetector" console="false" env-hash="478447636549809998" id="com.infineon.aurix.buildsystem.managed.CrossGCC11BuiltinSpecsDetector" keep-relative-paths="false" name="AURIXCrossGCC11compilerSpecsDetector" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
3636
<language-scope id="org.eclipse.cdt.core.gcc"/>
3737
<language-scope id="org.eclipse.cdt.core.g++"/>
3838
</provider>

IDE/AURIX/test-app/Cpu0_Main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
IFX_ALIGN(4) IfxCpu_syncEvent g_cpuSyncEvent = 0;
2828

2929

30-
#define LED &MODULE_P00, 6 /* LED: Port, Pin definition */
30+
#define LED &MODULE_P00, 5 /* LED: Port, Pin definition */
3131
#define BLINK_TIME_BASE 500 /* Wait time constant in milliseconds */
3232
#define BLINK_TIME_UPDATE 100 /* Wait time constant in milliseconds */
3333

0 commit comments

Comments
 (0)