From c0344d22736861aeb731107da90c40a78c323e68 Mon Sep 17 00:00:00 2001 From: Gustavo Henrique Nihei Date: Wed, 1 Sep 2021 19:19:47 -0300 Subject: [PATCH] tools/esp32: Create option for merging all binaries into a single file This is only useful when the path to binary files (e.g. bootloader) is provided via the ESPTOOL_BINDIR variable. Signed-off-by: Gustavo Henrique Nihei --- boards/xtensa/esp32/common/Kconfig | 9 +++++++++ tools/esp32/Config.mk | 26 ++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/boards/xtensa/esp32/common/Kconfig b/boards/xtensa/esp32/common/Kconfig index bd3e8621f1..944e54cbf8 100644 --- a/boards/xtensa/esp32/common/Kconfig +++ b/boards/xtensa/esp32/common/Kconfig @@ -2,6 +2,15 @@ # For a description of the syntax of this configuration file, # see the file kconfig-language.txt in the NuttX tools repository. # +config ESP32_MERGE_BINS + bool "Merge raw binary files into a single file" + default n + ---help--- + Merge the raw binary files into a single file for flashing to the + device. + This is only useful when the path to binary files (e.g. bootloader) + is provided via the ESPTOOL_BINDIR variable. + config ESP32_QEMU_IMAGE bool "ESP32 binary image for QEMU" default n diff --git a/tools/esp32/Config.mk b/tools/esp32/Config.mk index 21740c0b20..dcbeae2c1c 100644 --- a/tools/esp32/Config.mk +++ b/tools/esp32/Config.mk @@ -104,6 +104,30 @@ else MK_QEMU_IMG= endif +# MERGEBIN -- Merge raw binary files into a single file + +ifeq ($(CONFIG_ESP32_MERGE_BINS),y) +define MERGEBIN + $(Q) if [ -z $(ESPTOOL_BINDIR) ]; then \ + echo "MERGEBIN error: Missing argument for binary files directory."; \ + echo "USAGE: make ESPTOOL_BINDIR="; \ + exit 1; \ + fi + $(Q) if [ -z $(FLASH_SIZE) ]; then \ + echo "Missing Flash memory size configuration for the ESP32 chip."; \ + exit 1; \ + fi + $(eval ESPTOOL_MERGEBIN_OPTS := -fs $(FLASH_SIZE) -fm $(FLASH_MODE) -ff $(FLASH_FREQ)) + esptool.py -c esp32 merge_bin --output nuttx.merged.bin $(ESPTOOL_MERGEBIN_OPTS) $(ESPTOOL_BINS) + $(Q) echo nuttx.merged.bin >> nuttx.manifest + $(Q) echo "Generated: nuttx.merged.bin" +endef +else +define MERGEBIN + +endef +endif + # POSTBUILD -- Perform post build operations ifeq ($(CONFIG_ESP32_APP_FORMAT_MCUBOOT),y) @@ -121,6 +145,7 @@ define POSTBUILD -S $(CONFIG_ESP32_OTA_SLOT_SIZE) \ nuttx.bin nuttx.signed.bin $(Q) echo "Generated: nuttx.signed.bin (MCUboot compatible)" + $(call MERGEBIN) endef else define POSTBUILD @@ -139,6 +164,7 @@ 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)" + $(call MERGEBIN) $(Q) $(MK_QEMU_IMG) endef endif