Skip to content

riotboot: add multislot support#10215

Merged
emmanuelsearch merged 6 commits intoRIOT-OS:masterfrom
kYc0o:pr/riotboot_multislot
Jan 15, 2019
Merged

riotboot: add multislot support#10215
emmanuelsearch merged 6 commits intoRIOT-OS:masterfrom
kYc0o:pr/riotboot_multislot

Conversation

@kYc0o
Copy link
Copy Markdown
Contributor

@kYc0o kYc0o commented Oct 19, 2018

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 test

For the second slot:

BOARD=samr21-xpro APP_VER=$(date +%s) make -C tests/riotboot/ riotboot/flash-slot1 test

Issues/PRs references

Depends on #10065

@kYc0o kYc0o added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Platform: ARM Platform: This PR/issue effects ARM-based platforms State: WIP State: The PR is still work-in-progress and its code is not in its final presentable form yet Type: new feature The issue requests / The PR implemements a new feature for RIOT Impact: major The PR changes a significant part of the code base. It should be reviewed carefully State: waiting for other PR State: The PR requires another PR to be merged first Area: OTA Area: Over-the-air updates labels Oct 19, 2018
@emmanuelsearch
Copy link
Copy Markdown
Member

@kYc0o needs a rebase on #10065

@emmanuelsearch
Copy link
Copy Markdown
Member

(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)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kYc0o @cladmi are lines 37-38 not redundant with what precedes?

int slot = -1;

if (slot_util_validate(slot) == 0) {
for (unsigned i = 0; i < slot_util_num_slots; i++) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use riotboot_slot_numof instead?


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);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

riotboot_hdr_t and riotboot_slot_get_hdr instead

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)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

riotboot_slot_validate instead

/* skip slot if metadata broken */
continue;
}
if (riot_hdr->start_addr != slot_util_get_image_startaddr(i)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

riotboot_slot_get_image_startaddr instead

}

if (slot != -1) {
slot_util_jump(slot);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

riotboot_slot_jump instead

Francisco Acosta and others added 4 commits January 2, 2019 17:56
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.
@kYc0o kYc0o force-pushed the pr/riotboot_multislot branch from 0b5f206 to e613cbf Compare January 2, 2019 17:13
@kYc0o kYc0o added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR CI: run tests If set, CI server will run tests on hardware for the labeled PR and removed State: WIP State: The PR is still work-in-progress and its code is not in its final presentable form yet State: waiting for other PR State: The PR requires another PR to be merged first labels Jan 2, 2019
@kYc0o
Copy link
Copy Markdown
Contributor Author

kYc0o commented Jan 2, 2019

Rebased to current master and solved issues. Should be ready for review.

@kYc0o kYc0o added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Jan 3, 2019
@emmanuelsearch
Copy link
Copy Markdown
Member

@kYc0o great!
For wannabe testers, how about slightly more documentation (in the README?)
For instance a concrete example of commands which

  1. build and flash bootloader + an image in slot0
  2. how to observe that slot0 is booted
  3. build and flash a (distinguishable) image in slot1
  4. how to observe that slot1 is booted

@emmanuelsearch
Copy link
Copy Markdown
Member

emmanuelsearch commented Jan 8, 2019

@kYc0o testing on samr21: even if I flash a newer image in slot 1, it still boots slot 0. Can you reproduce the issue?

@danpetry danpetry self-requested a review January 9, 2019 09:40
@danpetry
Copy link
Copy Markdown
Contributor

danpetry commented Jan 9, 2019

It boots slot 1, for me...
Concretely, I did the following:

  1. Plug in samr21
  2. Run BOARD=samr21-xpro APP_VER=$(date +%s) make -C tests/riotboot/ riotboot/flash-combined-slot0 test from RIOT base dir
  3. Observe "Current slot = 0" in output
  4. Run BOARD=samr21-xpro APP_VER=$(date +%s) make -C tests/riotboot/ riotboot/flash-slot1 test from RIOT base dir
  5. Observe "Current slot = 1" in output

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

@emmanuelsearch
Copy link
Copy Markdown
Member

@kYc0o @danpetry tested again, can't reproduce my issue, so let's go forward as is for now, I'd say.

@emmanuelsearch
Copy link
Copy Markdown
Member

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]")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO if the regexp is changed, the comment above needs changing, too.

@kaspar030
Copy link
Copy Markdown
Contributor

Looks good to me. (No time to test, though).
@emmanuelsearch did you test the individual make tagets (flash0-combined, extended, ...)?

@kaspar030 kaspar030 added Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Reviewed: 2-code-design The code design of the PR was reviewed according to the maintainer guidelines Reviewed: 4-code-style The adherence to coding conventions by the PR were reviewed according to the maintainer guidelines labels Jan 14, 2019
@emmanuelsearch
Copy link
Copy Markdown
Member

@kaspar030 yes I tested the individual make targets, works like a charm.

@emmanuelsearch emmanuelsearch removed the Impact: major The PR changes a significant part of the code base. It should be reviewed carefully label Jan 14, 2019
@emmanuelsearch
Copy link
Copy Markdown
Member

This PR was mislabeled as "major", which obviously it is not, hence removed the label.

@emmanuelsearch emmanuelsearch added the Reviewed: 3-testing The PR was tested according to the maintainer guidelines label Jan 14, 2019
Modify the test to accept slot values 0 and 1.
@kYc0o kYc0o force-pushed the pr/riotboot_multislot branch from e613cbf to e0c73a2 Compare January 14, 2019 17:32
@kYc0o
Copy link
Copy Markdown
Contributor Author

kYc0o commented Jan 14, 2019

Updated and force-pushed.

@emmanuelsearch emmanuelsearch added the Reviewed: 5-documentation The documentation details of the PR were reviewed according to the maintainer guidelines label Jan 15, 2019
@emmanuelsearch
Copy link
Copy Markdown
Member

emmanuelsearch commented Jan 15, 2019

@kYc0o force-pushed some hopefully even better documentation.

@kYc0o
Copy link
Copy Markdown
Contributor Author

kYc0o commented Jan 15, 2019

Thanks @emmanuelsearch ! Yes, it looks better, however your commit introduced some whitespaces.

@emmanuelsearch
Copy link
Copy Markdown
Member

@kYc0o I just fixed that hopefuly

@emmanuelsearch emmanuelsearch merged commit 209d90b into RIOT-OS:master Jan 15, 2019
@bergzand
Copy link
Copy Markdown
Member

🎉 !

@kYc0o
Copy link
Copy Markdown
Contributor Author

kYc0o commented Jan 15, 2019

Yay! Thanks to everyone!

@fedepell
Copy link
Copy Markdown
Contributor

Great stuff! Sorry I arrived a bit late ;)

Just tested a bit on my saml21-xpro everything works out of the box!

@kYc0o kYc0o deleted the pr/riotboot_multislot branch January 21, 2019 10:56
@aabadie aabadie added this to the Release 2019.01 milestone Jan 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: OTA Area: Over-the-air updates CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR CI: run tests If set, CI server will run tests on hardware for the labeled PR Platform: ARM Platform: This PR/issue effects ARM-based platforms Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Reviewed: 2-code-design The code design of the PR was reviewed according to the maintainer guidelines Reviewed: 3-testing The PR was tested according to the maintainer guidelines Reviewed: 4-code-style The adherence to coding conventions by the PR were reviewed according to the maintainer guidelines Reviewed: 5-documentation The documentation details of the PR were reviewed according to the maintainer guidelines Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Type: new feature The issue requests / The PR implemements a new feature for RIOT

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants