Skip to content

Commit 16bdc19

Browse files
committed
Fixes for building STM32H5 without PKCS11.
1 parent 0d41724 commit 16bdc19

File tree

6 files changed

+51
-13
lines changed

6 files changed

+51
-13
lines changed

hal/stm32h5.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ int RAMFUNCTION hal_flash_erase(uint32_t address, int len)
216216
if ((FLASH_OPTSR_CUR & FLASH_OPTSR_SWAP_BANK) >> 31)
217217
bnksel = !bnksel;
218218

219-
#if !TZ_SECURE() && !defined(__FLASH_OTP_PRIMER)
219+
#if !TZ_SECURE() && !defined(__FLASH_OTP_PRIMER) && defined(DEBUG)
220220
printf("Erasing bank %d, page %d\r\n", bnksel, (p - base) >> 13);
221221
#endif
222222

test-app/ARM-stm32h5-ns.ld

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,5 @@ SECTIONS
5050
}
5151

5252
PROVIDE(_start_heap = _end);
53+
PROVIDE(_heap_size = 4K);
5354
PROVIDE(_end_stack = ORIGIN(RAM) + LENGTH(RAM));

test-app/ARM-stm32h5.ld

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,5 @@ SECTIONS
5050
}
5151

5252
PROVIDE(_start_heap = _end);
53+
PROVIDE(_heap_size = 4K);
5354
PROVIDE(_end_stack = ORIGIN(RAM) + LENGTH(RAM));

test-app/Makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,11 @@ ifeq ($(TARGET),stm32h5)
157157
ifeq ($(TZEN),1)
158158
LSCRIPT_TEMPLATE=ARM-stm32h5-ns.ld
159159
APP_OBJS+=wcs/wolfcrypt_secure.o
160-
APP_OBJS+=../lib/wolfssl/wolfcrypt/src/logging.o
160+
ifeq ($(WOLFCRYPT_TZ),1)
161+
APP_OBJS+=../lib/wolfssl/wolfcrypt/src/logging.o
162+
APP_OBJS+=../lib/wolfssl/wolfcrypt/benchmark/benchmark.o
163+
APP_OBJS+=../lib/wolfssl/wolfcrypt/test/test.o
164+
endif
161165
else
162166
LSCRIPT_TEMPLATE=ARM-stm32h5.ld
163167
endif
@@ -173,8 +177,6 @@ ifeq ($(TARGET),stm32h5)
173177
else
174178
APP_OBJS+=../src/keystore.o
175179
endif
176-
APP_OBJS+=../lib/wolfssl/wolfcrypt/benchmark/benchmark.o
177-
APP_OBJS+=../lib/wolfssl/wolfcrypt/test/test.o
178180
endif
179181

180182
ifeq ($(TARGET),stm32u5)

test-app/app_stm32h5.c

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@
3131
#include "hal/stm32h5.h"
3232
#include "uart_drv.h"
3333
#include "wolfboot/wolfboot.h"
34-
#include "wolfcrypt/benchmark/benchmark.h"
35-
#include "wolfcrypt/test/test.h"
3634
#include "keystore.h"
3735

3836
#ifdef SECURE_PKCS11
3937
#include "wcs/user_settings.h"
40-
#include <wolfssl/wolfcrypt/settings.h>
41-
#include <wolfssl/wolfcrypt/wc_pkcs11.h>
42-
#include <wolfssl/wolfcrypt/random.h>
38+
#include "wolfssl/wolfcrypt/settings.h"
39+
#include "wolfssl/wolfcrypt/wc_pkcs11.h"
40+
#include "wolfssl/wolfcrypt/random.h"
41+
#include "wolfcrypt/benchmark/benchmark.h"
42+
#include "wolfcrypt/test/test.h"
4343
extern const char pkcs11_library_name[];
4444
extern const CK_FUNCTION_LIST wolfpkcs11nsFunctionList;
4545
#endif
@@ -487,6 +487,7 @@ static int cmd_success(const char *args)
487487

