From 10b6cde6427fc2fe066c50e5ac543e08230f0e33 Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Thu, 24 Oct 2024 16:31:56 +0200 Subject: [PATCH] Added NO_ARM_ASM option --- arch.mk | 8 +++++--- docs/compile.md | 12 ++++++++++++ tools/config.mk | 4 +++- tools/test.mk | 30 +++++++++++++++--------------- 4 files changed, 35 insertions(+), 19 deletions(-) diff --git a/arch.mk b/arch.mk index 3f5674246..bad4cdede 100644 --- a/arch.mk +++ b/arch.mk @@ -205,7 +205,8 @@ ifeq ($(CORTEX_A5),1) else # All others use boot_arm.o OBJS+=src/boot_arm.o - CORTEXM_ARM_EXTRA_OBJS= \ + ifneq ($(NO_ARM_ASM),1) + CORTEXM_ARM_EXTRA_OBJS= \ ./lib/wolfssl/wolfcrypt/src/port/arm/armv8-sha256.o \ ./lib/wolfssl/wolfcrypt/src/port/arm/armv8-sha512.o \ ./lib/wolfssl/wolfcrypt/src/port/arm/armv8-32-sha256-asm.o \ @@ -216,12 +217,13 @@ else ./lib/wolfssl/wolfcrypt/src/port/arm/armv8-32-sha3-asm_c.o - CORTEXM_ARM_THUMB_EXTRA_OBJS= \ + CORTEXM_ARM_THUMB_EXTRA_OBJS= \ ./lib/wolfssl/wolfcrypt/src/port/arm/thumb2-sha256-asm.o \ ./lib/wolfssl/wolfcrypt/src/port/arm/thumb2-sha256-asm_c.o - CORTEXM_ARM_EXTRA_CFLAGS+=-DWOLFSSL_ARMASM -DWOLFSSL_ARMASM_NO_HW_CRYPTO \ + CORTEXM_ARM_EXTRA_CFLAGS+=-DWOLFSSL_ARMASM -DWOLFSSL_ARMASM_NO_HW_CRYPTO \ -DWOLFSSL_ARMASM_INLINE -DWOLFSSL_ARMASM_NO_NEON + endif ifeq ($(CORTEX_M33),1) CFLAGS+=-mcpu=cortex-m33 -DCORTEX_M33 LDFLAGS+=-mcpu=cortex-m33 diff --git a/docs/compile.md b/docs/compile.md index 76fdca285..9643193be 100644 --- a/docs/compile.md +++ b/docs/compile.md @@ -42,6 +42,18 @@ By default, wolfBoot is compiled for ARM Cortex-M3/4/7. To compile for Cortex-M0 `CORTEX_M0=1` +### Speed vs. size + +On a number of targets, algorithm may be optimized automatically to use assembly +optimizations. To disable assembly optimizations, use `NO_ASM=1`. This option will +produce smaller code, but will also impact on the boot time. + +ARM-specific ARM optimizations affecting hash and symmetric key ciphers can be +disabled with the option `NO_ARM_ASM=1`. This is useful for example when you want +to use SP math optimizations for key verification, but exclude SHA2/AES optimizations +to save some space. + + ### Flash partitions The file [include/target.h](../include/target.h) is generated according to the configured flash geometry, diff --git a/tools/config.mk b/tools/config.mk index 1b91346f5..7f70024cd 100644 --- a/tools/config.mk +++ b/tools/config.mk @@ -23,6 +23,7 @@ ifeq ($(ARCH),) CORTEX_M7?=0 CORTEX_M3?=0 NO_ASM?=0 + NO_ARM_ASM?=0 EXT_FLASH?=0 SPI_FLASH?=0 QSPI_FLASH?=0 @@ -104,5 +105,6 @@ CONFIG_VARS:= ARCH TARGET SIGN HASH MCUXSDK MCUXPRESSO MCUXPRESSO_CPU MCUXPRESSO NXP_CUSTOM_DCD NXP_CUSTOM_DCD_OBJS \ FLASH_OTP_KEYSTORE \ KEYVAULT_OBJ_SIZE \ - KEYVAULT_MAX_ITEMS + KEYVAULT_MAX_ITEMS \ + NO_ARM_ASM diff --git a/tools/test.mk b/tools/test.mk index 167b9accc..36cae4a04 100644 --- a/tools/test.mk +++ b/tools/test.mk @@ -986,37 +986,37 @@ test-all: clean test-size-all: - make test-size SIGN=NONE LIMIT=4816 + make test-size SIGN=NONE LIMIT=4816 NO_ARM_ASM=1 make keysclean - make test-size SIGN=ED25519 LIMIT=11396 + make test-size SIGN=ED25519 LIMIT=11396 NO_ARM_ASM=1 make keysclean - make test-size SIGN=ECC256 LIMIT=17936 + make test-size SIGN=ECC256 LIMIT=17936 NO_ARM_ASM=1 make clean - make test-size SIGN=ECC256 NO_ASM=1 LIMIT=13480 + make test-size SIGN=ECC256 NO_ASM=1 LIMIT=13480 NO_ARM_ASM=1 make keysclean - make test-size SIGN=RSA2048 LIMIT=11212 + make test-size SIGN=RSA2048 LIMIT=11212 NO_ARM_ASM=1 make clean - make test-size SIGN=RSA2048 NO_ASM=1 LIMIT=11788 + make test-size SIGN=RSA2048 NO_ASM=1 LIMIT=11788 NO_ARM_ASM=1 make keysclean - make test-size SIGN=RSA4096 LIMIT=11500 + make test-size SIGN=RSA4096 LIMIT=11500 NO_ARM_ASM=1 make clean - make test-size SIGN=RSA4096 NO_ASM=1 LIMIT=12076 + make test-size SIGN=RSA4096 NO_ASM=1 LIMIT=12076 NO_ARM_ASM=1 make keysclean - make test-size SIGN=ECC384 LIMIT=17504 + make test-size SIGN=ECC384 LIMIT=17504 NO_ARM_ASM=1 make clean - make test-size SIGN=ECC384 NO_ASM=1 LIMIT=14872 + make test-size SIGN=ECC384 NO_ASM=1 LIMIT=14872 NO_ARM_ASM=1 make keysclean - make test-size SIGN=ED448 LIMIT=13408 + make test-size SIGN=ED448 LIMIT=13408 NO_ARM_ASM=1 make keysclean - make test-size SIGN=RSA3072 LIMIT=11352 + make test-size SIGN=RSA3072 LIMIT=11352 NO_ARM_ASM=1 make clean - make test-size SIGN=RSA3072 NO_ASM=1 LIMIT=11892 + make test-size SIGN=RSA3072 NO_ASM=1 LIMIT=11892 NO_ARM_ASM=1 make keysclean make test-size SIGN=LMS LMS_LEVELS=2 LMS_HEIGHT=5 LMS_WINTERNITZ=8 \ WOLFBOOT_SMALL_STACK=0 IMAGE_SIGNATURE_SIZE=2644 \ - IMAGE_HEADER_SIZE?=5288 LIMIT=7504 + IMAGE_HEADER_SIZE?=5288 LIMIT=7504 NO_ARM_ASM=1 make keysclean make test-size SIGN=XMSS XMSS_PARAMS='XMSS-SHA2_10_256' \ IMAGE_SIGNATURE_SIZE=2500 IMAGE_HEADER_SIZE?=4096 \ - LIMIT=8220 + LIMIT=8220 NO_ARM_ASM=1 make keysclean