Skip to content

Commit

Permalink
Do not enable OTP write protect unless ENABLE_OTP_WP=1 is passed du…
Browse files Browse the repository at this point in the history
…ring make.
  • Loading branch information
dgarske committed Jul 9, 2024
1 parent 463cc32 commit 1854383
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/flash-OTP.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion tools/keytools/otp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -56,7 +60,7 @@ stm32h5.o: ../../../hal/stm32h5.c
$(Q)$(CC) $(CFLAGS) -c -o $@ $<




clean:
$(Q)rm -rf $(PRI_KS_OBJS) *.bin *.elf
7 changes: 5 additions & 2 deletions tools/keytools/otp/otp-keystore-primer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1854383

Please sign in to comment.