488488
static int cmd_random(const char *args)
489489
{
490+
#ifdef WOLFCRYPT_SECURE_MODE
490491
WC_RNG rng;
491492
int ret;
492493
uint32_t rand;
@@ -505,6 +506,9 @@ static int cmd_random(const char *args)
505506
printf("Today's lucky number: 0x%08lX\r\n", rand);
506507
printf("Brought to you by wolfCrypt's DRBG fed by HW TRNG in Secure world\r\n");
507508
wc_FreeRng(&rng);
509+
#else
510+
printf("Feature only supported with WOLFCRYPT_TZ=1\n");
511+
#endif
508512
return 0;
509513
}
510514

@@ -521,6 +525,7 @@ static int cmd_timestamp(const char *args)
521525
static int cmd_login_pkcs11(const char *args)
522526
{
523527
int ret = -1;
528+
#ifdef SECURE_PKCS11
524529
unsigned int devId = 0;
525530
Pkcs11Token token;
526531
Pkcs11Dev PKCS11_d;
@@ -535,7 +540,6 @@ static int cmd_login_pkcs11(const char *args)
535540
return 0;
536541
}
537542

538-
#ifdef SECURE_PKCS11
539543
printf("PKCS11 Login\r\n");
540544

541545
printf("Initializing wolfCrypt...");
@@ -608,26 +612,30 @@ static int cmd_login_pkcs11(const char *args)
608612
}
609613
#endif
610614
}
611-
612-
#endif /* SECURE_PKCS11 */
613615
if (ret == 0) {
614616
printf("PKCS11 initialization completed successfully.\r\n");
615617
pkcs11_initialized = 1;
616618
}
619+
#else
620+
printf("Feature only supported with WOLFCRYPT_TZ=1\n");
621+
#endif /* SECURE_PKCS11 */
617622
return ret;
618623
}
619624

620625
static int cmd_benchmark(const char *args)
621626
{
622-
627+
#ifdef WOLFCRYPT_SECURE_MODE
623628
benchmark_test(NULL);
629+
#endif
624630
return 0;
625631
}
626632

627633
/* Test command */
628634
static int cmd_test(const char *args)
629635
{
636+
#ifdef WOLFCRYPT_SECURE_MODE
630637
wolfcrypt_test(NULL);
638+
#endif
631639
return 0;
632640
}
633641

@@ -836,3 +844,27 @@ int _fstat(int file, struct stat *st)
836844
return 0;
837845
}
838846

847+
#ifndef WOLFCRYPT_SECURE_MODE
848+
/* Back-end for malloc, used for token handling */
849+
extern unsigned int _start_heap; /* From linker script: heap memory */
850+
extern unsigned int _heap_size; /* From linker script: heap limit */
851+
852+
void * _sbrk(unsigned int incr)
853+
{
854+
static unsigned char *heap = (unsigned char *)&_start_heap;
855+
static uint32_t heapsize = (uint32_t)(&_heap_size);
856+
void *old_heap = heap;
857+
if (((incr >> 2) << 2) != incr)
858+
incr = ((incr >> 2) + 1) << 2;
859+
860+
if (heap == NULL)
861+
heap = (unsigned char *)&_start_heap;
862+
else
863+
heap += incr;
864+
if (((uint32_t)heap - (uint32_t)(&_start_heap)) > heapsize) {
865+
heap -= incr;
866+
return NULL;
867+
}
868+
return old_heap;
869+
}
870+
#endif

test-app/wcs/user_settings.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ extern int tolower(int c);
133133

134134
#define BENCH_EMBEDDED
135135

136+
#ifdef SECURE_PKCS11
136137
#define CUSTOM_RAND_GENERATE_BLOCK wcs_get_random
138+
#endif
137139

138140
/* Disable VLAs */
139141
#define WOLFSSL_SP_NO_DYN_STACK

0 commit comments

Comments
 (0)