xtensa/esp32s2: Enable booting from MCUboot bootloader

Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>
This commit is contained in:
Gustavo Henrique Nihei
2021-09-13 13:56:55 -03:00
committed by Xiang Xiao
parent e72680bb46
commit 800678ca78
10 changed files with 1055 additions and 80 deletions
+81 -25
View File
@@ -60,36 +60,43 @@ endif
ESPTOOL_FLASH_OPTS := -fs $(FLASH_SIZE) -fm $(FLASH_MODE) -ff $(FLASH_FREQ)
# Configure the variables according to build environment
ifdef ESPTOOL_BINDIR
BL_OFFSET := 0x1000
PT_OFFSET := 0x8000
BOOTLOADER := $(ESPTOOL_BINDIR)/bootloader-esp32s2.bin
PARTITION_TABLE := $(ESPTOOL_BINDIR)/partition-table-esp32s2.bin
FLASH_BL := $(BL_OFFSET) $(BOOTLOADER)
FLASH_PT := $(PT_OFFSET) $(PARTITION_TABLE)
ESPTOOL_BINS := $(FLASH_BL) $(FLASH_PT)
ifeq ($(CONFIG_ESP32S2_APP_FORMAT_LEGACY),y)
BL_OFFSET := 0x1000
PT_OFFSET := 0x8000
BOOTLOADER := $(ESPTOOL_BINDIR)/bootloader-esp32s2.bin
PARTITION_TABLE := $(ESPTOOL_BINDIR)/partition-table-esp32s2.bin
FLASH_BL := $(BL_OFFSET) $(BOOTLOADER)
FLASH_PT := $(PT_OFFSET) $(PARTITION_TABLE)
ESPTOOL_BINS := $(FLASH_BL) $(FLASH_PT)
else ifeq ($(CONFIG_ESP32S2_APP_FORMAT_MCUBOOT),y)
BL_OFFSET := 0x1000
BOOTLOADER := $(ESPTOOL_BINDIR)/mcuboot-esp32s2.bin
FLASH_BL := $(BL_OFFSET) $(BOOTLOADER)
ESPTOOL_BINS := $(FLASH_BL)
endif
endif
ESPTOOL_BINS += 0x10000 nuttx.bin
ifeq ($(CONFIG_ESP32S2_APP_FORMAT_LEGACY),y)
APP_OFFSET := 0x10000
APP_IMAGE := nuttx.bin
FLASH_APP := $(APP_OFFSET) $(APP_IMAGE)
else ifeq ($(CONFIG_ESP32S2_APP_FORMAT_MCUBOOT),y)
ifeq ($(CONFIG_ESP32S2_ESPTOOL_TARGET_PRIMARY),y)
VERIFIED := --confirm
APP_OFFSET := $(CONFIG_ESP32S2_OTA_PRIMARY_SLOT_OFFSET)
else ifeq ($(CONFIG_ESP32S2_ESPTOOL_TARGET_SECONDARY),y)
VERIFIED :=
APP_OFFSET := $(CONFIG_ESP32S2_OTA_SECONDARY_SLOT_OFFSET)
endif
# ELF2IMAGE -- Convert an ELF file into a binary file in Espressif application image format
APP_IMAGE := nuttx.signed.bin
FLASH_APP := $(APP_OFFSET) $(APP_IMAGE)
endif
define ELF2IMAGE
$(Q) echo "MKIMAGE: ESP32-S2 binary"
$(Q) if ! esptool.py version 1>/dev/null 2>&1; then \
echo ""; \
echo "esptool.py not found. Please run: \"pip install esptool\""; \
echo ""; \
echo "Run make again to create the nuttx.bin image."; \
exit 1; \
fi
$(Q) if [ -z $(FLASH_SIZE) ]; then \
echo "Missing Flash memory size configuration for the ESP32-S2 chip."; \
exit 1; \
fi
esptool.py -c esp32s2 elf2image $(ESPTOOL_FLASH_OPTS) -o nuttx.bin nuttx
$(Q) echo "Generated: nuttx.bin (ESP32-S2 compatible)"
endef
ESPTOOL_BINS += $(FLASH_APP)
# MERGEBIN -- Merge raw binary files into a single file
@@ -114,12 +121,61 @@ define MERGEBIN
endef
endif
# SIGNBIN -- Sign the binary image file
ifeq ($(CONFIG_ESP32S2_APP_FORMAT_MCUBOOT),y)
define SIGNBIN
$(Q) echo "MKIMAGE: ESP32-S2 binary"
$(Q) if ! imgtool version 1>/dev/null 2>&1; then \
echo ""; \
echo "imgtool not found. Please run: \"pip install imgtool\""; \
echo ""; \
echo "Run make again to create the nuttx.signed.bin image."; \
exit 1; \
fi
imgtool sign --pad --pad-sig $(VERIFIED) --align 4 -v 0 \
-H $(CONFIG_ESP32S2_APP_MCUBOOT_HEADER_SIZE) --pad-header \
-S $(CONFIG_ESP32S2_OTA_SLOT_SIZE) \
nuttx.bin nuttx.signed.bin
$(Q) echo nuttx.signed.bin >> nuttx.manifest
$(Q) echo "Generated: nuttx.signed.bin (MCUboot compatible)"
endef
endif
# ELF2IMAGE -- Convert an ELF file into a binary file in Espressif application image format
ifeq ($(CONFIG_ESP32S2_APP_FORMAT_LEGACY),y)
define ELF2IMAGE
$(Q) echo "MKIMAGE: ESP32-S2 binary"
$(Q) if ! esptool.py version 1>/dev/null 2>&1; then \
echo ""; \
echo "esptool.py not found. Please run: \"pip install esptool\""; \
echo ""; \
echo "Run make again to create the nuttx.bin image."; \
exit 1; \
fi
$(Q) if [ -z $(FLASH_SIZE) ]; then \
echo "Missing Flash memory size configuration for the ESP32-S2 chip."; \
exit 1; \
fi
esptool.py -c esp32s2 elf2image $(ESPTOOL_FLASH_OPTS) -o nuttx.bin nuttx
$(Q) echo "Generated: nuttx.bin (ESP32-S2 compatible)"
endef
endif
# POSTBUILD -- Perform post build operations
ifeq ($(CONFIG_ESP32S2_APP_FORMAT_MCUBOOT),y)
define POSTBUILD
$(call SIGNBIN)
$(call MERGEBIN)
endef
else ifeq ($(CONFIG_ESP32S2_APP_FORMAT_LEGACY),y)
define POSTBUILD
$(call ELF2IMAGE)
$(call MERGEBIN)
endef
endif
# ESPTOOL_BAUD -- Serial port baud rate used when flashing/reading via esptool.py