From f23b20f91f7a14d9b231a19fd7ec3c279aa8b257 Mon Sep 17 00:00:00 2001 From: Gunar Schorcht Date: Tue, 27 Dec 2022 01:55:28 +0100 Subject: [PATCH 1/3] cpu/esp: use FLASHFILE_POS for image position in flash Instead of using a fixed position of the image file in the flash, the variable `FLASHFILE_POS` is used which allows to override the default position of the image in the flash at 0x10000. --- cpu/esp32/Makefile.include | 3 ++- cpu/esp8266/Makefile.include | 1 + cpu/esp_common/Makefile.include | 3 +-- makefiles/tools/esptool.inc.mk | 6 +++--- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/cpu/esp32/Makefile.include b/cpu/esp32/Makefile.include index 12a4be6e1778..cb42615d10ce 100644 --- a/cpu/esp32/Makefile.include +++ b/cpu/esp32/Makefile.include @@ -23,6 +23,7 @@ else ifneq (,$(filter esp32s2,$(CPU_FAM))) else $(error Unkwnown ESP32x SoC variant (family)) endif +FLASHFILE_POS ?= 0x10000 ESPTOOL ?= $(RIOTTOOLS)/esptools/esptool_v3.2.py @@ -244,7 +245,7 @@ ifneq (,$(filter esp_jtag,$(USEMODULE))) -c 'flash write_image erase "$(BOOTLOADER_BIN)" $(BOOTLOADER_POS) bin' \ -c 'echo "Installing partition table at $(PARTITION_POS)"' \ -c 'flash write_image erase "$(BINDIR)/partitions.bin" $(PARTITION_POS) bin' - IMAGE_OFFSET = 0x10000 + IMAGE_OFFSET = $(FLASHFILE_POS) # Flash checksumming not supported on xtensa OPENOCD_SKIP_VERIFY = yes # Without resets debug target fails with 'Target not examined yet' diff --git a/cpu/esp8266/Makefile.include b/cpu/esp8266/Makefile.include index daa32a61cd6d..898b5d668f8b 100644 --- a/cpu/esp8266/Makefile.include +++ b/cpu/esp8266/Makefile.include @@ -11,6 +11,7 @@ FLASH_MODE = dout FLASH_FREQ = 26m FLASH_SIZE ?= 1 BOOTLOADER_POS = 0x0000 +FLASHFILE_POS = 0x10000 include $(RIOTCPU)/esp_common/Makefile.include diff --git a/cpu/esp_common/Makefile.include b/cpu/esp_common/Makefile.include index 15538f9a6916..c86316f29881 100644 --- a/cpu/esp_common/Makefile.include +++ b/cpu/esp_common/Makefile.include @@ -140,7 +140,6 @@ $(ELFFILE).bin: $(ELFFILE) --flash_size $(FLASH_SIZE)MB --flash_freq $(FLASH_FREQ) $(FLASH_OPTS) \ -o $@ $< - # Convert .elf and .csv to .bin files at build time, but make them available for # tests at flash time. These can't be added to FLASHDEPS because they depend on # on ELFFILE and would trigger a rebuild with "flash-only". @@ -155,7 +154,7 @@ $(BINDIR)/partitions.csv: $(FLASHFILE) $(Q)printf "\n" > $(BINDIR)/partitions.csv $(Q)printf "nvs, data, nvs, 0x9000, 0x6000\n" >> $@ $(Q)printf "phy_init, data, phy, 0xf000, 0x1000\n" >> $@ - $(Q)printf "factory, app, factory, 0x10000, " >> $@ + $(Q)printf "factory, app, factory, $(FLASHFILE_POS), " >> $@ $(Q)ls -l $< | awk '{ print $$5 }' >> $@ $(BINDIR)/partitions.bin: $(PARTITION_TABLE_CSV) diff --git a/makefiles/tools/esptool.inc.mk b/makefiles/tools/esptool.inc.mk index ef632d35db5c..04aeb59063a4 100644 --- a/makefiles/tools/esptool.inc.mk +++ b/makefiles/tools/esptool.inc.mk @@ -32,7 +32,7 @@ else FFLAGS += --flash_size detect FFLAGS += $(BOOTLOADER_POS) $(BOOTLOADER_BIN) FFLAGS += 0x8000 $(BINDIR)/partitions.bin - FFLAGS += 0x10000 $(FLASHFILE) + FFLAGS += $(FLASHFILE_POS) $(FLASHFILE) endif .PHONY: esp-qemu @@ -44,7 +44,7 @@ ifeq (esp32,$(CPU)) "--flash_size $(FLASH_SIZE)MB" \ "$(BOOTLOADER_POS) $(BOOTLOADER_BIN)" \ "0x8000 $(BINDIR)/partitions.bin" \ - "0x10000 $(FLASHFILE)" > $(BINDIR)/qemu_flash_args + "$(FLASHFILE_POS) $(FLASHFILE)" > $(BINDIR)/qemu_flash_args $(Q)$(ESPTOOL) \ --chip $(CPU_FAM) merge_bin \ --fill-flash-size 4MB \ @@ -58,7 +58,7 @@ else cat - $(BOOTLOADER_BIN) tmp.bin | \ head -c $$((0x8000)) | \ cat - $(BINDIR)/partitions.bin tmp.bin | \ - head -c $$((0x10000)) | \ + head -c $$(($(FLASHFILE_POS))) | \ cat - $(FLASHFILE) tmp.bin | \ head -c $(FLASH_SIZE)MB > $(BINDIR)/$(CPU)flash.bin && rm tmp.bin endif From a71f457f23457029199a703cbf138dc75b39133d Mon Sep 17 00:00:00 2001 From: Gunar Schorcht Date: Sat, 31 Dec 2022 13:09:37 +0100 Subject: [PATCH 2/3] makefile/tools/esptool.inc.mk: fix esp-qemu dependency --- makefiles/tools/esptool.inc.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makefiles/tools/esptool.inc.mk b/makefiles/tools/esptool.inc.mk index 04aeb59063a4..900d73bdea5f 100644 --- a/makefiles/tools/esptool.inc.mk +++ b/makefiles/tools/esptool.inc.mk @@ -37,7 +37,7 @@ endif .PHONY: esp-qemu -esp-qemu: +esp-qemu: $(FLASHFILE) ifeq (esp32,$(CPU)) $(Q)echo \ "--flash_mode $(FLASH_MODE) --flash_freq $(FLASH_FREQ) " \ From a0715b281b7804b22dea65cb7afb031bda98be9b Mon Sep 17 00:00:00 2001 From: Gunar Schorcht Date: Sat, 31 Dec 2022 13:13:13 +0100 Subject: [PATCH 3/3] cpu/esp32: export FLASH_SIZE to SDK configuration --- cpu/esp32/Makefile.include | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/cpu/esp32/Makefile.include b/cpu/esp32/Makefile.include index cb42615d10ce..79159f1939ab 100644 --- a/cpu/esp32/Makefile.include +++ b/cpu/esp32/Makefile.include @@ -152,6 +152,19 @@ else ifeq (120m,$(FLASH_FREQ)) CFLAGS += -DCONFIG_ESPTOOLPY_FLASHFREQ_120M endif +#extend CFLAGS by the corresponding FLASH_SIZE +ifeq (1,$(FLASH_SIZE)) + CFLAGS += -DCONFIG_ESPTOOLPY_FLASHSIZE_1MB +else ifeq (2,$(FLASH_SIZE)) + CFLAGS += -DCONFIG_ESPTOOLPY_FLASHSIZE_2MB +else ifeq (4,$(FLASH_SIZE)) + CFLAGS += -DCONFIG_ESPTOOLPY_FLASHSIZE_4MB +else ifeq (8,$(FLASH_SIZE)) + CFLAGS += -DCONFIG_ESPTOOLPY_FLASHSIZE_8MB +else ifeq (16,$(FLASH_SIZE)) + CFLAGS += -DCONFIG_ESPTOOLPY_FLASHSIZE_16MB +endif + # shortcuts used by ESP-IDF CFLAGS += -Dasm=__asm CFLAGS += -Dtypeof=__typeof__