riotboot: add multislot support#10215
Conversation
|
(this PR seems to contain quite some commits that should not be here) |
| SLOT0_LEN ?= $(shell printf "0x%x" $$((($(ROM_LEN:%K=%*1024)-$(RIOTBOOT_LEN)) / $(NUM_SLOTS)))) | ||
| SLOT1_LEN ?= $(SLOT0_LEN) | ||
| SLOT0_LEN := $(SLOT0_LEN) | ||
| SLOT1_LEN := $(SLOT1_LEN) |
bootloaders/riotboot/main.c
Outdated
| int slot = -1; | ||
|
|
||
| if (slot_util_validate(slot) == 0) { | ||
| for (unsigned i = 0; i < slot_util_num_slots; i++) { |
There was a problem hiding this comment.
use riotboot_slot_numof instead?
bootloaders/riotboot/main.c
Outdated
|
|
||
| if (slot_util_validate(slot) == 0) { | ||
| for (unsigned i = 0; i < slot_util_num_slots; i++) { | ||
| const riot_hdr_t *riot_hdr = slot_util_get_hdr(i); |
There was a problem hiding this comment.
riotboot_hdr_t and riotboot_slot_get_hdr instead
bootloaders/riotboot/main.c
Outdated
| if (slot_util_validate(slot) == 0) { | ||
| for (unsigned i = 0; i < slot_util_num_slots; i++) { | ||
| const riot_hdr_t *riot_hdr = slot_util_get_hdr(i); | ||
| if (slot_util_validate(i)) { |
There was a problem hiding this comment.
riotboot_slot_validate instead
bootloaders/riotboot/main.c
Outdated
| /* skip slot if metadata broken */ | ||
| continue; | ||
| } | ||
| if (riot_hdr->start_addr != slot_util_get_image_startaddr(i)) { |
There was a problem hiding this comment.
riotboot_slot_get_image_startaddr instead
bootloaders/riotboot/main.c
Outdated
| } | ||
|
|
||
| if (slot != -1) { | ||
| slot_util_jump(slot); |
There was a problem hiding this comment.
riotboot_slot_jump instead
When a second slot is defined, the "partition table" gets a second field which represents the starting of the second slot, at a defined offset.
riotboot looks for valid, available slots and compares its version. The slot with the highest version is booted, otherwise if no valid slot is found it loops on `while(1);`
By erasing slot 1 header the slot gets invalidated. This is very useful while debugging, since we can force the bootloader to ignore anything on that slot.
A second slot is defined with a calculated size, from the remaining flash after the bootloader and the first slot. Both slots are defined as equal size, but it can be overriden.
0b5f206 to
e613cbf
Compare
|
Rebased to current master and solved issues. Should be ready for review. |
|
@kYc0o great!
|
|
@kYc0o testing on samr21: even if I flash a newer image in slot 1, it still boots slot 0. Can you reproduce the issue? |
|
It boots slot 1, for me...
However, it's not running pyexpect, it's just showing me the output. I'll have a closer look when I do a thorough review |
|
tested to work on samr21 and iotlab-m3 |
| # Ask for current slot, should be 0 (riotboot slot) | ||
| child.sendline("curslotnr") | ||
| child.expect_exact("Current slot=0") | ||
| child.expect("Current slot=[0-1]") |
There was a problem hiding this comment.
IMO if the regexp is changed, the comment above needs changing, too.
|
Looks good to me. (No time to test, though). |
|
@kaspar030 yes I tested the individual make targets, works like a charm. |
|
This PR was mislabeled as "major", which obviously it is not, hence removed the label. |
Modify the test to accept slot values 0 and 1.
e613cbf to
e0c73a2
Compare
|
Updated and force-pushed. |
e0c73a2 to
bee0af3
Compare
|
@kYc0o force-pushed some hopefully even better documentation. |
bee0af3 to
d8f64a3
Compare
|
Thanks @emmanuelsearch ! Yes, it looks better, however your commit introduced some whitespaces. |
|
@kYc0o I just fixed that hopefuly |
|
🎉 ! |
|
Yay! Thanks to everyone! |
|
Great stuff! Sorry I arrived a bit late ;) Just tested a bit on my saml21-xpro everything works out of the box! |
Contribution description
This PR adds the multislot capabilities for the riotboot bootloader. The bootloader now checks for the available slots headers and compares its version, the greatest version is kept and the corresponding slot is booted.
Testing procedure
To test the first slot:
BOARD=samr21-xpro APP_VER=$(date +%s) make -C tests/riotboot/ riotboot/flash-combined-slot0 testFor the second slot:
BOARD=samr21-xpro APP_VER=$(date +%s) make -C tests/riotboot/ riotboot/flash-slot1 testIssues/PRs references
Depends on #10065