Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bootloaders/riotboot/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ APPLICATION = riotboot

# Include riotboot flash partition functionality
USEMODULE += riotboot_slot
USEMODULE += riotboot_flashwrite

# We don't want to re-configure any hardware
CFLAGS += -DDISABLE_BOARD_INIT=1
Expand Down
35 changes: 8 additions & 27 deletions bootloaders/riotboot/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,41 +20,22 @@
* @}
*/

#include "cpu.h"
#include "panic.h"
#include "riotboot/bootloader.h"
#include "riotboot/slot.h"
#include "riotboot/wdt.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;
}
}

riotboot_hdr_t riot_hdr;
int slot = riotboot_bootloader_get_slot(&riot_hdr);
if (slot != -1) {
#if MODULE_RIOTBOOT_WDT
unsigned boot = riotboot_hdr_get_boot_count(&riot_hdr);
riotboot_wdt_start(CONFIG_RIOTBOOT_WDT_TIMEOUT_MSEC << boot);
#endif
riotboot_slot_jump(slot);
}

/* serious trouble! nothing to boot */
while (1) {}
}

NORETURN void core_panic(core_panic_t crash_code, const char *message)
{
(void)crash_code;
(void)message;
while (1) {}
}
1 change: 1 addition & 0 deletions bootloaders/riotboot_common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ DISABLE_MODULE += pm_layered

# avoid using stdio
USEMODULE += stdio_null
USEMODULE += riotboot_bootloader

# RIOT codebase
RIOTBASE ?= $(CURDIR)/../..
Expand Down
29 changes: 3 additions & 26 deletions bootloaders/riotboot_dfu/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
* @}
*/

#include "cpu.h"
#include "panic.h"
#include "riotboot/bootloader.h"
#include "riotboot/slot.h"
#include "riotboot/usb_dfu.h"
#include "ztimer.h"
Expand Down Expand Up @@ -56,23 +55,8 @@ static bool _bootloader_alternative_mode(void)

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;
}
}
riotboot_hdr_t riot_hdr;
int slot = riotboot_bootloader_get_slot(&riot_hdr);

/* Init ztimer before starting DFU mode */
ztimer_init();
Expand All @@ -87,10 +71,3 @@ void kernel_init(void)
/* 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) {}
}
39 changes: 3 additions & 36 deletions bootloaders/riotboot_serial/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,10 @@
*/

#include "cpu.h"
#include "panic.h"
#include "riotboot/bootloader.h"
#include "riotboot/slot.h"
#include "riotboot/serial.h"

static int _get_slot(void)
{
uint32_t version = 0;
int slot = -1;

if (!IS_USED(MODULE_RIOTBOOT_SLOT)) {
return -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;
}
}

return slot;
}

static void _boot_default(int slot)
{
if (!IS_USED(MODULE_RIOTBOOT_SLOT)) {
Expand All @@ -62,7 +35,8 @@ static void _boot_default(int slot)
}

if (slot == -1) {
slot = _get_slot();
riotboot_hdr_t riot_hdr;
slot = riotboot_bootloader_get_slot(&riot_hdr);
}

if (slot != -1) {
Expand All @@ -84,10 +58,3 @@ void kernel_init(void)
/* serious trouble! nothing to boot */
while (1) {}
}

NORETURN void core_panic(core_panic_t crash_code, const char *message)
{
(void)crash_code;
(void)message;
while (1) {}
}
29 changes: 3 additions & 26 deletions bootloaders/riotboot_tinyusb_dfu/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
* @}
*/

#include "cpu.h"
#include "panic.h"
#include "riotboot/bootloader.h"
#include "riotboot/slot.h"
#include "riotboot/usb_dfu.h"
#include "ztimer.h"
Expand Down Expand Up @@ -56,23 +55,8 @@ static bool _bootloader_alternative_mode(void)

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;
}
}
riotboot_hdr_t riot_hdr;
int slot = riotboot_bootloader_get_slot(&riot_hdr);

/* Init ztimer before starting DFU mode */
ztimer_init();
Expand All @@ -87,10 +71,3 @@ void kernel_init(void)
/* 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) {}
}
13 changes: 12 additions & 1 deletion core/lib/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
#include "periph/pm.h"
#include "thread.h"
#include "stdio_base.h"

#if IS_USED(MODULE_RIOTBOOT)
# include "riotboot/slot.h"
# include "riotboot/wdt.h"
#endif
#if IS_USED(MODULE_VFS)
#include "vfs.h"
#endif
Expand Down Expand Up @@ -60,6 +63,14 @@ static void *main_trampoline(void *arg)
LOG_INFO(CONFIG_BOOT_MSG_STRING "\n");
}

#if IS_USED(MODULE_RIOTBOOT)
if (IS_USED(MODULE_RIOTBOOT_HDR_AUTO_CONFIRM)) {
riotboot_slot_confirm();
if (IS_USED(MODULE_RIOTBOOT_WDT)) {
riotboot_wdt_stop();
}
}
#endif
int res = main();

if (IS_USED(MODULE_TEST_UTILS_MAIN_EXIT_CB)) {
Expand Down
Loading
Loading