Skip to content
Open
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
8 changes: 8 additions & 0 deletions boot/zephyr/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,14 @@ config BOOT_USB_DFU_DETECT_DELAY
Useful for powering on when using the same button as
the one used to place the device in bootloader mode.

config BOOT_USB_DFU_BOOT_MODE
bool "Check boot mode via retention subsystem"
depends on RETENTION_BOOT_MODE
help
Allows for entering USB DFU mode by using Zephyr's boot mode
retention system (i.e. an application must set the boot mode to stay
in USB DFU mode and reboot the module).

config BOOT_USB_DFU_NO_APPLICATION
bool "Stay in bootloader if no application"
help
Expand Down
3 changes: 2 additions & 1 deletion boot/zephyr/include/mcuboot_config/mcuboot_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,8 @@
#endif

#if (defined(CONFIG_BOOT_USB_DFU_WAIT) || \
defined(CONFIG_BOOT_USB_DFU_GPIO))
defined(CONFIG_BOOT_USB_DFU_GPIO) || \
defined(CONFIG_BOOT_USB_DFU_BOOT_MODE))
#define MCUBOOT_USB_DFU
#endif

Expand Down
6 changes: 4 additions & 2 deletions boot/zephyr/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ BOOT_LOG_MODULE_DECLARE(mcuboot);
#include <zephyr/drivers/hwinfo.h>
#endif

#if defined(CONFIG_BOOT_SERIAL_BOOT_MODE) || defined(CONFIG_BOOT_FIRMWARE_LOADER_BOOT_MODE)
#if defined(CONFIG_BOOT_SERIAL_BOOT_MODE) || defined(CONFIG_BOOT_FIRMWARE_LOADER_BOOT_MODE) \
|| defined(CONFIG_BOOT_USB_DFU_BOOT_MODE)
#include <zephyr/retention/bootmode.h>
#endif

Expand Down Expand Up @@ -197,7 +198,8 @@ bool io_detect_pin_reset(void)
}
#endif

#if defined(CONFIG_BOOT_SERIAL_BOOT_MODE) || defined(CONFIG_BOOT_FIRMWARE_LOADER_BOOT_MODE)
#if defined(CONFIG_BOOT_SERIAL_BOOT_MODE) || defined(CONFIG_BOOT_FIRMWARE_LOADER_BOOT_MODE) \
|| defined(CONFIG_BOOT_USB_DFU_BOOT_MODE)
bool io_detect_boot_mode(void)
{
int32_t boot_mode;
Expand Down
25 changes: 22 additions & 3 deletions boot/zephyr/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ const struct boot_uart_funcs boot_funcs = {
};
#endif

#if defined(CONFIG_BOOT_USB_DFU_WAIT) || defined(CONFIG_BOOT_USB_DFU_GPIO)
#if defined(CONFIG_BOOT_USB_DFU_WAIT) || defined(CONFIG_BOOT_USB_DFU_GPIO) \
|| defined(CONFIG_BOOT_USB_DFU_BOOT_MODE)
#include <zephyr/usb/class/usb_dfu.h>
#endif

Expand Down Expand Up @@ -187,7 +188,8 @@ int main(void)
{
struct boot_rsp rsp;
int rc;
#if defined(CONFIG_BOOT_USB_DFU_GPIO) || defined(CONFIG_BOOT_USB_DFU_WAIT)
#if defined(CONFIG_BOOT_USB_DFU_GPIO) || defined(CONFIG_BOOT_USB_DFU_WAIT) || \
defined(CONFIG_BOOT_USB_DFU_BOOT_MODE)
bool usb_dfu_requested = false;
bool usb_dfu_forever = false;
#endif
Expand Down Expand Up @@ -258,7 +260,24 @@ int main(void)
usb_dfu_requested = true;
#endif

#if defined(CONFIG_BOOT_USB_DFU_GPIO) || defined(CONFIG_BOOT_USB_DFU_WAIT)
#if defined(CONFIG_BOOT_USB_DFU_BOOT_MODE)
BOOT_LOG_DBG("Checking boot mode for USB DFU request");
if (io_detect_boot_mode()) {
BOOT_LOG_DBG("Staying in USB DFU");

usb_dfu_requested = true;
usb_dfu_forever = true;

#ifdef CONFIG_MCUBOOT_INDICATION_LED
io_led_set(1);
#endif

mcuboot_status_change(MCUBOOT_STATUS_USB_DFU_ENTERED);
}
#endif

#if defined(CONFIG_BOOT_USB_DFU_GPIO) || defined(CONFIG_BOOT_USB_DFU_WAIT) || \
defined(CONFIG_BOOT_USB_DFU_BOOT_MODE)
if (usb_dfu_requested) {
rc = usb_enable(NULL);
if (rc) {
Expand Down
Loading