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 <m.niestroj@grinn-global.com>
This commit is contained in:
Marcin Niestroj 2020-07-21 04:09:23 +02:00 committed by Anas Nashif
commit f74feca027
4 changed files with 15 additions and 7 deletions

View file

@ -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

View file

@ -10,9 +10,7 @@
#include <shell/shell.h>
#include <sys/ring_buffer.h>
#include <sys/atomic.h>
#ifdef CONFIG_MCUMGR_SMP_SHELL
#include "mgmt/mcumgr/smp_shell.h"
#endif
#ifdef __cplusplus
extern "C" {

View file

@ -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);

View file

@ -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;