Skip to content

mcumgr: relocate uart transport #92359

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 11 additions & 19 deletions drivers/console/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -203,34 +203,26 @@ config IPM_CONSOLE_LINE_BUF_LEN
where characters are stored before sending the whole line.

config UART_MCUMGR
bool "Mcumgr UART driver"
select UART_INTERRUPT_DRIVEN
bool "Mcumgr UART driver [DEPRECATED]"
select DEPRECATED
help
Enable the mcumgr UART driver. This driver allows the application to
communicate over UART using the mcumgr protocol for image upgrade and
device management. The driver doesn't inspect received data (as
contrary to console UART driver) and all aspects of received protocol
data are handled by an application provided callback.
This option is deprecated.

if UART_MCUMGR

config UART_MCUMGR_RX_BUF_SIZE
int "Size of receive buffer for mcumgr fragments received over UART, in bytes"
default 128
int "Size of receive buffer for mcumgr fragments received over UART, in bytes [DEPRECATED]"
default 0
help
Specifies the size of the mcumgr UART receive buffer, in bytes. This
value must be large enough to accommodate any line sent by an mcumgr
client.
This option is deprecated.
Please use MCUMGR_TRANSPORT_UART_RX_BUF_SIZE instead.

config UART_MCUMGR_RX_BUF_COUNT
int "Number of receive buffers for mcumgr fragments received over UART"
default 2
int "Number of receive buffers for mcumgr fragments received over UART [DEPRECATED]"
default 0
help
Specifies the number of the mcumgr UART receive buffers. Receive
buffers hold received mcumgr fragments prior to reassembly. This
setting's value must satisfy the following relation:
UART_MCUMGR_RX_BUF_COUNT * UART_MCUMGR_RX_BUF_SIZE >=
MCUMGR_TRANSPORT_UART_MTU
This option is deprecated.
Please use MCUMGR_TRANSPORT_UART_RX_BUF_COUNT instead.

endif # UART_MCUMGR

