[riot-notifications] [RIOT-OS/RIOT] rioboot: implement serial flasher (#15493)

benpicco notifications at github.com
Sun Nov 22 21:11:17 CET 2020

### Contribution description

I got annoyed by boards that require wiring up a debugger 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).

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.

### 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`. 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

Examples: Fixes #1234. See also #5678. Depends on PR #9876.

Please use keywords (e.g., fixes, resolve) with the links to the issues you
resolved, this way they will be automatically closed when your pull request
is merged. See https://help.github.com/articles/closing-issues-using-keywords/.

You can view, comment on, or merge this pull request online at:


-- Commit Summary --

  * cpu/sam0_common: flashpage: enable Automatic Quad Word Write
  * riotboot: implement serial bootloader feature
  * tools/riotboot_serial: add flasher tool for riotboot serial loader
  * bootloaders/riotboot: add serial bootloader feature
  * makefiles: add riotboot_serial as flash tool
  * rioboot: add option to reset to riotboot

-- File Changes --

    M bootloaders/riotboot/Makefile (3)
    M bootloaders/riotboot/main.c (34)
    M cpu/sam0_common/periph/flashpage.c (5)
    A dist/tools/riotboot_serial/Makefile (14)
    A dist/tools/riotboot_serial/main.c (331)
    A dist/tools/riotboot_serial/serial.c (166)
    M makefiles/boards/sam0.inc.mk (3)
    A makefiles/tools/riotboot_serial.inc.mk (13)
    M sys/Makefile.dep (12)
    M sys/Makefile.include (4)
    A sys/include/riotboot/serial.h (117)
    A sys/riotboot/Makefile.reset.include (3)
    A sys/riotboot/reset.c (32)
    A sys/riotboot/serial.c (301)

-- Patch Links --


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20201122/b5d5653c/attachment.htm>

More information about the notifications mailing list