Skip to content

Commit 7e94bdf

Browse files
committed
fixup! sys/riotboot: riotboot head v2
1 parent b3d988b commit 7e94bdf

File tree

5 files changed

+37
-5
lines changed

5 files changed

+37
-5
lines changed

core/lib/init.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "thread.h"
3232
#include "stdio_base.h"
3333
#if IS_USED(MODULE_RIOTBOOT)
34+
# include "riotboot/slot.h"
3435
# include "riotboot/wdt.h"
3536
#endif
3637
#if IS_USED(MODULE_VFS)
@@ -63,8 +64,11 @@ static void *main_trampoline(void *arg)
6364
}
6465

6566
#if IS_USED(MODULE_RIOTBOOT)
66-
if (IS_USED(MODULE_RIOTBOOT_HDR_MAIN_CONFIRM)) {
67-
riotboot_wdt_stop();
67+
if (IS_USED(MODULE_RIOTBOOT_HDR_AUTO_CONFIRM)) {
68+
riotboot_slot_confirm();
69+
if (IS_USED(MODULE_RIOTBOOT_WDT)) {
70+
riotboot_wdt_stop();
71+
}
6872
}
6973
#endif
7074
int res = main();

sys/include/riotboot/slot.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,15 @@ size_t riotboot_slot_offset(unsigned slot);
119119
*/
120120
void riotboot_slot_dump_addrs(void);
121121

122+
/**
123+
* @brief Confirm the currently running image slot
124+
*
125+
* This function sets the image state to CONFIRMED in the header of the
126+
* currently running image, if it is in ACTIVATED state.
127+
* It must be called manually if not module `riotboot_hdr_auto_confirm` is used.
128+
*/
129+
void riotboot_slot_confirm(void);
130+
122131
/**
123132
* @brief Get the size of a slot
124133
*

sys/riotboot/Makefile.dep

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,7 @@ endif
3737
ifneq (,$(filter riotboot_tinyusb_dfu, $(USEMODULE)))
3838
USEPKG += tinyusb
3939
endif
40+
41+
# should be explicitly disabled
42+
DEFAULT_MODULE += riotboot_hdr_auto_activate
43+
DEFAULT_MODULE += riotboot_hdr_auto_confirm

sys/riotboot/Makefile.include

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,3 @@ PSEUDOMODULES += riotboot_hdr_v2
3434
PSEUDOMODULES += riotboot_hdr_auto_activate
3535
# Confirm image on first boot once main is reached
3636
PSEUDOMODULES += riotboot_hdr_auto_confirm
37-
# should be explicitly disabled
38-
DEFAULT_MODULE += riotboot_hdr_auto_activate
39-
DEFAULT_MODULE += riotboot_hdr_auto_confirm

sys/riotboot/slot.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828

2929
#include "container.h"
3030
#include "cpu.h"
31+
#ifdef MODULE_PERIPH_FLASHPAGE
32+
# include "periph/flashpage.h"
33+
#endif
3134
#include "riotboot/slot.h"
3235
#include "riotboot/hdr.h"
3336

@@ -103,3 +106,18 @@ size_t riotboot_slot_offset(unsigned slot)
103106
{
104107
return (size_t)riotboot_slot_get_hdr(slot) - CPU_FLASH_BASE;
105108
}
109+
110+
void riotboot_slot_confirm(void)
111+
{
112+
int slot = riotboot_slot_current();
113+
riotboot_hdr_t riot_hdr = *riotboot_slot_get_hdr(slot);
114+
if (riotboot_hdr_is_v2(&riot_hdr)) {
115+
riotboot_hdr_set_img_state(&riot_hdr, RIOTBOOT_HDR_IMG_STATE_CONFIRMED);
116+
if (memcmp(&riot_hdr, riotboot_slot_get_hdr(slot), sizeof(riot_hdr.v2))) {
117+
#ifdef MODULE_PERIPH_FLASHPAGE
118+
flashpage_write(flashpage_addr(flashpage_page(riotboot_slot_get_hdr(slot))),
119+
&riot_hdr.v2, sizeof(riot_hdr.v2));
120+
#endif
121+
}
122+
}
123+
}

0 commit comments

Comments
 (0)