Skip to content

Commit 831dcdf

Browse files
committed
app: Add version file and releasing information
- Added version file, which is used in application rollback prevention. - Changed AT#XSMVER to use VERSION_MAJOR.VERSION_MINOR.PATCHLEVEL from version file. The format of the #XSMVER stays the same, and the remainder comes from git describe as previously. - Added information on how to modify version file and MCUboot monotonic counter for releases. Signed-off-by: Markus Lassila <markus.lassila@nordicsemi.no>
1 parent ec2fe6e commit 831dcdf

18 files changed

Lines changed: 189 additions & 23 deletions

app/VERSION

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
VERSION_MAJOR = 1
2+
VERSION_MINOR = 99
3+
PATCHLEVEL = 0
4+
VERSION_TWEAK = 0
5+
EXTRAVERSION =

app/cmake/sm_version.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ endif()
1616
add_custom_target(
1717
generate_version_header ALL
1818
COMMAND ${CMAKE_COMMAND}
19-
-D OUTPUT_FILE=${GENERATED_DIR}/sm_version.h
19+
-DOUTPUT_FILE=${GENERATED_DIR}/sm_version.h
20+
-DVERSION_FILE=${PROJECT_SOURCE_DIR}/VERSION
2021
-P ${PROJECT_SOURCE_DIR}/cmake/write_sm_version_header.cmake
2122
BYPRODUCTS ${GENERATED_DIR}/sm_version.h
2223
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}

app/cmake/write_sm_version_header.cmake

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,45 @@ if(NOT GIT_RESULT EQUAL 0)
1818
set(GIT_DESCRIBE "unknown")
1919
endif()
2020

21-
# Validate OUTPUT_FILE variable is set
2221
if(NOT DEFINED OUTPUT_FILE)
2322
message(FATAL_ERROR "OUTPUT_FILE must be defined")
2423
endif()
2524

