Skip to content

Commit bd40457

Browse files
Naveen KajeNaveen Kaje
authored andcommitted
tools: Update build_api padding method
Update the padding sequence so that the gaps are padded after all the regions are merged. This avoids overwriting active regions and serializes the process.
1 parent e28c260 commit bd40457

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

tools/build_api.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -433,30 +433,25 @@ def merge_region_list(region_list, destination, notify, padding=b'\xFF'):
433433

434434
# make same assumption as in region builder; first segment must fit.
435435
# this is only to get a neat ToolException anyway, since IntelHex.merge will
436-
# throw intelhex.AddressOverlapError if there's overlapping
436+
# throw IntelHex.AddressOverlapError if there's overlapping
437437
part_size = 0
438438
for es in part.segments():
439-
# Add padding in between segments starting from end of first segment
440-
if (len(part.segments()) > 1 and (merged.maxaddr() != None)):
441-
pad_size = es[0] - (merged.maxaddr() + 1)
442-
merged.puts(merged.maxaddr()+1, padding * pad_size)
443439
part_size += es[1] - es[0]
444440
merged.merge(part[es[0]:_end_addr_inclusive(es[1])])
445441

446442
if part_size > region.size:
447443
raise ToolException("Contents of region %s does not fit"
448444
% region.name)
449445

450-
# This padding applies for only files with one segment
451-
if (len(part.segments()) == 1):
452-
pad_size = region.size - part_size
453-
else:
454-
pad_size = 0
455-
456-
if pad_size > 0 and region != region_list[-1] and format != ".hex":
457-
notify.info(" Padding region %s with 0x%x bytes" %
458-
(region.name, pad_size))
459-
merged.puts(merged.maxaddr() + 1, padding * pad_size)
446+
# Hex file can have gaps, so no padding needed. While other formats may
447+
# need padding. Iterate through segments and pad the gaps.
448+
if (format != ".hex"):
449+
begin = 0
450+
for es in merged.segments():
451+
if (begin < es[0]):
452+
pad_size = es[0] - begin
453+
merged.puts(begin, padding * pad_size)
454+
begin = es[1] + 1
460455

461456
if not exists(dirname(destination)):
462457
makedirs(dirname(destination))

0 commit comments

Comments
 (0)