xtensa/esp32: Enable boot from Espressif's port of MCUboot

Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>
This commit is contained in:
Gustavo Henrique Nihei
2021-06-23 15:26:33 -03:00
committed by Alan Carvalho de Assis
parent 1a1b1cc2b4
commit 1dfcc6ab49
12 changed files with 1077 additions and 57 deletions
+58 -12
View File
@@ -52,21 +52,51 @@ else ifeq ($(CONFIG_ESP32_FLASH_FREQ_20M),y)
FLASH_FREQ := 20m
endif
ESPTOOL_ELF2IMG_OPTS := -fs $(FLASH_SIZE) -fm $(FLASH_MODE) -ff $(FLASH_FREQ)
ifeq ($(CONFIG_ESP32_FLASH_DETECT),y)
ESPTOOL_WRITEFLASH_OPTS := -fs detect -fm dio -ff $(FLASH_FREQ)
else
ESPTOOL_WRITEFLASH_OPTS := -fs $(FLASH_SIZE) -fm dio -ff $(FLASH_FREQ)
endif
ifdef ESPTOOL_BINDIR
BL_OFFSET=0x1000
PT_OFFSET=0x8000
BOOTLOADER=$(ESPTOOL_BINDIR)/bootloader-esp32.bin
PARTITION_TABLE=$(ESPTOOL_BINDIR)/partition-table-esp32.bin
FLASH_BL=$(BL_OFFSET) $(BOOTLOADER)
FLASH_PT=$(PT_OFFSET) $(PARTITION_TABLE)
# ESPTOOL_BINDIR -- Directory for the Bootloader and Partition Table binary
# files. If not provided, assume the current directory.
ESPTOOL_BINDIR ?= .
# Configure the variables according to build environment
ifeq ($(CONFIG_ESP32_BOOTLOADER_BUILD),y)
BL_OFFSET := 0x1000
BOOTLOADER := nuttx.bin
FLASH_BL := $(BL_OFFSET) $(BOOTLOADER)
ESPTOOL_BINS := $(FLASH_BL)
else ifeq ($(CONFIG_ESP32_APP_FORMAT_LEGACY),y)
BL_OFFSET := 0x1000
PT_OFFSET := 0x8000
APP_OFFSET := 0x10000
BOOTLOADER := $(ESPTOOL_BINDIR)/bootloader-esp32.bin
PARTITION_TABLE := $(ESPTOOL_BINDIR)/partition-table-esp32.bin
APP_IMAGE := nuttx.bin
FLASH_BL := $(BL_OFFSET) $(BOOTLOADER)
FLASH_PT := $(PT_OFFSET) $(PARTITION_TABLE)
FLASH_APP := $(APP_OFFSET) $(APP_IMAGE)
ESPTOOL_BINS := $(FLASH_BL) $(FLASH_PT) $(FLASH_APP)
else ifeq ($(CONFIG_ESP32_APP_FORMAT_MCUBOOT),y)
BL_OFFSET := 0x1000
BOOTLOADER := $(ESPTOOL_BINDIR)/mcuboot-esp32.bin
FLASH_BL := $(BL_OFFSET) $(BOOTLOADER)
ifeq ($(CONFIG_ESP32_ESPTOOL_TARGET_PRIMARY),y)
VERIFIED := --confirm
APP_OFFSET := $(CONFIG_ESP32_OTA_PRIMARY_SLOT_OFFSET)
else ifeq ($(CONFIG_ESP32_ESPTOOL_TARGET_SECONDARY),y)
VERIFIED :=
APP_OFFSET := $(CONFIG_ESP32_OTA_SECONDARY_SLOT_OFFSET)
endif
APP_IMAGE := nuttx_signed.bin
FLASH_APP := $(APP_OFFSET) $(APP_IMAGE)
ESPTOOL_BINS := $(FLASH_BL) $(FLASH_APP)
endif
ifeq ($(CONFIG_ESP32_QEMU_IMAGE),y)
@@ -77,6 +107,23 @@ endif
# POSTBUILD -- Perform post build operations
ifeq ($(CONFIG_ESP32_APP_FORMAT_MCUBOOT),y)
define POSTBUILD
$(Q) echo "MKIMAGE: ESP32 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_ESP32_APP_MCUBOOT_HEADER_SIZE) --pad-header \
-S $(CONFIG_ESP32_OTA_SLOT_SIZE) \
nuttx.bin nuttx_signed.bin
$(Q) echo "Generated: nuttx_signed.bin (MCUboot compatible)"
endef
else
define POSTBUILD
$(Q) echo "MKIMAGE: ESP32 binary"
$(Q) if ! esptool.py version 1>/dev/null 2>&1; then \
@@ -90,10 +137,12 @@ define POSTBUILD
echo "Missing Flash memory size configuration for the ESP32 chip."; \
exit 1; \
fi
$(eval ESPTOOL_ELF2IMG_OPTS := -fs $(FLASH_SIZE) -fm $(FLASH_MODE) -ff $(FLASH_FREQ))
esptool.py -c esp32 elf2image $(ESPTOOL_ELF2IMG_OPTS) -o nuttx.bin nuttx
$(Q) echo "Generated: nuttx.bin (ESP32 compatible)"
$(Q) $(MK_QEMU_IMG)
endef
endif
# ESPTOOL_BAUD -- Serial port baud rate used when flashing/reading via esptool.py
@@ -102,9 +151,6 @@ ESPTOOL_BAUD ?= 921600
# DOWNLOAD -- Download binary image via esptool.py
define DOWNLOAD
$(eval ESPTOOL_BINS := $(FLASH_BL) $(FLASH_PT) 0x10000 $(1).bin)
$(Q) if [ -z $(ESPTOOL_PORT) ]; then \
echo "DOWNLOAD error: Missing serial port device argument."; \
echo "USAGE: make download ESPTOOL_PORT=<port> [ ESPTOOL_BAUD=<baud> ] [ ESPTOOL_BINDIR=<dir> ]"; \