Skip to content

Commit 4393e4b

Browse files
author
Naveen Kaje
committed
tools: check part size is not exceeding region size
If config is specified, check that part size is not exceeding the region. Normally we now assume that part.maxaddr() can be beyond end of rom.
1 parent b56ab51 commit 4393e4b

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

tools/build_api.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ def _fill_header(region_list, current_region):
411411
return header
412412

413413

414-
def merge_region_list(region_list, destination, notify, padding=b'\xFF'):
414+
def merge_region_list(region_list, destination, notify, config, padding=b'\xFF'):
415415
"""Merge the region_list into a single image
416416
417417
Positional Arguments:
@@ -435,6 +435,13 @@ def merge_region_list(region_list, destination, notify, padding=b'\xFF'):
435435
notify.info(" Filling region %s with %s" % (region.name, region.filename))
436436
part = intelhex_offset(region.filename, offset=region.start)
437437
part.start_addr = None
438+
# Normally, we assume that part.maxddr() can be beyond
439+
# end of rom. However, if the size is restricted with config, do check.
440+
if config.target.restrict_size is not None:
441+
part_size = (part.maxaddr() - part.minaddr()) + 1
442+
if part_size > region.size:
443+
raise ToolException("Contents of region %s does not fit"
444+
% region.name)
438445
merged.merge(part)
439446

440447
# Hex file can have gaps, so no padding needed. While other formats may
@@ -555,13 +562,13 @@ def build_project(src_paths, build_path, target, toolchain_name,
555562
for r in region_list]
556563
res = "%s.%s" % (join(build_path, name),
557564
getattr(toolchain.target, "OUTPUT_EXT", "bin"))
558-
merge_region_list(region_list, res, notify)
565+
merge_region_list(region_list, res, notify, toolchain.config)
559566
update_regions = [
560567
r for r in region_list if r.name in UPDATE_WHITELIST
561568
]
562569
if update_regions:
563570
update_res = join(build_path, generate_update_filename(name, toolchain.target))
564-
merge_region_list(update_regions, update_res, notify)
571+
merge_region_list(update_regions, update_res, notify, toolchain.config)
565572
res = (res, update_res)
566573
else:
567574
res = (res, None)

0 commit comments

Comments
 (0)