Skip to content

Commit 671cf40

Browse files
authored
Merge pull request #6007 from theotherjimmy/bl-heed-outputext
Take OUTPUT_EXT into account in managed bl
2 parents 779ee84 + c09142e commit 671cf40

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

tools/build_api.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ def merge_region_list(region_list, destination, padding=b'\xFF'):
346346
padding - bytes to fill gapps with
347347
"""
348348
merged = IntelHex()
349+
_, format = splitext(destination)
349350

350351
print("Merging Regions:")
351352

@@ -363,14 +364,18 @@ def merge_region_list(region_list, destination, padding=b'\xFF'):
363364
pad_size = region.size - part_size
364365
if pad_size > 0 and region != region_list[-1]:
365366
print(" Padding region %s with 0x%x bytes" % (region.name, pad_size))
366-
merged.puts(merged.maxaddr() + 1, padding * pad_size)
367+
if format is ".hex":
368+
"""The offset will be in the hex file generated when we're done,
369+
so we can skip padding here"""
370+
else:
371+
merged.puts(merged.maxaddr() + 1, padding * pad_size)
367372

368373
if not exists(dirname(destination)):
369374
makedirs(dirname(destination))
370375
print("Space used after regions merged: 0x%x" %
371376
(merged.maxaddr() - merged.minaddr() + 1))
372377
with open(destination, "wb+") as output:
373-
merged.tofile(output, format='bin')
378+
merged.tofile(output, format=format.strip("."))
374379

375380
def scan_resources(src_paths, toolchain, dependencies_paths=None,
376381
inc_dirs=None, base_path=None, collect_ignores=False):
@@ -512,7 +517,8 @@ def build_project(src_paths, build_path, target, toolchain_name,
512517
region_list = list(toolchain.config.regions)
513518
region_list = [r._replace(filename=res) if r.active else r
514519
for r in region_list]
515-
res = join(build_path, name) + ".bin"
520+
res = "%s.%s" % (join(build_path, name),
521+
getattr(toolchain.target, "OUTPUT_EXT", "bin"))
516522
merge_region_list(region_list, res)
517523
else:
518524
res, _ = toolchain.link_program(resources, build_path, name)

0 commit comments

Comments
 (0)