diff --git a/arch.mk b/arch.mk index 2bfaaea8e9..469cdd32b2 100644 --- a/arch.mk +++ b/arch.mk @@ -3506,5 +3506,9 @@ ifeq ($(BIG_ENDIAN),1) CFLAGS+=-D"BIG_ENDIAN_ORDER" endif +ifneq ($(WOLFBOOT_VERSION_SECTION),) + CFLAGS+=-DVERSION_SECTION=$(WOLFBOOT_VERSION_SECTION) +endif + CFLAGS+=-DWOLFBOOT_ARCH_$(ARCH) CFLAGS+=-DTARGET_$(TARGET) diff --git a/include/wolfboot/wolfboot.h b/include/wolfboot/wolfboot.h index 65824e6dcf..91582f8d45 100644 --- a/include/wolfboot/wolfboot.h +++ b/include/wolfboot/wolfboot.h @@ -113,6 +113,16 @@ extern "C" { # endif #endif +#ifndef WB_STRINGIFY +#define _WB_STRINGIFY_L2(str) #str +#define WB_STRINGIFY(str) _WB_STRINGIFY_L2(str) +#endif + +#if defined(VERSION_SECTION) +#define WOLFBOOT_VERSION_SECTION __attribute__((section(WB_STRINGIFY(VERSION_SECTION)))) +#else +#define WOLFBOOT_VERSION_SECTION +#endif /* Helpers for memory alignment */ #ifndef XALIGNED diff --git a/src/loader.c b/src/loader.c index bf8e5551c3..cbe5711a94 100644 --- a/src/loader.c +++ b/src/loader.c @@ -51,7 +51,7 @@ extern unsigned int _start_text; /** * @brief wolfBoot version number (used in RAM code). */ -static volatile const uint32_t __attribute__((used)) wolfboot_version = WOLFBOOT_VERSION; +static volatile const uint32_t __attribute__((used)) WOLFBOOT_VERSION_SECTION wolfboot_version = WOLFBOOT_VERSION; /** * @brief RAM Interrupt Vector table. */ diff --git a/src/update_flash.c b/src/update_flash.c index 05eb937a16..074c141137 100644 --- a/src/update_flash.c +++ b/src/update_flash.c @@ -133,7 +133,8 @@ extern unsigned int _start_text; extern unsigned int __logical_binary_start; unsigned int _start_text = (unsigned int)&__logical_binary_start; #endif -static volatile const uint32_t __attribute__((used)) wolfboot_version = WOLFBOOT_VERSION; + +static volatile const uint32_t __attribute__((used)) WOLFBOOT_VERSION_SECTION wolfboot_version = WOLFBOOT_VERSION; #ifdef EXT_FLASH # ifndef BUFFER_DECLARED diff --git a/tools/config.mk b/tools/config.mk index 02dc6757b7..651c6cfa2d 100644 --- a/tools/config.mk +++ b/tools/config.mk @@ -170,4 +170,5 @@ CONFIG_VARS:= ARCH TARGET SIGN HASH MCUXSDK MCUXPRESSO MCUXPRESSO_CPU MCUXPRESSO CERT_CHAIN_GEN_CA_ALGO \ CERT_CHAIN_GEN_CA_HASH \ CERT_CHAIN_NAME_CONSTRAINTS \ - ENCRYPT_CACHE + ENCRYPT_CACHE \ + WOLFBOOT_VERSION_SECTION