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:05 UTC

[incubator-nuttx] 06/06: tools/esp32[s2, c3]: Extract POSTBUILD operations into functions

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 adef19704d278c4eca515873b605252cb2dd3f2b
Author: Gustavo Henrique Nihei <gu...@espressif.com>
AuthorDate: Sat Sep 4 07:28:53 2021 -0300

    tools/esp32[s2,c3]: Extract POSTBUILD operations into functions
    
    Signed-off-by: Gustavo Henrique Nihei <gu...@espressif.com>
---
 tools/esp32/Config.mk   | 26 +++++++++++++++++++++-----
 tools/esp32c3/Config.mk | 37 +++++++++++++++++++++----------------
 tools/esp32s2/Config.mk | 37 +++++++++++++++++++++----------------
 3 files changed, 63 insertions(+), 37 deletions(-)

diff --git a/tools/esp32/Config.mk b/tools/esp32/Config.mk
index 229d18c..71a033b 100644
--- a/tools/esp32/Config.mk
+++ b/tools/esp32/Config.mk
@@ -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
diff --git a/tools/esp32c3/Config.mk b/tools/esp32c3/Config.mk
index 0659b70..8030121 100644
--- a/tools/esp32c3/Config.mk
+++ b/tools/esp32c3/Config.mk
@@ -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
 
diff --git a/tools/esp32s2/Config.mk b/tools/esp32s2/Config.mk
index bd61b10..f53f19e 100644
--- a/tools/esp32s2/Config.mk
+++ b/tools/esp32s2/Config.mk
@@ -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