File tree Expand file tree Collapse file tree 5 files changed +37
-5
lines changed Expand file tree Collapse file tree 5 files changed +37
-5
lines changed Original file line number Diff line number Diff line change 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 ();
Original file line number Diff line number Diff line change @@ -119,6 +119,15 @@ size_t riotboot_slot_offset(unsigned slot);
119119 */
120120void 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 *
Original file line number Diff line number Diff line change 3737ifneq (,$(filter riotboot_tinyusb_dfu, $(USEMODULE)))
3838 USEPKG += tinyusb
3939endif
40+
41+ # should be explicitly disabled
42+ DEFAULT_MODULE += riotboot_hdr_auto_activate
43+ DEFAULT_MODULE += riotboot_hdr_auto_confirm
Original file line number Diff line number Diff line change @@ -34,6 +34,3 @@ PSEUDOMODULES += riotboot_hdr_v2
3434PSEUDOMODULES += riotboot_hdr_auto_activate
3535# Confirm image on first boot once main is reached
3636PSEUDOMODULES += riotboot_hdr_auto_confirm
37- # should be explicitly disabled
38- DEFAULT_MODULE += riotboot_hdr_auto_activate
39- DEFAULT_MODULE += riotboot_hdr_auto_confirm
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments