@@ -905,10 +905,21 @@ def write_flash(
905
905
raise # Reconnect limit reached
906
906
907
907
if esp .IS_STUB :
908
+ # Get the "encrypted" flag for the last file flashed
909
+ # Note: all_files list contains quadruplets like:
910
+ # (address: int, filename: str | None, data: bytes, encrypted: bool)
911
+ last_file_encrypted = all_files [- 1 ][3 ]
912
+
908
913
# Stub only writes each block to flash after 'ack'ing the receive,
909
- # so do a final dummy operation which will not be 'ack'ed
914
+ # so do a final operation which will not be 'ack'ed
910
915
# until the last block has actually been written out to flash
911
- esp .read_reg (ESPLoader .CHIP_DETECT_MAGIC_REG_ADDR , timeout = timeout )
916
+ if compress and not last_file_encrypted :
917
+ esp .flash_defl_finish (reboot = False , timeout = timeout )
918
+ else :
919
+ esp .flash_finish (reboot = False , timeout = timeout )
920
+
921
+ # Skip sending flash_finish to ROM loader here,
922
+ # as it causes the loader to exit and run user code
912
923
913
924
t = time .time () - t
914
925
speed_msg = ""
@@ -948,22 +959,6 @@ def write_flash(
948
959
"Cannot verify written data if encrypted or in secure download mode."
949
960
)
950
961
951
- if esp .IS_STUB :
952
- # skip sending flash_finish to ROM loader here,
953
- # as it causes the loader to exit and run user code
954
- esp .flash_begin (0 , 0 )
955
-
956
- # Get the "encrypted" flag for the last file flashed
957
- # Note: all_files list contains quadruplets like:
958
- # (address: int, filename: str | None, data: bytes, encrypted: bool)
959
- last_file_encrypted = all_files [- 1 ][3 ]
960
-
961
- # Check whether the last file flashed was compressed or not
962
- if compress and not last_file_encrypted :
963
- esp .flash_defl_finish (False )
964
- else :
965
- esp .flash_finish (False )
966
-
967
962
968
963
def read_mac (esp : ESPLoader ) -> None :
969
964
"""
0 commit comments