Skip to content

Commit f797140

Browse files
committed
Flash OTP missing target is warning, not error. Add TARGET_sim support
1 parent 6c31838 commit f797140

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

include/otp_keystore.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,15 @@
3030
/* Specific includes for supported targets
3131
* (needed for OTP_SIZE)
3232
*/
33+
#undef NO_FLASH_OTP_KEYSTORE_TARGET
3334
#if defined(TARGET_stm32h7)
3435
#include "hal/stm32h7.h"
3536
#elif defined(TARGET_stm32h5)
3637
#include "hal/stm32h5.h"
3738
#elif defined(TARGET_sim)
3839
#include "hal_host_sim_stub.h"
3940
#else
40-
#error "Define a target"
41+
#define NO_FLASH_OTP_KEYSTORE_TARGET
4142
#endif
4243

4344
#include "keystore.h"

tools/keytools/otp/hal_host_sim_stub.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* hal_host_sim_stub.f
1+
/* hal_host_sim_stub.c
22
*
33
* Helper for storing/retrieving Trust Anchor to/from OTP flash
44
*

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

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,26 @@
2727
#include "hal.h"
2828
#include "otp_keystore.h"
2929

30+
#ifdef NO_FLASH_OTP_KEYSTORE_TARGET
31+
/* See otp_keystore.h */
32+
#ifndef _MSC_VER
33+
#warning "No device target defined and no TARGET_sim"
34+
#else
35+
#pragma message("Warning: No device target defined and no TARGET_sim")
36+
#endif
37+
#endif
38+
39+
#ifdef TARGET_sim
40+
#include <stdio.h>
41+
#define SIM_PRINTF(...) \
42+
do { \
43+
printf(__VA_ARGS__); \
44+
fflush(stdout); \
45+
} while (0)
46+
#else
47+
#define SIM_PRINTF(...) do {} while (0)
48+
#endif
49+
3050
extern struct keystore_slot PubKeys[];
3151

3252
void main(void)
@@ -37,6 +57,8 @@ void main(void)
3757
uint32_t tot_len;
3858

3959
hal_init();
60+
SIM_PRINTF("[primer] hal_init() done\n");
61+
SIM_PRINTF("[primer] detected %d public key(s)\n", n_keys);
4062

4163
memcpy(hdr.keystore_hdr_magic, KEYSTORE_HDR_MAGIC, 8);
4264
hdr.item_count = n_keys;
@@ -45,13 +67,20 @@ void main(void)
4567

4668
/* Sanity check to avoid writing an empty keystore */
4769
if (n_keys < 1) {
70+
#ifdef TARGET_sim
71+
SIM_PRINTF("Error: too few keys (%d), refusing to write\n", n_keys);
72+
exit(1);
73+
#else
4874
while(1)
4975
;
76+
/* no exit */
77+
#endif
5078
}
5179

5280
/* Write the header to the beginning of the OTP memory */
5381
hal_flash_otp_write(FLASH_OTP_BASE, (uint16_t *)&hdr, sizeof(hdr));
54-
82+
SIM_PRINTF("[primer] wrote OTP header at 0x%08lX (size %lu)\n",
83+
(unsigned long)FLASH_OTP_BASE, (unsigned long)sizeof(hdr));
5584
for (i = 0; i < n_keys; i++) {
5685
/* Write each public key to its slot in OTP */
5786
hal_flash_otp_write(FLASH_OTP_BASE +
@@ -67,8 +96,13 @@ void main(void)
6796
#endif
6897
(void)tot_len;
6998

99+
#ifdef TARGET_sim
100+
SIM_PRINTF("Done!\n");
101+
exit(0);
102+
#else
70103
/* Done! */
71104
while(1)
72105
;
73-
106+
/* no exit */
107+
#endif
74108
}

0 commit comments

Comments
 (0)