Skip to content

Commit 4bc8d5b

Browse files
Marek Matejradimkarnis
authored andcommitted
revert(elf2image): revert the use of ELF flags as merge condition
Remove the flags condition from merging function because it prevents merging segments in certain conditions. This reverts commit e87cc3e. Signed-off-by: Marek Matej <[email protected]>
1 parent c06ce1e commit 4bc8d5b

File tree

3 files changed

+16
-22
lines changed

3 files changed

+16
-22
lines changed

esptool/bin_image.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,10 @@ class ImageSegment(object):
115115
"""Wrapper class for a segment in an ESP image
116116
(very similar to a section in an ELFImage also)"""
117117

118-
def __init__(self, addr, data, file_offs=None, flags=0):
118+
def __init__(self, addr, data, file_offs=None):
119119
self.addr = addr
120120
self.data = data
121121
self.file_offs = file_offs
122-
self.flags = flags
123122
self.include_in_checksum = True
124123
if self.addr != 0:
125124
self.pad_to_alignment(
@@ -168,8 +167,8 @@ class ELFSection(ImageSegment):
168167
"""Wrapper class for a section in an ELF image, has a section
169168
name as well as the common properties of an ImageSegment."""
170169

171-
def __init__(self, name, addr, data, flags):
172-
super(ELFSection, self).__init__(addr, data, flags=flags)
170+
def __init__(self, name, addr, data):
171+
super(ELFSection, self).__init__(addr, data)
173172
self.name = name.decode("utf-8")
174173

175174
def __repr__(self):
@@ -179,9 +178,6 @@ def __repr__(self):
179178
class BaseFirmwareImage(object):
180179
SEG_HEADER_LEN = 8
181180
SHA256_DIGEST_LEN = 32
182-
ELF_FLAG_WRITE = 0x1
183-
ELF_FLAG_READ = 0x2
184-
ELF_FLAG_EXEC = 0x4
185181

186182
""" Base class with common firmware image functions """
187183

@@ -377,8 +373,6 @@ def merge_adjacent_segments(self):
377373
elem.get_memory_type(self) == next_elem.get_memory_type(self),
378374
elem.include_in_checksum == next_elem.include_in_checksum,
379375
next_elem.addr == elem.addr + len(elem.data),
380-
next_elem.flags & self.ELF_FLAG_EXEC
381-
== elem.flags & self.ELF_FLAG_EXEC,
382376
)
383377
):
384378
# Merge any segment that ends where the next one starts,
@@ -1285,7 +1279,7 @@ def read_section_header(offs):
12851279
name_offs, sec_type, _flags, lma, sec_offs, size = struct.unpack_from(
12861280
"<LLLLLL", section_header[offs:]
12871281
)
1288-
return (name_offs, sec_type, lma, size, sec_offs, _flags)
1282+
return (name_offs, sec_type, lma, size, sec_offs)
12891283

12901284
all_sections = [read_section_header(offs) for offs in section_header_offsets]
12911285
prog_sections = [s for s in all_sections if s[1] in ELFFile.PROG_SEC_TYPES]
@@ -1294,7 +1288,7 @@ def read_section_header(offs):
12941288
# search for the string table section
12951289
if (shstrndx * self.LEN_SEC_HEADER) not in section_header_offsets:
12961290
raise FatalError("ELF file has no STRTAB section at shstrndx %d" % shstrndx)
1297-
_, sec_type, _, sec_size, sec_offs, _ = read_section_header(
1291+
_, sec_type, _, sec_size, sec_offs = read_section_header(
12981292
shstrndx * self.LEN_SEC_HEADER
12991293
)
13001294
if sec_type != ELFFile.SEC_TYPE_STRTAB:
@@ -1316,14 +1310,14 @@ def read_data(offs, size):
13161310
return f.read(size)
13171311

13181312
prog_sections = [
1319-
ELFSection(lookup_string(n_offs), lma, read_data(offs, size), flags=_flags)
1320-
for (n_offs, _type, lma, size, offs, _flags) in prog_sections
1313+
ELFSection(lookup_string(n_offs), lma, read_data(offs, size))
1314+
for (n_offs, _type, lma, size, offs) in prog_sections
13211315
if lma != 0 and size > 0
13221316
]
13231317
self.sections = prog_sections
13241318
self.nobits_sections = [
1325-
ELFSection(lookup_string(n_offs), lma, b"", flags=_flags)
1326-
for (n_offs, _type, lma, size, offs, _flags) in nobits_secitons
1319+
ELFSection(lookup_string(n_offs), lma, b"")
1320+
for (n_offs, _type, lma, size, offs) in nobits_secitons
13271321
if lma != 0 and size > 0
13281322
]
13291323

@@ -1356,7 +1350,7 @@ def read_segment_header(offs):
13561350
_flags,
13571351
_align,
13581352
) = struct.unpack_from("<LLLLLLLL", segment_header[offs:])
1359-
return (seg_type, lma, size, seg_offs, _flags)
1353+
return (seg_type, lma, size, seg_offs)
13601354

13611355
all_segments = [read_segment_header(offs) for offs in segment_header_offsets]
13621356
prog_segments = [s for s in all_segments if s[0] == ELFFile.SEG_TYPE_LOAD]
@@ -1366,8 +1360,8 @@ def read_data(offs, size):
13661360
return f.read(size)
13671361

13681362
prog_segments = [
1369-
ELFSection(b"PHDR", lma, read_data(offs, size), flags=_flags)
1370-
for (_type, lma, size, offs, _flags) in prog_segments
1363+
ELFSection(b"PHDR", lma, read_data(offs, size))
1364+
for (_type, lma, size, offs) in prog_segments
13711365
if lma != 0 and size > 0
13721366
]
13731367
self.segments = prog_segments

esptool/cmds.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ def write_flash(esp, args):
724724
print("Flash md5: %s" % res)
725725
print(
726726
"MD5 of 0xFF is %s"
727-
% (hashlib.md5(b"\xff" * uncsize).hexdigest())
727+
% (hashlib.md5(b"\xFF" * uncsize).hexdigest())
728728
)
729729
raise FatalError("MD5 of file does not match data in flash!")
730730
else:
@@ -1457,7 +1457,7 @@ def merge_bin(args):
14571457

14581458
def pad_to(flash_offs):
14591459
# account for output file offset if there is any
1460-
of.write(b"\xff" * (flash_offs - args.target_offset - of.tell()))
1460+
of.write(b"\xFF" * (flash_offs - args.target_offset - of.tell()))
14611461

14621462
for addr, argfile in input_files:
14631463
pad_to(addr)

test/test_imagegen.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,8 @@ def test_use_segments(self):
326326
# this ELF will produce 8 segments in the bin
327327
image = self._test_elf2image(ELF, BIN)
328328
# Adjacent sections are now merged, len(image.segments) should
329-
# equal 5 (instead of 8).
330-
assert len(image.segments) == 5
329+
# equal 4 (instead of 8).
330+
assert len(image.segments) == 4
331331

332332
# --use_segments uses ELF segments(phdrs), produces just 2 segments in the bin
333333
image = self._test_elf2image(ELF, BIN, ["--use_segments"])

0 commit comments

Comments
 (0)