Commit 88bd5676 authored by Dominik Ermel's avatar Dominik Ermel Committed by Andrzej Puzdrowski
Browse files

boot_serial: Fix echo command code no longer compiling

Fixing missed update from cddl to zcbor.

Signed-off-by: default avatarDominik Ermel <dominik.ermel@nordicsemi.no>
parent 9feea8c6
Loading
Loading
Loading
Loading
+21 −23
Changes for boot/boot_serial/src/boot_serial.c: 21 added lines, 23 removed lines.
Original line number Diff line number Diff line
@@ -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 @@ bs_rc_rsp(int rc_code)


#ifdef MCUBOOT_BOOT_MGMT_ECHO
static bool
decode_echo(cbor_state_t *state, cbor_string_type_t *result)
static void
bs_echo(char *buf, int len)
{
    size_t bsstrdecoded;
    int ret;
    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 (!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;
    if ((result != ZCBOR_SUCCESS) || (len != decoded_len)) {
        goto out;
    }

    if (echo._Echo_d.value == NULL) {
        goto out;
    }

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");
        if (tstrx_encode(&cbor_state, &str[1]) && map_end_encode(&cbor_state, 10)) {
    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 {
            reset_cbor_state();
            bs_rc_rsp(MGMT_ERR_ENOMEM);
        }
        rc = MGMT_ERR_ENOMEM;
    }

out:
    reset_cbor_state();
    bs_rc_rsp(rc);
}
#endif

+9 −0
Changes for boot/boot_serial/src/echo.cddl: 9 added lines, 0 removed lines.
Original line number Diff line number Diff line
;
; Copyright (c) 2022 Nordic Semiconductor ASA
;
; SPDX-License-Identifier: Apache-2.0
;

Echo = {
	"d" => tstr
}
+60 −0
Changes for boot/boot_serial/src/serial_recovery_echo.c: 60 added lines, 0 removed lines.
Original line number Diff line number Diff line
/*
 * 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;
}
+28 −0
Changes for boot/boot_serial/src/serial_recovery_echo.h: 28 added lines, 0 removed lines.
Original line number Diff line number Diff line
/*
 * 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__ */
+30 −0
Changes for boot/boot_serial/src/serial_recovery_echo_types.h: 30 added lines, 0 removed lines.
Original line number Diff line number Diff line
/*
 * 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__ */
Loading