Skip to content

Commit 4a53bd1

Browse files
dgarskedanielinux
authored andcommitted
Added support for running test-app and benchmarks. Added example trace32 scripts.
1 parent a5356b8 commit 4a53bd1

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
@@ -3315,10 +3315,13 @@ placed in `.ramcode`, copied to DDR, and remapped via TLB9. Key rules:
33153315

33163316
- **No calls to flash-resident code.** The linker generates trampolines that
33173317
jump back to flash addresses. Any helper called from RAMFUNCTION code must
3318-
itself be RAMFUNCTION or fully inlined. Delay ticks are pre-computed in
3319-
`hal_flash_init()` to avoid calling `hal_get_plat_clk()` from flash `.text`.
3318+
itself be RAMFUNCTION or fully inlined. Delay/clock helpers (for example,
3319+
`udelay` and associated clock accessors) are provided by `nxp_ppc.c` and
3320+
are marked `RAMFUNCTION` so they can be safely invoked without executing
3321+
from flash `.text`.
33203322
- **Inline TLB/cache ops.** `hal_flash_cache_disable/enable` use
3321-
`ram_write_tlb()` (inline mtspr) and direct L1CSR0/L1CSR1 manipulation.
3323+
`set_tlb()` / `write_tlb()` (inline `mtspr` helpers) and direct
3324+
L1CSR0/L1CSR1 manipulation.
33223325
- **WBP timing.** The write-buffer-program sequence (unlock → 0x25 → count →
33233326
data → 0x29) must execute without bus-stalling delays. UART output between
33243327
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
@@ -478,11 +478,11 @@ extern int tolower(int c);
478478

479479
#if !defined(WOLFCRYPT_SECURE_MODE) && !defined(WOLFBOOT_TPM_PARMENC) && \
480480
!defined(WOLFCRYPT_TEST) && !defined(WOLFCRYPT_BENCHMARK)
481-
#if !(defined(WOLFBOOT_ENABLE_WOLFHSM_CLIENT) && \
482-
defined(WOLFBOOT_SIGN_ML_DSA)) && \
483-
!defined(WOLFBOOT_ENABLE_WOLFHSM_SERVER)
484-
#define WC_NO_RNG
485-
#endif
481+
#if !(defined(WOLFBOOT_ENABLE_WOLFHSM_CLIENT) && \
482+
defined(WOLFBOOT_SIGN_ML_DSA)) && \
483+
!defined(WOLFBOOT_ENABLE_WOLFHSM_SERVER)
484+
#define WC_NO_RNG
485+
#endif
486486
#define WC_NO_HASHDRBG
487487
#define NO_AES_CBC
488488
#else
@@ -494,6 +494,9 @@ extern int tolower(int c);
494494
#define CUSTOM_RAND_GENERATE_SEED my_rng_seed_gen
495495
#define CUSTOM_RAND_GENERATE_BLOCK my_rng_seed_gen
496496
extern int my_rng_seed_gen(unsigned char* output, unsigned int sz);
497+
498+
#define HAVE_AESGCM
499+
#define GCM_TABLE
497500
#else
498501
#define HAVE_HASHDRBG
499502
#define WOLFSSL_AES_CFB
@@ -591,6 +594,9 @@ extern int tolower(int c);
591594
#if defined(WOLFCRYPT_TEST) || defined(WOLFCRYPT_BENCHMARK)
592595
#define NO_WRITE_TEMP_FILES
593596

