boot_serial: Fix echo command code no longer compiling

Fixing missed update from cddl to zcbor.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
diff --git a/boot/boot_serial/src/boot_serial.c b/boot/boot_serial/src/boot_serial.c
index 4a4a63d..e8c2fe2 100644
--- a/boot/boot_serial/src/boot_serial.c
+++ b/boot/boot_serial/src/boot_serial.c
@@ -63,6 +63,7 @@
 #endif
 
 #include "serial_recovery_cbor.h"
+#include "serial_recovery_echo.h"
 #include "bootutil/boot_hooks.h"
 
 BOOT_LOG_MODULE_DECLARE(mcuboot);
@@ -491,37 +492,34 @@
 
 
 #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];
+    struct Echo echo = { 0 };
+    size_t decoded_len;
+    uint32_t rc = MGMT_ERR_EINVAL;
+    uint_fast8_t result = cbor_decode_Echo((const uint8_t *)buf, len, &echo, &decoded_len);
 
-    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");
-        if (tstrx_encode(&cbor_state, &str[1]) && map_end_encode(&cbor_state, 10)) {
-            boot_serial_output();
-        } else {
-            reset_cbor_state();
-            bs_rc_rsp(MGMT_ERR_ENOMEM);
-        }
+    if ((result != ZCBOR_SUCCESS) || (len != decoded_len)) {
+        goto out;
     }
+
+    if (echo._Echo_d.value == NULL) {
+        goto out;
+    }
+
+    zcbor_map_start_encode(cbor_state, 10);
+    zcbor_tstr_put_term(cbor_state, "r");
+    if (zcbor_tstr_encode(cbor_state, &echo._Echo_d) && zcbor_map_end_encode(cbor_state, 10)) {
+        boot_serial_output();
+        return;
+    } else {
+        rc = MGMT_ERR_ENOMEM;
+    }
+
+out:
+    reset_cbor_state();
+    bs_rc_rsp(rc);
 }
 #endif
 
