Skip to content

Commit

Permalink
STM32H5: Fixed memory access for NS app.
Browse files Browse the repository at this point in the history
Trustzone-M example working.
  • Loading branch information
danielinux committed May 7, 2024
1 parent db58f51 commit dd723d1
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 11 deletions.
10 changes: 5 additions & 5 deletions hal/stm32_tz.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ void hal_tz_release_nonsecure_area(void)
#define GTZC1_BASE (0x50032400)
#define GTZC1_TZSC (*(volatile uint32_t *)(GTZC1_BASE + 0x00))
#define GTZC1_TZIC (*(volatile uint32_t *)(GTZC1_BASE + 0x0400))
#define GTZC1_MPCBB1_S ((volatile uint32_t *)(GTZC1_BASE + 0x0800))
#define GTZC1_MPCBB2_S ((volatile uint32_t *)(GTZC1_BASE + 0x0C00))
#define GTZC1_MPCBB3_S ((volatile uint32_t *)(GTZC1_BASE + 0x1000))
#define GTZC1_MPCBB1_S ((volatile uint32_t *)(GTZC1_BASE + 0x0800 + 0x100))
#define GTZC1_MPCBB2_S ((volatile uint32_t *)(GTZC1_BASE + 0x0C00 + 0x100))
#define GTZC1_MPCBB3_S ((volatile uint32_t *)(GTZC1_BASE + 0x1000 + 0x100))

#define SET_GTZC1_MPCBBx_S_VCTR(bank,n,val) \
(*((volatile uint32_t *)(GTZC1_MPCBB##bank##_S) + n ))= val
Expand Down Expand Up @@ -209,10 +209,10 @@ void hal_tz_sau_init(void)
sau_init_region(2, 0x08140000, 0x081FFFFF, 0);

/* Secure RAM regions in SRAM1/SRAM2 */
sau_init_region(3, 0x0A000000, 0x0A04FFFF, 1);
sau_init_region(3, 0x30000000, 0x3004FFFF, 1);

/* Non-secure RAM region in SRAM3 */
sau_init_region(4, 0x0A050000, 0x0A09FFFF, 0);
sau_init_region(4, 0x20050000, 0x2008FFFF, 0);

/* Non-secure: internal peripherals */
sau_init_region(5, 0x40000000, 0x4FFFFFFF, 0);
Expand Down
2 changes: 2 additions & 0 deletions hal/stm32h5.h
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,8 @@
#define TRNG_AHB2_CLOCK_ER (1 << 18)
#define PKA_AHB2_CLOCK_ER (1 << 19)
#define SAES_AHB2_CLOCK_ER (1 << 20)
#define SRAM2_AHB2_CLOCK_ER (1 << 30)
#define SRAM3_AHB2_CLOCK_ER (1 << 31)

#define RCC_APB2_CLOCK_ER (*(volatile uint32_t *)(RCC_BASE + 0xA4))
#define UART1_APB2_CLOCK_ER_VAL (1 << 14)
Expand Down
6 changes: 3 additions & 3 deletions hal/stm32h5.ld
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
MEMORY
{
FLASH (rx) : ORIGIN = @WOLFBOOT_ORIGIN@, LENGTH = @BOOTLOADER_PARTITION_SIZE@ - 0x20000
RAM (rwx) : ORIGIN = 0x0A000000, LENGTH = 0x00020000
RAM_KV (rw): ORIGIN = 0x0A050000, LENGTH = 0x10000
RAM_HEAP (rw): ORIGIN = 0x0A040000, LENGTH = 0x10000 /* 64KB Heap for wolfcrypt/PKCS11 */
RAM (rwx) : ORIGIN = 0x30000000, LENGTH = 0x30000
RAM_KV (rw): ORIGIN = 0x30020000, LENGTH = 0x10000
RAM_HEAP (rw): ORIGIN = 0x30030000, LENGTH = 0x10000 /* 64KB Heap for wolfcrypt/PKCS11 */
FLASH_KEYVAULT(rw): ORIGIN = @WOLFBOOT_ORIGIN@ + 0x20000, LENGTH = 0x18000
FLASH_NSC(rx): ORIGIN = @WOLFBOOT_ORIGIN@ + 0x38000, LENGTH = 0x8000
}
Expand Down
2 changes: 1 addition & 1 deletion test-app/ARM-stm32h5-ns.ld
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
MEMORY
{
FLASH (rx) : ORIGIN = @WOLFBOOT_TEST_APP_ADDRESS@, LENGTH = @WOLFBOOT_TEST_APP_SIZE@
RAM (rwx) : ORIGIN = 0x0A050000, LENGTH = 0x20000
RAM (rwx) : ORIGIN = 0x20050000, LENGTH = 0x40000
}

SECTIONS
Expand Down
2 changes: 1 addition & 1 deletion test-app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ ifeq ($(TZEN),1)
APP_OBJS+=./wcs/wc_encrypt.o
APP_OBJS+=./wcs/wc_port.o
endif
CFLAGS+=-DWOLFBOOT_SECURE_CALLS -Wstack-usage=12940
CFLAGS+=-DWOLFBOOT_SECURE_CALLS -Wstack-usage=12944
endif
else
APP_OBJS+=../hal/$(TARGET).o
Expand Down
2 changes: 1 addition & 1 deletion test-app/startup_arm.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ extern void isr_tim2(void);
#endif

#ifndef STACK_PAINTING
#define STACK_PAINTING 1
#define STACK_PAINTING 0
#endif

static volatile unsigned int avail_mem = 0;
Expand Down
2 changes: 2 additions & 0 deletions test-app/wcs/pkcs11_stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ CK_FUNCTION_LIST wolfpkcs11nsFunctionList = {
const char pkcs11_library_name[]="wolfCrypt_secure_mode";

extern unsigned int _start_heap;
#ifndef NULL
#define NULL (((void *)0))
#endif

void * _sbrk(unsigned int incr)
{
Expand Down
1 change: 1 addition & 0 deletions test-app/wcs/user_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ extern int tolower(int c);
#define HAVE_WOLF_BIGINT
#define HAVE_PKCS11_STATIC
#define WOLF_CRYPTO_CB
#define MAX_CRYPTO_DEVID_CALLBACKS 2


/* ECC */
Expand Down

0 comments on commit dd723d1

Please sign in to comment.