From f74feca0275dc86be282d995f7c814984384b806 Mon Sep 17 00:00:00 2001 From: Marcin Niestroj Date: Tue, 21 Jul 2020 04:09:23 +0200 Subject: [PATCH] mgmt: smp: shell: initialize SMP before feeding with received bytes So far SMP shell transport was initialized in APPLICATION run level, but shell over UART was initialized in POST_KERNEL. This could end up in situation when received frames were scheduled for further processing in SMP layer, when it was not initialized yet. Export smp_shell_init() function declaration and call it before shell is initialized with all its receive data handlers. This prevents situation when data is scheduled for processing in SMP layer, when that one is not ready yet. Signed-off-by: Marcin Niestroj --- include/mgmt/mcumgr/smp_shell.h | 10 ++++++++++ include/shell/shell_uart.h | 2 -- subsys/mgmt/mcumgr/smp_shell.c | 6 +----- subsys/shell/shell_uart.c | 4 ++++ 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/include/mgmt/mcumgr/smp_shell.h b/include/mgmt/mcumgr/smp_shell.h index 4b4c999514e..0f220cc3dcf 100644 --- a/include/mgmt/mcumgr/smp_shell.h +++ b/include/mgmt/mcumgr/smp_shell.h @@ -47,6 +47,16 @@ bool smp_shell_rx_byte(struct smp_shell_data *data, uint8_t byte); */ void smp_shell_process(struct smp_shell_data *data); +/** + * @brief Initializes SMP transport over shell. + * + * This function should be called before feeding SMP transport with received + * data. + * + * @return 0 on success + */ +int smp_shell_init(void); + #ifdef __cplusplus } #endif diff --git a/include/shell/shell_uart.h b/include/shell/shell_uart.h index 68a3b0e5833..b1566a309ef 100644 --- a/include/shell/shell_uart.h +++ b/include/shell/shell_uart.h @@ -10,9 +10,7 @@ #include #include #include -#ifdef CONFIG_MCUMGR_SMP_SHELL #include "mgmt/mcumgr/smp_shell.h" -#endif #ifdef __cplusplus extern "C" { diff --git a/subsys/mgmt/mcumgr/smp_shell.c b/subsys/mgmt/mcumgr/smp_shell.c index f7bccc411c0..3f9d65fb5f3 100644 --- a/subsys/mgmt/mcumgr/smp_shell.c +++ b/subsys/mgmt/mcumgr/smp_shell.c @@ -154,14 +154,10 @@ static int smp_shell_tx_pkt(struct zephyr_smp_transport *zst, return rc; } -static int smp_shell_init(struct device *dev) +int smp_shell_init(void) { - ARG_UNUSED(dev); - zephyr_smp_transport_init(&smp_shell_transport, smp_shell_tx_pkt, smp_shell_get_mtu, NULL, NULL); return 0; } - -SYS_INIT(smp_shell_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY); diff --git a/subsys/shell/shell_uart.c b/subsys/shell/shell_uart.c index 1b1cbd5d0f1..74116850fb5 100644 --- a/subsys/shell/shell_uart.c +++ b/subsys/shell/shell_uart.c @@ -285,6 +285,10 @@ static int enable_shell_uart(struct device *arg) return -ENODEV; } + if (IS_ENABLED(CONFIG_MCUMGR_SMP_SHELL)) { + smp_shell_init(); + } + shell_init(&shell_uart, dev, true, log_backend, level); return 0;