Skip to content

Commit 8a04871

Browse files
authored
Merge pull request #664 from danielinux/m33mu-tests
Add new emulator 'm33mu' update tests
2 parents 16887c6 + 9e7f6c2 commit 8a04871

35 files changed

Lines changed: 2856 additions & 16 deletions
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: trustzone-emulator-tests
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
trustzone-emulator-tests:
9+
runs-on: ubuntu-latest
10+
container:
11+
image: ghcr.io/danielinux/m33mu-ci:1.2
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Init submodules
16+
run: |
17+
git config --global --add safe.directory "$GITHUB_WORKSPACE"
18+
git submodule update --init --single-branch
19+
20+
- name: Configure stm32h5 (TZ) and build wolfboot
21+
run: |
22+
cp config/examples/stm32h5-tz.config .config
23+
make wolfboot.bin
24+
25+
- name: Run emu test (stm32h5)
26+
working-directory: test-app/emu-test-apps
27+
run: |
28+
./test.sh
29+
30+
- name: Clean and build stm32u5 (TZ + wolfcrypt)
31+
run: |
32+
make clean distclean
33+
cp config/examples/stm32u5-wolfcrypt-tz.config .config
34+
make wolfboot.bin
35+
36+
- name: Run emu test (stm32u5)
37+
working-directory: test-app/emu-test-apps
38+
run: |
39+
TARGET=stm32u5 ./test.sh
40+
41+
- name: Clean and build stm32l5 (TZ + wolfcrypt)
42+
run: |
43+
make clean distclean
44+
cp config/examples/stm32l5-wolfcrypt-tz.config .config
45+
make wolfboot.bin
46+
47+
- name: Run emu test (stm32u5)
48+
working-directory: test-app/emu-test-apps
49+
run: |
50+
TARGET=stm32l5 ./test.sh

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
*.idb
4646
*.pdb
4747
*.gdb
48+
*.log
4849

4950
# automatically generated keys
5051
*.der
@@ -91,6 +92,9 @@ tools/delta/bmpatch
9192
# otp-keystore-gen binary
9293
tools/keytools/otp/otp-keystore-gen
9394

95+
# test-server binary
96+
test-app/emu-test-apps/*/test-update-server
97+
9498
# Vim swap files
9599
.*.swp
96100

@@ -300,3 +304,6 @@ language.settings.xml
300304

301305
# PolarFire SoC Device Tree Binary
302306
hal/mpfs.dtb
307+
308+
# Emulator test: generated linker scripts
309+
test-app/emu-test-apps/*/target.ld

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
url = https://github.com/wolfssl/wolfhsm.git
1313
[submodule "lib/wolfPSA"]
1414
path = lib/wolfPSA
15-
url = git@github.com:wolfSSL/wolfPSA.git
15+
url = https://github.com/wolfSSL/wolfPSA.git

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,9 @@ hal/$(TARGET).o:
340340

341341
keytools_check: keytools
342342

343+
test-emu:
344+
$(MAKE) -C test-app/emu-test-apps WOLFBOOT_ROOT="$(CURDIR)" test-emu
345+
343346
# Generate the initial signing key (only if not using user-provided keys)
344347
# - Creates wolfboot_signing_private_key.der when USER_PRIVATE_KEY is not set
345348
# - If CERT_CHAIN_VERIFY is enabled and USER_CERT_CHAIN not provided, also generates cert chain with leaf key

config/examples/stm32u5-wolfcrypt-tz.config

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ V?=0
1818
SPMATH?=1
1919
RAM_CODE?=0
2020
DUALBANK_SWAP?=0
21-
WOLFBOOT_PARTITION_SIZE?=0x1F800
22-
WOLFBOOT_SECTOR_SIZE?=0x800
21+
WOLFBOOT_PARTITION_SIZE?=0x20000
22+
WOLFBOOT_SECTOR_SIZE?=0x2000
2323
WOLFBOOT_KEYVAULT_ADDRESS?=0x0C020000
2424
WOLFBOOT_KEYVAULT_SIZE?=0x18000
2525
WOLFBOOT_NSC_ADDRESS?=0x0C038000
2626
WOLFBOOT_NSC_SIZE?=0x8000
2727
WOLFBOOT_PARTITION_BOOT_ADDRESS?=0x08040000
28-
WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x805F800
29-
WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x0807F000
28+
WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x08060000
29+
WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x08080000
3030
FLAGS_HOME=0
3131
DISABLE_BACKUP=0
3232
WOLFCRYPT_TZ=1

