Skip to content

Add support for nrf52_dk bootloader #8097

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

Merged
merged 9 commits into from
Dec 4, 2018
Merged
Show file tree
Hide file tree
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
25 changes: 11 additions & 14 deletions tools/build_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ def _fill_header(region_list, current_region):
start += Config.header_member_size(member)
return header


def merge_region_list(region_list, destination, notify, padding=b'\xFF'):
"""Merge the region_list into a single image

Expand All @@ -411,7 +412,6 @@ def merge_region_list(region_list, destination, notify, padding=b'\xFF'):
"""
merged = IntelHex()
_, format = splitext(destination)

notify.info("Merging Regions")

for region in region_list:
Expand All @@ -426,20 +426,17 @@ def merge_region_list(region_list, destination, notify, padding=b'\xFF'):
notify.info(" Filling region %s with %s" % (region.name, region.filename))
part = intelhex_offset(region.filename, offset=region.start)
part.start_addr = None
part_size = (part.maxaddr() - part.minaddr()) + 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]:
notify.info(" Padding region %s with 0x%x bytes" %
(region.name, pad_size))
if format is ".hex":
"""The offset will be in the hex file generated when we're done,
so we can skip padding here"""
else:
merged.puts(merged.maxaddr() + 1, padding * pad_size)

# 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 not exists(dirname(destination)):
makedirs(dirname(destination))
Expand Down
28 changes: 21 additions & 7 deletions tools/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ def _assign_new_offset(rom_start, start, new_offset, region_name):
newstart = rom_start + integer(new_offset, 0)
if newstart < start:
raise ConfigException(
"Can not place % region inside previous region" % region_name)
"Can not place %r region inside previous region" % region_name)
return newstart

def _generate_bootloader_build(self, rom_start, rom_size):
Expand All @@ -710,8 +710,19 @@ def _generate_bootloader_build(self, rom_start, rom_size):
if part.minaddr() != rom_start:
raise ConfigException("bootloader executable does not "
"start at 0x%x" % rom_start)
part_size = (part.maxaddr() - part.minaddr()) + 1
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 start, stop in part.segments():
if (stop < rom_end):
end_address = stop
else:
break
if end_address == None:
raise ConfigException("bootloader segments don't fit within rom region")
part_size = Config._align_ceiling(end_address, self.sectors) - rom_start

yield Region("bootloader", rom_start, part_size, False,
filename)
start = rom_start + part_size
Expand All @@ -722,9 +733,14 @@ def _generate_bootloader_build(self, rom_start, rom_size):
start, region = self._make_header_region(
start, self.target.header_format)
yield region._replace(filename=self.target.header_format)

if self.target.restrict_size is not None:
new_size = int(self.target.restrict_size, 0)
new_size = Config._align_floor(start + new_size, self.sectors) - start

if self.target.app_offset:
start = self._assign_new_offset(rom_start, start, self.target.app_offset, "application")

yield Region("application", start, new_size, True, None)
start += new_size
if self.target.header_format and not self.target.bootloader_img:
Expand All @@ -734,9 +750,7 @@ def _generate_bootloader_build(self, rom_start, rom_size):
start, region = self._make_header_region(
start, self.target.header_format)
yield region
if self.target.app_offset:
start = self._assign_new_offset(
rom_start, start, self.target.app_offset, "application")

yield Region("post_application", start, rom_end - start,
False, None)
else:
Expand All @@ -745,7 +759,7 @@ def _generate_bootloader_build(self, rom_start, rom_size):
rom_start, start, self.target.app_offset, "application")
yield Region("application", start, rom_end - start,
True, None)
if start > rom_start + rom_size:
if start > rom_end:
raise ConfigException("Not enough memory on device to fit all "
"application regions")

Expand Down