Commit e3ff1753 authored by Wouter Cappelle's avatar Wouter Cappelle Committed by David Brown
Browse files

Add support for the mcumgr echo command in serial boot mode

parent d8eff810
Loading
Loading
Loading
Loading
+37 −0
Original line number Diff line number Diff line
@@ -470,6 +470,38 @@ out:
#endif //#ifdef MCUBOOT_ENC_IMAGES
}

#ifdef MCUBOOT_BOOT_MGMT_ECHO
static bool
decode_echo(cbor_state_t *state, cbor_string_type_t *result)
{
    size_t bsstrdecoded;
    int ret;

    if (!map_start_decode(state)) {
        return false;
    }
    ret = multi_decode(2, 2, &bsstrdecoded, (void *)tstrx_decode, state, result, sizeof(cbor_string_type_t));
    map_end_decode(state);
    return ret;
}


static void
bs_echo(char *buf, int len)
{
    size_t bsstrdecoded;
    cbor_string_type_t str[2];

    if (entry_function((const uint8_t *)buf, len, str, &bsstrdecoded, (void *)decode_echo, 1, 2)) {
        map_start_encode(&cbor_state, 10);
        tstrx_put(&cbor_state, "r");
        tstrx_encode(&cbor_state, &str[1]);
        map_end_encode(&cbor_state, 10);
        boot_serial_output();
    }
}
#endif

/*
 * Send rc code only.
 */
@@ -547,6 +579,11 @@ boot_serial_input(char *buf, int len)
        }
    } else if (hdr->nh_group == MGMT_GROUP_ID_DEFAULT) {
        switch (hdr->nh_id) {
        case NMGR_ID_ECHO:
#ifdef MCUBOOT_BOOT_MGMT_ECHO
            bs_echo(buf, len);
#endif
            break;
        case NMGR_ID_CONS_ECHO_CTRL:
            bs_rc_rsp(0);
            break;
+1 −0
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ extern "C" {
#define MGMT_GROUP_ID_IMAGE     1
#define MGMT_GROUP_ID_PERUSER  64

#define NMGR_ID_ECHO            0
#define NMGR_ID_CONS_ECHO_CTRL  1
#define NMGR_ID_RESET           5

+5 −0
Original line number Diff line number Diff line
@@ -583,6 +583,11 @@ config BOOT_ERASE_PROGRESSIVELY
	 on some hardware that has long erase times, to prevent long wait
	 times at the beginning of the DFU process.

config BOOT_MGMT_ECHO
	bool "Enable echo command"
	help
	  if enabled, support for the mcumgr echo command is being added.

menuconfig ENABLE_MGMT_PERUSER
	bool "Enable system specific mcumgr commands"
	help
+4 −0
Original line number Diff line number Diff line
@@ -173,6 +173,10 @@
#define MCUBOOT_MGMT_CUSTOM_IMG_LIST
#endif

#ifdef CONFIG_BOOT_MGMT_ECHO
#define MCUBOOT_BOOT_MGMT_ECHO
#endif

#ifdef CONFIG_BOOT_IMAGE_ACCESS_HOOKS
#define MCUBOOT_IMAGE_ACCESS_HOOKS
#endif