Skip to content

Commit ab57e78

Browse files
committed
add secure boot to the platform specifications
1 parent fd330a9 commit ab57e78

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

docs/platform-specification.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,50 @@ All the tools launched to compile or upload a sketch will have the following env
768768
contain multiple space-delimited entries like `"arduino-cli/0.21.0 ArduinoIDE/2.0.0-rc1"` if this information is
769769
available.
770770

771+
### Secure Boot
772+
Some boards supports the secure boot. Basically the compiled sketch can be signed and encrypted with a [tool](#tools) before being flashed to the target board. The bootloader of the board is then responsible for starting the compiled sketch if the matching keys are used.
773+
774+
To be able to correctly carry out all the operations at the end of the build we can leverage the [post build hooks](#pre-and-post-build-hooks-since-arduino-ide-165) to sign and encrypt a binary by using `recipe.hooks.objcopy.postobjcopy.NUMBER.pattern` key in [`platform.txt`](#platformtxt). The security keys used are defined in the boards file, this way there could be different keys for different boards.
775+
776+
```
777+
[...]
778+
## Create output secure image (bin file)
779+
recipe.hooks.objcopy.postobjcopy.1.pattern={build.postbuild.cmd}
780+
#
781+
# IMGTOOL
782+
#
783+
784+
tools.imgtool.cmd=imgtool
785+
tools.imgtool.build.pattern=sign --key "{build.keys.keychain}/{build.keys.sign_key}" --encrypt "{build.keys.keychain}/{build.keys.encrypt_key}" "{build.path}/{build.project_name}.bin" "{build.path}/{build.project_name}.bin" --align {build.alignment} --max-align {build.alignment} --version {build.version} --header-size {build.header_size} --pad-header --slot-size {build.slot_size}
786+
[...]
787+
788+
```
789+
By having only `tools.TOOL_NAME.cmd` and `tools.TOOL_NAME.build.pattern`, we can customize the behavior with a [custom board option](#custom-board-options).
790+
Then in the [`boards.txt`](#boardstxt) we can define the new option to use a different `postbuild.cmd`:
791+
792+
```
793+
[...]
794+
menu.security=Security setting
795+
796+
envie_m7.menu.security.none=None
797+
envie_m7.menu.security.sien=Signature + Encryption
798+
799+
envie_m7.menu.security.sien.build.postbuild.cmd="{tools.imgtool.cmd}" {tools.imgtool.build.pattern}
800+
envie_m7.menu.security.none.build.postbuild.cmd="{tools.imgtool.cmd}" exit
801+
802+
envie_m7.menu.security.sien.build.keys.type=public_keys
803+
envie_m7.menu.security.sien.build.keys.keychain={runtime.hardware.path}/Default_Keys
804+
envie_m7.menu.security.sien.build.keys.sign_key=default-signing-key.pem
805+
envie_m7.menu.security.sien.build.keys.encrypt_key=default-encrypt-key.pem
806+
[...]
807+
```
808+
The currently we support the secure boot only with `build.keys.type=public_keys` but in the future other ways can be added.
809+
The security keys can be added with:
810+
811+
- `keys.keychain` indicates the path of the dir where to search for the custom keys to sign and encrypt a binary.
812+
- `keys.sign_key` indicates the name of the custom signing key to use to sign a binary during the compile process.
813+
- `keys.encrypt_key` indicates the name of the custom encryption key to use to encrypt a binary during the compile process.
814+
771815
### Pluggable discovery
772816

773817
Discovery tools are a special kind of tool used to find supported boards. A platform must declare one or more Pluggable
@@ -1294,7 +1338,7 @@ It can sometimes be useful to provide user selectable configuration options for
12941338
could be provided in two or more variants with different microcontrollers, or may have different crystal speed based on
12951339
the board model, and so on...
12961340

1297-
When using Arduino CLI, the option can be selected via the FQBN.
1341+
When using Arduino CLI, the option can be selected via the FQBN, or using the `--board-options` flag
12981342

12991343
In the Arduino IDE the options add extra menu items under the "Tools" menu.
13001344

0 commit comments

Comments
 (0)