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/Kconfig.serial_recovery b/boot/zephyr/Kconfig.serial_recovery
index b48ee9b..e703d59 100644
--- a/boot/zephyr/Kconfig.serial_recovery
+++ b/boot/zephyr/Kconfig.serial_recovery
@@ -30,10 +30,21 @@
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
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)) {