Skip to content

Commit 2da8950

Browse files
Naveen KajeNaveen Kaje
authored andcommitted
tools: process bootloader chunks
NRF Softdevice hex file can be in chunks. Make sure we account for the space where the bootloader resides by including all the chunks within the end of rom marker. This will clearly mark out the initial bootloader region.
1 parent fac5ff4 commit 2da8950

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

tools/build_api.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,11 @@ def _fill_header(region_list, current_region):
401401
start += Config.header_member_size(member)
402402
return header
403403

404+
def _end_addr_inclusive(addr):
405+
if addr is not None:
406+
return addr + 1
407+
return addr
408+
404409
def merge_region_list(region_list, destination, notify, padding=b'\xFF'):
405410
"""Merge the region_list into a single image
406411
@@ -429,12 +434,15 @@ def merge_region_list(region_list, destination, notify, padding=b'\xFF'):
429434
# make same assumption as in region builder; first segment must fit.
430435
# this is only to get a neat ToolException anyway, since IntelHex.merge will
431436
# throw intelhex.AddressOverlapError if there's overlapping
432-
part_size = part.segments()[0][1] - part.segments()[0][0]
437+
part_size = 0
438+
for es in part.segments():
439+
part_size += es[1] - es[0]
440+
merged.merge(part[es[0]:_end_addr_inclusive(es[1])])
433441

434442
if part_size > region.size:
435443
raise ToolException("Contents of region %s does not fit"
436444
% region.name)
437-
merged.merge(part)
445+
438446
pad_size = region.size - part_size
439447
if pad_size > 0 and region != region_list[-1] and format != ".hex":
440448
notify.info(" Padding region %s with 0x%x bytes" %

tools/config/__init__.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -711,9 +711,17 @@ def _generate_bootloader_build(self, rom_start, rom_size):
711711
raise ConfigException("bootloader executable does not "
712712
"start at 0x%x" % rom_start)
713713

714-
# segments returns start address and 'next after end' address
715-
part_size = part.segments()[0][1] - part.segments()[0][0]
716-
part_size = Config._align_ceiling(rom_start + part_size, self.sectors) - rom_start
714+
# find the last valid address that's within rom_end and use that
715+
# to compute the bootloader size
716+
end_address = None
717+
for each in part.segments():
718+
if (each[1] < rom_end):
719+
end_address = each[1]
720+
else:
721+
break
722+
if end_address == None:
723+
raise ConfigException("bootloader segments don't fit within rom region")
724+
part_size = Config._align_ceiling(rom_start + (end_address - start), self.sectors) - rom_start
717725

718726
yield Region("bootloader", rom_start, part_size, False,
719727
filename)

0 commit comments

Comments
 (0)