From e8b391154bc8d71d9f9f37dbdfdb6b21a1e9f21d Mon Sep 17 00:00:00 2001 From: Jakub Kocka Date: Wed, 31 Jul 2024 14:04:44 +0200 Subject: [PATCH] feat(esp32c61): Added stub flasher support --- ci/download_flasher_stubs.py | 5 ++-- esptool/targets/esp32c61.py | 23 ++++++++++++++-- esptool/targets/stub_flasher/1/README.md | 2 +- esptool/targets/stub_flasher/1/esp32c61.json | 8 ++++++ .../ram_helloworld/helloworld-esp32c61.bin | Bin 0 -> 128 bytes test/images/ram_helloworld/source/Makefile | 7 ++++- .../ram_helloworld/source/ld/app_32c61.ld | 26 ++++++++++++++++++ test/test_esptool.py | 12 ++++++-- 8 files changed, 75 insertions(+), 8 deletions(-) create mode 100644 esptool/targets/stub_flasher/1/esp32c61.json create mode 100644 test/images/ram_helloworld/helloworld-esp32c61.bin create mode 100644 test/images/ram_helloworld/source/ld/app_32c61.ld diff --git a/ci/download_flasher_stubs.py b/ci/download_flasher_stubs.py index 1b3ae4cb4..8f34c4129 100755 --- a/ci/download_flasher_stubs.py +++ b/ci/download_flasher_stubs.py @@ -12,7 +12,7 @@ "STUB_SET_VERSION": "1", "DOWNLOAD_URL": "https://github.com/espressif/esptool-legacy-flasher-stub/releases/download", "TAG_URL": "https://github.com/espressif/esptool-legacy-flasher-stub/releases/tag", - "VERSION": "v1.2.0", + "VERSION": "v1.3.0", "FILE_LIST": ( "esp32", "esp32c2", @@ -20,6 +20,7 @@ "esp32c5", "esp32c5beta3", "esp32c6", + "esp32c61", "esp32c6beta", "esp32h2", "esp32h2beta1", @@ -50,7 +51,7 @@ }, ) -DESTINATION_DIR = "esptool/targets/stub_flasher" +DESTINATION_DIR = os.path.join("esptool", "targets", "stub_flasher") README_TEMPLATE = """# Licensing diff --git a/esptool/targets/esp32c61.py b/esptool/targets/esp32c61.py index dd7f09ef7..81fad3610 100644 --- a/esptool/targets/esp32c61.py +++ b/esptool/targets/esp32c61.py @@ -13,7 +13,7 @@ class ESP32C61ROM(ESP32C6ROM): IMAGE_CHIP_ID = 20 # Magic value for ESP32C61 - CHIP_DETECT_MAGIC_VALUE = [0x33F0206F] + CHIP_DETECT_MAGIC_VALUE = [0x33F0206F, 0x2421606F] UART_DATE_REG_ADDR = 0x60000000 + 0x7C @@ -104,4 +104,23 @@ def read_mac(self, mac_type="BASE_MAC"): return macs.get(mac_type, None) -# TODO: IDF-9241, stub flasher support +class ESP32C61StubLoader(ESP32C61ROM): + """Access class for ESP32C61 stub loader, runs on top of ROM. + + (Basically the same as ESP32StubLoader, but different base class. + Can possibly be made into a mixin.) + """ + + FLASH_WRITE_SIZE = 0x4000 # matches MAX_WRITE_BLOCK in stub_loader.c + STATUS_BYTES_LENGTH = 2 # same as ESP8266, different to ESP32 ROM + IS_STUB = True + + def __init__(self, rom_loader): + self.secure_download_mode = rom_loader.secure_download_mode + self._port = rom_loader._port + self._trace_enabled = rom_loader._trace_enabled + self.cache = rom_loader.cache + self.flush_input() # resets _slip_reader + + +ESP32C61ROM.STUB_CLASS = ESP32C61StubLoader diff --git a/esptool/targets/stub_flasher/1/README.md b/esptool/targets/stub_flasher/1/README.md index 0d5ca3834..44e3ca315 100644 --- a/esptool/targets/stub_flasher/1/README.md +++ b/esptool/targets/stub_flasher/1/README.md @@ -1,3 +1,3 @@ # Licensing -The binaries in JSON format distributed in this directory are released as Free Software under GNU General Public License Version 2 or later. They were released at https://github.com/espressif/esptool-legacy-flasher-stub/releases/tag/v1.2.0 from where the sources can be obtained. +The binaries in JSON format distributed in this directory are released as Free Software under GNU General Public License Version 2 or later. They were released at https://github.com/espressif/esptool-legacy-flasher-stub/releases/tag/v1.3.0 from where the sources can be obtained. diff --git a/esptool/targets/stub_flasher/1/esp32c61.json b/esptool/targets/stub_flasher/1/esp32c61.json new file mode 100644 index 000000000..2a95414c8 --- /dev/null +++ b/esptool/targets/stub_flasher/1/esp32c61.json @@ -0,0 +1,8 @@ +{ + "entry": 1082132164, + "text": "QREixCbCBsa39wBgEUc3RIBA2Mu39ABgEw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cRGNb9Arv8I/Ldd3IQGKGk4WLAZfwf//ngCBEAcWTB0AM3MjcQOKX3MDcRLOHh0HcxJfwf//ngABDJbYJZRMFBXEDrMsAA6SLAJfwf//ngEAytwcAYNhLtwYAAcEWk1dHARIHdY+9i9mPs4eHAwFFs9WHApfwf//ngKAzEwWAPpfwf//ngOAu6byDpksBA6YLAYOlywADpYsA7/DP+9G0g8U7AIPHKwAThYsBogXdjcEV7/Bv1XW07/DPxD2/A8Q7AIPHKwATjIsBIgRdjNxEQRTN45FHhUtj/4cIkweQDNzIQbQDpw0AItAFSLOH7EA+1oMnirBjc/QADUhCxjrE7/BPwCJHMkg3xYBA4oV8EJOGSgEQEBMFxQKX8H//54BAMTf3gECTCEcBglcDp4iwg6UNAB2MHY8+nLJXI6TosKqLvpUjoL0Ak4dKAZ2NAcWhZ2OX9QBahe/wD8sjoG0BCcTcRJnD409w92PfCwCTB3AMvbeFS7d9gUC3zIBAk40Nu5OMTAHpv+OdC5zcROOKB5yTB4AMqbeDp4sA45MHnO/wD9MJZRMFBXGX8H//54BAHO/wj86X8H//54AAIVWyA6TLAOMPBJjv8I/QEwWAPpfwf//ngOAZ7/AvzAKUUbLv8K/L9lBmVNZURlm2WSZalloGW/ZLZkzWTEZNtk0JYYKA", + "text_start": 1082130432, + "data": "FECAQHQKgEDECoBAHAuAQOoLgEBWDIBABAyAQEAJgECmC4BA5guAQDALgEDwCIBAZAuAQPAIgEBOCoBAlAqAQMQKgEAcC4BAYAqAQKQJgEDUCYBAXAqAQK4OgEDECoBAbg2AQGYOgEAwCIBAjg6AQDAIgEAwCIBAMAiAQDAIgEAwCIBAMAiAQDAIgEAwCIBACg2AQDAIgECMDYBAZg6AQA==", + "data_start": 1082223536, + "bss_start": 1082146816 +} \ No newline at end of file diff --git a/test/images/ram_helloworld/helloworld-esp32c61.bin b/test/images/ram_helloworld/helloworld-esp32c61.bin new file mode 100644 index 0000000000000000000000000000000000000000..a9a60cf53b8c2e184e504fb48dbd3b2ac6fb30da GIT binary patch literal 128 zcmaFK!~g`%4)1`Z2#ERrKZs-miAew%j)F=@*p8XAG&=~hvItCPsQv%EA%XGgeg?*7 z2LYhGM`}(^zCw9^QBH~?7f2^6uuT0^aCMSLp4-0LwJKX|vL_s$$}Y6|&%|@?2fg0v Ia&BM%0G=Bood5s; literal 0 HcmV?d00001 diff --git a/test/images/ram_helloworld/source/Makefile b/test/images/ram_helloworld/source/Makefile index 1f4f050e7..0132b9ebe 100644 --- a/test/images/ram_helloworld/source/Makefile +++ b/test/images/ram_helloworld/source/Makefile @@ -26,6 +26,7 @@ APP_ELF_32S3 = $(BUILD_DIR)/$(APP)-esp32s3.elf APP_ELF_32C3 = $(BUILD_DIR)/$(APP)-esp32c3.elf APP_ELF_32C2 = $(BUILD_DIR)/$(APP)-esp32c2.elf APP_ELF_32C6 = $(BUILD_DIR)/$(APP)-esp32c6.elf +APP_ELF_32C61 = $(BUILD_DIR)/$(APP)-esp32c61.elf APP_ELF_32H2 = $(BUILD_DIR)/$(APP)-esp32h2.elf APP_ELF_32P4 = $(BUILD_DIR)/$(APP)-esp32p4.elf APP_ELF_32C5 = $(BUILD_DIR)/$(APP)-esp32c5.elf @@ -34,7 +35,7 @@ APP_ELF_32C5 = $(BUILD_DIR)/$(APP)-esp32c5.elf all: $(APP_ELF_8266) $(APP_ELF_32) $(APP_ELF_32S2) $(APP_ELF_32C3) $(APP_ELF_32S3) $(APP_ELF_32C2) $(APP_ELF_32C6) $(APP_ELF_32H2) $(APP_ELF_32P4) $(APP_ELF_32C5) -esp32: $(APP_ELF_32) $(APP_ELF_32S2) $(APP_ELF_32C3) $(APP_ELF_32S3) $(APP_ELF_32C2) $(APP_ELF_32C6) $(APP_ELF_32H2) $(APP_ELF_32P4) $(APP_ELF_32C5) +esp32: $(APP_ELF_32) $(APP_ELF_32S2) $(APP_ELF_32C3) $(APP_ELF_32S3) $(APP_ELF_32C2) $(APP_ELF_32C6) $(APP_ELF_32C61) $(APP_ELF_32H2) $(APP_ELF_32P4) $(APP_ELF_32C5) $(BUILD_DIR): $(Q) mkdir $@ @@ -80,6 +81,10 @@ $(APP_ELF_32C6): $(SRCS) $(BUILD_DIR) ld/app_32c6.ld @echo " CC(32C6) $^ -> $@" $(Q) $(CROSS_ESPRISCV32)gcc $(CFLAGS_ESPRISCV32) -DESP32C6=1 -Tapp_32c6.ld -Wl,-Map=$(@:.elf=.map) -o $@ $(filter %.c, $^) $(LDLIBS) +$(APP_ELF_32C61): $(SRCS) $(BUILD_DIR) ld/app_32c61.ld + @echo " CC(32C61) $^ -> $@" + $(Q) $(CROSS_ESPRISCV32)gcc $(CFLAGS_ESPRISCV32) -DESP32C61=1 -Tapp_32c61.ld -Wl,-Map=$(@:.elf=.map) -o $@ $(filter %.c, $^) $(LDLIBS) + $(APP_ELF_32H2): $(SRCS) $(BUILD_DIR) ld/app_32h2.ld @echo " CC(32H2) $^ -> $@" $(Q) $(CROSS_ESPRISCV32)gcc $(CFLAGS_ESPRISCV32) -DESP32H2=1 -Tapp_32h2.ld -Wl,-Map=$(@:.elf=.map) -o $@ $(filter %.c, $^) $(LDLIBS) diff --git a/test/images/ram_helloworld/source/ld/app_32c61.ld b/test/images/ram_helloworld/source/ld/app_32c61.ld new file mode 100644 index 000000000..7121cc935 --- /dev/null +++ b/test/images/ram_helloworld/source/ld/app_32c61.ld @@ -0,0 +1,26 @@ +MEMORY { + iram : org = 0x40830000, len = 0x100 + dram : org = 0x40830100, len = 0x100 +} + +ENTRY(ram_main) + +SECTIONS { + .text : ALIGN(4) { + *(.literal) + *(.text .text.*) + } > iram + + .bss : ALIGN(4) { + _bss_start = ABSOLUTE(.); + *(.bss) + _bss_end = ABSOLUTE(.); + } > dram + + .data : ALIGN(4) { + *(.data) + *(.rodata .rodata.*) + } > dram +} + +INCLUDE "../../../../flasher_stub/ld/rom_32c61.ld" diff --git a/test/test_esptool.py b/test/test_esptool.py index 6fae6ba43..03b2114c1 100755 --- a/test/test_esptool.py +++ b/test/test_esptool.py @@ -191,6 +191,7 @@ def run_esptool_process(cmd): "esp32h2", "esp32p4", "esp32c5", + "esp32c61", ] # With U-JS ): port_index = base_cmd.index("--port") + 1 @@ -1277,8 +1278,15 @@ def _test_read_write(self, esp): ]: # find a probably-unused memory type region = esp.get_memory_region(test_region) if region: - # Write at the end of DRAM on ESP32-C2 to avoid overwriting the stub - test_addr = region[1] - 8 if arg_chip == "esp32c2" else region[0] + if arg_chip == "esp32c61": + # Write into the "BYTE_ACCESSIBLE" space and after the stub + region = esp.get_memory_region("DRAM") + test_addr = region[1] - 0x2FFFF + elif arg_chip == "esp32c2": + # Write at the end of DRAM on ESP32-C2 to avoid overwriting the stub + test_addr = region[1] - 8 + else: + test_addr = region[0] break print(f"Using test address {test_addr:#x}")