Skip to content

Commit fbc6f02

Browse files
committed
More documentation updates. Cleanups in the otp-keystore-gen.
1 parent e89a10d commit fbc6f02

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

docs/flash-OTP.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,25 +89,29 @@ make keytools
8989
- Copy one of the generated keys to `wolfboot_signing_private_key.der`
9090
- `cp 1.key wolfboot_signing_private_key.der`
9191

92-
5) Setup the option bytes
93-
- User Configuration 2 -> TrustZone Enable (TZEN=0xB4)
94-
- Bank1 - Flash Watermark area (SECWM1_START=0x00, SECWM1_END=0x1F)
95-
- Bank2 - Flash Watermark area (SECWM2_START=0x00, SECWM2_END=0x1F)
92+
5) Flash the OTP keystore primer:
9693

97-
6) Build wolfBoot and test application using `make`
94+
- Flash `./tools/keytools/otp/otp-keystore-primer.bin` to `0x08000000`
95+
- Disconnect the tool and hit reset button
96+
- The primer will run and flash keystore.c to OTP and enable write protection on those blocks
9897

99-
7) Flash the OTP keystore primer:
98+
OR
10099

101-
- Flash `./tools/keytools/otp/otp-keystore-primer.bin` to `0x08000000`
100+
- Run `make otpgen` and run `./tools/keytools/otp/otp-keystore-gen` to generate an otp.bin file that can be programmed using STM32CubeProgrammer to `0x08FFF000`.
102101

103-
8) Disconnect the tool and reboot
104-
- The primer will run and flash keystore.c to OTP.
105-
- Verify you flashed the keystore in OTP
102+
6) Verify you flashed the keystore in OTP
106103
- Read memory from STM32CubeProgrammer at address `0x08FFF000` (should start with ASCII "WOLFBOOT")
107104

108-
9) Mass erase the device
105+
7) Setup the option bytes
106+
- User Configuration 2 -> TrustZone Enable (TZEN=0xB4)
107+
- Bank1 - Flash Watermark area (SECWM1_START=0x00, SECWM1_END=0x1F)
108+
- Bank2 - Flash Watermark area (SECWM2_START=0x00, SECWM2_END=0x1F)
109+
110+
8) Mass erase the device
109111
- STM32CubeProgrammer -> Full chip erase
110112

113+
9) Build wolfBoot and test application using `make`
114+
111115
10) Flash wolfBoot and test-app
112116

113117
- Flash `wolfboot.bin` at `0x0C000000`

tools/keytools/otp/otp-keystore-gen.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,17 @@ int main(void)
5959

6060
/* Sanity check to avoid writing an empty keystore */
6161
if (n_keys < 1) {
62-
fprintf(stderr, "Error: too few keys (%d), refusing to create %s\n", n_keys, outfile);
62+
fprintf(stderr, "Error: too few keys (%d), refusing to create %s\n",
63+
n_keys, outfile);
6364
exit(1);
6465
}
6566

6667
slot_size = keystore_get_size(0);
6768
slot_size += KEYSTORE_HDR_SIZE;
6869
fprintf(stderr, "Slot size: %d\n", slot_size);
6970
fprintf(stderr, "Number of slots: %d\n", n_keys);
70-
fprintf(stderr, "%s size: %d\n", outfile, slot_size * n_keys + sizeof(struct wolfBoot_otp_hdr));
71+
fprintf(stderr, "%s size: %d\n", outfile, (slot_size * n_keys) +
72+
(int)sizeof(struct wolfBoot_otp_hdr));
7173

7274
ofd = open(outfile, O_WRONLY|O_CREAT|O_TRUNC, 0600);
7375
if (ofd < 0) {
@@ -84,11 +86,13 @@ int main(void)
8486
/* Write each public key to its slot in OTP */
8587
if (write(ofd, &PubKeys[i],
8688
slot_size) < 0) {
87-
fprintf(stderr, "Error adding key %d to %s: %s\n", i, outfile, strerror(errno));
88-
exit(3);
89+
fprintf(stderr, "Error adding key %d to %s: %s\n", i, outfile,
90+
strerror(errno));
91+
exit(3);
8992
}
9093
}
9194
fprintf(stderr, "%s successfully created.\nGoodbye.\n", outfile);
9295
close(ofd);
96+
9397
return 0;
9498
}

0 commit comments

Comments
 (0)