Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
33 changes: 33 additions & 0 deletions boot/boot_serial/src/boot_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -1261,6 +1261,34 @@ bs_echo(char *buf, int len)
}
#endif

#ifdef MCUBOOT_BOOT_MGMT_MCUMGR_PARAMS
/*
* Reports the SMP transport buffer parameters so that clients can negotiate
* optimal serial fragmentation, mirroring the mcumgr OS group "MCUmgr
* parameters" command provided by Zephyr's SMP server. The serial recovery
* reassembles one command at a time into a single buffer, hence a buffer
* count of 1. The line length is not reported; enabling this command requires
* BOOT_MAX_LINE_INPUT_LEN to remain at the standard 128-byte fragment size.
*/
static void
bs_mcumgr_params(char *buf, int len)
{
if (
zcbor_map_start_encode(cbor_state, 10) &&
zcbor_tstr_put_lit_cast(cbor_state, "buf_size") &&
zcbor_uint32_put(cbor_state, MCUBOOT_SERIAL_MAX_RECEIVE_SIZE) &&
zcbor_tstr_put_lit_cast(cbor_state, "buf_count") &&
zcbor_uint32_put(cbor_state, 1) &&
zcbor_map_end_encode(cbor_state, 10)
) {
boot_serial_output();
} else {
reset_cbor_state();
bs_rc_rsp(MGMT_ERR_ENOMEM);
}
}
#endif

/*
* Reset, and (presumably) boot to newly uploaded image. Flush console
* before restarting.
Expand Down Expand Up @@ -1354,6 +1382,11 @@ boot_serial_input(char *buf, int len)
case NMGR_ID_RESET:
bs_reset(buf, len);
break;
#ifdef MCUBOOT_BOOT_MGMT_MCUMGR_PARAMS
case NMGR_ID_MCUMGR_PARAMS:
bs_mcumgr_params(buf, len);
break;
#endif
default:
bs_rc_rsp(MGMT_ERR_ENOTSUP);
break;
Expand Down
1 change: 1 addition & 0 deletions boot/boot_serial/src/boot_serial_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ extern "C" {
#define NMGR_ID_ECHO 0
#define NMGR_ID_CONS_ECHO_CTRL 1
#define NMGR_ID_RESET 5
#define NMGR_ID_MCUMGR_PARAMS 6

#ifndef __packed
#define __packed __attribute__((__packed__))
Expand Down
13 changes: 13 additions & 0 deletions boot/zephyr/Kconfig.serial_recovery
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,19 @@ config BOOT_MGMT_ECHO
help
if enabled, support for the mcumgr echo command is being added.

config BOOT_MGMT_MCUMGR_PARAMS
bool "SMP server buffer size"
depends on BOOT_MAX_LINE_INPUT_LEN = 128
help
If enabled, support for the mcumgr OS group "MCUmgr parameters"
command (command ID 6) is added, mirroring the command provided by
Zephyr's SMP server. It reports the SMP transport buffer size
(BOOT_SERIAL_MAX_RECEIVE_SIZE) and buffer count so that SMP clients
can negotiate optimal serial fragmentation. The parameters do not
carry the transport line length, so this option requires
BOOT_MAX_LINE_INPUT_LEN to remain at the standard 128-byte fragment
size. buf_count will always be 1.

menuconfig ENABLE_MGMT_PERUSER
bool "System specific mcumgr commands"
help
Expand Down
4 changes: 4 additions & 0 deletions boot/zephyr/include/mcuboot_config/mcuboot_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,10 @@
#define MCUBOOT_BOOT_MGMT_ECHO
#endif

#ifdef CONFIG_BOOT_MGMT_MCUMGR_PARAMS
#define MCUBOOT_BOOT_MGMT_MCUMGR_PARAMS
#endif

#ifdef CONFIG_BOOT_IMAGE_ACCESS_HOOKS
#define MCUBOOT_IMAGE_ACCESS_HOOKS
#endif
Expand Down
1 change: 1 addition & 0 deletions boot/zephyr/sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ tests:
- CONFIG_ENABLE_MGMT_PERUSER=y
- CONFIG_BOOT_MGMT_CUSTOM_STORAGE_ERASE=y
- CONFIG_BOOT_MGMT_ECHO=y
- CONFIG_BOOT_MGMT_MCUMGR_PARAMS=y
- CONFIG_BOOT_SERIAL_IMG_GRP_IMAGE_STATE=y
- CONFIG_BOOT_SERIAL_IMG_GRP_SLOT_INFO=y
platform_allow: nrf52840dk/nrf52840
Expand Down
7 changes: 7 additions & 0 deletions docs/release-notes.d/serial-recovery-mcumgr-params.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- Added an optional serial recovery ``MCUmgr parameters`` command (mcumgr OS
management group, command ID 6), enabled with
``CONFIG_BOOT_MGMT_MCUMGR_PARAMS``. The read-only command reports the SMP
transport ``buf_size`` and ``buf_count`` so that SMP clients can negotiate
optimal serial fragmentation, matching the command provided by Zephyr's SMP
server. It requires ``CONFIG_BOOT_MAX_LINE_INPUT_LEN`` to remain at its
default of 128.
1 change: 1 addition & 0 deletions docs/serial_recovery.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ See the Zephyr [Device Management](https://docs.zephyrproject.org/latest/service
MCUboot supports the following subset of the MCUmgr commands:
* echo (OS group)
* reset (OS group)
* MCUmgr parameters SMP buffer size (OS group), when ``MCUBOOT_BOOT_MGMT_MCUMGR_PARAMS`` is enabled
* image list (IMG group)
* image upload (IMG group)

Expand Down
Loading