diff --git a/bootloaders/riotboot_dfu/doc.txt b/bootloaders/riotboot_dfu/doc.txt index eeed1e98a2..f67ffb77a7 100644 --- a/bootloaders/riotboot_dfu/doc.txt +++ b/bootloaders/riotboot_dfu/doc.txt @@ -14,7 +14,7 @@ At startup, the DFU mode is entered when either - the first button was pressed when the board started (configurable at board level using @ref BTN_BOOTLOADER_PIN), or -- the last running firmware asked the bootloader to go to DFU mode by using a magic number (see @ref RIOTBOOT_DFU_ADDR). +- the last running firmware asked the bootloader to go to DFU mode by using a magic number (see @ref RIOTBOOT_MAGIC_ADDR). # Prerequisites diff --git a/sys/include/riotboot/magic.h b/sys/include/riotboot/magic.h new file mode 100644 index 0000000000..5ca8fcaf2f --- /dev/null +++ b/sys/include/riotboot/magic.h @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2020 Mesotic SAS + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup sys_riotboot_magic Magic values for riotboot + * @ingroup sys + * @{ + * + * @file + * @brief USB DFU/serial initialization constants for riotboot + * + * @author Dylan Laduranty + * + * @} + */ + +#ifndef RIOTBOOT_MAGIC_H +#define RIOTBOOT_MAGIC_H + +#include "riotboot/hdr.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @name USB RAM information for riotboot + * @{ + */ +#ifndef RIOTBOOT_MAGIC_ADDR +#define RIOTBOOT_MAGIC_ADDR (CPU_RAM_BASE + CPU_RAM_SIZE - 4) /**< default magic address */ +#endif +#ifndef RIOTBOOT_MAGIC_NUMBER +#define RIOTBOOT_MAGIC_NUMBER RIOTBOOT_MAGIC /**< default magic value */ +#endif +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* RIOTBOOT_MAGIC_H */ diff --git a/sys/include/riotboot/usb_dfu.h b/sys/include/riotboot/usb_dfu.h index 3eab034041..f1157099fe 100644 --- a/sys/include/riotboot/usb_dfu.h +++ b/sys/include/riotboot/usb_dfu.h @@ -29,18 +29,6 @@ extern "C" { #endif -/** - * @name USB DFU RAM information for riotboot - * @{ - */ -#ifndef RIOTBOOT_DFU_ADDR -#define RIOTBOOT_DFU_ADDR (CPU_RAM_BASE + CPU_RAM_SIZE - 4) /**< DFU default magic address */ -#endif -#ifndef RIOTBOOT_MAGIC_NUMBER -#define RIOTBOOT_MAGIC_NUMBER RIOTBOOT_MAGIC /**< DFU default magic value */ -#endif -/** @} */ - /** * @name USB DFU Default slots name * @{ diff --git a/sys/riotboot/usb_dfu.c b/sys/riotboot/usb_dfu.c index 4b82b173d9..7606fe5e23 100644 --- a/sys/riotboot/usb_dfu.c +++ b/sys/riotboot/usb_dfu.c @@ -24,6 +24,7 @@ #include "usb/usbus.h" #include "usb/dfu.h" #include "usb/usbus/dfu.h" +#include "riotboot/magic.h" #include "riotboot/usb_dfu.h" static usbus_dfu_device_t dfu; @@ -32,7 +33,7 @@ static usbus_t usbus; void riotboot_usb_dfu_init(unsigned forced) { - uint32_t *reset_addr = (uint32_t *)RIOTBOOT_DFU_ADDR; + uint32_t *reset_addr = (uint32_t *)RIOTBOOT_MAGIC_ADDR; if (forced == 1 || *reset_addr == RIOTBOOT_MAGIC_NUMBER) { *reset_addr = 0; diff --git a/sys/usb/usbus/dfu/Kconfig b/sys/usb/usbus/dfu/Kconfig index 55039b7427..f9934b67d6 100644 --- a/sys/usb/usbus/dfu/Kconfig +++ b/sys/usb/usbus/dfu/Kconfig @@ -23,13 +23,13 @@ config USB_DFU_DETACH_TIMEOUT_MS the host USB. Host USB should abort the pending operation if device doesn't detach after this timeout. -config CUSTOM_RIOTBOOT_DFU_ADDR +config CUSTOM_RIOTBOOT_MAGIC_ADDR bool "Use custom DFU magic address" help Say n to use the default address, which is the last in RAM. -config RIOTBOOT_DFU_ADDR +config RIOTBOOT_MAGIC_ADDR int "DFU magic address" - depends on CUSTOM_RIOTBOOT_DFU_ADDR + depends on CUSTOM_RIOTBOOT_MAGIC_ADDR endif # KCONFIG_USEMODULE_USBUS_DFU diff --git a/sys/usb/usbus/dfu/dfu.c b/sys/usb/usbus/dfu/dfu.c index 272118f00b..ee1a26409b 100644 --- a/sys/usb/usbus/dfu/dfu.c +++ b/sys/usb/usbus/dfu/dfu.c @@ -23,6 +23,7 @@ #include "usb/usbus.h" #include "usb/usbus/control.h" #include "usb/usbus/dfu.h" +#include "riotboot/magic.h" #include "riotboot/usb_dfu.h" #ifdef MODULE_RIOTBOOT_USB_DFU #include "xtimer.h" @@ -169,7 +170,7 @@ static void _dfu_class_control_req(usbus_t *usbus, usbus_dfu_device_t *dfu, usb_ /* Detach USB bus */ usbdev_set(usbus->dev, USBOPT_ATTACH, &disable, sizeof(usbopt_enable_t)); /* Restart and jump into the bootloader */ - uint32_t *reset_addr = (uint32_t *)RIOTBOOT_DFU_ADDR; + uint32_t *reset_addr = (uint32_t *)RIOTBOOT_MAGIC_ADDR; *reset_addr = RIOTBOOT_MAGIC_NUMBER; pm_reboot(); break;