Skip to content

Commit

Permalink
rioboot: add option to reset to riotboot
Browse files Browse the repository at this point in the history
  • Loading branch information
benpicco committed Jan 13, 2021
1 parent 6736a92 commit 0abd083
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
7 changes: 6 additions & 1 deletion sys/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -1000,10 +1000,15 @@ endif
ifneq (,$(filter riotboot_serial, $(USEMODULE)))
FEATURES_REQUIRED += periph_flashpage
FEATURES_REQUIRED += periph_uart
USEMODULE += riotboot
USEMODULE += riotboot_reset
USEMODULE += checksum
endif

ifneq (,$(filter riotboot_reset, $(USEMODULE)))
USEMODULE += riotboot
USEMODULE += usb_board_reset
endif

ifneq (,$(filter riotboot_hdr, $(USEMODULE)))
USEMODULE += checksum
USEMODULE += riotboot
Expand Down
2 changes: 1 addition & 1 deletion sys/Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ ifneq (,$(filter prng,$(USEMODULE)))
include $(RIOTBASE)/sys/random/Makefile.include
endif

ifneq (,$(filter usbus_dfu,$(USEMODULE)))
ifneq (,$(filter usbus_dfu riotboot_reset,$(USEMODULE)))
CFLAGS += -DCPU_RAM_BASE=$(RAM_START_ADDR)
CFLAGS += -DCPU_RAM_SIZE=$(RAM_LEN)
endif
32 changes: 32 additions & 0 deletions sys/riotboot/reset.c
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
* @}
*/

#include <string.h>
#include "periph/pm.h"
#include "riotboot/magic.h"

__attribute__((weak))
void usb_board_reset_in_bootloader(void)
{
uint32_t *magic = (void*)RIOTBOOT_MAGIC_ADDR;

irq_disable();
*magic = RIOTBOOT_MAGIC;
pm_reboot();
}
8 changes: 8 additions & 0 deletions sys/riotboot/serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "unaligned.h"
#include "checksum/crc8.h"
#include "riotboot/serial.h"
#include "riotboot/magic.h"

#include "board.h"

Expand Down Expand Up @@ -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 */
static bool _bootdelay(unsigned tries, volatile bool *boot_default)
{
uint32_t *magic = (void*)RIOTBOOT_MAGIC_ADDR;

if (*magic == RIOTBOOT_MAGIC) {
*magic = 0;
return false;
}

if (tries == 0) {
return true;
}
Expand Down

0 comments on commit 0abd083

Please sign in to comment.