Skip to content

Commit 49389b5

Browse files
tejlmandcarlescufi
authored andcommitted
west: sign: Add Kconfig with application version
Adds a Kconfig option which controls the version of the application to use when the image is signed using imgtool. When an application VERSION file is present, the default value will be identical to the application version, else it will be 0.0.0+0, but a project may still decide another value, if it so prefers. Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no> Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
1 parent 99064c2 commit 49389b5

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

Kconfig.mcuboot

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,15 @@ config MCUBOOT_ENCRYPTION_KEY_FILE
101101

102102
If left empty, you must encrypt the Zephyr binaries manually.
103103

104+
config MCUBOOT_IMGTOOL_SIGN_VERSION
105+
string "Version to pass to imgtool when signing"
106+
default "$(VERSION_MAJOR).$(VERSION_MINOR).$(PATCHLEVEL)" if "$(VERSION_MAJOR)" != ""
107+
default "0.0.0+0"
108+
help
109+
When signing with imgtool then this setting will be passed as version
110+
argument to the tool.
111+
The format is major.minor.revision+build.
112+
104113
config MCUBOOT_EXTRA_IMGTOOL_ARGS
105114
string "Extra arguments to pass to imgtool when signing"
106115
default ""

Kconfig.zephyr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# Copyright (c) 2023 Nordic Semiconductor ASA
66
# SPDX-License-Identifier: Apache-2.0
77

8+
osource "${APPLICATION_SOURCE_DIR}/VERSION"
89

910
# Include Kconfig.defconfig files first so that they can override defaults and
1011
# other symbol/choice properties by adding extra symbol/choice definitions.

cmake/modules/kconfig.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ set(COMMON_KCONFIG_ENV_SETTINGS
122122
PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}
123123
srctree=${ZEPHYR_BASE}
124124
KERNELVERSION=${KERNELVERSION}
125+
APPVERSION=${APP_VERSION_STRING}
125126
CONFIG_=${KCONFIG_NAMESPACE}_
126127
KCONFIG_CONFIG=${DOTCONFIG}
127128
# Set environment variables so that Kconfig can prune Kconfig source
@@ -131,6 +132,7 @@ set(COMMON_KCONFIG_ENV_SETTINGS
131132
BOARD_DIR=${BOARD_DIR}
132133
BOARD_REVISION=${BOARD_REVISION}
133134
KCONFIG_BINARY_DIR=${KCONFIG_BINARY_DIR}
135+
APPLICATION_SOURCE_DIR=${APPLICATION_SOURCE_DIR}
134136
ZEPHYR_TOOLCHAIN_VARIANT=${ZEPHYR_TOOLCHAIN_VARIANT}
135137
TOOLCHAIN_KCONFIG_DIR=${TOOLCHAIN_KCONFIG_DIR}
136138
TOOLCHAIN_HAS_NEWLIB=${_local_TOOLCHAIN_HAS_NEWLIB}

scripts/west_commands/sign.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
3737
The "ARGS_FOR_YOUR_TOOL" value can be any additional
3838
arguments you want to pass to the tool, such as the location of a
39-
signing key, a version identifier, etc.
39+
signing key etc.
4040
4141
See tool-specific help below for details.'''
4242

@@ -56,11 +56,10 @@
5656
imgtool, this creates zephyr.signed.bin and zephyr.signed.hex
5757
files which are ready for use by your bootloader.
5858
59-
The image header size, alignment, and slot sizes are determined from
60-
the build directory using .config and the device tree. A default
61-
version number of 0.0.0+0 is used (which can be overridden by passing
62-
"--version x.y.z+w" after "--key"). As shown above, extra arguments
63-
after a '--' are passed to imgtool directly.
59+
The version number, image header size, alignment, and slot sizes are
60+
determined from the build directory using .config and the device tree.
61+
As shown above, extra arguments after a '--' are passed to imgtool
62+
directly.
6463
6564
rimage
6665
------
@@ -245,7 +244,8 @@ def sign(self, command, build_dir, build_conf, formats):
245244
b = pathlib.Path(build_dir)
246245

247246
imgtool = self.find_imgtool(command, args)
248-
# The vector table offset is set in Kconfig:
247+
# The vector table offset and application version are set in Kconfig:
248+
appver = self.get_cfg(command, build_conf, 'CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION')
249249
vtoff = self.get_cfg(command, build_conf, 'CONFIG_ROM_START_OFFSET')
250250
# Flash device write alignment and the partition's slot size
251251
# come from devicetree:
@@ -280,12 +280,8 @@ def sign(self, command, build_dir, build_conf, formats):
280280
log.inf('rom start offset: {0} (0x{0:x})'.format(vtoff))
281281

282282
# Base sign command.
283-
#
284-
# We provide a default --version in case the user is just
285-
# messing around and doesn't want to set one. It will be
286-
# overridden if there is a --version in args.tool_args.
287283
sign_base = imgtool + ['sign',
288-
'--version', '0.0.0+0',
284+
'--version', str(appver),
289285
'--align', str(align),
290286
'--header-size', str(vtoff),
291287
'--slot-size', str(size)]

0 commit comments

Comments
 (0)