Skip to content

Commit 656a910

Browse files
nordicjmfabiobaltieri
authored andcommitted
mgmt: mcumgr: lib: cmd: os: Add device information handler
The device information handler can be used to retrieve information about the configuration of the configured device such as board name, board revision, firmware version and build date. Signed-off-by: Jamie McCrae <[email protected]>
1 parent ae97971 commit 656a910

File tree

6 files changed

+571
-0
lines changed

6 files changed

+571
-0
lines changed

include/zephyr/mgmt/mcumgr/grp/os_mgmt/os_mgmt.h

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,66 @@ extern "C" {
2222
#define OS_MGMT_ID_DATETIME_STR 4
2323
#define OS_MGMT_ID_RESET 5
2424
#define OS_MGMT_ID_MCUMGR_PARAMS 6
25+
#define OS_MGMT_ID_INFO 7
26+
27+
/* Bitmask values used by the os info command handler. Note that the width of this variable is
28+
* 32-bits, allowing 32 flags, custom user-level implementations should start at
29+
* OS_MGMT_INFO_FORMAT_USER_CUSTOM_START and reference that directly as additional format
30+
* specifiers might be added to this list in the future.
31+
*/
32+
enum os_mgmt_info_formats {
33+
OS_MGMT_INFO_FORMAT_KERNEL_NAME = BIT(0),
34+
OS_MGMT_INFO_FORMAT_NODE_NAME = BIT(1),
35+
OS_MGMT_INFO_FORMAT_KERNEL_RELEASE = BIT(2),
36+
OS_MGMT_INFO_FORMAT_KERNEL_VERSION = BIT(3),
37+
OS_MGMT_INFO_FORMAT_BUILD_DATE_TIME = BIT(4),
38+
OS_MGMT_INFO_FORMAT_MACHINE = BIT(5),
39+
OS_MGMT_INFO_FORMAT_PROCESSOR = BIT(6),
40+
OS_MGMT_INFO_FORMAT_HARDWARE_PLATFORM = BIT(7),
41+
OS_MGMT_INFO_FORMAT_OPERATING_SYSTEM = BIT(8),
42+
43+
OS_MGMT_INFO_FORMAT_USER_CUSTOM_START = BIT(9),
44+
};
45+
46+
/* Structure provided in the MGMT_EVT_OP_OS_MGMT_INFO_CHECK notification callback */
47+
struct os_mgmt_info_check {
48+
/* Input format string from the mcumgr client */
49+
struct zcbor_string *format;
50+
/* Bitmask of values specifying which outputs should be present */
51+
uint32_t *format_bitmask;
52+
/* Number of valid format characters parsed, must be incremented by 1 for each valid
53+
* character
54+
*/
55+
uint16_t *valid_formats;
56+
/* Needs to be set to true if the OS name is being provided by external code */
57+
bool *custom_os_name;
58+
};
59+
60+
/* Structure provided in the MGMT_EVT_OP_OS_MGMT_INFO_APPEND notification callback */
61+
struct os_mgmt_info_append {
62+
/* The format bitmask from the processed commands, the bits should be cleared once
63+
* processed, note that if all_format_specified is specified, the corrisponding bits here
64+
* will not be set
65+
*/
66+
uint32_t *format_bitmask;
67+
/* Will be true if the all 'a' specifier was provided */
68+
bool all_format_specified;
69+
/* The output buffer which the responses should be appended to. If prior_output is true, a
70+
* space must be added prior to the output response
71+
*/
72+
uint8_t *output;
73+
/* The current size of the output response in the output buffer, must be updated to be the
74+
* size of the output response after appending data
75+
*/
76+
uint16_t *output_length;
77+
/* The size of the output buffer, including null terminator character, if the output
78+
* response would exceed this size, the function must abort and return false to return a
79+
* memory error to the client
80+
*/
81+
uint16_t buffer_size;
82+
/* If there has been prior output, must be set to true if a response has been output */
83+
bool *prior_output;
84+
};
2585

2686
/**
2787
* @brief Registers the OS management command handler group.

include/zephyr/mgmt/mcumgr/mgmt/callbacks.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,12 @@ enum os_mgmt_group_events {
146146
/** Callback when a reset command has been received. */
147147
MGMT_EVT_OP_OS_MGMT_RESET = MGMT_DEF_EVT_OP_ID(MGMT_EVT_GRP_OS, 0),
148148

149+
/** Callback when an info command is processed, data is os_mgmt_info_check. */
150+
MGMT_EVT_OP_OS_MGMT_INFO_CHECK = MGMT_DEF_EVT_OP_ID(MGMT_EVT_GRP_OS, 1),
151+
152+
/** Callback when an info command needs to output data, data is os_mgmt_info_append. */
153+
MGMT_EVT_OP_OS_MGMT_INFO_APPEND = MGMT_DEF_EVT_OP_ID(MGMT_EVT_GRP_OS, 2),
154+
149155
/** Used to enable all os_mgmt_group events. */
150156
MGMT_EVT_OP_OS_MGMT_ALL = MGMT_DEF_EVT_OP_ALL(MGMT_EVT_GRP_OS),
151157
};

