From e862e10e63d587dcfa1a9f683791543cb33c5769 Mon Sep 17 00:00:00 2001 From: "radim.karnis" Date: Mon, 17 Jul 2023 16:55:08 +0200 Subject: [PATCH] fix(esp32-c2): Enable flashing in secure download mode Closes https://github.com/espressif/esptool/issues/895 --- esptool/cmds.py | 2 +- esptool/targets/esp32c2.py | 2 +- esptool/util.py | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/esptool/cmds.py b/esptool/cmds.py index 156a27fb4..9f27b3835 100644 --- a/esptool/cmds.py +++ b/esptool/cmds.py @@ -466,7 +466,7 @@ def write_flash(esp, args): flash_end = flash_size_bytes( detect_flash_size(esp) if args.flash_size == "keep" else args.flash_size ) - if flash_end is not None: # Secure download mode + if flash_end is not None: # Not in secure download mode for address, argfile in args.addr_filename: argfile.seek(0, os.SEEK_END) if address + argfile.tell() > flash_end: diff --git a/esptool/targets/esp32c2.py b/esptool/targets/esp32c2.py index f70d4a826..f28ee24f4 100644 --- a/esptool/targets/esp32c2.py +++ b/esptool/targets/esp32c2.py @@ -110,7 +110,7 @@ def change_baud(self, baud): def _post_connect(self): # ESP32C2 ECO0 is no longer supported by the flasher stub - if self.get_chip_revision() == 0: + if not self.secure_download_mode and self.get_chip_revision() == 0: self.stub_is_disabled = True self.IS_STUB = False diff --git a/esptool/util.py b/esptool/util.py index e390e1045..91e4ee16b 100644 --- a/esptool/util.py +++ b/esptool/util.py @@ -34,6 +34,8 @@ def flash_size_bytes(size): """Given a flash size of the type passed in args.flash_size (ie 512KB or 1MB) then return the size in bytes. """ + if size is None: + return None if "MB" in size: return int(size[: size.index("MB")]) * 1024 * 1024 elif "KB" in size: