rioboot: add option to reset to riotboot

This commit is contained in:
Benjamin Valentin 2020-11-22 19:38:21 +01:00 committed by Benjamin Valentin
parent cabe639d04
commit a05723e5cb
4 changed files with 47 additions and 2 deletions

View File

@ -625,10 +625,15 @@ endif
ifneq (,$(filter riotboot_serial, $(USEMODULE))) ifneq (,$(filter riotboot_serial, $(USEMODULE)))
FEATURES_REQUIRED += periph_flashpage FEATURES_REQUIRED += periph_flashpage
FEATURES_REQUIRED += periph_uart FEATURES_REQUIRED += periph_uart
USEMODULE += riotboot USEMODULE += riotboot_reset
USEMODULE += checksum USEMODULE += checksum
endif endif
ifneq (,$(filter riotboot_reset, $(USEMODULE)))
USEMODULE += riotboot
USEMODULE += usb_board_reset
endif
ifneq (,$(filter riotboot_hdr, $(USEMODULE))) ifneq (,$(filter riotboot_hdr, $(USEMODULE)))
USEMODULE += checksum USEMODULE += checksum
USEMODULE += riotboot USEMODULE += riotboot

View File

@ -141,7 +141,7 @@ ifneq (,$(filter prng,$(USEMODULE)))
include $(RIOTBASE)/sys/random/Makefile.include include $(RIOTBASE)/sys/random/Makefile.include
endif endif
ifneq (,$(filter usbus_dfu,$(USEMODULE))) ifneq (,$(filter usbus_dfu riotboot_reset,$(USEMODULE)))
CFLAGS += -DCPU_RAM_BASE=$(RAM_START_ADDR) CFLAGS += -DCPU_RAM_BASE=$(RAM_START_ADDR)
CFLAGS += -DCPU_RAM_SIZE=$(RAM_LEN) CFLAGS += -DCPU_RAM_SIZE=$(RAM_LEN)
endif endif

32
sys/riotboot/reset.c Normal file
View File

@ -0,0 +1,32 @@
/*
* Copyright (C) 2020 Benjamin Valentin
*
* 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_serial
* @{
*
* @file
* @brief Trigger reset to riotboot.
*
* @author Benjamin Valentin <benpicco@googlemail.com>
* @}
*/
#include <string.h>
#include "periph/pm.h"
#include "riotboot/magic.h"
__attribute__((weak))
void usb_board_reset_in_bootloader(void)
{
uint32_t *magic = (void *)(uintptr_t)RIOTBOOT_MAGIC_ADDR;
irq_disable();
*magic = RIOTBOOT_MAGIC;
pm_reboot();
}

View File

@ -27,6 +27,7 @@
#include "unaligned.h" #include "unaligned.h"
#include "checksum/crc8.h" #include "checksum/crc8.h"
#include "riotboot/serial.h" #include "riotboot/serial.h"
#include "riotboot/magic.h"
#include "board.h" #include "board.h"
@ -55,6 +56,13 @@ static inline void uart_write_byte(uart_t uart, uint8_t data)
/* send 'hello' byte until we get enter bootloader byte or timeout */ /* send 'hello' byte until we get enter bootloader byte or timeout */
static bool _bootdelay(unsigned tries, volatile bool *boot_default) static bool _bootdelay(unsigned tries, volatile bool *boot_default)
{ {
uint32_t *magic = (void *)(uintptr_t)RIOTBOOT_MAGIC_ADDR;
if (*magic == RIOTBOOT_MAGIC) {
*magic = 0;
return false;
}
if (tries == 0) { if (tries == 0) {
return true; return true;
} }