Skip to content

Commit fd80688

Browse files
committed
Added documentation on FLASH_OTP_KEYSTORE
1 parent 9dd8b7c commit fd80688

File tree

4 files changed

+59
-0
lines changed

4 files changed

+59
-0
lines changed

docs/Targets.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,11 @@ arm-none-eabi-gdb
850850
Like [STM32L5](#stm32l5) and [STM32U5](#stm32u5), STM32H5 support is also demonstrated
851851
through different scenarios.
852852

853+
Additionally, wolfBoot can be compiled with `FLASH_OTP_KEYSTORE` option, to store
854+
the public key(s) used for firmware authentication into a dedicated, one-time
855+
programmable flash area that can be write protected.
856+
For more information, see [/docs/flash-OTP.md](/docs/flash-OTP.md).
857+
853858
### Scenario 1: TrustZone enabled, staging non-secure application
854859

855860
#### Example description

docs/compile.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,10 @@ You can also manually override the fill bytes using `FILL_BYTE=` at build-time.
279279

280280
Note: if you are using an external FLASH (e.g. SPI) in combination with a flash with inverted logic, ensure that you store all the flags in one partition, by using the `FLAGS_HOME=1` option described above.
281281

282+
### Using One-time programmable (OTP) flash as keystore
283+
284+
By default, keys are directly incorporated in the firmware image. To store the keys in a separate, one-time programmable (OTP) flash memory, use the `FLASH_OTP_KEYSTORE=1` option.
285+
For more information, see [/docs/OTP-keystore.md](/docs/OTP-keystore.md).
282286

283287
### Using Mac OS/X
284288

docs/flash-OTP.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
## Using One-Time Programmable (OTP) flash area for keystore
2+
3+
Some microcontrollers provide a special area in flash memory that can
4+
only be written once and cannot be erased.
5+
6+
This feature comes particularly handy when you want to store the public keys required
7+
to authenticate the firmware update images, which has exactly the same requirements. A public
8+
key is a cryptographic key that can be freely distributed and is used to verify the signature
9+
of the firmware update image. By storing the public keys in the OTP area, you can ensure that
10+
they are immutable and cannot be tampered with.
11+
12+
### Compiling wolfBoot to access OTP as keystore
13+
14+
To use the OTP area as a keystore, you need to compile wolfBoot with the `FLASH_OTP_KEYSTORE`
15+
option enabled. This option is disabled by default, which means that the keystore is incorporated into
16+
the wolfBoot binary itself.
17+
18+
When wolfBoot uses the OTP area as a keystore, it reads the public keys from the OTP area at runtime.
19+
The public keys are stored in the OTP area, after an initial 16-byte header that contains the number of
20+
keys stored, the size of each key, and other information.
21+
22+
In order for wolfBoot to start authenticating the firmware images at boot and upon update, the public keys
23+
must be provisioned to the OTP area in a separate step, as described in the next section.
24+
25+
### Provisioning the public keys to the OTP area
26+
27+
After enabling the `FLASH_OTP_KEYSTORE` option in your `.config` file, when you compile wolfBoot by running "make",
28+
an additional application called `otp-keystore-primer` is generated under `tools/keytools/otp`. This application is used to
29+
provision the public keys to the OTP area. By flashing this application to the microcontroller, the public keys contained
30+
in your keystore (previously generated by `keygen`) are written to the OTP area.
31+
32+
The `otp-keystore-primer` application is generated with the public keys embedded in it. The keys are retrieved from the `keystore.c` file,
33+
generated by the `keygen` command. The `otp-keystore-primer` application reads the public keys from the `keystore.c` file and writes them to the OTP area.
34+
35+
After generating a new `keystore.c` with the `keygen` application, you can generate the `otp-keystore-primer` application again, by running `make otp`.
36+
37+
> [!WARNING]
38+
> The `otp-keystore-primer` application is a one-time use application. Once the application runs on your target, the public keys are written to the OTP area,
39+
> and it will be impossible to erase them. Therefore, it is important to ensure that the public keys are correct before provisioning them to the OTP area,
40+
> and that the associated private keys are stored securely. Accidentally losing the private keys will render the public keys stored in the OTP area useless.
41+
42+
> [!CAUTION]
43+
> ** Be very careful when using the `otp-keystore-primer` application. Use it at your own risk. **
44+

tools/keytools/otp/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## OTP keystore primer application
2+
3+
This application is used to provision the public keys into a dedicated FLASH OTP
4+
area. For more information about its usage, please refer to [/docs/flash-OTP.md](/docs/flash-OTP.md).
5+
6+

0 commit comments

Comments
 (0)