mirror of
https://github.com/espressif/esptool.git
synced 2025-10-19 20:13:00 +08:00
fix(detect_chip): Select correct loader before further operations to avoid silent failures
If there is a return statement in finally block, it will prevent unhandled exceptions from try block and all exceptions from except block to be propagated. Also, checking if esptool communicates with stub is performed earlier. Closes https://github.com/espressif/esptool/issues/1025
This commit is contained in:
@@ -97,6 +97,14 @@ def detect_chip(
|
||||
if detect_port.serial_port.startswith("rfc2217:"):
|
||||
detect_port.USES_RFC2217 = True
|
||||
detect_port.connect(connect_mode, connect_attempts, detecting=True)
|
||||
|
||||
def check_if_stub(instance):
|
||||
print(f" {instance.CHIP_NAME}", end="")
|
||||
if detect_port.sync_stub_detected:
|
||||
instance = instance.STUB_CLASS(instance)
|
||||
instance.sync_stub_detected = True
|
||||
return instance
|
||||
|
||||
try:
|
||||
print("Detecting chip type...", end="")
|
||||
chip_id = detect_port.get_chip_id()
|
||||
@@ -112,6 +120,7 @@ def detect_chip(
|
||||
) # Dummy read to check Secure Download mode
|
||||
except UnsupportedCommandError:
|
||||
inst.secure_download_mode = True
|
||||
inst = check_if_stub(inst)
|
||||
inst._post_connect()
|
||||
break
|
||||
else:
|
||||
@@ -137,6 +146,7 @@ def detect_chip(
|
||||
for cls in ROM_LIST:
|
||||
if chip_magic_value in cls.CHIP_DETECT_MAGIC_VALUE:
|
||||
inst = cls(detect_port._port, baud, trace_enabled=trace_enabled)
|
||||
inst = check_if_stub(inst)
|
||||
inst._post_connect()
|
||||
inst.check_chip_id()
|
||||
break
|
||||
@@ -148,14 +158,9 @@ def detect_chip(
|
||||
"Probably this means Secure Download Mode is enabled, "
|
||||
"autodetection will not work. Need to manually specify the chip."
|
||||
)
|
||||
finally:
|
||||
if inst is not None:
|
||||
print(" %s" % inst.CHIP_NAME, end="")
|
||||
if detect_port.sync_stub_detected:
|
||||
inst = inst.STUB_CLASS(inst)
|
||||
inst.sync_stub_detected = True
|
||||
print("") # end line
|
||||
return inst
|
||||
if inst is not None:
|
||||
return inst
|
||||
|
||||
raise FatalError(
|
||||
f"{err_msg} Failed to autodetect chip type."
|
||||
"\nProbably it is unsupported by this version of esptool."
|
||||
|
Reference in New Issue
Block a user