-
Notifications
You must be signed in to change notification settings - Fork 2.1k
[WIP] Add RIOT Bootloader and multislot firmware management #7396
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
Conversation
|
Marking WIP since I need to remove tweetnacl sources (and rather download them as a package). Forgot to mention: it only works on samr21-xpro for now. New boards will be added very soon, as only a few defines are needed per board. |
|
@kYc0o thanks for the work! Are there dependencies on other PRs? I added in hello-world example the following lines to try this PR out: But when I |
|
Oh! Not really, I didn't rebase yet to include the ota_update_tftp. Will do asap. |
|
please check my multislot branch. it basically does the same (based on your prior work). I'm afk still, so cannot comment on differences, other than it uses simple tftp push (and verification on the fly). it also has a slightly more sophisticated tool for key mansgement and signing images. |
|
@kaspar030 Actually this PR is the merge of the your multislot branch and my previous work. I didn't see any OTA mechanism though. This also includes your key management with some bugs corrected, as well as a better management of the keys. The OTA module is almost done, the download is successful but the node reboots in a loop, I'm investigating... |
|
The OTA module is pushed on #7398. This can be reviewed separately as it only includes the multislot approach to divide the internal ROM in 3 slots. I tested it with the OTA module with success on a samr21-xpro. |
4eafb13 to
928339c
Compare
|
Tweetnacl sources removed and added support for iotlab-m3. No more WIP. |
|
@kYc0o Hi, can you tell me what is wrong here? dimitri@dimitri-Latitude-E6410:~/RIOT/examples/hello-world$ BOARD=samr21-xpro make multislot Providing default crypto keys to current firmware. Building application "hello-world" for "samr21-xpro" with MCU "samd21". "make" -C /home/dimitri/RIOT/boards/samr21-xpro "make" -C /home/dimitri/RIOT/pkg/tweetnacl |
|
Uhm... did you modify the bootloader? According to the message you're using more ROM than its allowed for the bootloader (16KB). With the default configuration the bootloader should be ~15KB |
|
No, the bootloader is unchanged. |
|
I just built the same example and it gives me these sizes: Hello world: text data bss dec hex filename
8612 136 2748 11496 2ce8 /Users/facosta/git/RIOT2/RIOT/examples/hello-world/bin/samr21-xpro/hello-world.elfBootloader: text data bss dec hex filename
15432 168 6464 22064 5630 /Users/facosta/git/RIOT2/RIOT/bootloader/bin/samr21-xpro/bootloader.elfI see that you're using arm-none-eabi-gcc 5.4, I was in that version before and the numbers were quite similar... Did you have a special config? because your firmwares are 2K bigger in any situation. |
|
@kYc0o Thanks, it works with arm-none-eabi-gcc 6.3.1. |
|
Closing this PR as it's a subset of #8902, that one offers a similar bootloader and the multislot approach. |
Third effort to add the RIOT bootloader and the tools to manage internal ROM slots based on @kaspar030 work.
This PR provides the use of a bootloader to verify the integrity of the firmware prior to boot. This ensures the firmware comes from a trusted entity and also ensure its integrity, since two things are verified:
This prevents to boot firmwares from a non-trusted source, as well as malformed firmwares if they're downloaded over the air.
Compiling a valid image
This PR provides several make targets to build, link, and flash valid images into a selected set of boards. The targets are listed as:
make bootloader: Builds and links the bootloader (only valid for the bootloader application)make multislot: Builds, links and signs an application for the two slots which are available in the internal ROM of the MCU board.make combined: Creates Ready-To-Send images for both slots, including metadata and signatures.make verify: Verifies if the image's signature is valid, using the provided public key.make flash-multislot: Builds, links, sings and flashes an image including the bootloader and the application on the first slot. Flashing the bootlaoder with the application in slot 2 is not supported.make multislot-clean: Deletes all the files created by any of the previous targetsWith this commands several files are created, namely:
slot, with its corresponding metadata ready to be sent over the air.
bootloader and the application on the first slot. It is used to flash it directly on the
board.
Very useful for debugging purposes.
You can find these files in the binary folder of your application.
Managing signatures
RIOT already provides tools for creating Ed52219 signatures using tweetnacl. We prefer this implementation for its easy to use and compact presentation, but we're putting efforts to export this to a more robust implementation of this curve.
If you execute one of the above commands, and no keys are given, a pair of keys will be created and stored on the bin folder of your application. This are named
ed25519.pubanded25519.sec. The public key is then exported to the include path which will be embedded on the bootloader firmware.If you want to provide your own keys (remember, only Ed25519 is supported) you can provide them through the environment variables
PUBKEYandSECKEY, e.g.:or whatever the name they have. The public key will be automatically exported to the bootloader.
Requirements for building and flashing
You may require
bcfor building the multislot firmware. This is required since we need to do computations with the provided variables in the MakefileIn Debian based platforms
sudo apt-get install bcwould suffice.