Skip to content

Commit fc1fb44

Browse files
committed
tutorial updated and tested
1 parent 5290724 commit fc1fb44

File tree

2 files changed

+42
-10
lines changed

2 files changed

+42
-10
lines changed
1.28 MB
Loading

content/hardware/04.pro/boards/portenta-h7/tutorials/secure-boot/secure-boot.md

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ description: 'Learn how to use secure boot on the Arduino Portenta H7.'
44
difficulty: beginner
55
tags:
66
- Secure Boot
7-
author: 'Umberto Baldi'
7+
author: 'Umberto Baldi & Christopher Méndez'
88
hardware:
99
- hardware/04.pro/boards/portenta-h7
1010

1111
software:
12-
- ide-v1
1312
- ide-v2
1413
- cli
1514
---
@@ -35,6 +34,27 @@ In order to enable the secure boot, you must **update** the bootloader on your P
3534

3635
Once the bootloader has been updated, it is possible to use [secure boot](https://www.keyfactor.com/blog/what-is-secure-boot-its-where-iot-security-starts/) to have an additional layer of security.
3736

37+
### Format the QSPI Flash
38+
39+
First, before enabling the secure boot feature on your Portenta H7, you might need to format the QSPI flash memory.
40+
41+
For this, navigate to **File > Examples > STM32H747_System > QSPIFormat** and follow the steps below:
42+
43+
![QSPIFormat example code](assets/qspi-format.png)
44+
45+
- Upload the **QSPIFormat** example to your Portenta H7.
46+
- Open the Arduino IDE Serial Monitor.
47+
- Follow the steps shown in the Serial Monitor.
48+
49+
You will be asked for:
50+
51+
- Permission to proceed and **erase** the QSPI flash. Type `Y` in the Serial Monitor and press enter.
52+
- Once done, you will be asked to **restore** the WiFi firmware. Type `Y` in the Serial Monitor and press enter.
53+
- Select between **LitteFS** or **FatFS** to format user partition. Type `Y` for LittleFS or `No` for FatFS.
54+
- Wait for the process to be done. It should say something like "It is now secure to reboot or disconnect the board".
55+
56+
Now you are ready to jump to the following step to enable the secure boot.
57+
3858
### Use Default Security Keys
3959

4060
Upload the `enableSecurity` example sketch that can be found under **File > Examples > MCUboot** in the IDE upper menu.
@@ -60,7 +80,8 @@ From that point on, you must configure your future sketches **Security setting**
6080

6181
***Not configuring this setting will cause the bootloader not to run the compiled sketch because it is not trusted.***
6282

63-
### 1. Generate Custom Security Keys
83+
### Generate Custom Security Keys
84+
6485
The default keys provided with the mbed platform are obviously only intended for development purposes. In a production environment it is strongly recommended to generate a new key pair (public and private key).
6586
This can be done with **imgtool**. You can download and install it directly from the [release section](https://github.com/arduino/imgtool-packing/releases/latest).
6687

@@ -72,17 +93,17 @@ The tool can be found in:
7293
- `~/.arduino15/packages/arduino/tools/imgtool` on Linux.
7394
- `~/Library/Arduino15/packages/arduino/tools/imgtool` on macOS.
7495

75-
To generate the new keys you can use this command line:
96+
To **generate** the new keys you can use this command line:
7697

7798
```bash
7899
imgtool keygen --key my-sign-keyfile.pem -t ecdsa-p256
79100
imgtool keygen --key my-encrypt-keyfile.pem -t ecdsa-p256
80101
```
81102
This command line will generate two private PEM encoded security keys and save them in the current directory with `my-sign-keyfile.pem` and `my-encrypt-keyfile.pem` names. The algorithm used to generate the keys is ECDSA 256bit.
82103

83-
Remember to **save the keys and keep them in a secure location** and not to lose them.
104+
***Remember to __save the keys and keep them in a secure location__ and not to lose them.***
84105

85-
### 2. Upload the Custom Keys to the Board
106+
### Upload the Custom Keys to the Board
86107
Once the keys have been generated, they have to be uploaded to the Portenta H7. This procedure has to be done only once, because it is persistent. To extract the public\private key and encode it in to a "C" byte array inside a `.h` header file you can use:
87108

88109
```bash
@@ -94,16 +115,27 @@ Now you have to replace the keys inside the `enableSecurity` sketch found under
94115

95116
To do so, just save the sketch to another location and replace the `ecsda-p256-encrypt-priv-key.h` and `ecsda-p256-signing-pub-key.h` files with the newly generated ones and then upload the sketch again.
96117

97-
***NOTE: In case the keys are compromised, this process can be performed again with a new set of keys, but any firmware signed with the previous pair will no longer work.***
118+
***__NOTE:__ In case the keys are compromised, this process can be performed again with a new set of keys, but any firmware signed with the previous pair will no longer work.***
98119

99-
### 3. Use the Custom Keys when Compiling
120+
### Use the Custom Keys when Compiling
100121
Since the default keys have been changed in favour of custom generated ones, the new ones have to be used when compiling and uploading a sketch, because the compiled sketch is signed and encrypted using such keys.
101122

102-
To override the security keys used during the compilation, you have to use the Arduino CLI and specify the keys with:
123+
To override the security keys used during the compilation, we recommend using the **Arduino CLI** and specify the keys with:
103124

104125
```bash
105126
arduino-cli compile -b arduino:mbed_portenta:envie_m7 --board-options security=sien --keys-keychain <path-to-your-keys> --sign-key ecdsa-p256-signing-priv-key.pem --encrypt-key ecdsa-p256-encrypt-pub-key.pem <directory-of-sketch-to-compile>
106127
```
107128

129+
You can also navigate to your `mbed_portenta` core found in:
130+
131+
- `%LOCALAPPDATA%\Arduino15\packages\arduino\hardware\mbed_portenta\x.x.x\boards.txt` (this may vary depending on the operating system).
132+
- Then, change the default location your IDE search for the security keys by updating these lines inside the `boards.txt` file:
133+
134+
```bash
135+
envie_m7.menu.security.sien.build.keys.keychain={runtime.platform.path}/libraries/MCUboot/default_keys
136+
envie_m7.menu.security.sien.build.keys.sign_key=ecdsa-p256-signing-priv-key.pem
137+
envie_m7.menu.security.sien.build.keys.encrypt_key=ecdsa-p256-encrypt-pub-key.pem
138+
```
139+
108140
## Learn More
109-
If you want to implement secure boot for your platform, have a look at [this article](https://arduino.github.io/arduino-cli/latest/guides/secure-boot/).
141+
If you want to implement secure boot for your platform, take a look at [this article](https://arduino.github.io/arduino-cli/latest/guides/secure-boot/).

0 commit comments

Comments
 (0)