diff --git a/ion/Makefile b/ion/Makefile index e0bc162ec..8c8df523a 100644 --- a/ion/Makefile +++ b/ion/Makefile @@ -1,15 +1,16 @@ GIT := $(shell command -v git 2> /dev/null) PATCH_LEVEL = NONE ifdef GIT - PATCH_LEVEL = `git rev-parse HEAD` + PATCH_LEVEL = `git rev-parse --short HEAD` endif SFLAGS += -Iion/include -DKD_CONFIG_H=1 -ion/src/shared/software_version.o: SFLAGS += -DPATCH_LEVEL=$(PATCH_LEVEL) -DVERSION=$(VERSION) -include ion/src/$(PLATFORM)/Makefile +include ion/src/$(PLATFORM)/Makefile include ion/src/shared/tools/Makefile +ion/src/shared/software_version.o: SFLAGS += -DPATCH_LEVEL=$(PATCH_LEVEL) -DVERSION=$(VERSION) + objs += $(addprefix ion/src/shared/, \ events.o \ software_version.o \ diff --git a/ion/src/device/Makefile b/ion/src/device/Makefile index 168a943da..9db5907ec 100644 --- a/ion/src/device/Makefile +++ b/ion/src/device/Makefile @@ -1,6 +1,8 @@ include ion/src/device/boot/Makefile include ion/src/device/bench/Makefile +ion/src/shared/software_version.o: SFLAGS += -DHEADER_SECTION="__attribute__((section(\".header\")))" + objs += $(addprefix ion/src/shared/, \ console_line.o \ events_keyboard.o \ diff --git a/ion/src/device/boot/flash.ld b/ion/src/device/boot/flash.ld index fc68ffec2..e5ddcc9e4 100644 --- a/ion/src/device/boot/flash.ld +++ b/ion/src/device/boot/flash.ld @@ -34,6 +34,10 @@ SECTIONS { KEEP(*(.isr_vector_table)) } >FLASH + .header : { + KEEP(*(.header)) + } >FLASH + .text : { . = ALIGN(4); *(.text) diff --git a/ion/src/shared/software_version.cpp b/ion/src/shared/software_version.cpp index 522e83fcf..9ec9030e9 100644 --- a/ion/src/shared/software_version.cpp +++ b/ion/src/shared/software_version.cpp @@ -1,4 +1,5 @@ #include +#include #define STR_EXPAND(arg) #arg #define STR(arg) STR_EXPAND(arg) @@ -7,14 +8,41 @@ #error This file expects PATCH_LEVEL to be defined #endif +#ifndef HEADER_SECTION +#define HEADER_SECTION +#endif + +class VersionInfo { +public: + constexpr VersionInfo() : + m_header(Magic), + m_version(STR(VERSION)), + m_patchLevel(STR(PATCH_LEVEL)), + m_footer(Magic) { } + const char * version() const { + assert(m_header == Magic); + assert(m_footer == Magic); + return m_version; + } + const char * patchLevel() const { + assert(m_header == Magic); + assert(m_footer == Magic); + return m_patchLevel; + } +private: + constexpr static uint32_t Magic = 0xDEC00DF0; + uint32_t m_header; + const char m_version[8]; + const char m_patchLevel[8]; + uint32_t m_footer; +}; + +constexpr VersionInfo HEADER_SECTION version_infos; + const char * Ion::softwareVersion() { - return STR(VERSION); + return version_infos.version(); } const char * Ion::patchLevel() { - static char patchLevel[20] = {0}; - if (patchLevel[0] == 0) { - strlcpy(patchLevel, STR(PATCH_LEVEL), 6+1); - } - return patchLevel; + return version_infos.patchLevel(); }