Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

riotboot: implement serial flasher #15493

Merged
merged 11 commits into from
Jul 21, 2021
Merged

Conversation

benpicco
Copy link
Contributor

@benpicco benpicco commented Nov 22, 2020

Contribution description

I got annoyed by boards that require wiring up a programmer and that are finicky to flash.
Therefore I added a simple protocol to riotboot that allows to erase sectors / write data over a serial connection.

There are only four commands:

  • erase sector
  • get sector of address
  • write data to address
  • boot

This comes with a custom flash tool (riotboot_serial) that is used to transfer the firmware onto a board using riotboot.
So far, this is only wired up for the sam0 family (and comes with a patch that fixes a hard fault on samd5x when writing small chunks).

edit also added efm32 and nrf52, successfully flashed boards using riotboot serial with those platforms.

The flash tool is rather simple and does not do proper error handling yet (it expects the user to just interrupt it if it gets stuck).
The lines from the .hex file are converted to binary

I considered sending raw lines from the .hex file directly, but decided against so the bootloader doesn't have to parse text.
Also sending binary over the wire should be faster.

If the sync protocol makes sense / the 'double sync' is necessary is up for debate, also batching multiple lines of the hex file would probably be faster.

There is also no support for doing anything with riotboot headers yet.
If they are part of the hex file and can be handled transparently, it should just work, but I did not test this.

Testing procedure

For the riotboot bootloader, enable the riotboot_serial and disable riotboot_slot.
It is possible to have both modules active at the same time, but then riotboot will also check if the slot has a valid header, which makes testing/firmware generation more complicated.

With this configuration, 'raw' images (plain RIOT firmware) will boot.

--- a/bootloaders/riotboot/Makefile
+++ b/bootloaders/riotboot/Makefile
@@ -21,10 +21,10 @@ DISABLE_MODULE += auto_init auto_init_%
 USEMODULE += stdio_null
 
 # Include riotboot flash partition functionality
-USEMODULE += riotboot_slot
+# USEMODULE += riotboot_slot
 
 # Include serial bootloader functionality
-# USEMODULE += riotboot_serial
+USEMODULE += riotboot_serial

Now you should be able to flash any RIOT application using PROGRAMMER=riotboot_serial. Start the flashing procedure, then reset the board for the flasher to sync up with the bootloader.
You can also enable the riotboot_reset module which gives you the bootloader command to reboot to the bootloader from the shell.

Issues/PRs references

@benpicco benpicco added Area: tools Area: Supplementary tools Type: new feature The issue requests / The PR implemements a new feature for RIOT State: demonstrator State: This PR (loosely) demonstrates a concept and is not necessarily meant to be merged. labels Nov 22, 2020
@benpicco benpicco changed the title rioboot: implement serial flasher riotboot: implement serial flasher Nov 22, 2020
sys/riotboot/reset.c Outdated Show resolved Hide resolved
@aabadie
Copy link
Contributor

aabadie commented Nov 23, 2020

For the CI, I would also add:

  • a step for dist/tools/riotboot_serial in the tools-buildtest action
  • a test application like test/riotboot_serial

Otherwise the code in this PR is not built on Murdock.

@dylad
Copy link
Member

dylad commented Nov 23, 2020

How about creating a new application under bootloader/ instead ?
something like bootloader/riotboot_serial ?
Otherwise bootloader/riotboot will become a mess with serial flasher and DFU addition...

@benpicco benpicco added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed State: demonstrator State: This PR (loosely) demonstrates a concept and is not necessarily meant to be merged. labels Jan 13, 2021
@benpicco benpicco force-pushed the riotboot-serial branch 2 times, most recently from 02f418c to 9ea597b Compare January 13, 2021 21:38
@fjmolinas
Copy link
Contributor

For the CI, I would also add:

* a step for ` dist/tools/riotboot_serial` in the tools-buildtest action

* a test application like `test/riotboot_serial`

Otherwise the code in this PR is not built on Murdock.

These change requests seem to still be pending. I'll give this a test

RIOTBOOT_SERIAL := $(RIOTTOOLS)/riotboot_serial/riotboot_serial

FLASHER ?= $(RIOTBOOT_SERIAL)
FLASHFILE ?= $(HEXFILE)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why a hex file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because it contains the target addresses and is easy to parse

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it should check that the firmware to be flashed is a hex then (should still be overridable in case a user specifies a firmware path)

@github-actions github-actions bot added Area: sys Area: System Area: USB Area: Universal Serial Bus Platform: ARM Platform: This PR/issue effects ARM-based platforms labels Jul 4, 2021
@fjmolinas
Copy link
Contributor

@benpicco do you think it's possible to add a README.md for the new bootloader? Something simple on how the BOARD needs to be bootstrapped and flashed?

@benpicco benpicco force-pushed the riotboot-serial branch 2 times, most recently from fcd15fc to b999329 Compare July 6, 2021 17:42
Comment on lines +4 to +5
# Include riotboot flash partition functionality
# USEMODULE += riotboot_slot
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's better to remove riotboot_slot, right now the bootloader can't possible support riotboot_slot since it can only flash hexfiles and all riotboot functionality relies on flashing bin.

Sure it could initially be bootstrapped with a riotboot_serial + riotboot_slot firmware but no firmware upgrades over serial can be made.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, although that's not a limitation of the bootloader but the flasher tool

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, but will it make sense to use the bootloader in that case?

@fjmolinas
Copy link
Contributor

Please squash!

@fjmolinas
Copy link
Contributor

Ah wai

Please squash!

Ah wait this is still missing:

For the CI, I would also add:

a step for dist/tools/riotboot_serial in the tools-buildtest action
a test application like test/riotboot_serial

Otherwise the code in this PR is not built on Murdock.

@MrKevinWeiss MrKevinWeiss removed this from the Release 2021.07 milestone Jul 15, 2021
@fjmolinas
Copy link
Contributor

@benpicco can you add:

diff --git a/.github/workflows/tools-buildtest.yml b/.github/workflows/tools-buildtest.yml
index fee41ab581..7cd5e28d21 100644
--- a/.github/workflows/tools-buildtest.yml
+++ b/.github/workflows/tools-buildtest.yml
@@ -71,3 +71,7 @@ jobs:
       uses: aabadie/riot-action@v1
       with:
         cmd: make -C dist/tools/lpc2k_pgm
+    - name: Build riotboot_serial tool
+      uses: aabadie/riot-action@v1
+      with:
+        cmd: make -C dist/tools/riotboot_serial

You can squash afterwards.

@github-actions github-actions bot added the Area: CI Area: Continuous Integration of RIOT components label Jul 20, 2021
Copy link
Contributor

@fjmolinas fjmolinas left a comment

Choose a reason for hiding this comment

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

ACK, I think there is still some improvements to be had (in the future) like being able to flash binaries, but the current state works already and is usable for many applications BOARD's where an external programmer is currently needed.

@benpicco
Copy link
Contributor Author

Thank you for the review!

@benpicco benpicco merged commit 4f905bf into RIOT-OS:master Jul 21, 2021
@benpicco benpicco deleted the riotboot-serial branch July 21, 2021 09:01
@benpicco benpicco added this to the Release 2021.10 milestone Oct 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: boards Area: Board ports Area: build system Area: Build system Area: CI Area: Continuous Integration of RIOT components Area: cpu Area: CPU/MCU ports Area: doc Area: Documentation Area: Kconfig Area: Kconfig integration Area: sys Area: System Area: tools Area: Supplementary tools Area: USB Area: Universal Serial Bus CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Platform: ARM Platform: This PR/issue effects ARM-based platforms 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.

5 participants