subsys/mgmt/mcumgr/grp/os_mgmt/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,10 @@ if (CONFIG_REBOOT)
2020
endif()
2121

2222
target_link_libraries(mgmt_mcumgr INTERFACE mgmt_mcumgr_grp_os)
23+
24+
if(DEFINED CONFIG_MCUMGR_GRP_OS_INFO_BUILD_DATE_TIME)
25+
set(MCUMGR_GRP_OS_INFO_BUILD_DATE_TIME_DIR ${PROJECT_BINARY_DIR}/os_mgmt_auto)
26+
file(MAKE_DIRECTORY ${MCUMGR_GRP_OS_INFO_BUILD_DATE_TIME_DIR})
27+
file(WRITE ${MCUMGR_GRP_OS_INFO_BUILD_DATE_TIME_DIR}/os_mgmt_build_date.c "/* Auto generated file, do not edit */\n#include <stdint.h>\nuint8_t *MCUMGR_GRP_OS_INFO_BUILD_DATE_TIME = __TIMESTAMP__;")
28+
zephyr_library_sources(${MCUMGR_GRP_OS_INFO_BUILD_DATE_TIME_DIR}/os_mgmt_build_date.c)
29+
endif()

subsys/mgmt/mcumgr/grp/os_mgmt/Kconfig

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,39 @@ config OS_MGMT_ECHO
123123
config OS_MGMT_MCUMGR_PARAMS
124124
bool "MCUMGR Parameters retrieval command"
125125

