From b2e4c447348490bc23565aa701ea0ffdadb73871 Mon Sep 17 00:00:00 2001 From: Naveen Kaje Date: Mon, 29 Oct 2018 16:36:56 -0500 Subject: [PATCH] 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. --- tools/build_api.py | 12 ++++++++++-- tools/config/__init__.py | 14 +++++++++++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/tools/build_api.py b/tools/build_api.py index 70af5ee94b..88dede8679 100644 --- a/tools/build_api.py +++ b/tools/build_api.py @@ -401,6 +401,11 @@ def _fill_header(region_list, current_region): start += Config.header_member_size(member) return header +def _end_addr_inclusive(addr): + if addr is not None: + return addr + 1 + return addr + def merge_region_list(region_list, destination, notify, padding=b'\xFF'): """Merge the region_list into a single image @@ -429,12 +434,15 @@ def merge_region_list(region_list, destination, notify, padding=b'\xFF'): # make same assumption as in region builder; first segment must fit. # this is only to get a neat ToolException anyway, since IntelHex.merge will # throw intelhex.AddressOverlapError if there's overlapping - part_size = part.segments()[0][1] - part.segments()[0][0] + part_size = 0 + for es in part.segments(): + part_size += es[1] - es[0] + merged.merge(part[es[0]:_end_addr_inclusive(es[1])]) if part_size > region.size: raise ToolException("Contents of region %s does not fit" % region.name) - merged.merge(part) + pad_size = region.size - part_size if pad_size > 0 and region != region_list[-1] and format != ".hex": notify.info(" Padding region %s with 0x%x bytes" % diff --git a/tools/config/__init__.py b/tools/config/__init__.py index 91d4ad2ed7..f78d2cdabe 100644 --- a/tools/config/__init__.py +++ b/tools/config/__init__.py @@ -798,9 +798,17 @@ class Config(object): raise ConfigException("bootloader executable does not " "start at 0x%x" % rom_start) - # segments returns start address and 'next after end' address - part_size = part.segments()[0][1] - part.segments()[0][0] - part_size = Config._align_ceiling(rom_start + part_size, self.sectors) - rom_start + # find the last valid address that's within rom_end and use that + # to compute the bootloader size + end_address = None + for each in part.segments(): + if (each[1] < rom_end): + end_address = each[1] + else: + break + if end_address == None: + raise ConfigException("bootloader segments don't fit within rom region") + part_size = Config._align_ceiling(rom_start + (end_address - start), self.sectors) - rom_start yield Region("bootloader", rom_start, part_size, False, filename)