2018-02-06 16:41:48 +01:00
|
|
|
ifdef MCUBOOT_SLOT0_SIZE
|
2017-06-20 02:34:49 +02:00
|
|
|
|
2018-03-22 17:24:10 +01:00
|
|
|
IMGTOOL ?= $(RIOTTOOLS)/mcuboot/imgtool.py
|
2017-06-20 02:34:49 +02:00
|
|
|
override IMGTOOL := $(abspath $(IMGTOOL))
|
|
|
|
|
|
|
|
BINFILE ?= $(BINDIR)/$(APPLICATION).bin
|
|
|
|
SIGN_BINFILE = $(BINDIR)/signed-$(APPLICATION).bin
|
|
|
|
MCUBOOT_KEYFILE ?= $(BINDIR)/key.pem
|
|
|
|
MCUBOOT_BIN ?= $(BINDIR)/mcuboot.bin
|
|
|
|
MCUBOOT_BIN_URL ?= http://download.riot-os.org/mynewt.mcuboot.bin
|
|
|
|
MCUBOOT_BIN_MD5 ?= 0c71a0589bd3709fc2d90f07a0035ce7
|
|
|
|
|
2017-11-07 12:27:13 +01:00
|
|
|
export IMAGE_HDR_SIZE ?= 512
|
|
|
|
|
2018-11-28 10:42:38 +01:00
|
|
|
$(MCUBOOT_KEYFILE) $(MCUBOOT_BIN): $(filter clean, $(MAKECMDGOALS))
|
|
|
|
|
2017-11-07 12:44:38 +01:00
|
|
|
mcuboot-create-key: $(MCUBOOT_KEYFILE)
|
2017-06-20 02:34:49 +02:00
|
|
|
|
|
|
|
ifeq ($(BINDIR)/key.pem,$(MCUBOOT_KEYFILE))
|
|
|
|
$(MCUBOOT_KEYFILE):
|
|
|
|
$(Q)mkdir -p $(BINDIR)
|
|
|
|
$(Q)$(IMGTOOL) keygen -k $@ -t rsa-2048
|
|
|
|
endif
|
|
|
|
|
2019-03-07 16:47:38 +01:00
|
|
|
mcuboot: ROM_OFFSET=$$(($(MCUBOOT_SLOT0_SIZE) + $(IMAGE_HDR_SIZE)))
|
2017-11-07 12:44:38 +01:00
|
|
|
mcuboot: mcuboot-create-key link
|
2017-06-20 02:34:49 +02:00
|
|
|
@$(COLOR_ECHO)
|
2018-03-22 16:20:19 +01:00
|
|
|
@$(COLOR_ECHO) '$(COLOR_PURPLE)Re-linking for MCUBoot at $(MCUBOOT_SLOT0_SIZE)...$(COLOR_RESET)'
|
2017-06-20 02:34:49 +02:00
|
|
|
@$(COLOR_ECHO)
|
2019-03-07 16:49:44 +01:00
|
|
|
$(Q)$(_LINK) -o $(ELFFILE) && \
|
2018-03-27 12:28:35 +02:00
|
|
|
$(OBJCOPY) $(OFLAGS) -Obinary $(ELFFILE) $(BINFILE) && \
|
2017-06-20 02:34:49 +02:00
|
|
|
$(IMGTOOL) sign --key $(MCUBOOT_KEYFILE) --version $(IMAGE_VERSION) --align \
|
2018-02-06 16:41:48 +01:00
|
|
|
$(MCUBOOT_IMAGE_ALIGN) -H $(IMAGE_HDR_SIZE) $(BINFILE) $(SIGN_BINFILE)
|
2017-06-20 02:34:49 +02:00
|
|
|
@$(COLOR_ECHO)
|
2018-03-22 16:20:19 +01:00
|
|
|
@$(COLOR_ECHO) '$(COLOR_PURPLE)Signed with $(MCUBOOT_KEYFILE) for version $(IMAGE_VERSION)\
|
|
|
|
$(COLOR_RESET)'
|
2017-06-20 02:34:49 +02:00
|
|
|
@$(COLOR_ECHO)
|
|
|
|
|
|
|
|
$(MCUBOOT_BIN):
|
|
|
|
$(Q)$(DLCACHE) $(MCUBOOT_BIN_URL) $(MCUBOOT_BIN_MD5) $@
|
|
|
|
|
2017-11-07 12:44:38 +01:00
|
|
|
.PHONY: mcuboot-flash-bootloader mcuboot-flash
|
2017-06-20 02:34:49 +02:00
|
|
|
|
2019-03-01 17:11:22 +01:00
|
|
|
mcuboot-flash-bootloader: FLASHFILE = $(MCUBOOT_BIN)
|
2019-03-05 14:45:48 +01:00
|
|
|
mcuboot-flash-bootloader: export FLASH_ADDR = 0x0
|
2017-11-07 12:44:38 +01:00
|
|
|
mcuboot-flash-bootloader: $(MCUBOOT_BIN) $(FLASHDEPS)
|
2019-03-05 14:45:48 +01:00
|
|
|
$(flash-recipe)
|
2017-06-20 02:34:49 +02:00
|
|
|
|
2019-03-01 17:11:22 +01:00
|
|
|
mcuboot-flash: FLASHFILE = $(SIGN_BINFILE)
|
2019-03-05 14:45:48 +01:00
|
|
|
mcuboot-flash: export FLASH_ADDR = $(MCUBOOT_SLOT0_SIZE)
|
2017-11-07 12:44:38 +01:00
|
|
|
mcuboot-flash: mcuboot $(FLASHDEPS) mcuboot-flash-bootloader
|
2019-03-05 14:45:48 +01:00
|
|
|
$(flash-recipe)
|
2017-06-20 02:34:49 +02:00
|
|
|
|
|
|
|
else
|
|
|
|
mcuboot:
|
|
|
|
$(Q)echo "error: mcuboot not supported on board $(BOARD)!"
|
|
|
|
$(Q)false
|
2018-02-06 16:41:48 +01:00
|
|
|
endif # MCUBOOT_SLOT0_SIZE
|