diff --git a/boards/risc-v/esp32c3/esp32c3-devkit/Kconfig b/boards/risc-v/esp32c3/esp32c3-devkit/Kconfig index 153e528920d..0ab22836c86 100644 --- a/boards/risc-v/esp32c3/esp32c3-devkit/Kconfig +++ b/boards/risc-v/esp32c3/esp32c3-devkit/Kconfig @@ -41,6 +41,15 @@ config ESP32C3_DEVKIT_RUN_IRAM bool "Run from IRAM" default n +config ESP32C3_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. + choice prompt "SPIFLASH File System" default ESP32C3_SPIFLASH_SMARTFS diff --git a/tools/esp32c3/Config.mk b/tools/esp32c3/Config.mk index 9952f702a95..0659b70dabc 100644 --- a/tools/esp32c3/Config.mk +++ b/tools/esp32c3/Config.mk @@ -61,12 +61,39 @@ else endif ifdef ESPTOOL_BINDIR - BL_OFFSET := 0x0 - PT_OFFSET := 0x8000 - BOOTLOADER := $(ESPTOOL_BINDIR)/bootloader-esp32c3.bin + BL_OFFSET := 0x0 + PT_OFFSET := 0x8000 + BOOTLOADER := $(ESPTOOL_BINDIR)/bootloader-esp32c3.bin PARTITION_TABLE := $(ESPTOOL_BINDIR)/partition-table-esp32c3.bin - FLASH_BL := $(BL_OFFSET) $(BOOTLOADER) - FLASH_PT := $(PT_OFFSET) $(PARTITION_TABLE) + 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_ESP32C3_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-C3 chip."; \ + exit 1; \ + fi + $(eval ESPTOOL_MERGEBIN_OPTS := -fs $(FLASH_SIZE) -fm $(FLASH_MODE) -ff $(FLASH_FREQ)) + esptool.py -c esp32c3 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 @@ -86,6 +113,7 @@ define POSTBUILD fi esptool.py -c esp32c3 elf2image $(ESPTOOL_ELF2IMG_OPTS) -o nuttx.bin nuttx $(Q) echo "Generated: nuttx.bin (ESP32-C3 compatible)" + $(call MERGEBIN) endef # ESPTOOL_BAUD -- Serial port baud rate used when flashing/reading via esptool.py @@ -95,9 +123,6 @@ 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= [ ESPTOOL_BAUD= ]"; \