Skip to content

Commit fce71af

Browse files
committed
Added support for running test-app and benchmarks. Added example trace32 scripts.
1 parent 9ffdbd0 commit fce71af

12 files changed

Lines changed: 1343 additions & 53 deletions

File tree

config/examples/nxp-t2080.config

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,26 @@ OPTIMIZATION_LEVEL?=1
3838
# NOR Base Address
3939
ARCH_FLASH_OFFSET?=0xEFFE0000
4040

41-
# Flash Sector Size (must match physical NOR erase block: 128 KB)
42-
WOLFBOOT_SECTOR_SIZE?=0x20000
41+
# Flash Sector Size
42+
WOLFBOOT_SECTOR_SIZE?=0x10000
4343

4444
# wolfBoot start address
4545
WOLFBOOT_ORIGIN?=0xEFFE0000
4646
# wolfBoot partition size (custom)
4747
BOOTLOADER_PARTITION_SIZE=0x20000
4848

4949
# Application Partition Size
50-
WOLFBOOT_PARTITION_SIZE?=0x20000
50+
WOLFBOOT_PARTITION_SIZE?=0x100000
5151
# Location in Flash for Application Partition
52-
WOLFBOOT_PARTITION_BOOT_ADDRESS?=0xEFFC0000
52+
WOLFBOOT_PARTITION_BOOT_ADDRESS?=0xEFEE0000
5353
# Load Partition to RAM Address
5454
WOLFBOOT_LOAD_ADDRESS?=0x19000
5555

5656
# Location in Flash for Update Partition
57-
WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0xEFFA0000
57+
WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0xEFDE0000
5858

5959
# Location of temporary sector used during updates
60-
WOLFBOOT_PARTITION_SWAP_ADDRESS?=0xEFF90000
60+
WOLFBOOT_PARTITION_SWAP_ADDRESS?=0xEFDD0000
6161

6262
# DTS (Device Tree)
6363
WOLFBOOT_DTS_BOOT_ADDRESS?=0xE8040000
@@ -67,3 +67,7 @@ WOLFBOOT_LOAD_DTS_ADDRESS?=0x200000
6767

6868
# Flash erase/write/read test at update partition address
6969
#TEST_FLASH?=1
70+
71+
# wolfCrypt Test and Benchmark (requires larger partition size)
72+
#WOLFCRYPT_TEST?=1
73+
#WOLFCRYPT_BENCHMARK?=1

docs/Targets.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3115,10 +3115,13 @@ placed in `.ramcode`, copied to DDR, and remapped via TLB9. Key rules:
31153115

31163116
- **No calls to flash-resident code.** The linker generates trampolines that
31173117
jump back to flash addresses. Any helper called from RAMFUNCTION code must
3118-
itself be RAMFUNCTION or fully inlined. Delay ticks are pre-computed in
3119-
`hal_flash_init()` to avoid calling `hal_get_plat_clk()` from flash `.text`.
3118+
itself be RAMFUNCTION or fully inlined. Delay/clock helpers (for example,
3119+
`udelay` and associated clock accessors) are provided by `nxp_ppc.c` and
3120+
are marked `RAMFUNCTION` so they can be safely invoked without executing
3121+
from flash `.text`.
31203122
- **Inline TLB/cache ops.** `hal_flash_cache_disable/enable` use
3121-
`ram_write_tlb()` (inline mtspr) and direct L1CSR0/L1CSR1 manipulation.
3123+
`set_tlb()` / `write_tlb()` (inline `mtspr` helpers) and direct
3124+
L1CSR0/L1CSR1 manipulation.
31223125
- **WBP timing.** The write-buffer-program sequence (unlock → 0x25 → count →
31233126
data → 0x29) must execute without bus-stalling delays. UART output between
31243127
steps (~87us per character at 115200) triggers DQ1 abort.

hal/nxp_t2080.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,16 @@ void hal_init(void)
400400
#ifndef WOLFBOOT_REPRODUCIBLE_BUILD
401401
wolfBoot_printf("Build: %s %s\n", __DATE__, __TIME__);
402402
#endif
403+
wolfBoot_printf("System Clock: %lu MHz\n",
404+
(unsigned long)(SYS_CLK / 1000000));
405+
wolfBoot_printf("Platform Clock: %lu MHz\n",
406+
(unsigned long)(hal_get_plat_clk() / 1000000));
407+
wolfBoot_printf("Core Clock: %lu MHz\n",
408+
(unsigned long)(hal_get_core_clk() / 1000000));
409+
wolfBoot_printf("Bus Clock: %lu MHz\n",
410+
(unsigned long)(hal_get_bus_clk() / 1000000));
411+
wolfBoot_printf("Timebase: %lu MHz\n",
412+
(unsigned long)(TIMEBASE_HZ / 1000000));
403413
#endif
404414

