Skip to content

Commit 6607b66

Browse files
bigbrettdanielinux
authored andcommitted
Allow user to pass their own NVM init file
1 parent 6a1120d commit 6607b66

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

Makefile

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,29 @@ ifneq ($(USER_CERT_CHAIN),)
7878
endif
7979
endif
8080

81+
# Validate USER_NVM_INIT if provided
82+
# - USER_NVM_INIT: Path to user's NVM init file for wolfHSM NVM image generation
83+
ifneq ($(USER_NVM_INIT),)
84+
ifeq ($(wildcard $(USER_NVM_INIT)),)
85+
$(error USER_NVM_INIT file not found: $(USER_NVM_INIT))
86+
endif
87+
endif
88+
89+
# Helper variable to detect if user-provided keys are being used
90+
# This is used to skip auto-generated NVM images when users provide their own keys
91+
ifneq ($(USER_PRIVATE_KEY),)
92+
_USER_PROVIDED_KEYS:=1
93+
else ifneq ($(USER_PUBLIC_KEY),)
94+
_USER_PROVIDED_KEYS:=1
95+
else ifneq ($(USER_CERT_CHAIN),)
96+
_USER_PROVIDED_KEYS:=1
97+
endif
98+
99+
# USER_NVM_INIT overrides default NVM_CONFIG when provided
100+
ifneq ($(USER_NVM_INIT),)
101+
NVM_CONFIG:=$(USER_NVM_INIT)
102+
endif
103+
81104
ifeq ($(SIGN),NONE)
82105
PRIVATE_KEY=
83106
else
@@ -375,6 +398,13 @@ endif
375398
ifeq ($(WOLFHSM_SERVER),1)
376399
_DO_WH_NVMTOOL:=1
377400
endif
401+
# Disable NVM image generation if user-provided keys without explicit USER_NVM_INIT
402+
# (providing USER_NVM_INIT allows users to supply keys and still generate a custom NVM image)
403+
ifeq ($(_USER_PROVIDED_KEYS),1)
404+
ifeq ($(USER_NVM_INIT),)
405+
_DO_WH_NVMTOOL:=
406+
endif
407+
endif
378408
ifeq ($(_DO_WH_NVMTOOL),1)
379409
whnvmtool:
380410
@echo "Building wolfHSM NVM tool"
@@ -418,9 +448,7 @@ internal_flash.dd: $(BINASSEMBLE) wolfboot.bin $(BOOT_IMG) $(PRIVATE_KEY) test-a
418448
$(Q)dd if=/dev/zero bs=1 count=$$(($(WOLFBOOT_SECTOR_SIZE))) > /tmp/swap
419449
make assemble_internal_flash.dd
420450

421-
ifeq ($(WOLFHSM_CLIENT),1)
422-
factory.bin: $(BINASSEMBLE) wolfboot.bin $(BOOT_IMG) $(PRIVATE_KEY) test-app/image_v1_signed.bin nvm-image
423-
else ifeq ($(WOLFHSM_SERVER),1)
451+
ifeq ($(_DO_WH_NVMTOOL),1)
424452
factory.bin: $(BINASSEMBLE) wolfboot.bin $(BOOT_IMG) $(PRIVATE_KEY) test-app/image_v1_signed.bin nvm-image
425453
else
426454
factory.bin: $(BINASSEMBLE) wolfboot.bin $(BOOT_IMG) $(PRIVATE_KEY) test-app/image_v1_signed.bin

0 commit comments

Comments
 (0)