Skip to content

Fix expansion of application to target.restrict_size #14994

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions tools/regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,13 @@ def merge_region_list(
region_list,
destination,
notify,
padding=b'\xFF',
restrict_size=None
):
"""Merge the region_list into a single image

Positional Arguments:
region_list - list of regions, which should contain filenames
destination - file name to write all regions to
padding - bytes to fill gaps with
restrict_size - check to ensure a region fits within the given size
"""
merged = IntelHex()
Expand Down Expand Up @@ -159,15 +157,10 @@ def merge_region_list(
" Skipping %s as it is merged previously" % (region.name)
)

# Hex file can have gaps, so no padding needed. While other formats may
# need padding. Iterate through segments and pad the gaps.
if format != ".hex":
# begin patching from the end of the first segment
_, begin = merged.segments()[0]
for start, stop in merged.segments()[1:]:
pad_size = start - begin
merged.puts(begin, padding * pad_size)
begin = stop + 1
if restrict_size is not None:
desired_size = int(restrict_size, 0)
# Rely on IntelHex to pad the binary as required
merged[merged.minaddr() + desired_size - 1] = merged.padding

if not exists(dirname(destination)):
makedirs(dirname(destination))
Expand Down