Expand Down
1 change: 1 addition & 0 deletions subsys/mgmt/mcumgr/transport/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ zephyr_library_sources_ifdef(CONFIG_MCUMGR_TRANSPORT_SHELL
)
zephyr_library_sources_ifdef(CONFIG_MCUMGR_TRANSPORT_UART
src/smp_uart.c
src/uart_mcumgr.c
)
zephyr_library_sources_ifdef(CONFIG_MCUMGR_TRANSPORT_UDP
src/smp_udp.c
Expand Down
19 changes: 18 additions & 1 deletion subsys/mgmt/mcumgr/transport/Kconfig.uart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ menuconfig MCUMGR_TRANSPORT_UART
depends on CONSOLE
depends on BASE64
depends on CRC
select UART_MCUMGR
help
Enables handling of SMP commands received over UART. This is a
lightweight alternative to MCUMGR_TRANSPORT_SHELL. It allows mcumgr
Expand Down Expand Up @@ -60,4 +59,22 @@ config MCUMGR_TRANSPORT_UART_MTU
This value must satisfy the following relation:
MCUMGR_TRANSPORT_UART_MTU <= MCUMGR_TRANSPORT_NETBUF_SIZE + 2

config MCUMGR_TRANSPORT_UART_RX_BUF_SIZE
int "Size of receive buffer for mcumgr fragments received over UART, in bytes"
default 128
help
Specifies the size of the mcumgr UART receive buffer, in bytes. This
value must be large enough to accommodate any line sent by an mcumgr
client.

config MCUMGR_TRANSPORT_UART_RX_BUF_COUNT
int "Number of receive buffers for mcumgr fragments received over UART"
default 2
help
Specifies the number of the mcumgr UART receive buffers. Receive
buffers hold received mcumgr fragments prior to reassembly. This
setting's value must satisfy the following relation:
MCUMGR_TRANSPORT_UART_RX_BUF_COUNT * MCUMGR_TRANSPORT_UART_RX_BUF_SIZE >=
MCUMGR_TRANSPORT_UART_MTU

endif # MCUMGR_TRANSPORT_UART
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
* @see include/mgmt/serial.h
*/

#ifndef ZEPHYR_INCLUDE_DRIVERS_CONSOLE_UART_MCUMGR_H_
#define ZEPHYR_INCLUDE_DRIVERS_CONSOLE_UART_MCUMGR_H_
#ifndef ZEPHYR_INCLUDE_MGMT_SMP_UART_MCUMGR_H_
#define ZEPHYR_INCLUDE_MGMT_SMP_UART_MCUMGR_H_

#include <stdlib.h>
#include <zephyr/types.h>
Expand All @@ -25,7 +25,7 @@ extern "C" {
*/
struct uart_mcumgr_rx_buf {
void *fifo_reserved; /* 1st word reserved for use by fifo */
uint8_t data[CONFIG_UART_MCUMGR_RX_BUF_SIZE];
uint8_t data[CONFIG_MCUMGR_TRANSPORT_UART_RX_BUF_SIZE];
int length;
};

Expand Down
4 changes: 2 additions & 2 deletions subsys/mgmt/mcumgr/transport/src/smp_dummy.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
*/

/* Define required for uart_mcumgr.h functionality reuse */
#define CONFIG_UART_MCUMGR_RX_BUF_SIZE CONFIG_MCUMGR_TRANSPORT_DUMMY_RX_BUF_SIZE
#define CONFIG_MCUMGR_TRANSPORT_UART_RX_BUF_SIZE CONFIG_MCUMGR_TRANSPORT_DUMMY_RX_BUF_SIZE
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RFC: I'm also inclined to remove the uart/serial dependencies so that smp_dummy is completely standalone, at the expense of some code duplication, any idea?

#define MCUMGR_DUMMY_MAX_FRAME CONFIG_MCUMGR_TRANSPORT_DUMMY_RX_BUF_SIZE

#include <mgmt/mcumgr/transport/uart_mcumgr.h>
#include <zephyr/kernel.h>
#include <zephyr/init.h>
#include <zephyr/sys/crc.h>
#include <zephyr/sys/byteorder.h>
#include <zephyr/net_buf.h>
#include <zephyr/sys/base64.h>
#include <zephyr/drivers/console/uart_mcumgr.h>
#include <zephyr/mgmt/mcumgr/mgmt/mgmt.h>
#include <zephyr/mgmt/mcumgr/smp/smp.h>
#include <zephyr/mgmt/mcumgr/transport/smp.h>
Expand Down
2 changes: 1 addition & 1 deletion subsys/mgmt/mcumgr/transport/src/smp_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
*/

#include <string.h>
#include <mgmt/mcumgr/transport/uart_mcumgr.h>
#include <zephyr/kernel.h>
#include <zephyr/init.h>
#include <zephyr/net_buf.h>
#include <zephyr/drivers/console/uart_mcumgr.h>
#include <zephyr/mgmt/mcumgr/mgmt/mgmt.h>
#include <zephyr/mgmt/mcumgr/smp/smp.h>
#include <zephyr/mgmt/mcumgr/transport/smp.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
*/

#include <string.h>
#include <mgmt/mcumgr/transport/uart_mcumgr.h>
#include <zephyr/kernel.h>
#include <zephyr/drivers/uart.h>
#include <zephyr/mgmt/mcumgr/transport/serial.h>
#include <zephyr/drivers/console/uart_mcumgr.h>

static const struct device *const uart_mcumgr_dev =
DEVICE_DT_GET(DT_CHOSEN(zephyr_uart_mcumgr));
Expand All @@ -32,7 +32,7 @@ static bool uart_mcumgr_ignoring;

/** Contains buffers to hold incoming request fragments. */
K_MEM_SLAB_DEFINE(uart_mcumgr_slab, sizeof(struct uart_mcumgr_rx_buf),
CONFIG_UART_MCUMGR_RX_BUF_COUNT, 1);
CONFIG_MCUMGR_TRANSPORT_UART_RX_BUF_COUNT, 1);

#if defined(CONFIG_MCUMGR_TRANSPORT_UART_ASYNC)
uint8_t async_buffer[CONFIG_MCUMGR_TRANSPORT_UART_ASYNC_BUFS]
Expand Down