From e864cf2fc3de16b6e50ff17e9359990da5df9066 Mon Sep 17 00:00:00 2001 From: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Wed, 28 Dec 2022 16:05:54 +0100 Subject: [PATCH] S3 16MB fix (#4) * fix(setup): Use latest reedsolo package which can be installed with Python3.10 and Cython Closes https://github.com/espressif/esptool/issues/711 * feat(ci): Publish development releases with custom pipeline * fix(ci): The development release job should not run by default Gitlab rules:if adds the job if any of the rules are true. * fix(ci): Merge two "ci" directories and build_tools into one * fix(secure download mode): Fix SDM detection on S2/S3 * fix(secure download mode): Reconnect if ROM refuses to respond Closes https://github.com/espressif/esptool/issues/813 * fix(flasher_stub): Correct boundaries for SPIWrite4B and SPIRead4B SPIWrite4B and SPIRead4B functions are required for flash sizes bigger than 16MB. This fix corrects the boundaries so SPIWrite and SPIRead would be used for the whole 16MB area. The octal flash support for 32 MB chips (https://github.com/espressif/esptool/issues/795) will be added in a follow-up commit. Closes https://github.com/espressif/esptool/issues/745 Co-authored-by: Roland Dobai Co-authored-by: radim.karnis --- .github/workflows/test_esptool.yml | 2 +- .gitlab-ci.yml | 25 +++++++++- {build_tools => ci}/Sign-File.ps1 | 0 {build_tools => ci}/espressif.ico | Bin ci/patch_dev_release.py | 43 ++++++++++++++++++ {test/ci => ci}/setup_ci_build_env.sh | 0 esptool/cmds.py | 2 +- esptool/loader.py | 11 ++++- .../stub_flasher/stub_flasher_32s3beta2.json | 1 + flasher_stub/stub_commands.c | 4 +- flasher_stub/stub_write_flash.c | 2 +- setup.py | 2 +- 12 files changed, 84 insertions(+), 8 deletions(-) rename {build_tools => ci}/Sign-File.ps1 (100%) rename {build_tools => ci}/espressif.ico (100%) create mode 100644 ci/patch_dev_release.py rename {test/ci => ci}/setup_ci_build_env.sh (100%) diff --git a/.github/workflows/test_esptool.yml b/.github/workflows/test_esptool.yml index ef0378719..6c3e03bf8 100644 --- a/.github/workflows/test_esptool.yml +++ b/.github/workflows/test_esptool.yml @@ -48,7 +48,7 @@ jobs: export PATH=$PATH:$ESP8266_BINDIR:$ESP32_BINDIR:$ESP32S2_BINDIR:$ESP32S3_BINDIR:$ESP32C3_BINDIR - ./test/ci/setup_ci_build_env.sh + ./ci/setup_ci_build_env.sh make -C flasher_stub V=1 cd flasher_stub && python ./compare_stubs.py diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a2d3617c4..de9efcda3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,6 +6,7 @@ stages: - report - build_docs - deploy_docs + - deploy_development_package # cache the pip download directory in all jobs variables: @@ -175,7 +176,7 @@ check_stub_build: TOOLCHAIN_PATHS: "${ESP8266_BINDIR}:${ESP32_BINDIR}:${ESP32S2_BINDIR}:${ESP32S3_BINDIR}:${ESP32C3_BINDIR}" script: - - ./test/ci/setup_ci_build_env.sh + - ./ci/setup_ci_build_env.sh - make -C flasher_stub V=1 PATH="${TOOLCHAIN_PATHS}:${PATH}" - cd flasher_stub && coverage run --parallel-mode ./compare_stubs.py @@ -366,3 +367,25 @@ deploy_docs_production: DOCS_DEPLOY_SERVER_USER: "$DOCS_PROD_SERVER_USER" DOCS_DEPLOY_PATH: "$DOCS_PROD_PATH" DOCS_DEPLOY_URL_BASE: "https://docs.espressif.com/projects/esptool" + +deploy_dev_package: + <<: *test_template + rules: + - if: $CI_DEV_PUBLISH != null && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH + variables: + TWINE_NON_INTERACTIVE: "true" + TWINE_USERNAME: __token__ + TWINE_PASSWORD: ${PYPI_ESPTOOL_TOKEN} + stage: deploy_development_package + dependencies: [] + script: + - python -m pip install --upgrade pip + - python -m pip install twine setuptools + - python ci/patch_dev_release.py --dev-no ${CI_DEV_PUBLISH} esptool/__init__.py + # check what has been changed with git + - git diff + - python setup.py sdist + # skip release if it has already been released (with failure) + - python -m pip download esptool==$(python setup.py -V) && exit 1 + - tar -ztvf dist/* + - python -m twine upload dist/* diff --git a/build_tools/Sign-File.ps1 b/ci/Sign-File.ps1 similarity index 100% rename from build_tools/Sign-File.ps1 rename to ci/Sign-File.ps1 diff --git a/build_tools/espressif.ico b/ci/espressif.ico similarity index 100% rename from build_tools/espressif.ico rename to ci/espressif.ico diff --git a/ci/patch_dev_release.py b/ci/patch_dev_release.py new file mode 100644 index 000000000..a157c8f3f --- /dev/null +++ b/ci/patch_dev_release.py @@ -0,0 +1,43 @@ +# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD +# +# SPDX-License-Identifier: GPL-2.0-or-later + +import argparse +import re + +LINE_RE = re.compile(r"^__version__ = ['\"]([^'\"]*)['\"]") +NEW_LINE = '__version__ = "{}"' + + +def get_new_version(old_version, dev_number): + assert old_version.endswith("-dev") + return old_version.replace("-dev", ".dev{}".format(dev_number), 1) + + +def patch_file(path, dev_number): + with open(path, "r") as fin: + lines = fin.readlines() + + for i, line in enumerate(lines, start=0): + m = LINE_RE.search(line) + if m: + old_version = m.group(1) + lines[i] = NEW_LINE.format(get_new_version(old_version, dev_number)) + break + + with open(path, "w") as fout: + fout.writelines(lines) + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("file", help="Path to script with __version__") + parser.add_argument( + "--dev-no", type=int, help="Number N to patch the version to '.devN'" + ) + args = parser.parse_args() + patch_file(args.file, args.dev_no) + + +if __name__ == "__main__": + main() diff --git a/test/ci/setup_ci_build_env.sh b/ci/setup_ci_build_env.sh similarity index 100% rename from test/ci/setup_ci_build_env.sh rename to ci/setup_ci_build_env.sh diff --git a/esptool/cmds.py b/esptool/cmds.py index 199df8aa5..cd2a0a041 100644 --- a/esptool/cmds.py +++ b/esptool/cmds.py @@ -104,13 +104,13 @@ def detect_chip( # cmd not supported on ESP8266 and ESP32 + ESP32-S2 doesn't return chip_id if chip_id == cls.IMAGE_CHIP_ID: inst = cls(detect_port._port, baud, trace_enabled=trace_enabled) - inst._post_connect() try: inst.read_reg( ESPLoader.CHIP_DETECT_MAGIC_REG_ADDR ) # Dummy read to check Secure Download mode except UnsupportedCommandError: inst.secure_download_mode = True + inst._post_connect() except (UnsupportedCommandError, struct.error, FatalError) as e: # UnsupportedCommmanddError: ESP8266/ESP32 ROM # struct.error: ESP32-S2 diff --git a/esptool/loader.py b/esptool/loader.py index 6530182b3..fc034ccbe 100644 --- a/esptool/loader.py +++ b/esptool/loader.py @@ -672,8 +672,17 @@ def connect( ) except UnsupportedCommandError: self.secure_download_mode = True + + try: + self.check_chip_id() + except UnsupportedCommandError: + # Fix for ROM not responding in SDM, reconnect and try again + if self.secure_download_mode: + self._connect_attempt(mode, usb_jtag_serial, extra_delay) + self.check_chip_id() + else: + raise self._post_connect() - self.check_chip_id() def _post_connect(self): """ diff --git a/esptool/targets/stub_flasher/stub_flasher_32s3beta2.json b/esptool/targets/stub_flasher/stub_flasher_32s3beta2.json index 20eeb5f57..015d9502e 100644 --- a/esptool/targets/stub_flasher/stub_flasher_32s3beta2.json +++ b/esptool/targets/stub_flasher/stub_flasher_32s3beta2.json @@ -1,4 +1,5 @@ { +<< block_size) n = block_size; #if defined(ESP32S3) - if (addr + len-1 > 0x00ffffff) + if (addr + n > 0x01000000) res = SPIRead4B(1, SPI_FLASH_FASTRD_MODE, addr, buf, n); else res = SPIRead(addr, (uint32_t *)buf, n); @@ -158,7 +158,7 @@ int handle_flash_get_md5sum(uint32_t addr, uint32_t len) { n = FLASH_SECTOR_SIZE; } #if defined(ESP32S3) - if (addr + len > 0x00ffffff) + if (addr + n > 0x01000000) res = SPIRead4B(1, SPI_FLASH_FASTRD_MODE, addr, buf, n); else res = SPIRead(addr, (uint32_t *)buf, n); diff --git a/flasher_stub/stub_write_flash.c b/flasher_stub/stub_write_flash.c index 4aa179d18..9c2271fea 100644 --- a/flasher_stub/stub_write_flash.c +++ b/flasher_stub/stub_write_flash.c @@ -320,7 +320,7 @@ void handle_flash_data(void *data_buf, uint32_t length) { /* do the actual write */ #if defined(ESP32S3) - if (fs.next_write + length > 0x00ffffff) + if (fs.next_write + length > 0x01000000) res = SPIWrite4B(1, SPI_FLASH_FASTRD_MODE, fs.next_write, data_buf, length); else res = SPIWrite(fs.next_write, data_buf, length); diff --git a/setup.py b/setup.py index b2d653838..639288e40 100644 --- a/setup.py +++ b/setup.py @@ -121,7 +121,7 @@ def find_version(*file_paths): "cryptography>=2.1.4", "ecdsa>=0.16.0", "pyserial>=3.0", - "reedsolo>=1.5.3,<=1.5.4", + "reedsolo>=1.5.3,<=1.6.0", ], packages=find_packages(), include_package_data=True,