Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions include/zephyr/mgmt/mcumgr/grp/os_mgmt/os_mgmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,66 @@ extern "C" {
#define OS_MGMT_ID_DATETIME_STR 4
#define OS_MGMT_ID_RESET 5
#define OS_MGMT_ID_MCUMGR_PARAMS 6
#define OS_MGMT_ID_INFO 7

/* Bitmask values used by the os info command handler. Note that the width of this variable is
* 32-bits, allowing 32 flags, custom user-level implementations should start at
* OS_MGMT_INFO_FORMAT_USER_CUSTOM_START and reference that directly as additional format
* specifiers might be added to this list in the future.
*/
enum os_mgmt_info_formats {
OS_MGMT_INFO_FORMAT_KERNEL_NAME = BIT(0),
OS_MGMT_INFO_FORMAT_NODE_NAME = BIT(1),
OS_MGMT_INFO_FORMAT_KERNEL_RELEASE = BIT(2),
OS_MGMT_INFO_FORMAT_KERNEL_VERSION = BIT(3),
OS_MGMT_INFO_FORMAT_BUILD_DATE_TIME = BIT(4),
OS_MGMT_INFO_FORMAT_MACHINE = BIT(5),
OS_MGMT_INFO_FORMAT_PROCESSOR = BIT(6),
OS_MGMT_INFO_FORMAT_HARDWARE_PLATFORM = BIT(7),
OS_MGMT_INFO_FORMAT_OPERATING_SYSTEM = BIT(8),

OS_MGMT_INFO_FORMAT_USER_CUSTOM_START = BIT(9),
};

/* Structure provided in the MGMT_EVT_OP_OS_MGMT_INFO_CHECK notification callback */
struct os_mgmt_info_check {
/* Input format string from the mcumgr client */
struct zcbor_string *format;
/* Bitmask of values specifying which outputs should be present */
uint32_t *format_bitmask;
/* Number of valid format characters parsed, must be incremented by 1 for each valid
* character
*/
uint16_t *valid_formats;
/* Needs to be set to true if the OS name is being provided by external code */
bool *custom_os_name;
};

/* Structure provided in the MGMT_EVT_OP_OS_MGMT_INFO_APPEND notification callback */
struct os_mgmt_info_append {
/* The format bitmask from the processed commands, the bits should be cleared once
* processed, note that if all_format_specified is specified, the corrisponding bits here
* will not be set
*/
uint32_t *format_bitmask;
/* Will be true if the all 'a' specifier was provided */
bool all_format_specified;
/* The output buffer which the responses should be appended to. If prior_output is true, a
* space must be added prior to the output response
*/
uint8_t *output;
/* The current size of the output response in the output buffer, must be updated to be the
* size of the output response after appending data
*/
uint16_t *output_length;
/* The size of the output buffer, including null terminator character, if the output
* response would exceed this size, the function must abort and return false to return a
* memory error to the client
*/
uint16_t buffer_size;
/* If there has been prior output, must be set to true if a response has been output */
bool *prior_output;
};

/**
* @brief Registers the OS management command handler group.
Expand Down
6 changes: 6 additions & 0 deletions include/zephyr/mgmt/mcumgr/mgmt/callbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ enum os_mgmt_group_events {
/** Callback when a reset command has been received. */
MGMT_EVT_OP_OS_MGMT_RESET = MGMT_DEF_EVT_OP_ID(MGMT_EVT_GRP_OS, 0),

/** Callback when an info command is processed, data is os_mgmt_info_check. */
MGMT_EVT_OP_OS_MGMT_INFO_CHECK = MGMT_DEF_EVT_OP_ID(MGMT_EVT_GRP_OS, 1),

/** Callback when an info command needs to output data, data is os_mgmt_info_append. */
MGMT_EVT_OP_OS_MGMT_INFO_APPEND = MGMT_DEF_EVT_OP_ID(MGMT_EVT_GRP_OS, 2),

/** Used to enable all os_mgmt_group events. */
MGMT_EVT_OP_OS_MGMT_ALL = MGMT_DEF_EVT_OP_ALL(MGMT_EVT_GRP_OS),
};
Expand Down
7 changes: 7 additions & 0 deletions subsys/mgmt/mcumgr/grp/os_mgmt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,10 @@ if (CONFIG_REBOOT)
endif()