405415
hal_flash_init();

include/user_settings.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -477,11 +477,11 @@ extern int tolower(int c);
477477

478478
#if !defined(WOLFCRYPT_SECURE_MODE) && !defined(WOLFBOOT_TPM_PARMENC) && \
479479
!defined(WOLFCRYPT_TEST) && !defined(WOLFCRYPT_BENCHMARK)
480-
#if !(defined(WOLFBOOT_ENABLE_WOLFHSM_CLIENT) && \
481-
defined(WOLFBOOT_SIGN_ML_DSA)) && \
482-
!defined(WOLFBOOT_ENABLE_WOLFHSM_SERVER)
483-
#define WC_NO_RNG
484-
#endif
480+
#if !(defined(WOLFBOOT_ENABLE_WOLFHSM_CLIENT) && \
481+
defined(WOLFBOOT_SIGN_ML_DSA)) && \
482+
!defined(WOLFBOOT_ENABLE_WOLFHSM_SERVER)
483+
#define WC_NO_RNG
484+
#endif
485485
#define WC_NO_HASHDRBG
486486
#define NO_AES_CBC
487487
#else
@@ -493,6 +493,9 @@ extern int tolower(int c);
493493
#define CUSTOM_RAND_GENERATE_SEED my_rng_seed_gen
494494
#define CUSTOM_RAND_GENERATE_BLOCK my_rng_seed_gen
495495
extern int my_rng_seed_gen(unsigned char* output, unsigned int sz);
496+
497+
#define HAVE_AESGCM
498+
#define GCM_TABLE
496499
#else
497500
#define HAVE_HASHDRBG
498501
#define WOLFSSL_AES_CFB
@@ -590,6 +593,9 @@ extern int tolower(int c);
590593
#if defined(WOLFCRYPT_TEST) || defined(WOLFCRYPT_BENCHMARK)
591594
#define NO_WRITE_TEMP_FILES
592595

596+
/* Use printf for wolfSSL logging (redirected to UART via syscalls.c) */
597+
#define WOLFSSL_LOG_PRINTF
598+
593599
/* Use static memory pool to avoid system malloc dependency.
594600
* benchmark.c provides gBenchMemory static buffer.
595601
* Default is 50KB with BENCH_EMBEDDED, override for smaller targets */

src/string.c

