Introduce sector ceiling/floor rounding

Use ceiling for bootloader end address
Use floor for application size
pull/6056/head
sarahmarshy 2018-01-11 16:33:14 -06:00 committed by adbridge
parent 9cdc6c75e3
commit 32b8cff1b3
1 changed files with 22 additions and 16 deletions

View File

@ -564,31 +564,26 @@ class Config(object):
raise ConfigException("bootloader executable does not " raise ConfigException("bootloader executable does not "
"start at 0x%x" % rom_start) "start at 0x%x" % rom_start)
part_size = (part.maxaddr() - part.minaddr()) + 1 part_size = (part.maxaddr() - part.minaddr()) + 1
start = Config._align_on_sector(rom_start + start, self.sectors) - rom_start part_size = Config._align_ceiling(rom_start + part_size, self.sectors) - rom_start
offset = start + rom_start yield Region("bootloader", rom_start, part_size, False,
part_size = Config._align_on_sector(offset + part_size, self.sectors) - offset
yield Region("bootloader", offset, part_size, False,
filename) filename)
start += part_size start = rom_start + part_size
if 'target.restrict_size' in target_overrides: if 'target.restrict_size' in target_overrides:
new_size = int(target_overrides['target.restrict_size'], 0) new_size = int(target_overrides['target.restrict_size'], 0)
start = Config._align_on_sector(rom_start + start, self.sectors) - rom_start new_size = Config._align_floor(start + new_size, self.sectors) - start
offset = rom_start + start yield Region("application", start, new_size, True, None)
new_size = Config._align_on_sector(offset + new_size, self.sectors) - offset
yield Region("application", offset, new_size, True, None)
start += new_size start += new_size
start = Config._align_on_sector(rom_start + start, self.sectors) - rom_start
yield Region("post_application", rom_start + start, rom_size - start, yield Region("post_application", rom_start + start, rom_size - start,
False, None) False, None)
else: else:
start = Config._align_on_sector(rom_start + start, self.sectors) - rom_start yield Region("application", start, rom_size - start,
yield Region("application", rom_start + start, rom_size - start,
True, None) True, None)
if start > rom_size: if start > rom_start + rom_size:
raise ConfigException("Not enough memory on device to fit all " raise ConfigException("Not enough memory on device to fit all "
"application regions") "application regions")
@staticmethod @staticmethod
def _align_on_sector(address, sectors): def _find_sector(address, sectors):
target_size = -1 target_size = -1
target_start = -1 target_start = -1
for (start, size) in sectors: for (start, size) in sectors:
@ -598,9 +593,20 @@ class Config(object):
target_size = size target_size = size
if (target_size < 0): if (target_size < 0):
raise ConfigException("No valid sector found") raise ConfigException("No valid sector found")
return target_start, target_size
@staticmethod
def _align_floor(address, sectors):
target_start, target_size = Config._find_sector(address, sectors)
sector_num = (address - target_start) // target_size sector_num = (address - target_start) // target_size
return target_start + (sector_num * target_size) return target_start + (sector_num * target_size)
@staticmethod
def _align_ceiling(address, sectors):
target_start, target_size = Config._find_sector(address, sectors)
sector_num = ((address - target_start) + target_size - 1) // target_size
return target_start + (sector_num * target_size)
@property @property
def report(self): def report(self):
return {'app_config': self.app_config_location, return {'app_config': self.app_config_location,