forked from skullbox305/RIOT
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bootloader: create new bootloader application with DFU support
- Loading branch information
Showing
2 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Default RIOT bootloader | ||
APPLICATION = riotboot_dfu | ||
|
||
# Default testing board | ||
BOARD ?= samr21-xpro | ||
|
||
# Select the boards with riotboot feature | ||
FEATURES_REQUIRED += riotboot | ||
|
||
# Set RIOTBOOT_BUILD to indicate a riotboot application build | ||
RIOTBOOT_BUILD = 1 | ||
# Provide a define to detect if building the bootloader | ||
CFLAGS += -DRIOTBOOT | ||
|
||
# Disable unused modules | ||
CFLAGS += -DNDEBUG -DLOG_LEVEL=LOG_NONE | ||
DISABLE_MODULE += core_init core_msg core_panic | ||
DISABLE_MODULE += auto_init auto_init_% | ||
|
||
# avoid using stdio | ||
USEMODULE += stdio_null | ||
|
||
# Include riotboot flash partition functionality | ||
USEMODULE += riotboot_slot | ||
|
||
# Add RIOTBOOT USB DFU integration | ||
USEMODULE=riotboot_usb_dfu | ||
|
||
# Use xtimer for scheduled reboot | ||
USEMODULE += xtimer | ||
|
||
# RIOT codebase | ||
RIOTBASE ?= $(CURDIR)/../../ | ||
|
||
# USB device vendor and product ID | ||
# pid.codes test VID/PID, not globally unique | ||
|
||
USB_VID ?= ${USB_VID_TESTING} | ||
USB_PID ?= ${USB_PID_TESTING} | ||
|
||
include $(RIOTBASE)/Makefile.include | ||
|
||
# limit riotboot bootloader size | ||
# TODO: Manage to set this variable for boards which already embed a | ||
# bootloader, currently it will be overwritten | ||
ROM_LEN := $(RIOTBOOT_LEN) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright (C) 2017 Kaspar Schleiser <[email protected]> | ||
* Inria | ||
* 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 bootloaders | ||
* @{ | ||
* | ||
* @file | ||
* @brief RIOT-based bootloader with USB-DFU support | ||
* | ||
* @author Kaspar Schleiser <[email protected]> | ||
* @author Francisco Acosta <[email protected]> | ||
* @author Dylan Laduranty <[email protected]> | ||
* | ||
* @} | ||
*/ | ||
|
||
#include "cpu.h" | ||
#include "panic.h" | ||
#include "riotboot/slot.h" | ||
#include "riotboot/usb_dfu.h" | ||
|
||
void kernel_init(void) | ||
{ | ||
uint32_t version = 0; | ||
int slot = -1; | ||
|
||
for (unsigned i = 0; i < riotboot_slot_numof; i++) { | ||
const riotboot_hdr_t *riot_hdr = riotboot_slot_get_hdr(i); | ||
if (riotboot_slot_validate(i)) { | ||
/* skip slot if metadata broken */ | ||
continue; | ||
} | ||
if (riot_hdr->start_addr != riotboot_slot_get_image_startaddr(i)) { | ||
continue; | ||
} | ||
if (slot == -1 || riot_hdr->version > version) { | ||
version = riot_hdr->version; | ||
slot = i; | ||
} | ||
} | ||
|
||
/* Flash the unused slot if magic word is set */ | ||
riotboot_usb_dfu_init(0); | ||
|
||
if (slot != -1) { | ||
riotboot_slot_jump(slot); | ||
} | ||
|
||
/* Nothing to boot, stay in DFU mode to flash a slot */ | ||
riotboot_usb_dfu_init(1); | ||
} | ||
|
||
NORETURN void core_panic(core_panic_t crash_code, const char *message) | ||
{ | ||
(void)crash_code; | ||
(void)message; | ||
while (1) {} | ||
} |