Lines changed: 81 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ void uart_writenum(int num, int base, int zeropad, int maxdigits)
342342
void uart_vprintf(const char* fmt, va_list argp)
343343
{
344344
char* fmtp = (char*)fmt;
345-
int zeropad, maxdigits;
345+
int zeropad, maxdigits, precision, leftjust;
346346
while (fmtp != NULL && *fmtp != '\0') {
347347
/* print non formatting characters */
348348
if (*fmtp != '%') {
@@ -352,17 +352,42 @@ void uart_vprintf(const char* fmt, va_list argp)
352352
fmtp++; /* skip % */
353353

354354
/* find formatters */
355-
zeropad = maxdigits = 0;
355+
zeropad = maxdigits = leftjust = 0;
356+
precision = -1; /* -1 = not specified */
357+
/* check for left-justify flag */
358+
if (*fmtp == '-') {
359+
leftjust = 1;
360+
fmtp++;
361+
}
356362
while (*fmtp != '\0') {
357-
if (*fmtp >= '0' && *fmtp <= '9') {
363+
if (*fmtp == '*') {
364+
/* width from argument */
365+
maxdigits = va_arg(argp, int);
366+
fmtp++;
367+
}
368+
else if (*fmtp >= '0' && *fmtp <= '9') {
358369
/* length formatter */
359-
if (*fmtp == '0') {
370+
if (*fmtp == '0' && maxdigits == 0) {
360371
zeropad = 1;
361372
}
362373
maxdigits <<= 8;
363374
maxdigits += (*fmtp - '0');
364375
fmtp++;
365376
}
377+
else if (*fmtp == '.') {
378+
/* precision */
379+
fmtp++;
380+
if (*fmtp == '*') {
381+
precision = va_arg(argp, int);
382+
fmtp++;
383+
} else {
384+
precision = 0;
385+
while (*fmtp >= '0' && *fmtp <= '9') {
386+
precision = precision * 10 + (*fmtp - '0');
387+
fmtp++;
388+
}
389+
}
390+
}
366391
else if (*fmtp == 'l') {
367392
/* long - skip */
368393
fmtp++;
@@ -401,7 +426,20 @@ void uart_vprintf(const char* fmt, va_list argp)
401426
case 's':
402427
{
403428
char* str = (char*)va_arg(argp, char*);
404-
uart_write(str, (uint32_t)strlen(str));
429+
int slen = (int)strlen(str);
430+
if (leftjust) {
431+
uart_write(str, slen);
432+
while (slen < maxdigits) {
433+
uart_write(" ", 1);
434+
slen++;
435+
}
436+
} else {
437+
while (slen < maxdigits) {
438+
uart_write(" ", 1);
439+
slen++;
440+
}
441+
uart_write(str, (uint32_t)strlen(str));
442+
}
405443
break;
406444
}
407445
case 'c':
@@ -410,6 +448,44 @@ void uart_vprintf(const char* fmt, va_list argp)
410448
uart_write(&c, 1);
411449
break;
412450
}
451+
#ifdef UART_PRINTF_FLOAT
452+
case 'f':
453+
case 'e':
454+
case 'g':
455+
{
456+
double val = va_arg(argp, double);
457+
int prec = (precision >= 0) ? precision : 3;
458+
int digit;
459+
unsigned int ipart;
460+
461+
/* handle negative */
462+
if (val < 0.0) {
463+
uart_write("-", 1);
464+
val = -val;
465+
}
466+
467+
/* integer part */
468+
ipart = (unsigned int)val;
469+
uart_writenum((int)ipart, 10, 0, 0);
470+
471+
/* fractional part */
472+
if (prec > 0) {
473+
double frac = val - (double)ipart;
474+
char c;
475+
int i;
476+
uart_write(".", 1);
477+
for (i = 0; i < prec; i++) {
478+
frac *= 10.0;
479+
digit = (int)frac;
480+
if (digit > 9) digit = 9;
481+
c = '0' + digit;
482+
uart_write(&c, 1);
483+
frac -= (double)digit;
484+
}
485+
}
486+
break;
487+
}
488+
#endif /* UART_PRINTF_FLOAT */
413489
default:
414490
break;
415491
}

test-app/Makefile

Lines changed: 68 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,14 @@ endif
107107
ifeq ($(WOLFCRYPT_BENCHMARK),1)
108108
CFLAGS+=-DWOLFCRYPT_BENCHMARK
109109
WOLFCRYPT_SUPPORT=1
110+
UART_PRINTF_FLOAT?=1
110111
APP_OBJS+=$(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/benchmark/benchmark.o
111112
endif
112113

114+
ifeq ($(UART_PRINTF_FLOAT),1)
115+
CFLAGS+=-DUART_PRINTF_FLOAT
116+
endif
117+
113118
ifeq ($(WOLFCRYPT_SUPPORT),1)
114119
# Add support infrastructure
115120
APP_OBJS+=wolfcrypt_support.o
@@ -141,25 +146,60 @@ ifeq ($(WOLFCRYPT_SUPPORT),1)
141146
APP_OBJS+=$(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/ecc.o
142147
APP_OBJS+=$(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/sp_int.o
143148

144-
# Add SP math implementations for ARM Cortex-M
145-
APP_OBJS+=$(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/sp_cortexm.o
149+
# Add SP C math (all architectures)
146150
APP_OBJS+=$(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/sp_c32.o
147151

148-
ifneq ($(NO_ARM_ASM),1)
149-
APP_OBJS+= \
150-
$(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/arm/thumb2-aes-asm_c.o \
151-
$(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/arm/thumb2-sha256-asm_c.o \
152-
$(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/arm/thumb2-sha512-asm_c.o \
153-
$(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/arm/thumb2-sha3-asm_c.o \
154-
$(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/arm/thumb2-chacha-asm_c.o
152+
ifneq ($(NO_ASM),1)
153+
# SP Cortex M
154+
ifneq ($(filter ARM ARM_BE,$(ARCH)),)
155+
ifeq ($(SPMATH),1)
156+
APP_OBJS+=$(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/sp_cortexm.o
157+
endif
158+
159+
ifneq ($(NO_ARM_ASM),1)
160+
APP_OBJS+= \
161+
$(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/arm/thumb2-aes-asm_c.o \
162+
$(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/arm/thumb2-sha256-asm_c.o \
163+
$(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/arm/thumb2-sha512-asm_c.o \
164+
$(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/arm/thumb2-sha3-asm_c.o \
165+
$(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/arm/thumb2-chacha-asm_c.o
166+
167+
CFLAGS+=-DWOLFSSL_ARMASM -DWOLFSSL_ARMASM_NO_HW_CRYPTO -DWOLFSSL_ARMASM_INLINE \
168+
-DWOLFSSL_ARMASM_NO_NEON -DWOLFSSL_ARMASM_THUMB2
169+
endif
170+
endif
171+
172+
# Power PC
173+
ifeq ($(ARCH),PPC)
174+
# SP mp int PowerPC ASM
175+
ifeq ($(PPC64),1)
176+
CFLAGS+=-DWOLFSSL_SP_PPC64
177+
else
178+
CFLAGS+=-DWOLFSSL_SP_PPC
179+
endif
180+
181+
# SHA256
182+
APP_OBJS+=$(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/ppc32/ppc32-sha256-asm_c.o
183+
CFLAGS+=-DWOLFSSL_PPC32_ASM
184+
CFLAGS+=-DWOLFSSL_PPC32_ASM_INLINE
185+
CFLAGS+=-DWOLFSSL_PPC32_ASM_SMALL
186+
187+
ifeq ($(PPC64),1) # requires wolfssl PR 9852
188+
# AES
189+
APP_OBJS+=$(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/ppc64/ppc64-aes-asm_c.o
190+
CFLAGS+=-DWOLFSSL_PPC64_ASM
191+
CFLAGS+=-DWOLFSSL_PPC64_ASM_INLINE
192+
CFLAGS+=-DWOLFSSL_PPC64_ASM_SMALL
193+
CFLAGS+=-DWOLFSSL_PPC64_ASM_AES_NO_HARDEN
194+
endif
155195

156-
CFLAGS+=-DWOLFSSL_ARMASM -DWOLFSSL_ARMASM_NO_HW_CRYPTO -DWOLFSSL_ARMASM_INLINE \
157-
-DWOLFSSL_ARMASM_NO_NEON -DWOLFSSL_ARMASM_THUMB2
196+
CFLAGS+=-fomit-frame-pointer
197+
endif
158198
endif
159199

160200
CFLAGS+=-DWOLFSSL_USER_SETTINGS
161201
CFLAGS+=-I"$(WOLFBOOT_LIB_WOLFSSL)"
162-
endif
202+
endif # WOLFCRYPT_SUPPORT
163203

164204
ifeq ($(TZEN),1)
165205
CFLAGS+=-DNONSECURE_APP
@@ -414,6 +454,22 @@ ifeq ($(TARGET),va416x0)
414454
CFLAGS+=-ffunction-sections -fdata-sections
415455
endif
416456

457+
PPC64=0
458+
ifeq ($(TARGET),nxp_t2080)
459+
ifneq ($(SIGN),NONE)
460+
APP_OBJS+=../src/keystore.o
461+
endif
462+
CFLAGS+=-ffunction-sections -fdata-sections
463+
464+
# PowerPC e6500
465+
PPC64=1
466+
endif
467+
468+
ifeq ($(TARGET),nxp_t1024)
469+
# PowerPC e5500
470+
PPC64=1
471+
endif
472+
417473
ifeq ($(TARGET),sim)
418474
# LD on MacOS does not support "-Map="
419475
LDMAPSUPPORTED=$(shell $(CC) -Wl,-Map=image.map 2>&1 | grep 'unknown option')

test-app/PPC.ld

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
OUTPUT_ARCH( "powerpc" )
22

3-
ENTRY( main )
3+
ENTRY( _app_entry )
44

55
PHDRS
66
{
@@ -14,6 +14,7 @@ SECTIONS
1414

1515
.text :
1616
{
17+
*(.text._app_entry)
1718
*(.text.main)
1819
*(.text*)
1920
*(.rodata*)
@@ -23,6 +24,7 @@ SECTIONS
2324
{
2425
_start_data = .;
2526
KEEP(*(.data*))
27+
*(.sdata*) /* PPC small initialized data */
2628
. = ALIGN(4);
2729
KEEP(*(.ramcode))
2830

@@ -54,6 +56,7 @@ SECTIONS
5456
_start_bss = .;
5557
__bss_start__ = .;
5658
*(.bss*)
59+
*(.sbss*) /* PPC small uninitialized data */
5760
*(COMMON)
5861
. = ALIGN(4);
5962
_end_bss = .;
@@ -62,4 +65,12 @@ SECTIONS
6265
}
6366
. = ALIGN(4);
6467

68+
/* Heap for _sbrk (used by syscalls.c malloc) */
69+
_Min_Heap_Size = 0x10000; /* 64KB */
70+
71+
/* Stack: 64KB, grows downward from _stack_top.
72+
* wolfCrypt ECC384 operations need deep stack (~11KB per frame). */
73+
_Min_Stack_Size = 0x10000; /* 64KB */
74+
_stack_end = _end + _Min_Heap_Size;
75+
_stack_top = _stack_end + _Min_Stack_Size;
6576
}

0 commit comments

Comments
 (0)