|
| 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 | +
|
0 commit comments