diff --git a/include/image.h b/include/image.h index eab349ed..02d7ae27 100644 --- a/include/image.h +++ b/include/image.h @@ -74,6 +74,7 @@ int wolfBot_get_dts_size(void *dts_addr); # endif #endif + /* Helpers for memory alignment */ #ifndef XALIGNED #if defined(__GNUC__) || defined(__llvm__) || \ @@ -88,6 +89,13 @@ int wolfBot_get_dts_size(void *dts_addr); #else #define XALIGNED(x) /* null expansion */ #endif + + /* Don't enforce stack alignment on IAR */ + #if defined (__IAR_SYSTEMS_ICC__) + #define XALIGNED_STACK(x) + #else + #define XALIGNED_STACK(x) XALIGNED(x) + #endif #endif diff --git a/src/libwolfboot.c b/src/libwolfboot.c index 6a2a6cd6..22e775aa 100644 --- a/src/libwolfboot.c +++ b/src/libwolfboot.c @@ -177,7 +177,7 @@ static const uint32_t wolfboot_magic_trail = WOLFBOOT_MAGIC_TRAIL; #include #include -static uint8_t NVM_CACHE[NVM_CACHE_SIZE] __attribute__((aligned(16))); +static uint8_t NVM_CACHE[NVM_CACHE_SIZE] XALIGNED(16) static int nvm_cached_sector = 0; static uint8_t get_base_offset(uint8_t *base, uintptr_t off) { @@ -1344,7 +1344,7 @@ int wolfBoot_fallback_is_possible(void) #define ENCRYPT_CACHE NVM_CACHE #else #ifdef WOLFBOOT_SMALL_STACK - static uint8_t ENCRYPT_CACHE[NVM_CACHE_SIZE] __attribute__((aligned(32))); + static uint8_t ENCRYPT_CACHE[NVM_CACHE_SIZE] XALIGNED(32); #endif #endif #else @@ -1363,7 +1363,7 @@ static int RAMFUNCTION hal_set_key(const uint8_t *k, const uint8_t *nonce) uint32_t trailer_relative_off = 4; #if !defined(WOLFBOOT_SMALL_STACK) && !defined(NVM_FLASH_WRITEONCE) && !defined(WOLFBOOT_ENCRYPT_CACHE) - uint8_t ENCRYPT_CACHE[NVM_CACHE_SIZE] __attribute__((aligned(32))); + uint8_t ENCRYPT_CACHE[NVM_CACHE_SIZE] XALIGNED_STACK(32); #endif #ifdef MMU @@ -1703,7 +1703,7 @@ int RAMFUNCTION ext_flash_encrypt_write(uintptr_t address, const uint8_t *data, uint8_t part; uint32_t iv_counter = 0; #if defined(EXT_ENCRYPTED) && !defined(WOLFBOOT_SMALL_STACK) && !defined(NVM_FLASH_WRITEONCE) - uint8_t ENCRYPT_CACHE[NVM_CACHE_SIZE] __attribute__((aligned(32))); + uint8_t ENCRYPT_CACHE[NVM_CACHE_SIZE] XALIGNED_STACK(32); #endif row_offset = address & (ENCRYPT_BLOCK_SIZE - 1); diff --git a/src/update_disk.c b/src/update_disk.c index c2cea6bc..0a5c82c9 100644 --- a/src/update_disk.c +++ b/src/update_disk.c @@ -79,7 +79,7 @@ extern uint8_t _end_wb[]; */ void RAMFUNCTION wolfBoot_start(void) { - uint8_t p_hdr[IMAGE_HEADER_SIZE] __attribute__((aligned(16))); + uint8_t p_hdr[IMAGE_HEADER_SIZE] XALIGN_STACK(16); struct stage2_parameter *stage2_params; struct wolfBoot_image os_image; int pA_ver = 0, pB_ver = 0; diff --git a/tools/keytools/user_settings.h b/tools/keytools/user_settings.h index 10e47823..b057df67 100644 --- a/tools/keytools/user_settings.h +++ b/tools/keytools/user_settings.h @@ -29,7 +29,9 @@ #include /* System */ -#define WOLFBOOT_KEYTOOLS +#ifndef WOLFBOOT_KEYTOOLS + #define WOLFBOOT_KEYTOOLS +#endif #define SINGLE_THREADED #define WOLFCRYPT_ONLY