597+
/* Use printf for wolfSSL logging (redirected to UART via syscalls.c) */
598+
#define WOLFSSL_LOG_PRINTF
599+
594600
/* Use static memory pool to avoid system malloc dependency.
595601
* benchmark.c provides gBenchMemory static buffer.
596602
* 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
@@ -346,7 +346,7 @@ void uart_writenum(int num, int base, int zeropad, int maxdigits)
346346
void uart_vprintf(const char* fmt, va_list argp)
347347
{
348348
char* fmtp = (char*)fmt;
349-
int zeropad, maxdigits;
349+
int zeropad, maxdigits, precision, leftjust;
350350
while (fmtp != NULL && *fmtp != '\0') {
351351
/* print non formatting characters */
352352
if (*fmtp != '%') {
@@ -356,17 +356,42 @@ void uart_vprintf(const char* fmt, va_list argp)
356356
fmtp++; /* skip % */
357357

358358
/* find formatters */
359-
zeropad = maxdigits = 0;
359+
zeropad = maxdigits = leftjust = 0;
360+
precision = -1; /* -1 = not specified */
361+
/* check for left-justify flag */
362+
if (*fmtp == '-') {
363+
leftjust = 1;
364+
fmtp++;
365+
}
360366
while (*fmtp != '\0') {
361-
if (*fmtp >= '0' && *fmtp <= '9') {
367+
if (*fmtp == '*') {
368+
/* width from argument */
369+
maxdigits = va_arg(argp, int);
370+
fmtp++;
371+
}
372+
else if (*fmtp >= '0' && *fmtp <= '9') {
362373
/* length formatter */
363-
if (*fmtp == '0') {
374+
if (*fmtp == '0' && maxdigits == 0) {
364375
zeropad = 1;
365376
}
366377
maxdigits <<= 8;
367378
maxdigits += (*fmtp - '0');
368379
fmtp++;
369380
}
381+
else if (*fmtp == '.') {
382+
/* precision */
383+
fmtp++;
384+
if (*fmtp == '*') {
385+
precision = va_arg(argp, int);
386+
fmtp++;
387+
} else {
388+
precision = 0;
389+
while (*fmtp >= '0' && *fmtp <= '9') {
390+
precision = precision * 10 + (*fmtp - '0');
391+
fmtp++;
392+
}
393+
}
394+
}
370395
else if (*fmtp == 'l') {
371396
/* long - skip */
372397
fmtp++;
@@ -405,7 +430,20 @@ void uart_vprintf(const char* fmt, va_list argp)
405430
case 's':
406431
{
407432
char* str = (char*)va_arg(argp, char*);
408-
uart_write(str, (uint32_t)strlen(str));
433+
int slen = (int)strlen(str);
434+
if (leftjust) {
435+
uart_write(str, slen);
436+
while (slen < maxdigits) {
437+
uart_write(" ", 1);
438+
slen++;
439+
}
440+
} else {
441+
while (slen < maxdigits) {
442+
uart_write(" ", 1);
443+
slen++;
444+
}
445+
uart_write(str, (uint32_t)strlen(str));
446+
}
409447
break;
410448
}
411449
case 'c':
@@ -414,6 +452,44 @@ void uart_vprintf(const char* fmt, va_list argp)
414452
uart_write(&c, 1);
415453
break;
416454
}
455+
#ifdef UART_PRINTF_FLOAT
456+
case 'f':
457+
case 'e':
458+
case 'g':
459+
{
460+
double val = va_arg(argp, double);
461+
int prec = (precision >= 0) ? precision : 3;
462+
int digit;
463+
unsigned int ipart;
464+
465+
/* handle negative */
466+
if (val < 0.0) {
467+
uart_write("-", 1);
468+
val = -val;
469+
}
470+
471+
/* integer part */
472+
ipart = (unsigned int)val;
473+
uart_writenum((int)ipart, 10, 0, 0);
474+
475+
/* fractional part */
476+
if (prec > 0) {
477+
double frac = val - (double)ipart;
478+
char c;
479+
int i;
480+
uart_write(".", 1);
481+
for (i = 0; i < prec; i++) {
482+
frac *= 10.0;
483+
digit = (int)frac;
484+
if (digit > 9) digit = 9;
485+
c = '0' + digit;
486+
uart_write(&c, 1);
487+
frac -= (double)digit;
488+
}
489+
}
490+
break;
491+
}
492+
#endif /* UART_PRINTF_FLOAT */
417493
default:
418494
break;
419495
}

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)