Commit 1090d8ff authored by Dominik Ermel's avatar Dominik Ermel Committed by Dominik Ermel
Browse files

zephyr: Check zephyr,uart-mcumgr as candidate for serial recovery



The commit modifies selection of boot serial UART by first checking
the Zephyr chosen zephyr,uart-mcumgr and then reverting to the
zephyr,console, as a secondary candidate.
In case when both nodes are present and point to the same device,
error will be reported.

Signed-off-by: default avatarDominik Ermel <dominik.ermel@nordicsemi.no>
parent 143485e3
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -30,10 +30,21 @@ choice BOOT_SERIAL_DEVICE
config BOOT_SERIAL_UART
	bool "UART"
	# SERIAL and UART_INTERRUPT_DRIVEN already selected
	help
	  The serial device to use will be fist selected via chosen
	  node "zephyr,uart-mcumgr", when such node does not exist
	  the "zephyr,console" is used.  In case when
	  the "zephyr,uart-mcumgr" points to the same device as
	  the "zephyr,console" compilation error will be triggered.

config BOOT_SERIAL_CDC_ACM
	bool "CDC ACM"
	select USB_DEVICE_STACK
	help
	  This setting will choose CDC ACM for serial recovery unless chosen
	  "zephyr,uart-mcumgr" is present, in which case the chosen takes
	  precedence and redirects serial recovery to uart pointed by
	  the chosen, leaving console on CDC ACM.

endchoice

+18 −4
Original line number Diff line number Diff line
@@ -22,10 +22,18 @@
#include "bootutil/bootutil_log.h"
#include <zephyr/usb/usb_device.h>

#if defined(CONFIG_BOOT_SERIAL_UART) && defined(CONFIG_UART_CONSOLE)
#if defined(CONFIG_BOOT_SERIAL_UART) && defined(CONFIG_UART_CONSOLE) && \
    (!DT_HAS_CHOSEN(zephyr_uart_mcumgr) ||                              \
     DT_SAME_NODE(DT_CHOSEN(zephyr_uart_mcumgr), DT_CHOSEN(zephyr_console)))
#error Zephyr UART console must been disabled if serial_adapter module is used.
#endif

#if defined(CONFIG_BOOT_SERIAL_CDC_ACM) && \
    defined(CONFIG_UART_CONSOLE) && !DT_HAS_CHOSEN(zephyr_uart_mcumgr)
#error Zephyr UART console must been disabled if CDC ACM is enabled and MCUmgr \
       has not been redirected to other UART with DTS chosen zephyr,uart-mcumgr.
#endif

BOOT_LOG_MODULE_REGISTER(serial_adapter);

/** @brief Console input representation
@@ -191,10 +199,16 @@ boot_uart_fifo_getline(char **line)
static int
boot_uart_fifo_init(void)
{
#ifdef CONFIG_BOOT_SERIAL_UART
#if DT_HAS_CHOSEN(zephyr_uart_mcumgr)
	uart_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_uart_mcumgr));
#else

#if defined(CONFIG_BOOT_SERIAL_UART)
	uart_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_console));
#elif CONFIG_BOOT_SERIAL_CDC_ACM
#elif defined(CONFIG_BOOT_SERIAL_CDC_ACM)
        uart_dev = DEVICE_DT_GET_ONE(zephyr_cdc_acm_uart);
#endif

#endif

	if (!device_is_ready(uart_dev)) {