Skip to content

Commit 9e8f246

Browse files
authored
Update esptool.py
1 parent e0b9957 commit 9e8f246

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

tools/esptool.py

+22-8
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,10 @@ def detect_chip(port=DEFAULT_PORT, baud=ESP_ROM_BAUD, connect_mode='default_rese
374374
if chip_id == cls.IMAGE_CHIP_ID:
375375
inst = cls(detect_port._port, baud, trace_enabled=trace_enabled)
376376
inst._post_connect()
377+
try:
378+
inst.read_reg(ESPLoader.CHIP_DETECT_MAGIC_REG_ADDR) # Dummy read to check Secure Download mode
379+
except UnsupportedCommandError:
380+
inst.secure_download_mode = True
377381
except (UnsupportedCommandError, struct.error, FatalError) as e:
378382
# UnsupportedCmdErr: ESP8266/ESP32 ROM | struct.err: ESP32-S2 | FatalErr: ESP8266/ESP32 STUB
379383
print(" Unsupported detection protocol, switching and trying again...")
@@ -2376,6 +2380,11 @@ class ESP32C2ROM(ESP32C3ROM):
23762380
CHIP_NAME = "ESP32-C2"
23772381
IMAGE_CHIP_ID = 12
23782382

2383+
IROM_MAP_START = 0x42000000
2384+
IROM_MAP_END = 0x42400000
2385+
DROM_MAP_START = 0x3c000000
2386+
DROM_MAP_END = 0x3c400000
2387+
23792388
CHIP_DETECT_MAGIC_VALUE = [0x6f51306f]
23802389

23812390
EFUSE_BASE = 0x60008800
@@ -4730,16 +4739,21 @@ def flash_xmc_startup():
47304739
print("XMC flash chip boot-up fix successful!")
47314740

47324741
# Check flash chip connection
4733-
try:
4734-
flash_id = esp.flash_id()
4735-
if flash_id in (0xffffff, 0x000000):
4736-
print('WARNING: Failed to communicate with the flash chip, read/write operations will fail. '
4737-
'Try checking the chip connections or removing any other hardware connected to IOs.')
4738-
except Exception as e:
4739-
esp.trace('Unable to verify flash chip connection ({}).'.format(e))
4742+
if not esp.secure_download_mode:
4743+
try:
4744+
flash_id = esp.flash_id()
4745+
if flash_id in (0xffffff, 0x000000):
4746+
print('WARNING: Failed to communicate with the flash chip, read/write operations will fail. '
4747+
'Try checking the chip connections or removing any other hardware connected to IOs.')
4748+
except Exception as e:
4749+
esp.trace('Unable to verify flash chip connection ({}).'.format(e))
47404750

47414751
# Check if XMC SPI flash chip booted-up successfully, fix if not
4742-
flash_xmc_startup()
4752+
if not esp.secure_download_mode:
4753+
try:
4754+
flash_xmc_startup()
4755+
except Exception as e:
4756+
esp.trace('Unable to perform XMC flash chip startup sequence ({}).'.format(e))
47434757

47444758
if hasattr(args, "flash_size"):
47454759
print("Configuring flash size...")

0 commit comments

Comments
 (0)