Skip to content

Commit bfd2ac7

Browse files
AlexFabrecfriedt
authored andcommitted
shell: add app version command
This commit brings a shell command to retreive the following application version information: - APP_VERSION_STRING - APP_VERSION_EXTENDED_STRING - APP_BUILD_VERSION Signed-off-by: Alex Fabre <[email protected]>
1 parent 62f62db commit bfd2ac7

File tree

4 files changed

+68
-0
lines changed

4 files changed

+68
-0
lines changed

doc/build/version/index.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ multiple scopes, including:
1212
* Code (C/C++)
1313
* Kconfig
1414
* CMake
15+
* Shell
1516

1617
which makes it a very versatile system for lifecycle management of applications. In addition, it
1718
can be used when building applications which target supported bootloaders (e.g. MCUboot) allowing
@@ -195,3 +196,18 @@ Use in MCUboot-supported applications
195196
No additional configuration needs to be done to the target application so long as it is configured
196197
to support MCUboot and a signed image is generated, the version information will be automatically
197198
included in the image data.
199+
200+
Use in Shell
201+
============
202+
203+
When a shell interface is configured, the following commands are available to retrieve application version information:
204+
205+
+----------------------+-----------------------------+-------------------------+
206+
| Command | Variable | Example |
207+
+----------------------+-----------------------------+-------------------------+
208+
| app version | APP_VERSION_STRING | 1.2.3-unstable.5 |
209+
+----------------------+-----------------------------+-------------------------+
210+
| app version-extended | APP_VERSION_EXTENDED_STRING | 1.2.3-unstable.5+4 |
211+
+----------------------+-----------------------------+-------------------------+
212+
| app build-version | APP_BUILD_VERSION | v3.3.0-18-g2c85d9224fca |
213+
+----------------------+-----------------------------+-------------------------+

subsys/shell/modules/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ zephyr_sources_ifdef(
1616
CONFIG_DEVMEM_SHELL
1717
devmem_service.c
1818
)
19+
zephyr_sources_ifdef(
20+
CONFIG_APP_VERSION_SHELL
21+
app_version_service.c
22+
)

subsys/shell/modules/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,11 @@ config DEVMEM_SHELL
2222
help
2323
This shell command provides read/write access to physical memory.
2424

25+
config APP_VERSION_SHELL
26+
bool "Application version information shell"
27+
default y if !SHELL_MINIMAL
28+
depends on "$(APP_VERSION_EXTENDED_STRING)" != ""
29+
help
30+
This shell command provides read access to application version information.
31+
2532
rsource "kernel_service/Kconfig"
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (c) 2025 Alex Fabre
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include "app_version.h"
8+
#include <zephyr/shell/shell.h>
9+
10+
static int cmd_app_version_string(const struct shell *sh)
11+
{
12+
shell_print(sh, APP_VERSION_STRING);
13+
return 0;
14+
}
15+
16+
static int cmd_app_version_extended_string(const struct shell *sh)
17+
{
18+
shell_print(sh, APP_VERSION_EXTENDED_STRING);
19+
return 0;
20+
}
21+
22+
static int cmd_app_build_version(const struct shell *sh)
23+
{
24+
shell_print(sh, STRINGIFY(APP_BUILD_VERSION));
25+
return 0;
26+
}
27+
28+
SHELL_STATIC_SUBCMD_SET_CREATE(
29+
sub_app,
30+
SHELL_CMD(version, NULL, "Application version. (ex. \"1.2.3-unstable.5\")",
31+
cmd_app_version_string),
32+
SHELL_CMD(version - extended, NULL,
33+
"Application version extended. (ex. \"1.2.3-unstable.5+4\")",
34+
cmd_app_version_extended_string),
35+
SHELL_CMD(build - version, NULL,
36+
"Application build version. (ex. \"v3.3.0-18-g2c85d9224fca\")",
37+
cmd_app_build_version),
38+
SHELL_SUBCMD_SET_END /* Array terminated. */
39+
);
40+
41+
SHELL_CMD_REGISTER(app, &sub_app, "Application version information commands", NULL);

0 commit comments

Comments
 (0)