From b6afd80b02260663219cff40b08418ed6ac9b2ed Mon Sep 17 00:00:00 2001 From: Thomas Cook Date: Thu, 26 Mar 2026 16:56:31 -0400 Subject: [PATCH 01/14] Add hw support for SHA1 and SHA256 --- arch.mk | 16 +++++++++++++--- config/examples/lpc55s69-tz.config | 2 +- config/examples/lpc55s69.config | 2 +- hal/lpc55s69.c | 16 +++++++++++++--- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/arch.mk b/arch.mk index 74663afa57..e42099deff 100644 --- a/arch.mk +++ b/arch.mk @@ -1199,9 +1199,11 @@ ifeq ($(TARGET),lpc55s69) -I$(MCUXPRESSO_DRIVERS)/drivers \ -I$(MCUXPRESSO_DRIVERS)/../periph \ -I$(MCUXPRESSO)/drivers \ + -I$(MCUXPRESSO)/drivers/casper \ -I$(MCUXPRESSO)/drivers/common \ -I$(MCUXPRESSO)/drivers/flexcomm \ -I$(MCUXPRESSO)/drivers/flexcomm/usart \ + -I$(MCUXPRESSO)/drivers/hashcrypt \ -I$(MCUXPRESSO)/drivers/iap1 \ -I$(MCUXPRESSO)/drivers/lpc_gpio \ -I$(MCUXPRESSO)/drivers/lpc_iocon \ @@ -1220,15 +1222,23 @@ ifeq ($(TARGET),lpc55s69) $(MCUXPRESSO)/drivers/common/fsl_common_arm.o \ $(MCUXPRESSO)/drivers/iap1/fsl_iap.o \ $(MCUXPRESSO)/drivers/lpc_gpio/fsl_gpio.o - ifeq ($(WOLFCRYPT_TZ),1) - OBJS+=$(MCUXPRESSO)/drivers/rng_1/fsl_rng.o - endif ifeq ($(DEBUG_UART),1) OBJS+=\ $(MCUXPRESSO_DRIVERS)/drivers/fsl_reset.o \ $(MCUXPRESSO)/drivers/flexcomm/fsl_flexcomm.o \ $(MCUXPRESSO)/drivers/flexcomm/usart/fsl_usart.o endif + ifeq ($(PKA),1) + CFLAGS+=-DWOLFSSL_NXP_CASPER -DWOLFSSL_NXP_HASHCRYPT + OBJS+=\ + $(MCUXPRESSO)/drivers/casper/fsl_casper.o \ + $(MCUXPRESSO)/drivers/hashcrypt/fsl_hashcrypt.o \ + $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/nxp/casper_port.o \ + $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/nxp/hashcrypt_port.o + endif + ifeq ($(WOLFCRYPT_TZ),1) + OBJS+=$(MCUXPRESSO)/drivers/rng_1/fsl_rng.o + endif endif ifeq ($(TARGET),psoc6) diff --git a/config/examples/lpc55s69-tz.config b/config/examples/lpc55s69-tz.config index f708099321..1aeb1e82b5 100644 --- a/config/examples/lpc55s69-tz.config +++ b/config/examples/lpc55s69-tz.config @@ -2,7 +2,7 @@ ARCH?=ARM TZEN?=1 TARGET?=lpc55s69 SIGN?=ECC384 -HASH?=SHA384 +HASH?=SHA256 MCUXSDK?=1 MCUXPRESSO?=$(PWD)/../NXP/mcuxpresso-sdk/mcuxsdk MCUXPRESSO_CMSIS?=$(PWD)/../NXP/CMSIS_5/CMSIS diff --git a/config/examples/lpc55s69.config b/config/examples/lpc55s69.config index 7020831a62..592b80c646 100644 --- a/config/examples/lpc55s69.config +++ b/config/examples/lpc55s69.config @@ -2,7 +2,7 @@ ARCH?=ARM TZEN?=0 TARGET?=lpc55s69 SIGN?=ECC384 -HASH?=SHA384 +HASH?=SHA256 MCUXSDK?=1 MCUXPRESSO?=$(PWD)/../NXP/mcuxpresso-sdk/mcuxsdk MCUXPRESSO_CMSIS?=$(PWD)/../NXP/CMSIS_5/CMSIS diff --git a/hal/lpc55s69.c b/hal/lpc55s69.c index 67d7637cb7..a9e68e8d65 100644 --- a/hal/lpc55s69.c +++ b/hal/lpc55s69.c @@ -93,17 +93,27 @@ static void hal_flash_fix_ecc(void) } } + +extern int wc_hashcrypt_init(void); + void hal_init(void) { #ifdef __WOLFBOOT /* lpc55s69 must run < 100 MHz for flash write/erase to work */ BOARD_BootClockFROHF96M(); // BOARD_BootClockPLL150M(); -#ifdef DEBUG_UART + +# ifdef WOLFSSL_NXP_HASHCRYPT + CLOCK_EnableClock(kCLOCK_HashCrypt); + wc_hashcrypt_init(); +# endif + +# ifdef DEBUG_UART uart_init(); uart_write("lpc55s69 init\n", 14); -#endif -#endif +# endif + +#endif /* __WOLFBOOT */ #if defined(__WOLFBOOT) || !defined(TZEN) memset(&pflash, 0, sizeof(pflash)); From 2b5aa3e9fd18466d5c37d90f4993e3083a6dded4 Mon Sep 17 00:00:00 2001 From: Thomas Cook Date: Tue, 31 Mar 2026 16:47:13 -0400 Subject: [PATCH 02/14] Bump up sector size to accomodate rsa4096 --- config/examples/lpc55s69-tz.config | 6 +++--- config/examples/lpc55s69.config | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/config/examples/lpc55s69-tz.config b/config/examples/lpc55s69-tz.config index 1aeb1e82b5..ce4b1df33d 100644 --- a/config/examples/lpc55s69-tz.config +++ b/config/examples/lpc55s69-tz.config @@ -31,10 +31,10 @@ FLASH_MULTI_SECTOR_ERASE?=1 WOLFCRYPT_TZ?=1 WOLFCRYPT_TZ_PKCS11?=1 -# 512-byte pages erasable/writeable -WOLFBOOT_SECTOR_SIZE?=0x200 +# 1024-byte sector to accomodate RSA4096 +WOLFBOOT_SECTOR_SIZE?=0x400 -# 200KB boot, 80KB keyvault, 8KB NSC, 56KB partitions, 512 swap +# 200KB boot, 80KB keyvault, 8KB NSC, 56KB partitions, 1024 swap WOLFBOOT_KEYVAULT_ADDRESS?=0x10032000 WOLFBOOT_KEYVAULT_SIZE?=0x14000 WOLFBOOT_NSC_ADDRESS?=0x10046000 diff --git a/config/examples/lpc55s69.config b/config/examples/lpc55s69.config index 592b80c646..5ddeee9c5b 100644 --- a/config/examples/lpc55s69.config +++ b/config/examples/lpc55s69.config @@ -29,11 +29,11 @@ DUALBANK_SWAP?=0 PKA?=1 FLASH_MULTI_SECTOR_ERASE?=1 -# 512-byte pages erasable/writeable -WOLFBOOT_SECTOR_SIZE?=0x200 +# 1024-byte sector to accomodate RSA4096 +WOLFBOOT_SECTOR_SIZE?=0x400 # Default configuration -# 40KB boot, 44KB partitions, 512 swap +# 40KB boot, 44KB partitions, 1024 swap WOLFBOOT_PARTITION_SIZE?=0xB000 WOLFBOOT_PARTITION_BOOT_ADDRESS?=0xA000 WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x15000 From a8a89610fd8c59f8ff0414db5e23c17ce0fe1481 Mon Sep 17 00:00:00 2001 From: Thomas Cook Date: Tue, 31 Mar 2026 16:47:52 -0400 Subject: [PATCH 03/14] initialize casper for rsa signing --- hal/lpc55s69.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/hal/lpc55s69.c b/hal/lpc55s69.c index a9e68e8d65..2c13bb99a4 100644 --- a/hal/lpc55s69.c +++ b/hal/lpc55s69.c @@ -95,6 +95,7 @@ static void hal_flash_fix_ecc(void) extern int wc_hashcrypt_init(void); +extern int wc_casper_init(void); void hal_init(void) { @@ -103,14 +104,19 @@ void hal_init(void) BOARD_BootClockFROHF96M(); // BOARD_BootClockPLL150M(); +# ifdef DEBUG_UART + uart_init(); + uart_write("lpc55s69 init\n", 14); +# endif + # ifdef WOLFSSL_NXP_HASHCRYPT CLOCK_EnableClock(kCLOCK_HashCrypt); wc_hashcrypt_init(); # endif -# ifdef DEBUG_UART - uart_init(); - uart_write("lpc55s69 init\n", 14); +# ifdef WOLFSSL_NXP_CASPER + CLOCK_EnableClock(kCLOCK_Casper); + wc_casper_init(); # endif #endif /* __WOLFBOOT */ From 687aafe585109031385e3238f141d023646df971 Mon Sep 17 00:00:00 2001 From: Thomas Cook Date: Sun, 12 Apr 2026 12:28:45 -0400 Subject: [PATCH 04/14] Better hook rng into wolfCrypt --- arch.mk | 11 ++++++----- hal/lpc55s69.c | 12 ++++++++++-- test-app/Makefile | 13 +++++++++++-- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/arch.mk b/arch.mk index e42099deff..8860705240 100644 --- a/arch.mk +++ b/arch.mk @@ -1229,15 +1229,16 @@ ifeq ($(TARGET),lpc55s69) $(MCUXPRESSO)/drivers/flexcomm/usart/fsl_usart.o endif ifeq ($(PKA),1) - CFLAGS+=-DWOLFSSL_NXP_CASPER -DWOLFSSL_NXP_HASHCRYPT + CFLAGS+=-DWOLFSSL_NXP_LPC55S69 OBJS+=\ $(MCUXPRESSO)/drivers/casper/fsl_casper.o \ $(MCUXPRESSO)/drivers/hashcrypt/fsl_hashcrypt.o \ + $(MCUXPRESSO)/drivers/rng_1/fsl_rng.o \ $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/nxp/casper_port.o \ - $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/nxp/hashcrypt_port.o - endif - ifeq ($(WOLFCRYPT_TZ),1) - OBJS+=$(MCUXPRESSO)/drivers/rng_1/fsl_rng.o + $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/nxp/hashcrypt_port.o \ + $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/nxp/rng_port.o + else + CFLAGS+=-DWOLFSSL_NXP_LPC55S69_NO_HWACCEL endif endif diff --git a/hal/lpc55s69.c b/hal/lpc55s69.c index 2c13bb99a4..24116914c7 100644 --- a/hal/lpc55s69.c +++ b/hal/lpc55s69.c @@ -71,6 +71,10 @@ static void hal_sau_init(void) static void periph_unsecure(void) { +#ifdef WOLFSSL_NXP_RNG_1 + CLOCK_EnableClock(kCLOCK_Rng); + RESET_PeripheralReset(kRNG_RST_SHIFT_RSTn); +#endif CLOCK_EnableClock(kCLOCK_Iocon); CLOCK_EnableClock(kCLOCK_Gpio1); } @@ -225,11 +229,13 @@ int RAMFUNCTION hal_flash_erase(uint32_t address, int len) #ifdef WOLFCRYPT_SECURE_MODE void hal_trng_init(void) { -#ifdef __WOLFBOOT +#ifdef WOLFSSL_NXP_RNG_1 +# ifdef __WOLFBOOT CLOCK_EnableClock(kCLOCK_Rng); RESET_PeripheralReset(kRNG_RST_SHIFT_RSTn); -#endif +# endif RNG_Init(RNG); +#endif } void hal_trng_fini(void) @@ -238,8 +244,10 @@ void hal_trng_fini(void) int hal_trng_get_entropy(unsigned char *out, unsigned int len) { +#ifdef WOLFSSL_NXP_RNG_1 if (RNG_GetRandomData(RNG, out, len) == kStatus_Success) return 0; +#endif return -1; } diff --git a/test-app/Makefile b/test-app/Makefile index 3a58795173..ffb1674232 100644 --- a/test-app/Makefile +++ b/test-app/Makefile @@ -673,8 +673,17 @@ ifeq ($(TARGET),lpc55s69) $(MCUXPRESSO)/drivers/flexcomm/usart/fsl_usart.o \ $(MCUXPRESSO)/drivers/iap1/fsl_iap.o \ $(MCUXPRESSO)/drivers/lpc_gpio/fsl_gpio.o - ifeq ($(WOLFCRYPT_TZ),1) - APP_OBJS+=$(MCUXPRESSO)/drivers/rng_1/fsl_rng.o + ifeq ($(PKA),1) + CFLAGS+=-DWOLFSSL_NXP_LPC55S69 + APP_OBJS+=\ + $(MCUXPRESSO)/drivers/casper/fsl_casper.o \ + $(MCUXPRESSO)/drivers/hashcrypt/fsl_hashcrypt.o \ + $(MCUXPRESSO)/drivers/rng_1/fsl_rng.o \ + $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/nxp/casper_port.o \ + $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/nxp/hashcrypt_port.o \ + $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/nxp/rng_port.o + else + CFLAGS+=-DWOLFSSL_NXP_LPC55S69_NO_HWACCEL endif ifeq (,$(findstring nosys.specs,$(LDFLAGS))) LDFLAGS+=--specs=nosys.specs From 0a3c40a524b406e3928424215d7520cbd4ceee57 Mon Sep 17 00:00:00 2001 From: Thomas Cook Date: Mon, 13 Apr 2026 10:59:39 -0400 Subject: [PATCH 05/14] Add benchmark and test capability to test-app --- config/examples/lpc55s69.config | 17 +++- include/user_settings.h | 25 +++-- test-app/ARM-lpc55s69.ld | 23 +++-- test-app/Makefile | 11 ++- test-app/app_lpc55s69.c | 156 +++++++++++++++++++++----------- test-app/startup_arm.c | 2 +- test-app/syscalls.c | 1 + test-app/wolfcrypt_support.c | 9 ++ 8 files changed, 171 insertions(+), 73 deletions(-) diff --git a/config/examples/lpc55s69.config b/config/examples/lpc55s69.config index 5ddeee9c5b..b1446e41b5 100644 --- a/config/examples/lpc55s69.config +++ b/config/examples/lpc55s69.config @@ -34,7 +34,16 @@ WOLFBOOT_SECTOR_SIZE?=0x400 # Default configuration # 40KB boot, 44KB partitions, 1024 swap -WOLFBOOT_PARTITION_SIZE?=0xB000 -WOLFBOOT_PARTITION_BOOT_ADDRESS?=0xA000 -WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x15000 -WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x20000 +#WOLFBOOT_PARTITION_SIZE?=0xB000 +#WOLFBOOT_PARTITION_BOOT_ADDRESS?=0xD000 +#WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x18000 +#WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x23000 + +# use these for test/benchmark +WOLFBOOT_PARTITION_SIZE?=0x26000 +WOLFBOOT_PARTITION_BOOT_ADDRESS?=0x10000 +WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x36000 +WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x5C000 + +WOLFCRYPT_TEST?=1 +WOLFCRYPT_BENCHMARK?=1 diff --git a/include/user_settings.h b/include/user_settings.h index c681839c07..7986665c9b 100644 --- a/include/user_settings.h +++ b/include/user_settings.h @@ -493,14 +493,19 @@ extern int tolower(int c); #define NO_AES_CBC #else #if defined(WOLFCRYPT_TEST) || defined(WOLFCRYPT_BENCHMARK) - /* Use custom RNG for tests/benchmarks (saves ~7KB vs HASHDRBG). - * WARNING: my_rng_seed_gen is NOT cryptographically secure. - * Only used in test-app builds, not in production wolfBoot. */ - #define WC_NO_HASHDRBG - #define CUSTOM_RAND_GENERATE_SEED my_rng_seed_gen - #define CUSTOM_RAND_GENERATE_BLOCK my_rng_seed_gen - extern int my_rng_seed_gen(unsigned char* output, unsigned int sz); - + #ifdef WOLFSSL_NXP_LPC55S69 + /* use actual rng hardware for seed, HASHDRBG for generation */ + #define HAVE_HASHDRBG + #else + /* Use custom RNG for tests/benchmarks (saves ~7KB vs HASHDRBG). + * WARNING: my_rng_seed_gen is NOT cryptographically secure. + * Only used in test-app builds, not in production wolfBoot. */ + #define WC_NO_HASHDRBG + #define CUSTOM_RAND_GENERATE_SEED my_rng_seed_gen + #define CUSTOM_RAND_GENERATE_BLOCK my_rng_seed_gen + extern int my_rng_seed_gen(unsigned char* output, unsigned int sz); + #endif + #define HAVE_AESGCM #define GCM_TABLE #else @@ -575,6 +580,10 @@ extern int tolower(int c); /* wolfCrypt Test/Benchmark Configuration */ #ifdef WOLFCRYPT_TEST + #ifdef WOLFSSL_NXP_LPC55S69 + /* lpc55s69 hashcrypt hw does not support interleaving */ + #define NO_WOLFSSL_SHA256_INTERLEAVE + #endif /* Skip extended tests to save memory */ #define NO_CRYPT_TEST_EXTENDED /* Use smaller certificate buffers */ diff --git a/test-app/ARM-lpc55s69.ld b/test-app/ARM-lpc55s69.ld index aa3200f9eb..959c569954 100644 --- a/test-app/ARM-lpc55s69.ld +++ b/test-app/ARM-lpc55s69.ld @@ -1,7 +1,10 @@ +_Min_Heap_Size = 0x00008000; /* minimal heap (not using malloc) */ +_Min_Stack_Size = 0x00008000; /* required amount of stack */ + MEMORY { FLASH (rx) : ORIGIN = @WOLFBOOT_TEST_APP_ADDRESS@, LENGTH = @WOLFBOOT_TEST_APP_SIZE@ - RAM (rwx) : ORIGIN = 0x20020000, LENGTH = 32K + RAM (rwx) : ORIGIN = 0x20020000, LENGTH = 96K } SECTIONS @@ -44,15 +47,23 @@ SECTIONS *(COMMON) . = ALIGN(4); _end_bss = .; - _end = .; } > RAM + + ._user_heap_stack : + { + . = ALIGN(8); + PROVIDE ( end = . ); + PROVIDE ( _end = . ); + PROVIDE ( _start_heap = . ); + . = . + _Min_Heap_Size; + . = . + _Min_Stack_Size; + . = ALIGN(8); + PROVIDE ( END_STACK = . ); + PROVIDE ( _end_stack = . ); + } > RAM } _wolfboot_partition_boot_address = @WOLFBOOT_PARTITION_BOOT_ADDRESS@; _wolfboot_partition_size = @WOLFBOOT_PARTITION_SIZE@; _wolfboot_partition_update_address = @WOLFBOOT_PARTITION_UPDATE_ADDRESS@; _wolfboot_partition_swap_address = @WOLFBOOT_PARTITION_SWAP_ADDRESS@; - -PROVIDE(_start_heap = _end); -PROVIDE(end = _end); -PROVIDE(_end_stack = ORIGIN(RAM) + LENGTH(RAM)); diff --git a/test-app/Makefile b/test-app/Makefile index ffb1674232..784757d85d 100644 --- a/test-app/Makefile +++ b/test-app/Makefile @@ -658,6 +658,7 @@ ifeq ($(TARGET),mcxn) endif ifeq ($(TARGET),lpc55s69) + CFLAGS+=-ffunction-sections -fdata-sections ifeq ($(TZEN),1) LSCRIPT_TEMPLATE=ARM-lpc55s69-ns.ld CFLAGS:=$(filter-out -mcmse, $(CFLAGS)) @@ -685,10 +686,16 @@ ifeq ($(TARGET),lpc55s69) else CFLAGS+=-DWOLFSSL_NXP_LPC55S69_NO_HWACCEL endif - ifeq (,$(findstring nosys.specs,$(LDFLAGS))) + LIBS+=--specs=nano.specs + ifneq ($(WOLFCRYPT_SUPPORT),1) + # Only use nosys stubs when not providing our own syscalls LDFLAGS+=--specs=nosys.specs endif - LDFLAGS+=-Wl,--no-warn-rwx-segments + ifeq ($(WOLFCRYPT_BENCHMARK),1) + # Benchmark needs float printf for results + LDFLAGS+=-Wl,-u_printf_float + endif + LDFLAGS+=-Wl,--no-warn-rwx-segments -Wl,--allow-multiple-definition endif ifeq ($(TARGET),imx_rt) diff --git a/test-app/app_lpc55s69.c b/test-app/app_lpc55s69.c index 4582bd7a1b..766d7ca5dc 100644 --- a/test-app/app_lpc55s69.c +++ b/test-app/app_lpc55s69.c @@ -28,12 +28,39 @@ #include "wolfboot/wolfboot.h" #include "printf.h" +/* wolfCrypt test/benchmark support */ +#ifdef WOLFCRYPT_TEST +#include +#include +int wolfcrypt_test(void *args); +#endif + +#ifdef WOLFCRYPT_BENCHMARK +#include +#include +int benchmark_test(void *args); +#endif + #define RED_LED 6 #define GREEN_LED 7 #define BLUE_LED 4 extern void hal_init(void); + +volatile uint64_t SysTick_time_ms; + +void SysTick_Handler(void) +{ + SysTick_time_ms++; +} + +static void systick_init(void) +{ + SysTick_Config(CLOCK_GetCoreSysClkFreq() / 1000U); /* 1 ms period */ +} + + #define IOCON_PIO_FUNC0 0x00u /*!<@brief Selects pin function 0 */ #define IOCON_PIO_MODE_PULLUP 0x20u /*!<@brief Selects pull-up function */ #define IOCON_PIO_SLEW_STANDARD 0x00u /*!<@brief Standard mode, output slew rate control is enabled */ @@ -106,7 +133,14 @@ void main(void) uint8_t boot_state, update_state; hal_init(); + systick_init(); leds_init(); + __enable_irq(); + + wolfBoot_printf("\n==================================\n"); + wolfBoot_printf("LPC55S69 wolfBoot demo Application\n"); + wolfBoot_printf("Copyright 2026 wolfSSL Inc\n"); + wolfBoot_printf("==================================\n"); check_parts(&boot_ver, &update_ver, &boot_state, &update_state); @@ -147,69 +181,87 @@ void main(void) GPIO_PinWrite(GPIO, 1, GREEN_LED, 0); } +#if defined(WOLFCRYPT_TEST) || defined(WOLFCRYPT_BENCHMARK) + wolfCrypt_Init(); + +# ifdef WOLFCRYPT_TEST + wolfBoot_printf("\nRunning wolfCrypt tests...\n"); + wolfcrypt_test(NULL); + wolfBoot_printf("Tests complete.\n\n"); +# endif + +# ifdef WOLFCRYPT_BENCHMARK + wolfBoot_printf("\nRunning wolfCrypt benchmarks...\n"); + benchmark_test(NULL); + wolfBoot_printf("Benchmarks complete.\n\n"); +# endif + + wolfCrypt_Cleanup(); +#endif + while (1) { __asm__ volatile ("wfi"); } } -#include "sys/stat.h" -int _getpid(void) -{ - return 1; -} +// #include "sys/stat.h" +// int _getpid(void) +// { +// return 1; +// } -int _kill(int pid, int sig) -{ - (void)pid; - (void)sig; - return -1; -} +// int _kill(int pid, int sig) +// { +// (void)pid; +// (void)sig; +// return -1; +// } -void _exit(int status) -{ - _kill(status, -1); - while (1) {} -} +// void _exit(int status) +// { +// _kill(status, -1); +// while (1) {} +// } -int _read(int file, char *ptr, int len) -{ - (void)file; - (void)ptr; - (void)len; - return -1; -} +// int _read(int file, char *ptr, int len) +// { +// (void)file; +// (void)ptr; +// (void)len; +// return -1; +// } -int _write(int file, char *ptr, int len) -{ - (void)file; - (void)ptr; - return len; -} +// int _write(int file, char *ptr, int len) +// { +// (void)file; +// (void)ptr; +// return len; +// } -int _close(int file) -{ - (void)file; - return -1; -} +// int _close(int file) +// { +// (void)file; +// return -1; +// } -int _isatty(int file) -{ - (void)file; - return 1; -} +// int _isatty(int file) +// { +// (void)file; +// return 1; +// } -int _lseek(int file, int ptr, int dir) -{ - (void)file; - (void)ptr; - (void)dir; - return 0; -} +// int _lseek(int file, int ptr, int dir) +// { +// (void)file; +// (void)ptr; +// (void)dir; +// return 0; +// } -int _fstat(int file, struct stat *st) -{ - (void)file; - st->st_mode = S_IFCHR; - return 0; -} +// int _fstat(int file, struct stat *st) +// { +// (void)file; +// st->st_mode = S_IFCHR; +// return 0; +// } diff --git a/test-app/startup_arm.c b/test-app/startup_arm.c index ff65084d34..0009c4811e 100644 --- a/test-app/startup_arm.c +++ b/test-app/startup_arm.c @@ -43,7 +43,7 @@ extern void isr_usart3(void); extern void isr_lpuart1(void); #endif -#ifdef TARGET_va416x0 +#if defined(TARGET_va416x0) || defined(TARGET_lpc55s69) #define isr_systick SysTick_Handler #elif !defined(APP_HAS_SYSTICK) #define isr_systick isr_empty diff --git a/test-app/syscalls.c b/test-app/syscalls.c index a167c3c8bb..2683da3ceb 100644 --- a/test-app/syscalls.c +++ b/test-app/syscalls.c @@ -135,6 +135,7 @@ int _getpid(void) * other OS facilities that don't exist in bare-metal. * wolfCrypt test/benchmark code calls standard printf, not wolfBoot_printf. */ +int vsnprintf(char *buf, unsigned int size, const char *fmt, va_list argp); /* Route all printf-family functions through our vsnprintf (in this file) * rather than uart_vprintf (in string.c). This ensures float formatting diff --git a/test-app/wolfcrypt_support.c b/test-app/wolfcrypt_support.c index d15df4f036..f1d417e56e 100644 --- a/test-app/wolfcrypt_support.c +++ b/test-app/wolfcrypt_support.c @@ -42,6 +42,8 @@ #elif defined(TARGET_va416x0) /* Use Vorago SDK HAL_time_ms (incremented by SysTick_Handler every 1ms) */ extern volatile uint64_t HAL_time_ms; +#elif defined(TARGET_lpc55s69) + extern volatile uint64_t SysTick_time_ms; #elif defined(TARGET_nxp_t2080) || defined(TARGET_nxp_t1024) /* PPC timebase register for accurate timing. * Timebase frequency = platform_clock / 16. */ @@ -96,6 +98,10 @@ unsigned long my_time(unsigned long* timer) unsigned long t = (unsigned long)(HAL_time_ms / 1000); if (timer) *timer = t; return t; +#elif defined(TARGET_lpc55s69) + unsigned long t = (unsigned long)(SysTick_time_ms / 1000); + if (timer) *timer = t; + return t; #elif defined(TARGET_nxp_t2080) || defined(TARGET_nxp_t1024) if (ppc_tb_hz == 0) ppc_tb_hz = ppc_get_timebase_hz(); @@ -125,6 +131,9 @@ double current_time(int reset) (void)reset; /* Use Vorago SDK SysTick-based millisecond counter */ return (double)HAL_time_ms / 1000.0; +#elif defined(TARGET_lpc55s69) + (void)reset; + return (double)SysTick_time_ms / 1000.0; #elif defined(TARGET_nxp_t2080) || defined(TARGET_nxp_t1024) if (ppc_tb_hz == 0) ppc_tb_hz = ppc_get_timebase_hz(); From 4e54f8ee8a1fa2a2ce738c472f91f965f56ba1b6 Mon Sep 17 00:00:00 2001 From: Thomas Cook Date: Fri, 17 Apr 2026 16:19:29 -0400 Subject: [PATCH 06/14] fix build flags for hw accel --- hal/lpc55s69.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/hal/lpc55s69.c b/hal/lpc55s69.c index 24116914c7..580aeeeea8 100644 --- a/hal/lpc55s69.c +++ b/hal/lpc55s69.c @@ -71,7 +71,7 @@ static void hal_sau_init(void) static void periph_unsecure(void) { -#ifdef WOLFSSL_NXP_RNG_1 +#ifndef WOLFSSL_NXP_LPC55S69_NO_HWACCEL CLOCK_EnableClock(kCLOCK_Rng); RESET_PeripheralReset(kRNG_RST_SHIFT_RSTn); #endif @@ -113,12 +113,12 @@ void hal_init(void) uart_write("lpc55s69 init\n", 14); # endif -# ifdef WOLFSSL_NXP_HASHCRYPT +# ifndef WOLFSSL_NXP_LPC55S69_NO_HWACCEL CLOCK_EnableClock(kCLOCK_HashCrypt); wc_hashcrypt_init(); # endif -# ifdef WOLFSSL_NXP_CASPER +# ifndef WOLFSSL_NXP_LPC55S69_NO_HWACCEL CLOCK_EnableClock(kCLOCK_Casper); wc_casper_init(); # endif @@ -229,7 +229,7 @@ int RAMFUNCTION hal_flash_erase(uint32_t address, int len) #ifdef WOLFCRYPT_SECURE_MODE void hal_trng_init(void) { -#ifdef WOLFSSL_NXP_RNG_1 +#ifndef WOLFSSL_NXP_LPC55S69_NO_HWACCEL # ifdef __WOLFBOOT CLOCK_EnableClock(kCLOCK_Rng); RESET_PeripheralReset(kRNG_RST_SHIFT_RSTn); @@ -244,7 +244,7 @@ void hal_trng_fini(void) int hal_trng_get_entropy(unsigned char *out, unsigned int len) { -#ifdef WOLFSSL_NXP_RNG_1 +#ifndef WOLFSSL_NXP_LPC55S69_NO_HWACCEL if (RNG_GetRandomData(RNG, out, len) == kStatus_Success) return 0; #endif From 3dff225c93bfc1814558fd343a7a3cd18faa4f9a Mon Sep 17 00:00:00 2001 From: Thomas Cook Date: Fri, 17 Apr 2026 16:20:26 -0400 Subject: [PATCH 07/14] turn on other aes algs for test/benchmark --- include/user_settings.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/user_settings.h b/include/user_settings.h index 7986665c9b..54b0081838 100644 --- a/include/user_settings.h +++ b/include/user_settings.h @@ -508,6 +508,10 @@ extern int tolower(int c); #define HAVE_AESGCM #define GCM_TABLE + #define HAVE_AES_ECB + #define WOLFSSL_AES_OFB + #define WOLFSSL_AES_CFB + #define WOLFSSL_AES_COUNTER #else #define HAVE_HASHDRBG #define WOLFSSL_AES_CFB From 2e0412db3a66cc1975f51d5cb37de3261ac83993 Mon Sep 17 00:00:00 2001 From: Thomas Cook Date: Tue, 21 Apr 2026 19:40:50 -0400 Subject: [PATCH 08/14] Regression test fixes --- config/examples/lpc55s69-tz.config | 7 +- config/examples/lpc55s69.config | 27 +++--- include/user_settings.h | 14 ++-- test-app/ARM-lpc55s69.ld | 4 +- test-app/Makefile | 9 +- test-app/app_lpc55s69.c | 130 +++++++++++++++-------------- 6 files changed, 103 insertions(+), 88 deletions(-) diff --git a/config/examples/lpc55s69-tz.config b/config/examples/lpc55s69-tz.config index ce4b1df33d..19b47cc788 100644 --- a/config/examples/lpc55s69-tz.config +++ b/config/examples/lpc55s69-tz.config @@ -31,10 +31,11 @@ FLASH_MULTI_SECTOR_ERASE?=1 WOLFCRYPT_TZ?=1 WOLFCRYPT_TZ_PKCS11?=1 -# 1024-byte sector to accomodate RSA4096 -WOLFBOOT_SECTOR_SIZE?=0x400 +# use 1024-byte sector to accomodate RSA4096 signature +# WOLFBOOT_SECTOR_SIZE?=0x400 +WOLFBOOT_SECTOR_SIZE?=0x200 -# 200KB boot, 80KB keyvault, 8KB NSC, 56KB partitions, 1024 swap +# 200KB boot, 80KB keyvault, 8KB NSC, 56KB partitions, 512/1024 swap WOLFBOOT_KEYVAULT_ADDRESS?=0x10032000 WOLFBOOT_KEYVAULT_SIZE?=0x14000 WOLFBOOT_NSC_ADDRESS?=0x10046000 diff --git a/config/examples/lpc55s69.config b/config/examples/lpc55s69.config index b1446e41b5..8787773855 100644 --- a/config/examples/lpc55s69.config +++ b/config/examples/lpc55s69.config @@ -29,21 +29,22 @@ DUALBANK_SWAP?=0 PKA?=1 FLASH_MULTI_SECTOR_ERASE?=1 -# 1024-byte sector to accomodate RSA4096 -WOLFBOOT_SECTOR_SIZE?=0x400 +# use 1024-byte sector to accomodate RSA4096 signature +# WOLFBOOT_SECTOR_SIZE?=0x400 +WOLFBOOT_SECTOR_SIZE?=0x200 # Default configuration -# 40KB boot, 44KB partitions, 1024 swap -#WOLFBOOT_PARTITION_SIZE?=0xB000 -#WOLFBOOT_PARTITION_BOOT_ADDRESS?=0xD000 -#WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x18000 -#WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x23000 +# 44KB boot, 52KB partitions, 512/1024 swap +WOLFBOOT_PARTITION_SIZE?=0xB000 +WOLFBOOT_PARTITION_BOOT_ADDRESS?=0xD000 +WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x18000 +WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x23000 # use these for test/benchmark -WOLFBOOT_PARTITION_SIZE?=0x26000 -WOLFBOOT_PARTITION_BOOT_ADDRESS?=0x10000 -WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x36000 -WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x5C000 +#WOLFBOOT_PARTITION_SIZE?=0x2b000 +#WOLFBOOT_PARTITION_BOOT_ADDRESS?=0x10000 +#WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x3b000 +#WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x66000 -WOLFCRYPT_TEST?=1 -WOLFCRYPT_BENCHMARK?=1 +#WOLFCRYPT_TEST?=1 +#WOLFCRYPT_BENCHMARK?=1 diff --git a/include/user_settings.h b/include/user_settings.h index 54b0081838..01f600edd6 100644 --- a/include/user_settings.h +++ b/include/user_settings.h @@ -505,13 +505,17 @@ extern int tolower(int c); #define CUSTOM_RAND_GENERATE_BLOCK my_rng_seed_gen extern int my_rng_seed_gen(unsigned char* output, unsigned int sz); #endif - + #define HAVE_AESGCM #define GCM_TABLE - #define HAVE_AES_ECB - #define WOLFSSL_AES_OFB - #define WOLFSSL_AES_CFB - #define WOLFSSL_AES_COUNTER + + #if defined(WOLFSSL_NXP_LPC55S69) || defined(WOLFSSL_NXP_LPC55S69_NO_HWACCEL) + #define HAVE_AES_ECB + #define WOLFSSL_AES_OFB + #define WOLFSSL_AES_CFB + #define WOLFSSL_AES_COUNTER + #define WOLFSSL_STATIC_MEMORY_TEST_SZ (30 * 1024) + #endif #else #define HAVE_HASHDRBG #define WOLFSSL_AES_CFB diff --git a/test-app/ARM-lpc55s69.ld b/test-app/ARM-lpc55s69.ld index 959c569954..078c125e3e 100644 --- a/test-app/ARM-lpc55s69.ld +++ b/test-app/ARM-lpc55s69.ld @@ -1,10 +1,10 @@ -_Min_Heap_Size = 0x00008000; /* minimal heap (not using malloc) */ +_Min_Heap_Size = 0x00000100; /* minimal heap (not using malloc) */ _Min_Stack_Size = 0x00008000; /* required amount of stack */ MEMORY { FLASH (rx) : ORIGIN = @WOLFBOOT_TEST_APP_ADDRESS@, LENGTH = @WOLFBOOT_TEST_APP_SIZE@ - RAM (rwx) : ORIGIN = 0x20020000, LENGTH = 96K + RAM (rwx) : ORIGIN = 0x20020000, LENGTH = 160K } SECTIONS diff --git a/test-app/Makefile b/test-app/Makefile index 784757d85d..795b198d91 100644 --- a/test-app/Makefile +++ b/test-app/Makefile @@ -162,6 +162,9 @@ ifeq ($(WOLFCRYPT_SUPPORT),1) # Add SP C math (all architectures) APP_OBJS+=$(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/sp_c32.o + # Add RSA support (needed by test suite) + APP_OBJS+=$(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/rsa.o + ifneq ($(NO_ASM),1) # SP Cortex M ifneq ($(filter ARM ARM_BE,$(ARCH)),) @@ -686,10 +689,8 @@ ifeq ($(TARGET),lpc55s69) else CFLAGS+=-DWOLFSSL_NXP_LPC55S69_NO_HWACCEL endif - LIBS+=--specs=nano.specs - ifneq ($(WOLFCRYPT_SUPPORT),1) - # Only use nosys stubs when not providing our own syscalls - LDFLAGS+=--specs=nosys.specs + ifeq ($(WOLFCRYPT_SUPPORT),1) + LIBS+=--specs=nano.specs endif ifeq ($(WOLFCRYPT_BENCHMARK),1) # Benchmark needs float printf for results diff --git a/test-app/app_lpc55s69.c b/test-app/app_lpc55s69.c index 766d7ca5dc..c64df98b24 100644 --- a/test-app/app_lpc55s69.c +++ b/test-app/app_lpc55s69.c @@ -133,9 +133,11 @@ void main(void) uint8_t boot_state, update_state; hal_init(); - systick_init(); leds_init(); +#ifndef TZEN + systick_init(); __enable_irq(); +#endif wolfBoot_printf("\n==================================\n"); wolfBoot_printf("LPC55S69 wolfBoot demo Application\n"); @@ -205,63 +207,69 @@ void main(void) } -// #include "sys/stat.h" -// int _getpid(void) -// { -// return 1; -// } - -// int _kill(int pid, int sig) -// { -// (void)pid; -// (void)sig; -// return -1; -// } - -// void _exit(int status) -// { -// _kill(status, -1); -// while (1) {} -// } - -// int _read(int file, char *ptr, int len) -// { -// (void)file; -// (void)ptr; -// (void)len; -// return -1; -// } - -// int _write(int file, char *ptr, int len) -// { -// (void)file; -// (void)ptr; -// return len; -// } - -// int _close(int file) -// { -// (void)file; -// return -1; -// } - -// int _isatty(int file) -// { -// (void)file; -// return 1; -// } - -// int _lseek(int file, int ptr, int dir) -// { -// (void)file; -// (void)ptr; -// (void)dir; -// return 0; -// } - -// int _fstat(int file, struct stat *st) -// { -// (void)file; -// st->st_mode = S_IFCHR; -// return 0; -// } +#include "sys/stat.h" +int WEAKFUNCTION _getpid(void) +{ + return 1; +} + +int WEAKFUNCTION _kill(int pid, int sig) +{ + (void)pid; + (void)sig; + return -1; +} + +void WEAKFUNCTION _exit(int status) +{ + _kill(status, -1); + while (1) {} +} + +int WEAKFUNCTION _read(int file, char *ptr, int len) +{ + (void)file; + (void)ptr; + (void)len; + return -1; +} + +int WEAKFUNCTION _write(int file, char *ptr, int len) +{ + (void)file; + (void)ptr; + return len; +} + +int WEAKFUNCTION _close(int file) +{ + (void)file; + return -1; +} + +int WEAKFUNCTION _isatty(int file) +{ + (void)file; + return 1; +} + +int WEAKFUNCTION _lseek(int file, int ptr, int dir) +{ + (void)file; + (void)ptr; + (void)dir; + return 0; +} + +int WEAKFUNCTION _fstat(int file, struct stat *st) +{ + (void)file; + st->st_mode = S_IFCHR; + return 0; +} + +void WEAKFUNCTION *_sbrk(int incr) +{ + (void)incr; + return 0; +} From a3bff940d1326fedc4943d6d6d7c9ea4aff6427c Mon Sep 17 00:00:00 2001 From: Thomas Cook Date: Tue, 21 Apr 2026 21:12:43 -0400 Subject: [PATCH 09/14] Add lauterbach scripts --- tools/scripts/lpc55s69/lpc55s69_debug.cmm | 38 +++++++++++++++++++ .../lpc55s69/lpc55s69_flash_factory_bin.cmm | 28 ++++++++++++++ .../lpc55s69/lpc55s69_flash_update.cmm | 30 +++++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 tools/scripts/lpc55s69/lpc55s69_debug.cmm create mode 100644 tools/scripts/lpc55s69/lpc55s69_flash_factory_bin.cmm create mode 100644 tools/scripts/lpc55s69/lpc55s69_flash_update.cmm diff --git a/tools/scripts/lpc55s69/lpc55s69_debug.cmm b/tools/scripts/lpc55s69/lpc55s69_debug.cmm new file mode 100644 index 0000000000..5fc2e5c6bd --- /dev/null +++ b/tools/scripts/lpc55s69/lpc55s69_debug.cmm @@ -0,0 +1,38 @@ +;; lpc55s69_debug.cmm +;; +;; "make DEBUG_SYMBOLS=1" + +RESet +SYStem.RESet +SYStem.CPU LPC55S69JBD100-CPU0 +SYStem.CONFIG.DEBUGPORTTYPE SWD +IF COMBIPROBE()||UTRACE() +( + SYStem.CONFIG.CONNECTOR MIPI20T +) +SYStem.Option DUALPORT ON +SYStem.MemAccess DAP +SYStem.JtagClock 10MHz +ITM.OFF +Trace.DISable +break.config.method program onchip +mode.hll + +SYStem.Up + +;; STOP in wolfBoot... +data.load "\\wsl.localhost\Ubuntu-22.04\home\tcook\wolf\wolfBoot\wolfboot.elf" /nocode +symbol.sourcepath.TranslateSUBpath "\home\tcook\wolf" "\\wsl.localhost\Ubuntu-22.04\home\tcook\wolf" +Register.Set PC isr_reset +Register.Set MSP END_STACK +break.set main /onchip /temporary +break.set do_boot /onchip /temporary +go + +;; STOP in test-app... +;; UNCOMMENT the following: +;;WAIT !STATE.RUN() +;;data.load "\\wsl.localhost\Ubuntu-22.04\home\tcook\wolf\wolfBoot\test-app\image.elf" /nocode +;;break.set main /onchip /temporary + +go diff --git a/tools/scripts/lpc55s69/lpc55s69_flash_factory_bin.cmm b/tools/scripts/lpc55s69/lpc55s69_flash_factory_bin.cmm new file mode 100644 index 0000000000..0cfd1697d0 --- /dev/null +++ b/tools/scripts/lpc55s69/lpc55s69_flash_factory_bin.cmm @@ -0,0 +1,28 @@ +;; lpc55s69_flash_factory_bin.cmm +;; +;; "make DEBUG_SYMBOLS=1" + +RESet +SYStem.RESet +SYStem.CPU LPC55S69JBD100-CPU0 +SYStem.CONFIG.DEBUGPORTTYPE SWD +IF COMBIPROBE()||UTRACE() +( + SYStem.CONFIG.CONNECTOR MIPI20T +) +SYStem.Option DUALPORT ON +SYStem.MemAccess DAP +SYStem.JtagClock 10MHz +ITM.OFF +Trace.DISable + +SYStem.Up + +DO ~~/demo/arm/flash/lpc55xx PREPAREONLY + +flash.erase all +FLASH.ReProgram ALL +Data.LOAD.Binary "\\wsl.localhost\Ubuntu-22.04\home\tcook\wolf\wolfBoot\factory.bin" 0 +FLASH.ReProgram OFF + +ENDDO diff --git a/tools/scripts/lpc55s69/lpc55s69_flash_update.cmm b/tools/scripts/lpc55s69/lpc55s69_flash_update.cmm new file mode 100644 index 0000000000..f1ebef503c --- /dev/null +++ b/tools/scripts/lpc55s69/lpc55s69_flash_update.cmm @@ -0,0 +1,30 @@ +;; lpc55s69_flash_update.cmm +;; +;; make DEBUG_SYMBOLS=1 +;; then +;; tools/keytools/sign --ecc384 --sha256 test-app/image.bin wolfboot_signing_private_key.der 2 + +RESet +SYStem.RESet +SYStem.CPU LPC55S69JBD100-CPU0 +SYStem.CONFIG.DEBUGPORTTYPE SWD +IF COMBIPROBE()||UTRACE() +( + SYStem.CONFIG.CONNECTOR MIPI20T +) +SYStem.Option DUALPORT ON +SYStem.MemAccess DAP +SYStem.JtagClock 10MHz +ITM.OFF +Trace.DISable + +SYStem.Up + +DO ~~/demo/arm/flash/lpc55xx PREPAREONLY + +;; flash.erase all ;; NOT FOR UPDATE +FLASH.ReProgram ALL +Data.LOAD.Binary "\\wsl.localhost\Ubuntu-22.04\home\tcook\wolf\wolfBoot\test-app\image_v2_signed.bin" 0x18000 +FLASH.ReProgram OFF + +ENDDO From cc5d8ff8ccdf8a3b7a33edc63f1c8d48bbfd27b1 Mon Sep 17 00:00:00 2001 From: Thomas Cook Date: Tue, 21 Apr 2026 22:04:10 -0400 Subject: [PATCH 10/14] Turn off lpc55s69 hw accel (PKA) be default --- config/examples/lpc55s69-tz.config | 2 +- config/examples/lpc55s69.config | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config/examples/lpc55s69-tz.config b/config/examples/lpc55s69-tz.config index 19b47cc788..3ce62029d8 100644 --- a/config/examples/lpc55s69-tz.config +++ b/config/examples/lpc55s69-tz.config @@ -26,7 +26,7 @@ V?=0 SPMATH?=1 RAM_CODE?=1 DUALBANK_SWAP?=0 -PKA?=1 +PKA?=0 FLASH_MULTI_SECTOR_ERASE?=1 WOLFCRYPT_TZ?=1 WOLFCRYPT_TZ_PKCS11?=1 diff --git a/config/examples/lpc55s69.config b/config/examples/lpc55s69.config index 8787773855..bb2c0f4234 100644 --- a/config/examples/lpc55s69.config +++ b/config/examples/lpc55s69.config @@ -26,7 +26,7 @@ V?=0 SPMATH?=1 RAM_CODE?=1 DUALBANK_SWAP?=0 -PKA?=1 +PKA?=0 FLASH_MULTI_SECTOR_ERASE?=1 # use 1024-byte sector to accomodate RSA4096 signature From d33454fa9a52de382e15c58bf91d83a7efd6d2c8 Mon Sep 17 00:00:00 2001 From: Thomas Cook Date: Thu, 23 Apr 2026 03:14:49 -0400 Subject: [PATCH 11/14] address several pr issues --- arch.mk | 8 +++--- config/examples/lpc55s69-tz.config | 2 +- config/examples/lpc55s69.config | 2 +- hal/lpc55s69.c | 11 +-------- include/user_settings.h | 18 ++++++-------- test-app/Makefile | 12 ++++----- test-app/app_lpc55s69.c | 39 +++++++++++++++++++++++++++--- 7 files changed, 56 insertions(+), 36 deletions(-) diff --git a/arch.mk b/arch.mk index 1e10ea4565..d4ab6ccd3c 100644 --- a/arch.mk +++ b/arch.mk @@ -1221,7 +1221,9 @@ ifeq ($(TARGET),lpc55s69) $(MCUXPRESSO_DRIVERS)/drivers/fsl_power.o \ $(MCUXPRESSO)/drivers/common/fsl_common_arm.o \ $(MCUXPRESSO)/drivers/iap1/fsl_iap.o \ - $(MCUXPRESSO)/drivers/lpc_gpio/fsl_gpio.o + $(MCUXPRESSO)/drivers/lpc_gpio/fsl_gpio.o \ + $(MCUXPRESSO)/drivers/rng_1/fsl_rng.o \ + $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/nxp/rng_port.o ifeq ($(DEBUG_UART),1) OBJS+=\ $(MCUXPRESSO_DRIVERS)/drivers/fsl_reset.o \ @@ -1233,10 +1235,8 @@ ifeq ($(TARGET),lpc55s69) OBJS+=\ $(MCUXPRESSO)/drivers/casper/fsl_casper.o \ $(MCUXPRESSO)/drivers/hashcrypt/fsl_hashcrypt.o \ - $(MCUXPRESSO)/drivers/rng_1/fsl_rng.o \ $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/nxp/casper_port.o \ - $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/nxp/hashcrypt_port.o \ - $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/nxp/rng_port.o + $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/nxp/hashcrypt_port.o else CFLAGS+=-DWOLFSSL_NXP_LPC55S69_NO_HWACCEL endif diff --git a/config/examples/lpc55s69-tz.config b/config/examples/lpc55s69-tz.config index 3ce62029d8..e22bce2439 100644 --- a/config/examples/lpc55s69-tz.config +++ b/config/examples/lpc55s69-tz.config @@ -31,7 +31,7 @@ FLASH_MULTI_SECTOR_ERASE?=1 WOLFCRYPT_TZ?=1 WOLFCRYPT_TZ_PKCS11?=1 -# use 1024-byte sector to accomodate RSA4096 signature +# use 1024-byte sector to accommodate RSA4096 signature # WOLFBOOT_SECTOR_SIZE?=0x400 WOLFBOOT_SECTOR_SIZE?=0x200 diff --git a/config/examples/lpc55s69.config b/config/examples/lpc55s69.config index bb2c0f4234..adac0439b0 100644 --- a/config/examples/lpc55s69.config +++ b/config/examples/lpc55s69.config @@ -29,7 +29,7 @@ DUALBANK_SWAP?=0 PKA?=0 FLASH_MULTI_SECTOR_ERASE?=1 -# use 1024-byte sector to accomodate RSA4096 signature +# use 1024-byte sector to accommodate RSA4096 signature # WOLFBOOT_SECTOR_SIZE?=0x400 WOLFBOOT_SECTOR_SIZE?=0x200 diff --git a/hal/lpc55s69.c b/hal/lpc55s69.c index 580aeeeea8..17c5cf9dc8 100644 --- a/hal/lpc55s69.c +++ b/hal/lpc55s69.c @@ -71,10 +71,8 @@ static void hal_sau_init(void) static void periph_unsecure(void) { -#ifndef WOLFSSL_NXP_LPC55S69_NO_HWACCEL CLOCK_EnableClock(kCLOCK_Rng); RESET_PeripheralReset(kRNG_RST_SHIFT_RSTn); -#endif CLOCK_EnableClock(kCLOCK_Iocon); CLOCK_EnableClock(kCLOCK_Gpio1); } @@ -113,12 +111,9 @@ void hal_init(void) uart_write("lpc55s69 init\n", 14); # endif -# ifndef WOLFSSL_NXP_LPC55S69_NO_HWACCEL +# ifdef WOLFSSL_NXP_LPC55S69_WITH_HWACCEL CLOCK_EnableClock(kCLOCK_HashCrypt); wc_hashcrypt_init(); -# endif - -# ifndef WOLFSSL_NXP_LPC55S69_NO_HWACCEL CLOCK_EnableClock(kCLOCK_Casper); wc_casper_init(); # endif @@ -229,13 +224,11 @@ int RAMFUNCTION hal_flash_erase(uint32_t address, int len) #ifdef WOLFCRYPT_SECURE_MODE void hal_trng_init(void) { -#ifndef WOLFSSL_NXP_LPC55S69_NO_HWACCEL # ifdef __WOLFBOOT CLOCK_EnableClock(kCLOCK_Rng); RESET_PeripheralReset(kRNG_RST_SHIFT_RSTn); # endif RNG_Init(RNG); -#endif } void hal_trng_fini(void) @@ -244,10 +237,8 @@ void hal_trng_fini(void) int hal_trng_get_entropy(unsigned char *out, unsigned int len) { -#ifndef WOLFSSL_NXP_LPC55S69_NO_HWACCEL if (RNG_GetRandomData(RNG, out, len) == kStatus_Success) return 0; -#endif return -1; } diff --git a/include/user_settings.h b/include/user_settings.h index a335026863..ca1bddc52c 100644 --- a/include/user_settings.h +++ b/include/user_settings.h @@ -493,9 +493,15 @@ extern int tolower(int c); #define NO_AES_CBC #else #if defined(WOLFCRYPT_TEST) || defined(WOLFCRYPT_BENCHMARK) - #ifdef WOLFSSL_NXP_LPC55S69 + #if defined(WOLFSSL_NXP_LPC55S69_WITH_HWACCEL) \ + || defined(WOLFSSL_NXP_LPC55S69_NO_HWACCEL) /* use actual rng hardware for seed, HASHDRBG for generation */ #define HAVE_HASHDRBG + #define HAVE_AES_ECB + #define WOLFSSL_AES_OFB + #define WOLFSSL_AES_CFB + #define WOLFSSL_AES_COUNTER + #define WOLFSSL_STATIC_MEMORY_TEST_SZ (30 * 1024) #else /* Use custom RNG for tests/benchmarks (saves ~7KB vs HASHDRBG). * WARNING: my_rng_seed_gen is NOT cryptographically secure. @@ -508,14 +514,6 @@ extern int tolower(int c); #define HAVE_AESGCM #define GCM_TABLE - - #if defined(WOLFSSL_NXP_LPC55S69) || defined(WOLFSSL_NXP_LPC55S69_NO_HWACCEL) - #define HAVE_AES_ECB - #define WOLFSSL_AES_OFB - #define WOLFSSL_AES_CFB - #define WOLFSSL_AES_COUNTER - #define WOLFSSL_STATIC_MEMORY_TEST_SZ (30 * 1024) - #endif #else #define HAVE_HASHDRBG #define WOLFSSL_AES_CFB @@ -588,7 +586,7 @@ extern int tolower(int c); /* wolfCrypt Test/Benchmark Configuration */ #ifdef WOLFCRYPT_TEST - #ifdef WOLFSSL_NXP_LPC55S69 + #ifdef WOLFSSL_NXP_LPC55S69_WITH_HWACCEL /* lpc55s69 hashcrypt hw does not support interleaving */ #define NO_WOLFSSL_SHA256_INTERLEAVE #endif diff --git a/test-app/Makefile b/test-app/Makefile index c4433054ae..d2bf3223c6 100644 --- a/test-app/Makefile +++ b/test-app/Makefile @@ -173,7 +173,7 @@ ifeq ($(WOLFCRYPT_SUPPORT),1) # Add SP C math (all architectures) APP_OBJS+=$(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/sp_c32.o - # Add RSA support (needed by test suite) + # Add RSA support APP_OBJS+=$(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/rsa.o ifneq ($(NO_ASM),1) @@ -693,16 +693,16 @@ ifeq ($(TARGET),lpc55s69) $(MCUXPRESSO)/drivers/flexcomm/fsl_flexcomm.o \ $(MCUXPRESSO)/drivers/flexcomm/usart/fsl_usart.o \ $(MCUXPRESSO)/drivers/iap1/fsl_iap.o \ - $(MCUXPRESSO)/drivers/lpc_gpio/fsl_gpio.o + $(MCUXPRESSO)/drivers/lpc_gpio/fsl_gpio.o \ + $(MCUXPRESSO)/drivers/rng_1/fsl_rng.o \ + $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/nxp/rng_port.o ifeq ($(PKA),1) - CFLAGS+=-DWOLFSSL_NXP_LPC55S69 + CFLAGS+=-DWOLFSSL_NXP_LPC55S69_WITH_HWACCEL APP_OBJS+=\ $(MCUXPRESSO)/drivers/casper/fsl_casper.o \ $(MCUXPRESSO)/drivers/hashcrypt/fsl_hashcrypt.o \ - $(MCUXPRESSO)/drivers/rng_1/fsl_rng.o \ $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/nxp/casper_port.o \ - $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/nxp/hashcrypt_port.o \ - $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/nxp/rng_port.o + $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/nxp/hashcrypt_port.o else CFLAGS+=-DWOLFSSL_NXP_LPC55S69_NO_HWACCEL endif diff --git a/test-app/app_lpc55s69.c b/test-app/app_lpc55s69.c index c64df98b24..5bacdf98fb 100644 --- a/test-app/app_lpc55s69.c +++ b/test-app/app_lpc55s69.c @@ -55,11 +55,12 @@ void SysTick_Handler(void) SysTick_time_ms++; } +#ifdef WOLFCRYPT_BENCHMARK static void systick_init(void) { SysTick_Config(CLOCK_GetCoreSysClkFreq() / 1000U); /* 1 ms period */ } - +#endif #define IOCON_PIO_FUNC0 0x00u /*!<@brief Selects pin function 0 */ #define IOCON_PIO_MODE_PULLUP 0x20u /*!<@brief Selects pull-up function */ @@ -134,7 +135,7 @@ void main(void) hal_init(); leds_init(); -#ifndef TZEN +#ifdef WOLFCRYPT_BENCHMARK systick_init(); __enable_irq(); #endif @@ -206,6 +207,16 @@ void main(void) } } +#ifndef ENOMEM +#define ENOMEM 12 +#endif +#ifndef EBADF +#define EBADF 9 +#endif +#ifndef EINVAL +#define EINVAL 22 +#endif +int errno; #include "sys/stat.h" int WEAKFUNCTION _getpid(void) @@ -268,8 +279,28 @@ int WEAKFUNCTION _fstat(int file, struct stat *st) return 0; } +/* Heap management */ +extern char _end; /* Defined by linker */ +extern char _Min_Heap_Size; /* Linker symbol: address is the value */ + void WEAKFUNCTION *_sbrk(int incr) { - (void)incr; - return 0; + static char *heap_end = 0; + char *prev_heap_end; + char *heap_limit; + + if (heap_end == 0) { + heap_end = &_end; + } + prev_heap_end = heap_end; + + heap_limit = &_end + (uintptr_t)&_Min_Heap_Size; + + if (heap_end + incr > heap_limit) { + errno = ENOMEM; + return (void *)-1; + } + + heap_end += incr; + return prev_heap_end; } From 9ee0f8299316efa0082f62a70eb15d699bf24841 Mon Sep 17 00:00:00 2001 From: Thomas Cook Date: Thu, 23 Apr 2026 08:53:21 -0400 Subject: [PATCH 12/14] Rework rng a bit --- arch.mk | 5 ++--- hal/lpc55s69.c | 13 ++++++------- test-app/Makefile | 3 +-- test-app/syscalls.c | 4 ++-- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/arch.mk b/arch.mk index d4ab6ccd3c..30c04ce6b3 100644 --- a/arch.mk +++ b/arch.mk @@ -1222,8 +1222,7 @@ ifeq ($(TARGET),lpc55s69) $(MCUXPRESSO)/drivers/common/fsl_common_arm.o \ $(MCUXPRESSO)/drivers/iap1/fsl_iap.o \ $(MCUXPRESSO)/drivers/lpc_gpio/fsl_gpio.o \ - $(MCUXPRESSO)/drivers/rng_1/fsl_rng.o \ - $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/nxp/rng_port.o + $(MCUXPRESSO)/drivers/rng_1/fsl_rng.o ifeq ($(DEBUG_UART),1) OBJS+=\ $(MCUXPRESSO_DRIVERS)/drivers/fsl_reset.o \ @@ -1231,7 +1230,7 @@ ifeq ($(TARGET),lpc55s69) $(MCUXPRESSO)/drivers/flexcomm/usart/fsl_usart.o endif ifeq ($(PKA),1) - CFLAGS+=-DWOLFSSL_NXP_LPC55S69 + CFLAGS+=-DWOLFSSL_NXP_LPC55S69_WITH_HWACCEL OBJS+=\ $(MCUXPRESSO)/drivers/casper/fsl_casper.o \ $(MCUXPRESSO)/drivers/hashcrypt/fsl_hashcrypt.o \ diff --git a/hal/lpc55s69.c b/hal/lpc55s69.c index 17c5cf9dc8..38f718f117 100644 --- a/hal/lpc55s69.c +++ b/hal/lpc55s69.c @@ -71,8 +71,6 @@ static void hal_sau_init(void) static void periph_unsecure(void) { - CLOCK_EnableClock(kCLOCK_Rng); - RESET_PeripheralReset(kRNG_RST_SHIFT_RSTn); CLOCK_EnableClock(kCLOCK_Iocon); CLOCK_EnableClock(kCLOCK_Gpio1); } @@ -118,8 +116,13 @@ void hal_init(void) wc_casper_init(); # endif + CLOCK_EnableClock(kCLOCK_Rng); + RESET_PeripheralReset(kRNG_RST_SHIFT_RSTn); + #endif /* __WOLFBOOT */ + RNG_Init(RNG); + #if defined(__WOLFBOOT) || !defined(TZEN) memset(&pflash, 0, sizeof(pflash)); FLASH_Init(&pflash); @@ -224,11 +227,7 @@ int RAMFUNCTION hal_flash_erase(uint32_t address, int len) #ifdef WOLFCRYPT_SECURE_MODE void hal_trng_init(void) { -# ifdef __WOLFBOOT - CLOCK_EnableClock(kCLOCK_Rng); - RESET_PeripheralReset(kRNG_RST_SHIFT_RSTn); -# endif - RNG_Init(RNG); + /* handled in hal_init() regardless */ } void hal_trng_fini(void) diff --git a/test-app/Makefile b/test-app/Makefile index d2bf3223c6..8c64dbdb78 100644 --- a/test-app/Makefile +++ b/test-app/Makefile @@ -694,8 +694,7 @@ ifeq ($(TARGET),lpc55s69) $(MCUXPRESSO)/drivers/flexcomm/usart/fsl_usart.o \ $(MCUXPRESSO)/drivers/iap1/fsl_iap.o \ $(MCUXPRESSO)/drivers/lpc_gpio/fsl_gpio.o \ - $(MCUXPRESSO)/drivers/rng_1/fsl_rng.o \ - $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/nxp/rng_port.o + $(MCUXPRESSO)/drivers/rng_1/fsl_rng.o ifeq ($(PKA),1) CFLAGS+=-DWOLFSSL_NXP_LPC55S69_WITH_HWACCEL APP_OBJS+=\ diff --git a/test-app/syscalls.c b/test-app/syscalls.c index 7eef2dc294..d4e502013c 100644 --- a/test-app/syscalls.c +++ b/test-app/syscalls.c @@ -135,7 +135,7 @@ int _getpid(void) * other OS facilities that don't exist in bare-metal. * wolfCrypt test/benchmark code calls standard printf, not wolfBoot_printf. */ -int vsnprintf(char *buf, unsigned int size, const char *fmt, va_list argp); +static int vsnprintf(char *buf, unsigned int size, const char *fmt, va_list argp); /* Route all printf-family functions through our vsnprintf (in this file) * rather than uart_vprintf (in string.c). This ensures float formatting @@ -216,7 +216,7 @@ static int buf_num(char *buf, int pos, int size, unsigned int num, return pos; } -int vsnprintf(char *buf, unsigned int size, const char *fmt, va_list argp) +static int vsnprintf(char *buf, unsigned int size, const char *fmt, va_list argp) { int pos = 0; const char *fmtp = fmt; From a1f3d3a5d3b2d1121786e5d18f7d9f117c62ba73 Mon Sep 17 00:00:00 2001 From: Thomas Cook Date: Thu, 23 Apr 2026 09:11:04 -0400 Subject: [PATCH 13/14] clean up lauterbach scripts --- tools/scripts/lpc55s69/lpc55s69_debug.cmm | 14 +++++++------- .../lpc55s69/lpc55s69_flash_factory_bin.cmm | 6 +++--- tools/scripts/lpc55s69/lpc55s69_flash_update.cmm | 10 ++++------ 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/tools/scripts/lpc55s69/lpc55s69_debug.cmm b/tools/scripts/lpc55s69/lpc55s69_debug.cmm index 5fc2e5c6bd..152fae7d19 100644 --- a/tools/scripts/lpc55s69/lpc55s69_debug.cmm +++ b/tools/scripts/lpc55s69/lpc55s69_debug.cmm @@ -1,6 +1,6 @@ ;; lpc55s69_debug.cmm -;; -;; "make DEBUG_SYMBOLS=1" + +&basedir="\\wsl.localhost\Ubuntu-22.04\home\tcook\wolf\wolfBoot" RESet SYStem.RESet @@ -21,8 +21,8 @@ mode.hll SYStem.Up ;; STOP in wolfBoot... -data.load "\\wsl.localhost\Ubuntu-22.04\home\tcook\wolf\wolfBoot\wolfboot.elf" /nocode -symbol.sourcepath.TranslateSUBpath "\home\tcook\wolf" "\\wsl.localhost\Ubuntu-22.04\home\tcook\wolf" +data.load "&basedir\wolfboot.elf" /nocode +symbol.sourcepath.TranslateSUBpath "\home\tcook\wolf\wolfBoot" "&basedir" Register.Set PC isr_reset Register.Set MSP END_STACK break.set main /onchip /temporary @@ -31,8 +31,8 @@ go ;; STOP in test-app... ;; UNCOMMENT the following: -;;WAIT !STATE.RUN() -;;data.load "\\wsl.localhost\Ubuntu-22.04\home\tcook\wolf\wolfBoot\test-app\image.elf" /nocode -;;break.set main /onchip /temporary +WAIT !STATE.RUN() +data.load "&basedir\test-app\image.elf" /nocode +;break.set wc_InitRng_ex /onchip /temporary go diff --git a/tools/scripts/lpc55s69/lpc55s69_flash_factory_bin.cmm b/tools/scripts/lpc55s69/lpc55s69_flash_factory_bin.cmm index 0cfd1697d0..e64a3550b1 100644 --- a/tools/scripts/lpc55s69/lpc55s69_flash_factory_bin.cmm +++ b/tools/scripts/lpc55s69/lpc55s69_flash_factory_bin.cmm @@ -1,6 +1,6 @@ ;; lpc55s69_flash_factory_bin.cmm -;; -;; "make DEBUG_SYMBOLS=1" + +&basedir="\\wsl.localhost\Ubuntu-22.04\home\tcook\wolf\wolfBoot" RESet SYStem.RESet @@ -22,7 +22,7 @@ DO ~~/demo/arm/flash/lpc55xx PREPAREONLY flash.erase all FLASH.ReProgram ALL -Data.LOAD.Binary "\\wsl.localhost\Ubuntu-22.04\home\tcook\wolf\wolfBoot\factory.bin" 0 +Data.LOAD.Binary "&basedir\factory.bin" 0 FLASH.ReProgram OFF ENDDO diff --git a/tools/scripts/lpc55s69/lpc55s69_flash_update.cmm b/tools/scripts/lpc55s69/lpc55s69_flash_update.cmm index f1ebef503c..86e56a9e43 100644 --- a/tools/scripts/lpc55s69/lpc55s69_flash_update.cmm +++ b/tools/scripts/lpc55s69/lpc55s69_flash_update.cmm @@ -1,8 +1,6 @@ ;; lpc55s69_flash_update.cmm -;; -;; make DEBUG_SYMBOLS=1 -;; then -;; tools/keytools/sign --ecc384 --sha256 test-app/image.bin wolfboot_signing_private_key.der 2 + +&basedir="\\wsl.localhost\Ubuntu-22.04\home\tcook\wolf\wolfBoot" RESet SYStem.RESet @@ -22,9 +20,9 @@ SYStem.Up DO ~~/demo/arm/flash/lpc55xx PREPAREONLY -;; flash.erase all ;; NOT FOR UPDATE + FLASH.ReProgram ALL -Data.LOAD.Binary "\\wsl.localhost\Ubuntu-22.04\home\tcook\wolf\wolfBoot\test-app\image_v2_signed.bin" 0x18000 +Data.LOAD.Binary "&basedir\test-app\image_v2_signed.bin" 0x18000 FLASH.ReProgram OFF ENDDO From bead801cdd9248dbdee9e8365be812ed38ae0b69 Mon Sep 17 00:00:00 2001 From: Thomas Cook Date: Thu, 23 Apr 2026 10:57:42 -0400 Subject: [PATCH 14/14] fix vsnprintf issue --- test-app/syscalls.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test-app/syscalls.c b/test-app/syscalls.c index d4e502013c..6910875599 100644 --- a/test-app/syscalls.c +++ b/test-app/syscalls.c @@ -135,7 +135,7 @@ int _getpid(void) * other OS facilities that don't exist in bare-metal. * wolfCrypt test/benchmark code calls standard printf, not wolfBoot_printf. */ -static int vsnprintf(char *buf, unsigned int size, const char *fmt, va_list argp); +static int ___vsnprintf(char *buf, unsigned int size, const char *fmt, va_list argp); /* Route all printf-family functions through our vsnprintf (in this file) * rather than uart_vprintf (in string.c). This ensures float formatting @@ -144,7 +144,7 @@ static int vsnprintf(char *buf, unsigned int size, const char *fmt, va_list argp int vprintf(const char *fmt, va_list args) { char buf[256]; - int len = vsnprintf(buf, sizeof(buf), fmt, args); + int len = ___vsnprintf(buf, sizeof(buf), fmt, args); if (len > 0) uart_write(buf, (len < (int)sizeof(buf)) ? len : (int)sizeof(buf) - 1); return len; @@ -216,7 +216,7 @@ static int buf_num(char *buf, int pos, int size, unsigned int num, return pos; } -static int vsnprintf(char *buf, unsigned int size, const char *fmt, va_list argp) +static int ___vsnprintf(char *buf, unsigned int size, const char *fmt, va_list argp) { int pos = 0; const char *fmtp = fmt; @@ -369,7 +369,7 @@ int snprintf(char *buf, unsigned int size, const char *fmt, ...) va_list args; int ret; va_start(args, fmt); - ret = vsnprintf(buf, size, fmt, args); + ret = ___vsnprintf(buf, size, fmt, args); va_end(args); return ret; } @@ -433,7 +433,7 @@ int __snprintf_chk(char *buf, unsigned int maxlen, int flag, int ret; (void)flag; va_start(args, fmt); - ret = vsnprintf(buf, size, fmt, args); + ret = ___vsnprintf(buf, size, fmt, args); va_end(args); return ret; }