From 1854383462f3ecd0fb8204ac7bcf727e9fc40d53 Mon Sep 17 00:00:00 2001 From: David Garske Date: Tue, 9 Jul 2024 16:18:08 -0700 Subject: [PATCH] Do not enable OTP write protect unless `ENABLE_OTP_WP=1` is passed during make. --- docs/flash-OTP.md | 1 + tools/keytools/otp/Makefile | 6 +++++- tools/keytools/otp/otp-keystore-primer.c | 7 +++++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/docs/flash-OTP.md b/docs/flash-OTP.md index c05e6a9b..4b2bcca2 100644 --- a/docs/flash-OTP.md +++ b/docs/flash-OTP.md @@ -92,6 +92,7 @@ make keytools 5) Setup the OTP keystore Flash the OTP keystore primer: + - Run `make otp` - Flash `./tools/keytools/otp/otp-keystore-primer.bin` to `0x08000000` - Disconnect the tool and hit reset button - The primer will run and flash keystore.c to OTP and enable write protection on those blocks diff --git a/tools/keytools/otp/Makefile b/tools/keytools/otp/Makefile index 6b89980b..7b44f3b1 100644 --- a/tools/keytools/otp/Makefile +++ b/tools/keytools/otp/Makefile @@ -32,6 +32,10 @@ CC=$(CROSS_COMPILE)gcc OBJCOPY?=$(CROSS_COMPILE)objcopy SIZE?=$(CROSS_COMPILE)size +ifeq ($(ENABLE_OTP_WP),1) + CFLAGS+=-DENABLE_OTP_WP +endif + all: otp-keystore-primer.bin otp-keystore-gen otp-keystore-gen: otp-keystore-gen.c @@ -56,7 +60,7 @@ stm32h5.o: ../../../hal/stm32h5.c $(Q)$(CC) $(CFLAGS) -c -o $@ $< - + clean: $(Q)rm -rf $(PRI_KS_OBJS) *.bin *.elf diff --git a/tools/keytools/otp/otp-keystore-primer.c b/tools/keytools/otp/otp-keystore-primer.c index ed15c40e..1a56754a 100644 --- a/tools/keytools/otp/otp-keystore-primer.c +++ b/tools/keytools/otp/otp-keystore-primer.c @@ -59,10 +59,13 @@ void main(void) sizeof(struct keystore_slot)); } - /* Protect the OTP area just written */ tot_len = OTP_HDR_SIZE + n_keys * SIZEOF_KEYSTORE_SLOT; - hal_flash_otp_set_readonly(FLASH_OTP_BASE, tot_len); +#ifdef ENABLE_OTP_WP + /* Protect the OTP area just written */ + hal_flash_otp_set_readonly(FLASH_OTP_BASE, tot_len); +#endif + (void)tot_len; /* Done! */ while(1)