You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ag...@apache.org on 2021/09/08 10:17:00 UTC

[incubator-nuttx] 01/06: tools/esp32: Create option for merging all binaries into a single file

This is an automated email from the ASF dual-hosted git repository.

aguettouche pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit c0344d22736861aeb731107da90c40a78c323e68
Author: Gustavo Henrique Nihei <gu...@espressif.com>
AuthorDate: Wed Sep 1 19:19:47 2021 -0300

    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 <gu...@espressif.com>
---
 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 bd3e862..944e54c 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 21740c0..dcbeae2 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=<dir>"; \
+		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