Skip to content

Commit b0e9875

Browse files
committed
Fixes for getting benchmark to run in test-app.
1 parent 1e96682 commit b0e9875

6 files changed

Lines changed: 59 additions & 21 deletions

File tree

include/user_settings.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,9 @@ extern int tolower(int c);
486486
#define NO_AES_CBC
487487
#else
488488
#if defined(WOLFCRYPT_TEST) || defined(WOLFCRYPT_BENCHMARK)
489-
/* Use custom RNG for tests (saves ~7KB vs HASHDRBG) */
489+
/* Use custom RNG for tests/benchmarks (saves ~7KB vs HASHDRBG).
490+
* WARNING: my_rng_seed_gen is NOT cryptographically secure.
491+
* Only used in test-app builds, not in production wolfBoot. */
490492
#define WC_NO_HASHDRBG
491493
#define CUSTOM_RAND_GENERATE_SEED my_rng_seed_gen
492494
#define CUSTOM_RAND_GENERATE_BLOCK my_rng_seed_gen

test-app/Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ ifeq ($(WOLFCRYPT_SUPPORT),1)
133133
# Add RNG support (needed for ECC signing and tests)
134134
APP_OBJS+=$(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/random.o
135135

136+
# Add AES support (needed by benchmark for AES-CBC etc.)
137+
APP_OBJS+=$(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/aes.o
138+
136139
# Add ECC support (needed by test suite)
137140
APP_OBJS+=$(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/ecc.o
138141
APP_OBJS+=$(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/sp_int.o
@@ -398,7 +401,11 @@ ifeq ($(TARGET),va416x0)
398401
APP_OBJS+=../src/keystore.o
399402
endif
400403
# Reduce size: newlib-nano and section GC
401-
LDFLAGS+=--specs=nano.specs --specs=nosys.specs
404+
LDFLAGS+=--specs=nano.specs
405+
ifneq ($(WOLFCRYPT_SUPPORT),1)
406+
# Only use nosys stubs when not providing our own syscalls
407+
LDFLAGS+=--specs=nosys.specs
408+
endif
402409
ifeq ($(WOLFCRYPT_BENCHMARK),1)
403410
# Benchmark needs float printf for results
404411
LDFLAGS+=-u _printf_float

test-app/syscalls.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
2222
*/
2323

24+
#include <stdint.h>
2425
#include <sys/stat.h>
2526
#include <errno.h>
2627

@@ -29,7 +30,7 @@ extern int errno;
2930

3031
/* Heap management */
3132
extern char _end; /* Defined by linker */
32-
extern char _Min_Heap_Size; /* Defined by linker (if available) */
33+
extern char _Min_Heap_Size; /* Linker symbol: address is the value */
3334

3435
char *__env[1] = { 0 };
3536
char **environ = __env;
@@ -71,8 +72,9 @@ void *_sbrk(int incr)
7172
}
7273
prev_heap_end = heap_end;
7374

74-
/* Calculate heap limit */
75-
heap_limit = &_end + _Min_Heap_Size;
75+
/* Calculate heap limit: _Min_Heap_Size is a linker symbol whose
76+
* address represents the size value */
77+
heap_limit = &_end + (uintptr_t)&_Min_Heap_Size;
7678

7779
if (heap_end + incr > heap_limit) {
7880
errno = ENOMEM;

test-app/wcs/user_settings.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@ extern int tolower(int c);
147147
#define NO_ERROR_STRINGS
148148
#define NO_KDF
149149

150-
#define WC_TEST_NO_CRYPTOCB_SW_TEST
150+
#ifdef WOLF_CRYPTO_CB
151+
#define WC_TEST_NO_CRYPTOCB_SW_TEST
152+
#endif
151153
#define BENCH_EMBEDDED
152154

153155
#define HAVE_ECC_KEY_EXPORT

tools/keytools/sign.c

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,22 +1744,47 @@ static int make_header_ex(int is_diff, uint8_t *pubkey, uint32_t pubkey_sz,
17441744
const char *env_psize = getenv("WOLFBOOT_PARTITION_SIZE");
17451745
const char *env_ssize = getenv("WOLFBOOT_SECTOR_SIZE");
17461746
if (env_psize) {
1747-
uint32_t partition_sz = (uint32_t)strtol(env_psize, NULL, 0);
1748-
uint32_t sector_sz = env_ssize ?
1749-
(uint32_t)strtol(env_ssize, NULL, 0) : 0;
1750-
uint32_t total_img_sz = CMD.header_sz + image_sz;
1751-
/* Only subtract sector for trailer when sector < partition.
1752-
* When sector >= partition (e.g. update_ram targets), the
1753-
* entire partition is available for the image. */
1754-
uint32_t max_img_sz = (sector_sz < partition_sz) ?
1755-
(partition_sz - sector_sz) : partition_sz;
1756-
if (total_img_sz > max_img_sz) {
1757-
printf("Error: Image size %u (header %u + firmware %u) "
1758-
"exceeds max %u (partition %u - sector %u)\n",
1759-
total_img_sz, CMD.header_sz, image_sz,
1760-
max_img_sz, partition_sz, sector_sz);
1747+
char *endptr;
1748+
unsigned long tmp;
1749+
uint32_t partition_sz, sector_sz = 0;
1750+
1751+
errno = 0;
1752+
tmp = strtoul(env_psize, &endptr, 0);
1753+
if (endptr == env_psize || *endptr != '\0' ||
1754+
errno == ERANGE || tmp == 0 || tmp > UINT32_MAX) {
1755+
printf("Error: Invalid WOLFBOOT_PARTITION_SIZE '%s'\n",
1756+
env_psize);
17611757
goto failure;
17621758
}
1759+
partition_sz = (uint32_t)tmp;
1760+
1761+
if (env_ssize) {
1762+
errno = 0;
1763+
tmp = strtoul(env_ssize, &endptr, 0);
1764+
if (endptr == env_ssize || *endptr != '\0' ||
1765+
errno == ERANGE || tmp == 0 || tmp > UINT32_MAX) {
1766+
printf("Error: Invalid WOLFBOOT_SECTOR_SIZE '%s'\n",
1767+
env_ssize);
1768+
goto failure;
1769+
}
1770+
sector_sz = (uint32_t)tmp;
1771+
}
1772+
1773+
{
1774+
uint32_t total_img_sz = CMD.header_sz + image_sz;
1775+
/* Only subtract sector for trailer when sector < partition.
1776+
* When sector >= partition (e.g. update_ram targets), the
1777+
* entire partition is available for the image. */
1778+
uint32_t max_img_sz = (sector_sz < partition_sz) ?
1779+
(partition_sz - sector_sz) : partition_sz;
1780+
if (total_img_sz > max_img_sz) {
1781+
printf("Error: Image size %u (header %u + firmware %u) "
1782+
"exceeds max %u (partition %u - sector %u)\n",
1783+
total_img_sz, CMD.header_sz, image_sz,
1784+
max_img_sz, partition_sz, sector_sz);
1785+
goto failure;
1786+
}
1787+
}
17631788
}
17641789
}
17651790

tools/scripts/va416x0/build_test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ MODE=$1
1717
VERSION=$([ "$MODE" = "clean" ] && echo "${2:-1}" || echo "${2:-2}")
1818

1919
# Find JLinkExe (in PATH on Linux, /Applications/SEGGER on macOS)
20-
if command -v JLinkExe &> /dev/null; then
20+
if command -v JLinkExe >/dev/null 2>&1; then
2121
JLINK="JLinkExe"
2222
else
2323
# Check for versioned JLink directory on macOS (e.g., JLink_V812g)

0 commit comments

Comments
 (0)