26-
# Prepare header content
25+
set(SM_VERSION "${GIT_DESCRIBE}")
26+
27+
if(DEFINED VERSION_FILE)
28+
file(READ "${VERSION_FILE}" VERSION_CONTENT)
29+
if(VERSION_CONTENT MATCHES "VERSION_MAJOR = ([0-9]+)")
30+
set(VERSION_MAJOR ${CMAKE_MATCH_1})
31+
else()
32+
message(FATAL_ERROR "Could not parse VERSION_MAJOR from ${VERSION_FILE}")
33+
endif()
34+
if(VERSION_CONTENT MATCHES "VERSION_MINOR = ([0-9]+)")
35+
set(VERSION_MINOR ${CMAKE_MATCH_1})
36+
else()
37+
message(FATAL_ERROR "Could not parse VERSION_MINOR from ${VERSION_FILE}")
38+
endif()
39+
if(VERSION_CONTENT MATCHES "PATCHLEVEL = ([0-9]+)")
40+
set(PATCHLEVEL ${CMAKE_MATCH_1})
41+
else()
42+
message(FATAL_ERROR "Could not parse PATCHLEVEL from ${VERSION_FILE}")
43+
endif()
44+
45+
# Append git describe suffix to v{major}.{minor}.{patch} from VERSION.
46+
# Drop the nearest-tag prefix; keep only distance/hash (or nothing on exact tag).
47+
set(GIT_SUFFIX "")
48+
# e.g. v2.0.0-preview1-67-g0b82ed3-dirty -> -67-g0b82ed3-dirty
49+
if(GIT_DESCRIBE MATCHES "-[0-9]+-g[0-9a-fA-F]+(-dirty)?$")
50+
string(REGEX MATCH "-[0-9]+-g[0-9a-fA-F]+(-dirty)?$" GIT_SUFFIX "${GIT_DESCRIBE}")
51+
# No tags: git describe --always -> 0b82ed3[-dirty] -> -g0b82ed3[-dirty]
52+
elseif(GIT_DESCRIBE MATCHES "^[0-9a-fA-F]+(-dirty)?$")
53+
set(GIT_SUFFIX "-g${GIT_DESCRIBE}")
54+
# Exact tag (e.g. v2.0.0) or unknown: GIT_SUFFIX stays empty -> v2.0.0
55+
endif()
56+
57+
set(SM_VERSION "v${VERSION_MAJOR}.${VERSION_MINOR}.${PATCHLEVEL}${GIT_SUFFIX}")
58+
endif()
59+
2760
set(HEADER_TEXT
2861
"/*
2962
* Copyright (c) 2025 Nordic Semiconductor ASA
@@ -34,11 +67,10 @@ set(HEADER_TEXT
3467
#ifndef SM_VERSION_H
3568
#define SM_VERSION_H
3669
37-
#define SM_VERSION \"${GIT_DESCRIBE}\"
70+
#define SM_VERSION \"${SM_VERSION}\"
3871
3972
#endif /* SM_VERSION_H */
4073
4174
")
4275

43-
# Write to output file
4476
file(WRITE "${OUTPUT_FILE}" "${HEADER_TEXT}")

app/prj.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ CONFIG_PICOLIBC_IO_FLOAT=y
1313
CONFIG_RING_BUFFER=y
1414
CONFIG_REBOOT=y
1515
CONFIG_EVENTFD=y
16+
CONFIG_NCS_APPLICATION_BOOT_BANNER_STRING="Serial Modem"
1617

1718
# Enable UART logging by default.
1819
CONFIG_UART_CONSOLE=y

app/src/sm_at_commands.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ STATIC int handle_at_smver(enum at_parser_cmd_type cmd_type, struct at_parser *,
7575

7676
if (cmd_type == AT_PARSER_CMD_TYPE_SET) {
7777
if (strlen(CONFIG_SM_CUSTOMER_VERSION) > 0) {
78-
rsp_send("\r\n#XSMVER: %s,%s,\"%s\"\r\n",
79-
STRINGIFY(SM_VERSION), STRINGIFY(NCS_VERSION_STRING),
78+
rsp_send("\r\n#XSMVER: \"%s\",\"%s\",\"%s\"\r\n",
79+
SM_VERSION, NCS_VERSION_STRING,
8080
CONFIG_SM_CUSTOMER_VERSION);
8181
} else {
82-
rsp_send("\r\n#XSMVER: %s,%s\r\n",
83-
STRINGIFY(SM_VERSION), STRINGIFY(NCS_VERSION_STRING));
82+
rsp_send("\r\n#XSMVER: \"%s\",\"%s\"\r\n",
83+
SM_VERSION, NCS_VERSION_STRING);
8484
}
8585
ret = 0;
8686
}

app/sysbuild/mcuboot/prj.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ CONFIG_FPROTECT=y
2727
CONFIG_LOG=y
2828
CONFIG_LOG_MODE_MINIMAL=y
2929
CONFIG_MCUBOOT_LOG_LEVEL_INF=y
30+
CONFIG_NCS_APPLICATION_BOOT_BANNER_STRING="MCUboot"
3031
### Decrease footprint by ~4 KB in comparison to CBPRINTF_COMPLETE=y
3132
CONFIG_CBPRINTF_NANO=y
3233
CONFIG_NRF_RTC_TIMER_USER_CHAN_COUNT=0

app/tests/at_commands/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ file(MAKE_DIRECTORY "${GENERATED_DIR}")
1313
add_custom_target(
1414
generate_version_header ALL
1515
COMMAND ${CMAKE_COMMAND}
16-
-D OUTPUT_FILE=${GENERATED_DIR}/sm_version.h
16+
-DOUTPUT_FILE=${GENERATED_DIR}/sm_version.h
17+
-DVERSION_FILE=${CMAKE_CURRENT_SOURCE_DIR}/VERSION
1718
-P ${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/write_sm_version_header.cmake
1819
BYPRODUCTS ${GENERATED_DIR}/sm_version.h
1920
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../..

app/tests/at_commands/VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../VERSION

app/tests/at_socket/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ file(MAKE_DIRECTORY "${GENERATED_DIR}")
1515
add_custom_target(
1616
generate_version_header ALL
1717
COMMAND ${CMAKE_COMMAND}
18-
-D OUTPUT_FILE=${GENERATED_DIR}/sm_version.h
18+
-DOUTPUT_FILE=${GENERATED_DIR}/sm_version.h
19+
-DVERSION_FILE=${CMAKE_CURRENT_SOURCE_DIR}/VERSION
1920
-P ${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/write_sm_version_header.cmake
2021
BYPRODUCTS ${GENERATED_DIR}/sm_version.h
2122
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../..

app/tests/at_socket/VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../VERSION

0 commit comments

Comments
 (0)