Skip to content

Commit e3ff175

Browse files
Wouter Cappelled3zd3z
authored andcommitted
Add support for the mcumgr echo command in serial boot mode
Signed-off-by: Wouter Cappelle <[email protected]>
1 parent d8eff81 commit e3ff175

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

boot/boot_serial/src/boot_serial.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,38 @@ bs_upload(char *buf, int len)
470470
#endif //#ifdef MCUBOOT_ENC_IMAGES
471471
}
472472

473+
#ifdef MCUBOOT_BOOT_MGMT_ECHO
474+
static bool
475+
decode_echo(cbor_state_t *state, cbor_string_type_t *result)
476+
{
477+
size_t bsstrdecoded;
478+
int ret;
479+
480+
if (!map_start_decode(state)) {
481+
return false;
482+
}
483+
ret = multi_decode(2, 2, &bsstrdecoded, (void *)tstrx_decode, state, result, sizeof(cbor_string_type_t));
484+
map_end_decode(state);
485+
return ret;
486+
}
487+
488+
489+
static void
490+
bs_echo(char *buf, int len)
491+
{
492+
size_t bsstrdecoded;
493+
cbor_string_type_t str[2];
494+
495+
if (entry_function((const uint8_t *)buf, len, str, &bsstrdecoded, (void *)decode_echo, 1, 2)) {
496+
map_start_encode(&cbor_state, 10);
497+
tstrx_put(&cbor_state, "r");
498+
tstrx_encode(&cbor_state, &str[1]);
499+
map_end_encode(&cbor_state, 10);
500+
boot_serial_output();
501+
}
502+
}
503+
#endif
504+
473505
/*
474506
* Send rc code only.
475507
*/
@@ -547,6 +579,11 @@ boot_serial_input(char *buf, int len)
547579
}
548580
} else if (hdr->nh_group == MGMT_GROUP_ID_DEFAULT) {
549581
switch (hdr->nh_id) {
582+
case NMGR_ID_ECHO:
583+
#ifdef MCUBOOT_BOOT_MGMT_ECHO
584+
bs_echo(buf, len);
585+
#endif
586+
break;
550587
case NMGR_ID_CONS_ECHO_CTRL:
551588
bs_rc_rsp(0);
552589
break;

boot/boot_serial/src/boot_serial_priv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ extern "C" {
4848
#define MGMT_GROUP_ID_IMAGE 1
4949
#define MGMT_GROUP_ID_PERUSER 64
5050

51+
#define NMGR_ID_ECHO 0
5152
#define NMGR_ID_CONS_ECHO_CTRL 1
5253
#define NMGR_ID_RESET 5
5354

boot/zephyr/Kconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,11 @@ config BOOT_ERASE_PROGRESSIVELY
583583
on some hardware that has long erase times, to prevent long wait
584584
times at the beginning of the DFU process.
585585

586+
config BOOT_MGMT_ECHO
587+
bool "Enable echo command"
588+
help
589+
if enabled, support for the mcumgr echo command is being added.
590+
586591
menuconfig ENABLE_MGMT_PERUSER
587592
bool "Enable system specific mcumgr commands"
588593
help

boot/zephyr/include/mcuboot_config/mcuboot_config.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@
173173
#define MCUBOOT_MGMT_CUSTOM_IMG_LIST
174174
#endif
175175

176+
#ifdef CONFIG_BOOT_MGMT_ECHO
177+
#define MCUBOOT_BOOT_MGMT_ECHO
178+
#endif
179+
176180
#ifdef CONFIG_BOOT_IMAGE_ACCESS_HOOKS
177181
#define MCUBOOT_IMAGE_ACCESS_HOOKS
178182
#endif

0 commit comments

Comments
 (0)