mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
sys/riotboot: add DFU support to riotboot
This commit is contained in:
parent
f3908bed9f
commit
beb0fb752c
@ -1002,6 +1002,12 @@ ifneq (,$(filter riotboot_hdr, $(USEMODULE)))
|
||||
USEMODULE += riotboot
|
||||
endif
|
||||
|
||||
ifneq (,$(filter riotboot_usb_dfu, $(USEMODULE)))
|
||||
USEMODULE += usbus_dfu
|
||||
USEMODULE += riotboot_flashwrite
|
||||
FEATURES_REQUIRED += no_idle_thread
|
||||
endif
|
||||
|
||||
ifneq (,$(filter irq_handler,$(USEMODULE)))
|
||||
USEMODULE += event
|
||||
endif
|
||||
|
69
sys/include/riotboot/usb_dfu.h
Normal file
69
sys/include/riotboot/usb_dfu.h
Normal file
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* 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_usb_dfu Initialization of USB Device Firmware
|
||||
* Upgrade for riotboot
|
||||
* @ingroup sys
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief USB DFU initialization for riotboot
|
||||
*
|
||||
* @author Dylan Laduranty <dylan.laduranty@mesotic.com>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifndef RIOTBOOT_USB_DFU_H
|
||||
#define RIOTBOOT_USB_DFU_H
|
||||
|
||||
#include "riotboot/hdr.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
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
|
||||
* @{
|
||||
*/
|
||||
#ifndef USB_DFU_MODE_SLOT0_NAME
|
||||
#define USB_DFU_MODE_SLOT0_NAME "RIOT-OS Slot 0"
|
||||
#endif
|
||||
#ifndef USB_DFU_MODE_SLOT1_NAME
|
||||
#define USB_DFU_MODE_SLOT1_NAME "RIOT-OS Slot 1"
|
||||
#endif
|
||||
#ifndef USB_APP_MODE_SLOT_NAME
|
||||
#define USB_APP_MODE_SLOT_NAME "RIOT-OS bootloader"
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @brief Initialize usbus DFU for riotboot bootloader
|
||||
*/
|
||||
void riotboot_usb_dfu_init(unsigned forced);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* RIOTBOOT_USB_DFU_H */
|
41
sys/riotboot/usb_dfu.c
Normal file
41
sys/riotboot/usb_dfu.c
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup sys_riotboot_usb_dfu
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief USB Device Firmware Upgrade initialization for riotboot
|
||||
*
|
||||
* @author Dylan Laduranty <dylan.laduranty@mesotic.com>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include "cpu.h"
|
||||
#include "thread.h"
|
||||
|
||||
#include "usb/usbus.h"
|
||||
#include "usb/dfu.h"
|
||||
#include "usb/usbus/dfu.h"
|
||||
#include "riotboot/usb_dfu.h"
|
||||
|
||||
static usbus_dfu_device_t dfu;
|
||||
static char _stack[USBUS_STACKSIZE];
|
||||
static usbus_t usbus;
|
||||
|
||||
void riotboot_usb_dfu_init(unsigned forced) {
|
||||
uint32_t *reset_addr = (uint32_t *)RIOTBOOT_DFU_ADDR;
|
||||
if (forced == 1 || *reset_addr == RIOTBOOT_MAGIC_NUMBER) {
|
||||
*reset_addr = 0;
|
||||
usbus_init(&usbus, usbdev_get_ctx(0));
|
||||
usbus_dfu_init(&usbus, &dfu, USB_DFU_PROTOCOL_DFU_MODE);
|
||||
usbus_create(_stack, USBUS_STACKSIZE, USBUS_PRIO, USBUS_TNAME, &usbus);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user