#!/usr/bin/env python3 """Wrap the segments of an ESP8266 (v1) app image in a minimal ELF so binutils can read it. Reads only the app image (the 0x1000 slot of a full flash dump), never SPIFFS. python tools/esp8266_image_to_elf.py [--offset 0x1000] Each image segment becomes one section (.irom0, .iram0_N, .dram0_N) at its load address, so `xtensa-lx106-elf-objdump -d out.elf` disassembles with real addresses. """ import argparse import struct APP_SLOT_MAX = 0x100000 # never read past the 1 MB app slot (SPIFFS starts at 0x200000) def read_segments(image): magic, nseg, _mode, _sizefreq, entry = struct.unpack_from("= 0x40000000 else 6 # R+X for code, R+W for data out += struct.pack("= 0x40000000 sh_flags = 0x2 | (0x4 if code else 0x1) # ALLOC + EXECINSTR / WRITE out += struct.pack("