Skip to content

Commit

Permalink
fixup! sys/riotboot: add helper functions for riotboot VFS
Browse files Browse the repository at this point in the history
  • Loading branch information
benpicco committed Dec 13, 2021
1 parent cea7078 commit c6c3b34
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions sys/riotboot/vfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@
#include "periph/flashpage.h"
#include "riotboot/vfs.h"

static const void *_first_free_page(const void *start)
/* try to guess the end of the firmware */
static const void *_first_free_chunk(const void *start)
{
const uword_t *cur = start;
const uword_t *end = flashpage_addr(FLASHPAGE_NUMOF);
uword_t empty;
unsigned i = flashpage_page(start);
unsigned const chunk_size = 256;
memset(&empty, FLASHPAGE_ERASE_STATE, sizeof(empty));

/* try to find the first unused page */
Expand All @@ -39,7 +40,7 @@ static const void *_first_free_page(const void *start)
cur[2] == empty && cur[3] == empty) {
break;
}
cur += flashpage_size(i++);
cur += chunk_size;
}

return cur;
Expand All @@ -51,7 +52,7 @@ int riotboot_vfs_dump_rom(const char* file)

if (IS_ACTIVE(RIOTBOOT)) {
start = (void *)(uintptr_t)SLOT0_OFFSET;
end = _first_free_page(start);
end = _first_free_chunk(start);
} else {
start = flashpage_addr(flashpage_first_used());
end = flashpage_addr(flashpage_first_free());
Expand Down

0 comments on commit c6c3b34

Please sign in to comment.