2016-08-17 11:08:22 -04:00
|
|
|
#
|
|
|
|
# Bootloader component
|
|
|
|
#
|
|
|
|
# The bootloader is not a real component that gets linked into the project.
|
|
|
|
# Instead it is an entire standalone project ( in src/) that gets built in
|
|
|
|
# the upper projects build directory. This Makefile.projbuild provides the
|
|
|
|
# glue to build the bootloader project from the original project. It
|
|
|
|
# basically runs Make in the src/ directory but it needs to zero some variables
|
2016-08-19 02:30:39 -04:00
|
|
|
# the ESP-IDF project.mk makefile exports first, to not let them interfere.
|
2016-08-17 11:08:22 -04:00
|
|
|
#
|
2016-10-21 02:44:34 -04:00
|
|
|
ifndef IS_BOOTLOADER_BUILD
|
2016-08-17 11:08:22 -04:00
|
|
|
|
|
|
|
BOOTLOADER_COMPONENT_PATH := $(COMPONENT_PATH)
|
2016-10-06 03:05:51 -04:00
|
|
|
BOOTLOADER_BUILD_DIR=$(abspath $(BUILD_DIR_BASE)/bootloader)
|
2016-08-18 00:36:15 -04:00
|
|
|
BOOTLOADER_BIN=$(BOOTLOADER_BUILD_DIR)/bootloader.bin
|
2016-10-04 00:38:20 -04:00
|
|
|
BOOTLOADER_SDKCONFIG=$(BOOTLOADER_BUILD_DIR)/sdkconfig
|
2016-08-17 11:08:22 -04:00
|
|
|
|
2016-11-03 02:33:30 -04:00
|
|
|
# both signing key paths are resolved relative to the project directory
|
|
|
|
SECURE_BOOTLOADER_KEY=$(abspath $(call dequote,$(CONFIG_SECURE_BOOTLOADER_KEY_FILE)))
|
|
|
|
SECURE_BOOT_SIGNING_KEY=$(abspath $(call dequote,$(CONFIG_SECURE_BOOT_SIGNING_KEY)))
|
|
|
|
export SECURE_BOOT_SIGNING_KEY # used by bootloader_support component
|
2016-10-31 19:50:16 -04:00
|
|
|
|
2016-10-04 00:03:48 -04:00
|
|
|
# Custom recursive make for bootloader sub-project
|
2016-10-06 03:29:34 -04:00
|
|
|
BOOTLOADER_MAKE=+$(MAKE) -C $(BOOTLOADER_COMPONENT_PATH)/src \
|
|
|
|
V=$(V) SDKCONFIG=$(BOOTLOADER_SDKCONFIG) \
|
2016-11-01 19:41:58 -04:00
|
|
|
BUILD_DIR_BASE=$(BOOTLOADER_BUILD_DIR) IS_BOOTLOADER_BUILD=1
|
2016-10-04 00:03:48 -04:00
|
|
|
|
2016-11-03 02:33:30 -04:00
|
|
|
|
2016-08-24 00:26:13 -04:00
|
|
|
.PHONY: bootloader-clean bootloader-flash bootloader $(BOOTLOADER_BIN)
|
2016-08-17 11:08:22 -04:00
|
|
|
|
2016-10-04 00:38:20 -04:00
|
|
|
$(BOOTLOADER_BIN): | $(BOOTLOADER_BUILD_DIR)/sdkconfig
|
2016-10-04 00:03:48 -04:00
|
|
|
$(Q) $(BOOTLOADER_MAKE) $@
|
2016-08-17 11:08:22 -04:00
|
|
|
|
|
|
|
bootloader-clean:
|
2016-10-04 00:38:20 -04:00
|
|
|
$(Q) $(BOOTLOADER_MAKE) app-clean config-clean
|
|
|
|
$(Q) rm -f $(BOOTLOADER_SDKCONFIG) $(BOOTLOADER_SDKCONFIG).old
|
2016-08-17 11:08:22 -04:00
|
|
|
|
2016-08-18 05:11:27 -04:00
|
|
|
clean: bootloader-clean
|
|
|
|
|
2016-10-31 19:50:16 -04:00
|
|
|
ifdef CONFIG_SECURE_BOOTLOADER_DISABLED
|
|
|
|
# If secure boot disabled, bootloader flashing is integrated
|
|
|
|
# with 'make flash' and no warnings are printed.
|
|
|
|
|
2016-08-18 00:36:15 -04:00
|
|
|
bootloader: $(BOOTLOADER_BIN)
|
2016-10-31 19:50:16 -04:00
|
|
|
@echo "$(SEPARATOR)"
|
2016-08-18 04:59:38 -04:00
|
|
|
@echo "Bootloader built. Default flash command is:"
|
2016-08-22 06:43:47 -04:00
|
|
|
@echo "$(ESPTOOLPY_WRITE_FLASH) 0x1000 $(BOOTLOADER_BIN)"
|
2016-08-17 11:08:22 -04:00
|
|
|
|
2016-08-18 05:11:27 -04:00
|
|
|
ESPTOOL_ALL_FLASH_ARGS += 0x1000 $(BOOTLOADER_BIN)
|
|
|
|
|
2016-08-17 11:08:22 -04:00
|
|
|
bootloader-flash: $(BOOTLOADER_BIN)
|
2016-10-04 00:03:48 -04:00
|
|
|
$(BOOTLOADER_MAKE) flash
|
|
|
|
|
2016-10-31 19:50:16 -04:00
|
|
|
else ifdef CONFIG_SECURE_BOOTLOADER_ONE_TIME_FLASH
|
|
|
|
# One time flashing requires user to run esptool.py command themselves,
|
|
|
|
# and warning is printed about inability to reflash.
|
|
|
|
|
|
|
|
bootloader: $(BOOTLOADER_BIN)
|
|
|
|
@echo $(SEPARATOR)
|
|
|
|
@echo "Bootloader built. One-time flash command is:"
|
|
|
|
@echo "$(ESPTOOLPY_WRITE_FLASH) 0x1000 $(BOOTLOADER_BIN)"
|
|
|
|
@echo $(SEPARATOR)
|
|
|
|
@echo "* IMPORTANT: After first boot, BOOTLOADER CANNOT BE RE-FLASHED on same device"
|
|
|
|
|
|
|
|
else ifdef CONFIG_SECURE_BOOTLOADER_REFLASHABLE
|
2016-11-03 02:33:30 -04:00
|
|
|
# Reflashable secure bootloader
|
|
|
|
# generates a digest binary (bootloader + digest)
|
2016-10-31 19:50:16 -04:00
|
|
|
|
|
|
|
BOOTLOADER_DIGEST_BIN=$(BOOTLOADER_BUILD_DIR)/bootloader-reflash-digest.bin
|
|
|
|
|
|
|
|
bootloader: $(BOOTLOADER_DIGEST_BIN)
|
|
|
|
@echo $(SEPARATOR)
|
|
|
|
@echo "Bootloader built and secure digest generated. First time flash command is:"
|
2016-11-03 02:33:30 -04:00
|
|
|
@echo "$(ESPEFUSEPY) burn_key secure_boot $(SECURE_BOOTLOADER_KEY)"
|
2016-10-31 19:50:16 -04:00
|
|
|
@echo "$(ESPTOOLPY_WRITE_FLASH) 0x1000 $(BOOTLOADER_BIN)"
|
|
|
|
@echo $(SEPARATOR)
|
|
|
|
@echo "To reflash the bootloader after initial flash:"
|
|
|
|
@echo "$(ESPTOOLPY_WRITE_FLASH) 0x0 $(BOOTLOADER_DIGEST_BIN)"
|
|
|
|
@echo $(SEPARATOR)
|
|
|
|
@echo "* After first boot, only re-flashes of this kind (with same key) will be accepted."
|
2016-11-01 02:41:27 -04:00
|
|
|
@echo "* Not recommended to re-use the same secure boot keyfile on multiple production devices."
|
2016-10-31 19:50:16 -04:00
|
|
|
|
2016-11-03 02:33:30 -04:00
|
|
|
$(BOOTLOADER_DIGEST_BIN): $(BOOTLOADER_BIN) $(SECURE_BOOTLOADER_KEY)
|
|
|
|
@echo "DIGEST $(notdir $@)"
|
|
|
|
$(Q) $(ESPSECUREPY) digest_secure_bootloader -k $(SECURE_BOOTLOADER_KEY) -o $@ $<
|
2016-10-31 19:50:16 -04:00
|
|
|
|
2016-11-03 02:33:30 -04:00
|
|
|
$(SECURE_BOOTLOADER_KEY):
|
2016-10-31 19:50:16 -04:00
|
|
|
@echo $(SEPARATOR)
|
2016-11-03 02:33:30 -04:00
|
|
|
@echo "Need to generate secure boot signing key. Run following command:"
|
2016-10-31 19:50:16 -04:00
|
|
|
@echo "$(ESPSECUREPY) generate_key $@"
|
|
|
|
@echo "Keep key file safe after generating."
|
2016-11-03 02:33:30 -04:00
|
|
|
@echo "(See secure boot documentation for caveats & alternatives.)")
|
2016-10-31 19:50:16 -04:00
|
|
|
@exit 1
|
|
|
|
|
|
|
|
else
|
2016-11-01 19:41:58 -04:00
|
|
|
bootloader:
|
|
|
|
@echo "Invalid bootloader target: bad sdkconfig?"
|
|
|
|
@exit 1
|
2016-10-31 19:50:16 -04:00
|
|
|
endif
|
|
|
|
|
|
|
|
all_binaries: $(BOOTLOADER_BIN)
|
|
|
|
|
2016-10-04 00:38:20 -04:00
|
|
|
# synchronise the project level config to the bootloader's
|
|
|
|
# config
|
|
|
|
$(BOOTLOADER_SDKCONFIG): $(PROJECT_PATH)/sdkconfig | $(BOOTLOADER_BUILD_DIR)
|
|
|
|
$(Q) cp $< $@
|
|
|
|
|
|
|
|
$(BOOTLOADER_BUILD_DIR):
|
|
|
|
$(Q) mkdir -p $@
|
2016-09-12 23:46:51 -04:00
|
|
|
|
2016-09-14 14:37:54 -04:00
|
|
|
else
|
|
|
|
CFLAGS += -D BOOTLOADER_BUILD=1 -I $(IDF_PATH)/components/esp32/include
|
|
|
|
|
2016-09-12 23:46:51 -04:00
|
|
|
endif
|