target_link_libraries(mgmt_mcumgr INTERFACE mgmt_mcumgr_grp_os)

if(DEFINED CONFIG_MCUMGR_GRP_OS_INFO_BUILD_DATE_TIME)
set(MCUMGR_GRP_OS_INFO_BUILD_DATE_TIME_DIR ${PROJECT_BINARY_DIR}/os_mgmt_auto)
file(MAKE_DIRECTORY ${MCUMGR_GRP_OS_INFO_BUILD_DATE_TIME_DIR})
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__;")
zephyr_library_sources(${MCUMGR_GRP_OS_INFO_BUILD_DATE_TIME_DIR}/os_mgmt_build_date.c)
endif()
35 changes: 35 additions & 0 deletions subsys/mgmt/mcumgr/grp/os_mgmt/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,39 @@ config OS_MGMT_ECHO
config OS_MGMT_MCUMGR_PARAMS
bool "MCUMGR Parameters retrieval command"

config MCUMGR_GRP_OS_INFO
bool "Support for info command"
help
Can be used similarly to the unix/linux uname command for retrieving system information
including kernel version, processor architecture and board name.

if MCUMGR_GRP_OS_INFO

config MCUMGR_GRP_OS_INFO_MAX_RESPONSE_SIZE
int "Maximum response size for info command"
default 256
range 32 512
help
The maximum size of the response to the info command, will use a stack buffer of this
size to store the data in. If the output response is too big then the output will not be
present in the response, which will just contain the result code (rc) of memory error.

config MCUMGR_GRP_OS_INFO_CUSTOM_HOOKS
bool "Custom info hooks"
depends on MCUMGR_MGMT_NOTIFICATION_HOOKS
help
Supports adding custom command/character processing to the info command by using
registered callbacks. Data can be appended to the struct provided in the callback.

config MCUMGR_GRP_OS_INFO_BUILD_DATE_TIME
bool "Show build date and time"
help
Will allow returning the build date and time of the firmware by using the info with
format option 'b' (will also be returned with all responses by using 'a').

Note: This will invalidate reproducible builds of the firmware as it will embed the
build date/time in the output firmware image.

endif

endif
137 changes: 137 additions & 0 deletions subsys/mgmt/mcumgr/grp/os_mgmt/include/os_mgmt_processor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/*
* Copyright (c) 2022 Zephyr authors
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef H_OS_MGMT_PROCESSOR_
#define H_OS_MGMT_PROCESSOR_

#ifdef __cplusplus
extern "C" {
#endif

/**
* Processor name (used in uname output command)
* Will be unknown if processor type is not listed
* (List extracted from /cmake/gcc-m-cpu.cmake)
*/
#if defined(CONFIG_ARM)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow this is really hard to follow, maybe worth indenting the defines in a followup patch? Not normally a fan of that either but editing this seems like a nightmare.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed it is horrible to look at and update, indentation would probably be a good idea, I'll give it a try and see if CI throws an error about it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if it's even worth reporting it in such details, maybe you could just report whatever is in cpu@0 compatible.

