Skip to content

Commit

Permalink
image_info: add -x option to extract segments to disk
Browse files Browse the repository at this point in the history
  • Loading branch information
sven337 committed Oct 24, 2024
1 parent 1b15738 commit 2d2c374
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions esptool/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,11 @@ def add_spi_flash_subparsers(
default="1",
)

parser_image_info.add_argument(
'--extract', '-x', action='store_true',
help='Extract image segments to files'
)

parser_make_image = subparsers.add_parser(
"make_image", help="Create an application image from binary files"
)
Expand Down
7 changes: 7 additions & 0 deletions esptool/cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,13 @@ def get_key_from_value(dict, val):
segs = seg.get_memory_type(image)
seg_name = ",".join(segs)
print("Segment {}: {} [{}]".format(idx, seg, seg_name))
if args.extract:
# Create filename for the extracted segment
filename = f"/tmp/seg{idx}_len0x{len(seg.data):x}_addr0x{seg.addr:x}"
with open(filename, "wb") as f:
f.write(seg.data)
print(f" Extracted to: {filename}")

calc_checksum = image.calculate_checksum()
print(
"Checksum: {:02x} ({})".format(
Expand Down

0 comments on commit 2d2c374

Please sign in to comment.