1
0
Fork 0
forked from nuttx/nuttx-update

tools/esp32[s2,c3]: Extract POSTBUILD operations into functions

Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>
This commit is contained in:
Gustavo Henrique Nihei 2021-09-04 07:28:53 -03:00 committed by Abdelatif Guettouche
parent 310a2dd0e4
commit adef19704d
3 changed files with 63 additions and 37 deletions

View file

@ -128,10 +128,10 @@ define MERGEBIN
endef
endif
# POSTBUILD -- Perform post build operations
# SIGNBIN -- Sign the binary image file
ifeq ($(CONFIG_ESP32_APP_FORMAT_MCUBOOT),y)
define POSTBUILD
define SIGNBIN
$(Q) echo "MKIMAGE: ESP32 binary"
$(Q) if ! imgtool version 1>/dev/null 2>&1; then \
echo ""; \
@ -146,10 +146,13 @@ define POSTBUILD
nuttx.bin nuttx.signed.bin
$(Q) echo nuttx.signed.bin >> nuttx.manifest
$(Q) echo "Generated: nuttx.signed.bin (MCUboot compatible)"
$(call MERGEBIN)
endef
else
define POSTBUILD
endif
# ELF2IMAGE -- Convert an ELF file into a binary file in Espressif application image format
ifeq ($(CONFIG_ESP32_APP_FORMAT_LEGACY),y)
define ELF2IMAGE
$(Q) echo "MKIMAGE: ESP32 binary"
$(Q) if ! esptool.py version 1>/dev/null 2>&1; then \
echo ""; \
@ -165,6 +168,19 @@ define POSTBUILD
$(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)"
endef
endif
# POSTBUILD -- Perform post build operations
ifeq ($(CONFIG_ESP32_APP_FORMAT_MCUBOOT),y)
define POSTBUILD
$(call SIGNBIN)
$(call MERGEBIN)
endef
else ifeq ($(CONFIG_ESP32_APP_FORMAT_LEGACY),y)
define POSTBUILD
$(call ELF2IMAGE)
$(call MERGEBIN)
$(Q) $(MK_QEMU_IMG)
endef

View file

@ -52,8 +52,6 @@ else ifeq ($(CONFIG_ESP32C3_FLASH_FREQ_20M),y)
FLASH_FREQ := 20m
endif
ESPTOOL_ELF2IMG_OPTS := -fs $(FLASH_SIZE) -fm $(FLASH_MODE) -ff $(FLASH_FREQ)
ifeq ($(CONFIG_ESP32C3_FLASH_DETECT),y)
ESPTOOL_WRITEFLASH_OPTS := -fs detect -fm dio -ff $(FLASH_FREQ)
else
@ -72,6 +70,26 @@ endif
ESPTOOL_BINS += 0x10000 nuttx.bin
# ELF2IMAGE -- Convert an ELF file into a binary file in Espressif application image format
define ELF2IMAGE
$(Q) echo "MKIMAGE: ESP32-C3 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-C3 chip."; \
exit 1; \
fi
$(eval ESPTOOL_ELF2IMG_OPTS := -fs $(FLASH_SIZE) -fm $(FLASH_MODE) -ff $(FLASH_FREQ))
esptool.py -c esp32c3 elf2image $(ESPTOOL_ELF2IMG_OPTS) -o nuttx.bin nuttx
$(Q) echo "Generated: nuttx.bin (ESP32-C3 compatible)"
endef
# MERGEBIN -- Merge raw binary files into a single file
ifeq ($(CONFIG_ESP32C3_MERGE_BINS),y)
@ -99,20 +117,7 @@ endif
# POSTBUILD -- Perform post build operations
define POSTBUILD
$(Q) echo "MKIMAGE: ESP32-C3 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-C3 chip."; \
exit 1; \
fi
esptool.py -c esp32c3 elf2image $(ESPTOOL_ELF2IMG_OPTS) -o nuttx.bin nuttx
$(Q) echo "Generated: nuttx.bin (ESP32-C3 compatible)"
$(call ELF2IMAGE)
$(call MERGEBIN)
endef

View file

@ -52,8 +52,6 @@ else ifeq ($(CONFIG_ESP32S2_FLASH_FREQ_20M),y)
FLASH_FREQ := 20m
endif
ESPTOOL_ELF2IMG_OPTS := -fs $(FLASH_SIZE) -fm $(FLASH_MODE) -ff $(FLASH_FREQ)
ifeq ($(CONFIG_ESP32S2_FLASH_DETECT),y)
ESPTOOL_WRITEFLASH_OPTS := -fs detect -fm dio -ff $(FLASH_FREQ)
else
@ -72,6 +70,26 @@ endif
ESPTOOL_BINS += 0x10000 nuttx.bin
# ELF2IMAGE -- Convert an ELF file into a binary file in Espressif application image format
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
$(eval ESPTOOL_ELF2IMG_OPTS := -fs $(FLASH_SIZE) -fm $(FLASH_MODE) -ff $(FLASH_FREQ))
esptool.py -c esp32s2 elf2image $(ESPTOOL_ELF2IMG_OPTS) -o nuttx.bin nuttx
$(Q) echo "Generated: nuttx.bin (ESP32-S2 compatible)"
endef
# MERGEBIN -- Merge raw binary files into a single file
ifeq ($(CONFIG_ESP32S2_MERGE_BINS),y)
@ -99,20 +117,7 @@ endif
# POSTBUILD -- Perform post build operations
define POSTBUILD
$(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_ELF2IMG_OPTS) -o nuttx.bin nuttx
$(Q) echo "Generated: nuttx.bin (ESP32-S2 compatible)"
$(call ELF2IMAGE)
$(call MERGEBIN)
endef