#if defined(CONFIG_CPU_CORTEX_M0)
#define PROCESSOR_NAME "cortex-m0"
#elif defined(CONFIG_CPU_CORTEX_M0PLUS)
#define PROCESSOR_NAME "cortex-m0plus"
#elif defined(CONFIG_CPU_CORTEX_M1)
#define PROCESSOR_NAME "cortex-m1"
#elif defined(CONFIG_CPU_CORTEX_M3)
#define PROCESSOR_NAME "cortex-m3"
#elif defined(CONFIG_CPU_CORTEX_M4)
#define PROCESSOR_NAME "cortex-m4"
#elif defined(CONFIG_CPU_CORTEX_M7)
#define PROCESSOR_NAME "cortex-m7"
#elif defined(CONFIG_CPU_CORTEX_M23)
#define PROCESSOR_NAME "cortex-m23"
#elif defined(CONFIG_CPU_CORTEX_M33)
#if defined(CONFIG_ARMV8_M_DSP)
#define PROCESSOR_NAME "cortex-m33"
#else
#define PROCESSOR_NAME "cortex-m33+nodsp"
#endif
#elif defined(CONFIG_CPU_CORTEX_M55)
#if defined(CONFIG_ARMV8_1_M_MVEF)
#define PROCESSOR_NAME "cortex-m55"
#elif defined(CONFIG_ARMV8_1_M_MVEI)
#define PROCESSOR_NAME "cortex-m55+nomve.fp"
#elif defined(CONFIG_ARMV8_M_DSP)
#define PROCESSOR_NAME "cortex-m55+nomve"
#else
#define PROCESSOR_NAME "cortex-m55+nodsp"
#endif
#elif defined(CONFIG_CPU_CORTEX_R4)
#if defined(CONFIG_FPU) && defined(CONFIG_CPU_HAS_VFP)
#define PROCESSOR_NAME "cortex-r4f"
#else
#define PROCESSOR_NAME "cortex-r4"
#endif
#elif defined(CONFIG_CPU_CORTEX_R5)
#if defined(CONFIG_FPU) && defined(CONFIG_CPU_HAS_VFP)
#if !defined(CONFIG_VFP_FEATURE_DOUBLE_PRECISION)
#define PROCESSOR_NAME "cortex-r5+nofp.dp"
#else
#define PROCESSOR_NAME "cortex-r5"
#endif
#else
#define PROCESSOR_NAME "cortex-r5+nofp"
#endif
#elif defined(CONFIG_CPU_CORTEX_R7)
#if defined(CONFIG_FPU) && defined(CONFIG_CPU_HAS_VFP)
#if !defined(CONFIG_VFP_FEATURE_DOUBLE_PRECISION)
#define PROCESSOR_NAME "cortex-r7+nofp.dp"
#else
#define PROCESSOR_NAME "cortex-r7"
#endif
#else
#define PROCESSOR_NAME "cortex-r7+nofp"
#endif
#elif defined(CONFIG_CPU_CORTEX_R52)
#if defined(CONFIG_FPU) && defined(CONFIG_CPU_HAS_VFP)
#if !defined(CONFIG_VFP_FEATURE_DOUBLE_PRECISION)
#define PROCESSOR_NAME "cortex-r52+nofp.dp"
#else
#define PROCESSOR_NAME "cortex-r52"
#endif
#else
#define PROCESSOR_NAME "cortex-r52"
#endif
#elif defined(CONFIG_CPU_CORTEX_A9)
#define PROCESSOR_NAME "cortex-a9"
#endif
#elif defined(CONFIG_ARM64)
#if defined(CONFIG_CPU_CORTEX_A53)
#define PROCESSOR_NAME "cortex-a53"
#if defined(CONFIG_CPU_CORTEX_A55)
#define PROCESSOR_NAME "cortex-a55"
#elif defined(CONFIG_CPU_CORTEX_A72)
#define PROCESSOR_NAME "cortex-a72"
#elif defined(CONFIG_CPU_CORTEX_R82)
#define PROCESSOR_NAME "armv8.4-a+nolse"
#endif
#endif
#elif defined(CONFIG_ARC)
#if defined(CONFIG_CPU_EM4_FPUS)
#define PROCESSOR_NAME "em4_fpus"
#elif defined(CONFIG_CPU_EM4_DMIPS)
#define PROCESSOR_NAME "em4_dmips"
#elif defined(CONFIG_CPU_EM4_FPUDA)
#define PROCESSOR_NAME "em4_fpuda"
#elif defined(CONFIG_CPU_HS3X)
#define PROCESSOR_NAME "archs"
#elif defined(CONFIG_CPU_HS5X)
#define PROCESSOR_NAME "hs5x"
#elif defined(CONFIG_CPU_HS6X)
#define PROCESSOR_NAME "hs6x"
#elif defined(CONFIG_CPU_EM4)
#define PROCESSOR_NAME "arcem"
#elif defined(CONFIG_CPU_EM6)
#define PROCESSOR_NAME "arcem"
#endif
#elif defined(CONFIG_X86)
#if defined(CONFIG_X86_64)
#define PROCESSOR_NAME "x86_64"
#else
#define PROCESSOR_NAME "x86"
#endif
#elif defined(CONFIG_RISCV)
#define PROCESSOR_NAME "riscv"
#endif

#ifndef PROCESSOR_NAME
#warning "Processor type could not be determined"
#define PROCESSOR_NAME "unknown"
#endif

#ifdef __cplusplus
}
#endif

#endif /* H_OS_MGMT_PROCESSOR_ */
Loading