diff --git a/boot/boot_serial/src/echo.cddl b/boot/boot_serial/src/echo.cddl
new file mode 100644
index 0000000..42ce0ba
--- /dev/null
+++ b/boot/boot_serial/src/echo.cddl
@@ -0,0 +1,9 @@
+;
+; Copyright (c) 2022 Nordic Semiconductor ASA
+;
+; SPDX-License-Identifier: Apache-2.0
+;
+
+Echo = {
+	"d" => tstr
+}
diff --git a/boot/boot_serial/src/serial_recovery_echo.c b/boot/boot_serial/src/serial_recovery_echo.c
new file mode 100644
index 0000000..d4f0e94
--- /dev/null
+++ b/boot/boot_serial/src/serial_recovery_echo.c
@@ -0,0 +1,60 @@
+/*
+ * Generated using zcbor version 0.4.99
+ * https://github.com/NordicSemiconductor/zcbor
+ * Generated with a --default-max-qty of 3
+ */
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <stddef.h>
+#include <string.h>
+#include "zcbor_decode.h"
+#include "serial_recovery_echo.h"
+
+#if DEFAULT_MAX_QTY != 3
+#error "The type file was generated with a different default_max_qty than this file"
+#endif
+
+static bool decode_Echo(zcbor_state_t *state, struct Echo *result);
+
+static bool decode_Echo(
+		zcbor_state_t *state, struct Echo *result)
+{
+	zcbor_print("%s\r\n", __func__);
+	struct zcbor_string tmp_str;
+
+	bool tmp_result = (((zcbor_map_start_decode(state) && (((((zcbor_tstr_expect(state, ((tmp_str.value = (uint8_t *)"d", tmp_str.len = sizeof("d") - 1, &tmp_str)))))
+	&& (zcbor_tstr_decode(state, (&(*result)._Echo_d))))) || (zcbor_list_map_end_force_decode(state), false)) && zcbor_map_end_decode(state))));
+
+	if (!tmp_result)
+		zcbor_trace();
+
+	return tmp_result;
+}
+
+
+
+int cbor_decode_Echo(
+		const uint8_t *payload, size_t payload_len,
+		struct Echo *result,
+		size_t *payload_len_out)
+{
+	zcbor_state_t states[3];
+
+	zcbor_new_state(states, sizeof(states) / sizeof(zcbor_state_t), payload, payload_len, 1);
+
+	bool ret = decode_Echo(states, result);
+
+	if (ret && (payload_len_out != NULL)) {
+		*payload_len_out = MIN(payload_len,
+				(size_t)states[0].payload - (size_t)payload);
+	}
+
+	if (!ret) {
+		int err = zcbor_pop_error(states);
+
+		zcbor_print("Return error: %d\r\n", err);
+		return (err == ZCBOR_SUCCESS) ? ZCBOR_ERR_UNKNOWN : err;
+	}
+	return ZCBOR_SUCCESS;
+}
diff --git a/boot/boot_serial/src/serial_recovery_echo.h b/boot/boot_serial/src/serial_recovery_echo.h
new file mode 100644
index 0000000..b4ea351
--- /dev/null
+++ b/boot/boot_serial/src/serial_recovery_echo.h
@@ -0,0 +1,28 @@
+/*
+ * Generated using zcbor version 0.4.99
+ * https://github.com/NordicSemiconductor/zcbor
+ * Generated with a --default-max-qty of 3
+ */
+
+#ifndef SERIAL_RECOVERY_ECHO_H__
+#define SERIAL_RECOVERY_ECHO_H__
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <stddef.h>
+#include <string.h>
+#include "zcbor_decode.h"
+#include "serial_recovery_echo_types.h"
+
+#if DEFAULT_MAX_QTY != 3
+#error "The type file was generated with a different default_max_qty than this file"
+#endif
+
+
+int cbor_decode_Echo(
+		const uint8_t *payload, size_t payload_len,
+		struct Echo *result,
+		size_t *payload_len_out);
+
+
+#endif /* SERIAL_RECOVERY_ECHO_H__ */
diff --git a/boot/boot_serial/src/serial_recovery_echo_types.h b/boot/boot_serial/src/serial_recovery_echo_types.h
new file mode 100644
index 0000000..508951c
--- /dev/null
+++ b/boot/boot_serial/src/serial_recovery_echo_types.h
@@ -0,0 +1,30 @@
+/*
+ * Generated using zcbor version 0.4.99
+ * https://github.com/NordicSemiconductor/zcbor
+ * Generated with a --default-max-qty of 3
+ */
+
+#ifndef SERIAL_RECOVERY_ECHO_TYPES_H__
+#define SERIAL_RECOVERY_ECHO_TYPES_H__
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <stddef.h>
+#include <string.h>
+#include "zcbor_decode.h"
+
+/** Which value for --default-max-qty this file was created with.
+ *
+ *  The define is used in the other generated file to do a build-time
+ *  compatibility check.
+ *
+ *  See `zcbor --help` for more information about --default-max-qty
+ */
+#define DEFAULT_MAX_QTY 3
+
+struct Echo {
+	struct zcbor_string _Echo_d;
+};
+
+
+#endif /* SERIAL_RECOVERY_ECHO_TYPES_H__ */
diff --git a/boot/zephyr/CMakeLists.txt b/boot/zephyr/CMakeLists.txt
index db9067a..6070cd5 100644
--- a/boot/zephyr/CMakeLists.txt
+++ b/boot/zephyr/CMakeLists.txt
@@ -256,6 +256,8 @@
   zephyr_sources(${BOOT_DIR}/boot_serial/src/zcbor_encode.c)
   zephyr_sources(${BOOT_DIR}/boot_serial/src/zcbor_common.c)
 
+  zephyr_sources_ifdef(CONFIG_BOOT_MGMT_ECHO ${BOOT_DIR}/boot_serial/src/serial_recovery_echo.c)
+
   zephyr_include_directories(${BOOT_DIR}/bootutil/include)
   zephyr_include_directories(${BOOT_DIR}/boot_serial/include)
   zephyr_include_directories(include)