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:03 UTC
[incubator-nuttx] 04/06: tools/esp32s2: 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 12b4d2275762fa025a13654a08460e19dfd28524
Author: Gustavo Henrique Nihei <gu...@espressif.com>
AuthorDate: Wed Sep 1 19:39:56 2021 -0300
tools/esp32s2: Create option for merging all binaries into a single file
Signed-off-by: Gustavo Henrique Nihei <gu...@espressif.com>
---
boards/xtensa/esp32s2/common/Kconfig | 8 ++++++
tools/esp32s2/Config.mk | 53 ++++++++++++++++++++++++++----------
2 files changed, 47 insertions(+), 14 deletions(-)
diff --git a/boards/xtensa/esp32s2/common/Kconfig b/boards/xtensa/esp32s2/common/Kconfig
index 18c7905..67d1292 100644
--- a/boards/xtensa/esp32s2/common/Kconfig
+++ b/boards/xtensa/esp32s2/common/Kconfig
@@ -3,3 +3,11 @@
# see the file kconfig-language.txt in the NuttX tools repository.
#
+config ESP32S2_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.
diff --git a/tools/esp32s2/Config.mk b/tools/esp32s2/Config.mk
index 54f9d76..bd61b10 100644
--- a/tools/esp32s2/Config.mk
+++ b/tools/esp32s2/Config.mk
@@ -61,18 +61,45 @@ else
endif
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)
+ 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)
+endif
+
+ESPTOOL_BINS += 0x10000 nuttx.bin
+
+# MERGEBIN -- Merge raw binary files into a single file
+
+ifeq ($(CONFIG_ESP32S2_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-S2 chip."; \
+ exit 1; \
+ fi
+ $(eval ESPTOOL_MERGEBIN_OPTS := -fs $(FLASH_SIZE) -fm $(FLASH_MODE) -ff $(FLASH_FREQ))
+ esptool.py -c esp32s2 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
define POSTBUILD
- $(Q) echo "MKIMAGE: ESP32S2 binary"
+ $(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\""; \
@@ -81,11 +108,12 @@ define POSTBUILD
exit 1; \
fi
$(Q) if [ -z $(FLASH_SIZE) ]; then \
- echo "Missing Flash memory size configuration for the ESP32S2 chip."; \
+ echo "Missing Flash memory size configuration for the ESP32-S2 chip."; \
exit 1; \
fi
- esptool.py -c esp32-s2 elf2image $(ESPTOOL_ELF2IMG_OPTS) -o nuttx.bin nuttx
- $(Q) echo "Generated: nuttx.bin (ESP32S2 compatible)"
+ esptool.py -c esp32s2 elf2image $(ESPTOOL_ELF2IMG_OPTS) -o nuttx.bin nuttx
+ $(Q) echo "Generated: nuttx.bin (ESP32-S2 compatible)"
+ $(call MERGEBIN)
endef
# ESPTOOL_BAUD -- Serial port baud rate used when flashing/reading via esptool.py
@@ -95,13 +123,10 @@ 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> ]"; \
exit 1; \
fi
- esptool.py -c esp32-s2 -p $(ESPTOOL_PORT) -b $(ESPTOOL_BAUD) write_flash $(ESPTOOL_WRITEFLASH_OPTS) $(ESPTOOL_BINS)
+ esptool.py -c esp32s2 -p $(ESPTOOL_PORT) -b $(ESPTOOL_BAUD) write_flash $(ESPTOOL_WRITEFLASH_OPTS) $(ESPTOOL_BINS)
endef