Skip to content

Commit

Permalink
fix factory flash
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason2866 committed Nov 17, 2023
1 parent 0f9fed9 commit a264d96
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions esp_flasher/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def run_esp_flasher(argv):

print(f" - Flash Size: {flash_size}")

flag_factory = ""
flag_factory = False
min_rev = 0
min_rev_full = 0
max_rev_full = 65535
Expand All @@ -186,7 +186,7 @@ def run_esp_flasher(argv):
args.input, secure_pad, secure_pad_v2, min_rev, min_rev_full, max_rev_full, elf_sha256_offset,
use_segments, flash_mmu_page_size, pad_to_size, spi_connection, output
)
if (not "ESP8266" in info.family) and ("False" in mock_args.flag_factory):
if (not "ESP8266" in info.family) and (not mock_args.flag_factory):
try:
esptool.elf2image(mock_args)
except esptool.FatalError as err:
Expand Down
18 changes: 9 additions & 9 deletions esp_flasher/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,12 @@ def detect_flash_size(stub_chip):
def read_firmware_info(firmware):
firmware.seek(0x10000)
header = firmware.read(4)
magic, _, _, _, = struct.unpack("BBBB", header)
magic, _, flash_mode_raw, flash_size_freq = struct.unpack("BBBB", header)
if magic == esptool.ESPLoader.ESP_IMAGE_MAGIC:
flash_mode = ""
flash_freq = ""
flag_factory = "True"
flash_freq_raw = flash_size_freq & 0x0F
flash_mode = {0: "qio", 1: "qout", 2: "dio", 3: "dout"}.get(flash_mode_raw)
flash_freq = {0: "40m", 1: "26m", 2: "20m", 0xF: "80m"}.get(flash_freq_raw)
flag_factory = True
return flash_mode, flash_freq, flag_factory

firmware.seek(0)
Expand All @@ -175,7 +176,7 @@ def read_firmware_info(firmware):
flash_freq_raw = flash_size_freq & 0x0F
flash_mode = {0: "qio", 1: "qout", 2: "dio", 3: "dout"}.get(flash_mode_raw)
flash_freq = {0: "40m", 1: "26m", 2: "20m", 0xF: "80m"}.get(flash_freq_raw)
flag_factory = "False"
flag_factory = False
return flash_mode, flash_freq, flag_factory

if magic != esptool.ESPLoader.ESP_IMAGE_MAGIC:
Expand Down Expand Up @@ -230,10 +231,9 @@ def configure_write_flash_args(
addr_filename = []
firmware = open_downloadable_binary(firmware_path)
flash_mode, flash_freq, flag_factory = read_firmware_info(firmware)
print("Flag Factory: ", flag_factory)
if "True" in flag_factory:
print("Detected Factory Firmware")
if (isinstance(info, ESP32ChipInfo)) and ("False" in flag_factory):
if flag_factory:
print("Detected factory firmware Image, flashing without changes")
if (isinstance(info, ESP32ChipInfo)) and not flag_factory:
ofs_partitions = 0x8000
ofs_otadata = 0xe000
ofs_factory_firm = 0x10000
Expand Down

0 comments on commit a264d96

Please sign in to comment.