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: Dominik Ermel <dominik.ermel@nordicsemi.no>
diff --git a/boot/zephyr/serial_adapter.c b/boot/zephyr/serial_adapter.c
index 9b6e76c..42af952 100644
--- a/boot/zephyr/serial_adapter.c
+++ b/boot/zephyr/serial_adapter.c
@@ -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 @@
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
- uart_dev = DEVICE_DT_GET_ONE(zephyr_cdc_acm_uart);
+#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)) {