126+
config MCUMGR_GRP_OS_INFO
127+
bool "Support for info command"
128+
help
129+
Can be used similarly to the unix/linux uname command for retrieving system information
130+
including kernel version, processor architecture and board name.
131+
132+
if MCUMGR_GRP_OS_INFO
133+
134+
config MCUMGR_GRP_OS_INFO_MAX_RESPONSE_SIZE
135+
int "Maximum response size for info command"
136+
default 256
137+
range 32 512
138+
help
139+
The maximum size of the response to the info command, will use a stack buffer of this
140+
size to store the data in. If the output response is too big then the output will not be
141+
present in the response, which will just contain the result code (rc) of memory error.
142+
143+
config MCUMGR_GRP_OS_INFO_CUSTOM_HOOKS
144+
bool "Custom info hooks"
145+
depends on MCUMGR_MGMT_NOTIFICATION_HOOKS
146+
help
147+
Supports adding custom command/character processing to the info command by using
148+
registered callbacks. Data can be appended to the struct provided in the callback.
149+
150+
config MCUMGR_GRP_OS_INFO_BUILD_DATE_TIME
151+
bool "Show build date and time"
152+
help
153+
Will allow returning the build date and time of the firmware by using the info with
154+
format option 'b' (will also be returned with all responses by using 'a').
155+
156+
Note: This will invalidate reproducible builds of the firmware as it will embed the
157+
build date/time in the output firmware image.
158+
159+
endif
160+
126161
endif
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
/*
2+
* Copyright (c) 2022 Zephyr authors
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef H_OS_MGMT_PROCESSOR_
8+
#define H_OS_MGMT_PROCESSOR_
9+
10+
#ifdef __cplusplus
11+
extern "C" {
12+
#endif
13+
14+
/**
15+
* Processor name (used in uname output command)
16+
* Will be unknown if processor type is not listed
17+
* (List extracted from /cmake/gcc-m-cpu.cmake)
18+
*/
19+
#if defined(CONFIG_ARM)
20+
#if defined(CONFIG_CPU_CORTEX_M0)
21+
#define PROCESSOR_NAME "cortex-m0"
22+
#elif defined(CONFIG_CPU_CORTEX_M0PLUS)
23+
#define PROCESSOR_NAME "cortex-m0plus"
24+
#elif defined(CONFIG_CPU_CORTEX_M1)
25+
#define PROCESSOR_NAME "cortex-m1"
26+
#elif defined(CONFIG_CPU_CORTEX_M3)
27+
#define PROCESSOR_NAME "cortex-m3"
28+
#elif defined(CONFIG_CPU_CORTEX_M4)
29+
#define PROCESSOR_NAME "cortex-m4"
30+
#elif defined(CONFIG_CPU_CORTEX_M7)
31+
#define PROCESSOR_NAME "cortex-m7"
32+
#elif defined(CONFIG_CPU_CORTEX_M23)
33+
#define PROCESSOR_NAME "cortex-m23"
34+
#elif defined(CONFIG_CPU_CORTEX_M33)
35+
#if defined(CONFIG_ARMV8_M_DSP)
36+
#define PROCESSOR_NAME "cortex-m33"
37+
#else
38+
#define PROCESSOR_NAME "cortex-m33+nodsp"
39+
#endif
40+
#elif defined(CONFIG_CPU_CORTEX_M55)
41+
#if defined(CONFIG_ARMV8_1_M_MVEF)
42+
#define PROCESSOR_NAME "cortex-m55"
43+
#elif defined(CONFIG_ARMV8_1_M_MVEI)
44+
#define PROCESSOR_NAME "cortex-m55+nomve.fp"
45+
#elif defined(CONFIG_ARMV8_M_DSP)
46+
#define PROCESSOR_NAME "cortex-m55+nomve"
47+
#else
48+
#define PROCESSOR_NAME "cortex-m55+nodsp"
49+
#endif
50+
#elif defined(CONFIG_CPU_CORTEX_R4)
51+
#if defined(CONFIG_FPU) && defined(CONFIG_CPU_HAS_VFP)
52+
#define PROCESSOR_NAME "cortex-r4f"
53+
#else
54+
#define PROCESSOR_NAME "cortex-r4"
55+
#endif
56+
#elif defined(CONFIG_CPU_CORTEX_R5)
57+
#if defined(CONFIG_FPU) && defined(CONFIG_CPU_HAS_VFP)
58+
#if !defined(CONFIG_VFP_FEATURE_DOUBLE_PRECISION)
59+
#define PROCESSOR_NAME "cortex-r5+nofp.dp"
60+
#else
61+
#define PROCESSOR_NAME "cortex-r5"
62+
#endif
63+
#else
64+
#define PROCESSOR_NAME "cortex-r5+nofp"
65+
#endif
66+
#elif defined(CONFIG_CPU_CORTEX_R7)
67+
#if defined(CONFIG_FPU) && defined(CONFIG_CPU_HAS_VFP)
68+
#if !defined(CONFIG_VFP_FEATURE_DOUBLE_PRECISION)
69+
#define PROCESSOR_NAME "cortex-r7+nofp.dp"
70+
#else
71+
#define PROCESSOR_NAME "cortex-r7"
72+
#endif
73+
#else
74+
#define PROCESSOR_NAME "cortex-r7+nofp"
75+
#endif
76+
#elif defined(CONFIG_CPU_CORTEX_R52)
77+
#if defined(CONFIG_FPU) && defined(CONFIG_CPU_HAS_VFP)
78+
#if !defined(CONFIG_VFP_FEATURE_DOUBLE_PRECISION)
79+
#define PROCESSOR_NAME "cortex-r52+nofp.dp"
80+
#else
81+
#define PROCESSOR_NAME "cortex-r52"
82+
#endif
83+
#else
84+
#define PROCESSOR_NAME "cortex-r52"
85+
#endif
86+
#elif defined(CONFIG_CPU_CORTEX_A9)
87+
#define PROCESSOR_NAME "cortex-a9"
88+
#endif
89+
#elif defined(CONFIG_ARM64)
90+
#if defined(CONFIG_CPU_CORTEX_A53)
91+
#define PROCESSOR_NAME "cortex-a53"
92+
#if defined(CONFIG_CPU_CORTEX_A55)
93+
#define PROCESSOR_NAME "cortex-a55"
94+
#elif defined(CONFIG_CPU_CORTEX_A72)
95+
#define PROCESSOR_NAME "cortex-a72"
96+
#elif defined(CONFIG_CPU_CORTEX_R82)
97+
#define PROCESSOR_NAME "armv8.4-a+nolse"
98+
#endif
99+
#endif
100+
#elif defined(CONFIG_ARC)
101+
#if defined(CONFIG_CPU_EM4_FPUS)
102+
#define PROCESSOR_NAME "em4_fpus"
103+
#elif defined(CONFIG_CPU_EM4_DMIPS)
104+
#define PROCESSOR_NAME "em4_dmips"
105+
#elif defined(CONFIG_CPU_EM4_FPUDA)
106+
#define PROCESSOR_NAME "em4_fpuda"
107+
#elif defined(CONFIG_CPU_HS3X)
108+
#define PROCESSOR_NAME "archs"
109+
#elif defined(CONFIG_CPU_HS5X)
110+
#define PROCESSOR_NAME "hs5x"
111+
#elif defined(CONFIG_CPU_HS6X)
112+
#define PROCESSOR_NAME "hs6x"
113+
#elif defined(CONFIG_CPU_EM4)
114+
#define PROCESSOR_NAME "arcem"
115+
#elif defined(CONFIG_CPU_EM6)
116+
#define PROCESSOR_NAME "arcem"
117+
#endif
118+
#elif defined(CONFIG_X86)
119+
#if defined(CONFIG_X86_64)
120+
#define PROCESSOR_NAME "x86_64"
121+
#else
122+
#define PROCESSOR_NAME "x86"
123+
#endif
124+
#elif defined(CONFIG_RISCV)
125+
#define PROCESSOR_NAME "riscv"
126+
#endif
127+
128+
#ifndef PROCESSOR_NAME
129+
#warning "Processor type could not be determined"
130+
#define PROCESSOR_NAME "unknown"
131+
#endif
132+
133+
#ifdef __cplusplus
134+
}
135+
#endif
136+
137+
#endif /* H_OS_MGMT_PROCESSOR_ */

0 commit comments

Comments
 (0)