config/examples/stm32u5.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ SPMATH?=1
2121
RAM_CODE?=0
2222
DUALBANK_SWAP?=0
2323
WOLFBOOT_PARTITION_SIZE?=0x1F800
24-
WOLFBOOT_SECTOR_SIZE?=0x800
24+
WOLFBOOT_SECTOR_SIZE?=0x2000
2525
WOLFBOOT_KEYVAULT_ADDRESS?=0x0C020000
2626
WOLFBOOT_KEYVAULT_SIZE?=0x18000
2727
WOLFBOOT_NSC_ADDRESS?=0x0C038000

hal/stm32_tz.c

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include "hal/stm32u5.h"
3030
#endif
3131

32-
#ifdef TARGET_stm32h5
32+
#if defined(TARGET_stm32h5)
3333
#include "hal/stm32h5.h"
3434
#endif
3535

@@ -225,6 +225,38 @@ void hal_gtzc_init(void)
225225
}
226226
}
227227

228+
#elif defined(TARGET_stm32u5)
229+
230+
#define GTZC_MPCBB1_S_BASE (0x50032C00)
231+
#define GTZC_MPCBB1_S_VCTR_BASE (GTZC_MPCBB1_S_BASE + 0x100)
232+
233+
#define GTZC_MPCBB2_S_BASE (0x50033000)
234+
#define GTZC_MPCBB2_S_VCTR_BASE (GTZC_MPCBB2_S_BASE + 0x100)
235+
236+
#define SET_GTZC_MPCBBx_S_VCTR(bank,n,val) \
237+
(*((volatile uint32_t *)(GTZC_MPCBB##bank##_S_VCTR_BASE ) + n ))= val
238+
239+
void hal_gtzc_init(void)
240+
{
241+
int i;
242+
/* One bit in the bitmask: 512B (STM32U5) */
243+
244+
/* Configure SRAM1 lower 128 KB as secure (0x20000000 - 0x2001FFFF). */
245+
for (i = 0; i < 8; i++) {
246+
SET_GTZC_MPCBBx_S_VCTR(1, i, 0xFFFFFFFF);
247+
}
248+
249+
/* Configure SRAM1 upper 128 KB as non-secure (0x20020000 - 0x2003FFFF). */
250+
for (i = 8; i < 16; i++) {
251+
SET_GTZC_MPCBBx_S_VCTR(1, i, 0x0);
252+
}
253+
254+
/* Configure SRAM2 as non-secure (0x20030000 - 0x2003FFFF). */
255+
for (i = 0; i < 4; i++) {
256+
SET_GTZC_MPCBBx_S_VCTR(2, i, 0x0);
257+
}
258+
}
259+
228260
#else
229261

230262
#define GTZC_MPCBB1_S_BASE (0x50032C00)

hal/stm32l5.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
#include "hal.h"
2727
#include "hal/stm32l5.h"
28-
#include "printf.h"
2928

3029

3130
static void RAMFUNCTION flash_set_waitstates(unsigned int waitstates)
@@ -152,13 +151,6 @@ int RAMFUNCTION hal_flash_erase(uint32_t address, int len)
152151
uint32_t end_address;
153152
uint32_t p;
154153

155-
if (address < WOLFBOOT_PARTITION_BOOT_ADDRESS) {
156-
wolfBoot_printf("hal_flash_erase: addr=0x%08x len=%d (below boot)\n",
157-
address, len);
158-
} else {
159-
wolfBoot_printf("hal_flash_erase: addr=0x%08x len=%d\n", address, len);
160-
}
161-
162154
hal_flash_clear_errors(0);
163155
if (len == 0)
164156
return -1;

hal/stm32u5.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,35 @@ static void led_unsecure()
489489
#endif
490490
}
491491

492+
#if TZ_SECURE()
493+
#define TZSC1_BASE 0x50032400u
494+
#define TZSC_SECCFGR1 (*(volatile uint32_t *)(TZSC1_BASE + 0x10u))
495+
#define TZSC_SECCFGR1_USART3SEC (1u << 10)
496+
497+
static void periph_unsecure(void)
498+
{
499+
volatile uint32_t reg;
500+
501+
/* Enable clock for GPIO D (USART3 pins PD8/PD9) */
502+
RCC_AHB2ENR1_CLOCK_ER |= GPIOD_AHB2ENR1_CLOCK_ER;
503+
504+
/* Enable clock for USART3 */
505+
RCC_APB1ENR |= (1u << 18);
506+
507+
/* Unsecure USART3 pins (PD8 TX, PD9 RX) */
508+
GPIOD_SECCFGR &= ~(1u << 8);
509+
GPIOD_SECCFGR &= ~(1u << 9);
510+
511+
/* Unsecure USART3 peripheral in GTZC TZSC */
512+
reg = TZSC_SECCFGR1;
513+
if (reg & TZSC_SECCFGR1_USART3SEC) {
514+
reg &= ~TZSC_SECCFGR1_USART3SEC;
515+
DMB();
516+
TZSC_SECCFGR1 = reg;
517+
}
518+
}
519+
#endif
520+
492521
#if defined(DUALBANK_SWAP) && defined(__WOLFBOOT)
493522
static uint8_t bootloader_copy_mem[BOOTLOADER_SIZE];
494523
static void RAMFUNCTION fork_bootloader(void)
@@ -530,6 +559,7 @@ void hal_prepare_boot(void)
530559
clock_pll_off();
531560
#endif
532561
#if TZ_SECURE()
562+
periph_unsecure();
533563
led_unsecure();
534564
#endif
535565
}

hal/stm32u5.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@
119119

120120
#define RCC_AHB3ENR (*(volatile uint32_t *)(RCC_BASE + 0x94)) /* RM0456 - Table 108 */
121121
#define RCC_AHB3ENR_GTZC2EN (1 << 12)
122+
123+
#define RCC_APB1ENR (*(volatile uint32_t *)(RCC_BASE + 0x9C)) /* RM0456 - Table 108 */
122124
#define RCC_AHB3ENR_PWREN (1 << 2)
123125

124126
#define RCC_ICSCR1 (*(volatile uint32_t *)(RCC_BASE + 0x08))
@@ -249,10 +251,12 @@
249251

250252
/* GPIO*/
251253
#define GPIOC_BASE 0x52020800
254+
#define GPIOD_BASE 0x52020C00
252255
#define GPIOG_BASE 0x52021800
253256
#define GPIOH_BASE 0x52021C00
254257

255258
#define GPIOC_SECCFGR (*(volatile uint32_t *)(GPIOC_BASE + 0x30))
259+
#define GPIOD_SECCFGR (*(volatile uint32_t *)(GPIOD_BASE + 0x30))
256260
#define GPIOG_SECCFGR (*(volatile uint32_t *)(GPIOG_BASE + 0x30))
257261
#define GPIOH_SECCFGR (*(volatile uint32_t *)(GPIOH_BASE + 0x30))
258262

@@ -266,6 +270,7 @@
266270

267271
#define RCC_AHB2ENR1_CLOCK_ER (*(volatile uint32_t *)(RCC_BASE + 0x8C ))
268272
#define GPIOC_AHB2ENR1_CLOCK_ER (1 << 2)
273+
#define GPIOD_AHB2ENR1_CLOCK_ER (1 << 3)
269274
#define GPIOG_AHB2ENR1_CLOCK_ER (1 << 6)
270275
#define GPIOH_AHB2ENR1_CLOCK_ER (1 << 7)
271276
#define TRNG_AHB2_CLOCK_ER (1 << 18)

0 commit comments

Comments
 (0)