espressif / esptool

Espressif SoC serial bootloader utility
https://docs.espressif.com/projects/esptool
GNU General Public License v2.0
5.48k stars 1.36k forks source link

ELFSection check missing in bin_image (ESPTOOL-888) #994

Closed delijati closed 1 month ago

delijati commented 1 month ago

Operating System

Manjaro

Esptool Version

4.7.0

Python Version

Python 3.12

Full Esptool Command Line that Was Run

No response

Esptool Output

No response

What is the Expected Behaviour?

https://github.com/espressif/esptool/blame/d83dd3be6e961ce97ba49f1b1e17a98a68ff2ef5/esptool/bin_image.py#L709

should be

if isinstance(segment, ELFSection) and segment.name == ".dram0.bootdesc":

I have a function that fixes the checksum of an OTA update image:

def fix_image(data, filename):
    global DRAM0_DATA_START, DRAM0_DATA_END

    try:
        f = io.BytesIO(data)
        image = esptool.bin_image.ESP32FirmwareImage(f)
        # calculate_checksum
    except Exception as inst:
        print("Failed to parse : " + filename)
        print(inst)
        return False

    print("Image version: {}".format(image.version))
    # TODO https://github.com/espressif/esptool/issues/994

    for seg in image.segments:
        if if_addr_in_seg(image, seg.addr, "DROM"):
            seg_app_data = ESP_APP_DESC_STRUCT(seg.data)
            print("App data: {}".format(seg_app_data))

    fixed_image = None
    fixed_filename = filename + ".fixed"

    image.save(fixed_filename)
    with open(fixed_filename, "rb") as f:
        fixed_image = f.read()

    output_image = fixed_image + data[len(fixed_image) : len(data)]

    with open(fixed_filename, "wb") as f:
        f.write(output_image)

    return True

More Information

No response

Other Steps to Reproduce

No response

peterdragun commented 1 month ago

Hi @delijati, thank you for the report, we will try to fix this as soon as possible.