Skip to content

Commit

Permalink
Added 32bit simulator via TARGET=sim FORCE_32BIT=1 (wolfSSL#485)
Browse files Browse the repository at this point in the history
* Added 32bit simulator via TARGET=sim FORCE_32BIT=1

Tests can now run on 32bit simulator (e.g. to match XMALLOC fixed
sizes with sp_math and WOLFBOOT_SMALL_STACK).

* Added draft for new workflow: test simulator with different memory config

* Fix 64bit, SMALL_STACK xmalloc sizes

* Test defaults to SPMATH

* Fixed test: defaults to spmath. Added RSA tests (failing)

* Fixed RSA allocation sizes for 64bit build

* Added 64bit fastmath test (failing)

* Fixed ecc_point size for 64bit builds (FASTMATH)

* simulator config: use SPMATH by default

* Attempt to fix i386 libc dep in workflow

* Added HUGE_STACK to silence warning in FASTMATH+RSA4096 tests
  • Loading branch information
danielinux authored Aug 9, 2024
1 parent 8273575 commit 30a1f67
Show file tree
Hide file tree
Showing 9 changed files with 601 additions and 9 deletions.
548 changes: 548 additions & 0 deletions .github/workflows/test-sunnyday-simulator.yml

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions arch.mk
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,10 @@ ifeq ($(TARGET),sim)
LD_END_GROUP=
BOOT_IMG=test-app/image.elf
CFLAGS+=-DARCH_SIM
ifeq ($(FORCE_32BIT),1)
CFLAGS+=-m32
LDFLAGS+=-m32
endif
ifeq ($(SPMATH),1)
MATH_OBJS += ./lib/wolfssl/wolfcrypt/src/sp_c32.o
CFLAGS+=-DWOLFSSL_SP_DIV_WORD_HALF
Expand Down
1 change: 0 additions & 1 deletion config/examples/sim-nobackup-flags-home.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ HASH?=SHA256
WOLFBOOT_SMALL_STACK?=1
SPI_FLASH=0
DEBUG=1
SPMATH?=0
DISABLE_BACKUP=1
FLAGS_HOME=1

Expand Down
1 change: 0 additions & 1 deletion config/examples/sim-nobackup-nvm-writeonce.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ HASH?=SHA256
WOLFBOOT_SMALL_STACK?=1
SPI_FLASH=0
DEBUG=1
SPMATH?=0
DISABLE_BACKUP=1
NVM_FLASH_WRITEONCE=1

Expand Down
1 change: 0 additions & 1 deletion config/examples/sim-nobackup.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ HASH?=SHA256
WOLFBOOT_SMALL_STACK?=1
SPI_FLASH=0
DEBUG=1
SPMATH?=0
DISABLE_BACKUP=1

# sizes should be multiple of system page size
Expand Down
3 changes: 1 addition & 2 deletions config/examples/sim.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ ARCH=sim
TARGET=sim
SIGN?=ED25519
HASH?=SHA256
WOLFBOOT_SMALL_STACK?=1
WOLFBOOT_SMALL_STACK?=0
SPI_FLASH=0
DEBUG=1
SPMATH?=0

# sizes should be multiple of system page size
WOLFBOOT_PARTITION_SIZE=0x40000
Expand Down
22 changes: 22 additions & 0 deletions config/examples/sim32.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
ARCH=sim
TARGET=sim
SIGN?=ECC256
HASH?=SHA256
WOLFBOOT_SMALL_STACK?=0
SPI_FLASH=0
DEBUG=1
FORCE_32BIT=1

# sizes should be multiple of system page size
WOLFBOOT_PARTITION_SIZE=0x40000
WOLFBOOT_SECTOR_SIZE=0x1000
WOLFBOOT_PARTITION_BOOT_ADDRESS=0x80000
# if on external flash, it should be multiple of system page size
WOLFBOOT_PARTITION_UPDATE_ADDRESS=0x100000
WOLFBOOT_PARTITION_SWAP_ADDRESS=0x180000

# required for keytools
WOLFBOOT_FIXED_PARTITIONS=1

# For debugging XMALLOC/XFREE
#CFLAGS_EXTRA+=-DWOLFBOOT_DEBUG_MALLOC
26 changes: 22 additions & 4 deletions src/xmalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ struct xmalloc_slot {
# error "No hash mechanism selected."
#endif


#if defined(WOLFBOOT_SIGN_ECC256) || defined(WOLFBOOT_SIGN_ECC384) || defined(WOLFBOOT_SIGN_ECC521)

#ifndef USE_FAST_MATH
Expand Down Expand Up @@ -135,15 +136,24 @@ struct xmalloc_slot {
#define MP_SCHEME "TFM ECC256"
#define MP_CURVE_SPECS_SIZE (MP_INT_TYPE_SIZE)
#define MP_CURVE_FIELD_COUNT_SIZE (380)
#define ECC_POINT_SIZE (228)
#ifndef _LP64
#define ECC_POINT_SIZE (228)
#else
#define ECC_POINT_SIZE (312)
#define MP_INT_BUFFER_SIZE_1 (MP_INT_TYPE_SIZE * 5)
#endif
#define MP_INT_BUFFER_SIZE (MP_INT_TYPE_SIZE * 6)
#define MP_DIGIT_BUFFER_MONT_SIZE (sizeof(fp_digit)*(FP_SIZE + 1))
#endif
#ifdef WOLFBOOT_SIGN_ECC384
#define MP_SCHEME "TFM ECC384"
#define MP_CURVE_SPECS_SIZE (MP_INT_TYPE_SIZE)
#define MP_CURVE_FIELD_COUNT_SIZE (380)
#define ECC_POINT_SIZE (408)
#ifndef _LP64
#define ECC_POINT_SIZE (408)
#else
#define ECC_POINT_SIZE (504)
#endif
#define MP_INT_BUFFER_SIZE (MP_INT_TYPE_SIZE * 5)
#define MP_INT_BUFFER_SIZE_1 (MP_INT_TYPE_SIZE * 6)
#define MP_DIGIT_BUFFER_MONT_SIZE (sizeof(fp_digit)*(FP_SIZE + 1))
Expand All @@ -152,7 +162,11 @@ struct xmalloc_slot {
#define MP_SCHEME "TFM ECC521"
#define MP_CURVE_SPECS_SIZE (MP_INT_TYPE_SIZE)
#define MP_CURVE_FIELD_COUNT_SIZE (380)
#define ECC_POINT_SIZE (516)
#ifndef _LP64
#define ECC_POINT_SIZE (516)
#else
#define ECC_POINT_SIZE (600)
#endif
#define MP_INT_BUFFER_SIZE (MP_INT_TYPE_SIZE * 5)
#define MP_INT_BUFFER_SIZE_1 (MP_INT_TYPE_SIZE * 6)
#define MP_DIGIT_BUFFER_MONT_SIZE (sizeof(fp_digit)*(FP_SIZE + 1))
Expand Down Expand Up @@ -280,7 +294,11 @@ static struct xmalloc_slot xmalloc_pool[] = {

static uint32_t sha_block[HASH_BLOCK_SIZE];

#ifndef _LP64
#define ASNCHECK_BUF_SIZE (224)
#else
#define ASNCHECK_BUF_SIZE (320)
#endif
static uint8_t asncheck_buf[ASNCHECK_BUF_SIZE];

#ifndef USE_FAST_MATH
Expand Down Expand Up @@ -326,7 +344,7 @@ static uint8_t asncheck_buf[ASNCHECK_BUF_SIZE];
#endif
{ NULL, 0, 0}
};
#else
#else /* FAST MATH */
#define MP_SCHEME "TFM RSA"
#define MP_INT_TYPE_SIZE (sizeof(mp_int))
#define MP_MONT_REDUCE_BUF_SIZE (sizeof(fp_digit)*(FP_SIZE + 1))
Expand Down
4 changes: 4 additions & 0 deletions test-app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ ifeq ($(TARGET),sim)
# LD on MacOS does not support "-Map="
LDMAPSUPPORTED=$(shell $(CC) -Wl,-Map=image.map 2>&1 | grep 'unknown option')
LDFLAGS=
ifeq ($(FORCE_32BIT),1)
LDFLAGS+=-m32
CFLAGS+=-m32
endif
ifeq ($(LDMAPSUPPORTED),)
# Override linker flags
LDFLAGS+=-Wl,-Map=image.map
Expand Down

0 comments on commit 30a1f67

Please sign in to comment.