def _generate_booloader_build(self, target_overrides, rom_start, rom_size): start = 0 if 'target.bootloader_img' in target_overrides: basedir = abspath(dirname(self.app_config_location)) filename = join(basedir, target_overrides['target.bootloader_img']) if not exists(filename): raise ConfigException("Bootloader %s not found" % filename) part = intelhex_offset(filename, offset=rom_start) if part.minaddr() != rom_start: raise ConfigException("bootloader executable does not " "start at 0x%x" % rom_start) part_size = (part.maxaddr() - part.minaddr()) + 1 yield Region("bootloader", rom_start + start, part_size, False, filename) start += part_size if 'target.restrict_size' in target_overrides: new_size = int(target_overrides['target.restrict_size'], 0) yield Region("application", rom_start + start, new_size, True, None) start += new_size yield Region("post_application", rom_start +start, rom_size - start, False, None) else: yield Region("application", rom_start + start, rom_size - start, True, None) if start > rom_size: raise ConfigException("Not enough memory on device to fit all " "application regions")
def _generate_bootloader_build(self, rom_start, rom_size): start = rom_start rom_end = rom_start + rom_size if self.target.bootloader_img: if isabs(self.target.bootloader_img): filename = self.target.bootloader_img else: basedir = abspath(dirname(self.app_config_location)) filename = join(basedir, self.target.bootloader_img) if not exists(filename): raise ConfigException("Bootloader %s not found" % filename) part = intelhex_offset(filename, offset=rom_start) 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 yield Region("bootloader", rom_start, part_size, False, filename) start = rom_start + part_size 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 yield Region("application", start, new_size, True, None) start += new_size yield Region("post_application", start, rom_end - start, False, None) else: yield Region("application", start, rom_end - start, True, None) if start > rom_start + rom_size: raise ConfigException("Not enough memory on device to fit all " "application regions")
def merge_region_list(region_list, destination, padding=b'\xFF'): """Merege the region_list into a single image Positional Arguments: region_list - list of regions, which should contain filenames destination - file name to write all regions to padding - bytes to fill gapps with """ merged = IntelHex() print("Merging Regions:") for region in region_list: if region.active and not region.filename: raise ToolException("Active region has no contents: No file found.") if region.filename: print(" Filling region %s with %s" % (region.name, region.filename)) part = intelhex_offset(region.filename, offset=region.start) 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]: print(" Padding region %s with 0x%x bytes" % (region.name, pad_size)) merged.puts(merged.maxaddr() + 1, padding * pad_size) if not exists(dirname(destination)): makedirs(dirname(destination)) print("Space used after regions merged: 0x%x" % (merged.maxaddr() - merged.minaddr() + 1)) with open(destination, "wb+") as output: merged.tofile(output, format='bin')
def regions(self): """Generate a list of regions from the config""" if not self.target.bootloader_supported: raise ConfigException("Bootloader not supported on this target.") cmsis_part = Cache(False, False).index[self.target.device_name] start = 0 target_overrides = self.app_config_data['target_overrides'].get( self.target.name, {}) try: rom_size = int(cmsis_part['memory']['IROM1']['size'], 0) rom_start = int(cmsis_part['memory']['IROM1']['start'], 0) except KeyError: raise ConfigException("Not enough information in CMSIS packs to " "build a bootloader project") if 'target.bootloader_img' in target_overrides: filename = target_overrides['target.bootloader_img'] if not exists(filename): raise ConfigException("Bootloader %s not found" % filename) part = intelhex_offset(filename, offset=rom_start) if part.minaddr() != rom_start: raise ConfigException("bootloader executable does not " "start at 0x%x" % rom_start) part_size = (part.maxaddr() - part.minaddr()) + 1 yield Region("bootloader", rom_start + start, part_size, False, filename) start += part_size if 'target.restrict_size' in target_overrides: new_size = int(target_overrides['target.restrict_size'], 0) yield Region("application", rom_start + start, new_size, True, None) start += new_size yield Region("post_application", rom_start + start, rom_size - start, False, None) else: yield Region("application", rom_start + start, rom_size - start, True, None) if start > rom_size: raise ConfigException("Not enough memory on device to fit all " "application regions")
def regions(self): """Generate a list of regions from the config""" if not self.target.bootloader_supported: raise ConfigException("Bootloader not supported on this target.") cmsis_part = Cache(False, False).index[self.target.device_name] start = 0 target_overrides = self.app_config_data['target_overrides'].get( self.target.name, {}) try: rom_size = int(cmsis_part['memory']['IROM1']['size'], 0) rom_start = int(cmsis_part['memory']['IROM1']['start'], 0) except KeyError: raise ConfigException("Not enough information in CMSIS packs to " "build a bootloader project") if 'target.bootloader_img' in target_overrides: filename = target_overrides['target.bootloader_img'] part = intelhex_offset(filename, offset=rom_start) if part.minaddr() != rom_start: raise ConfigException("bootloader executable does not " "start at 0x%x" % rom_start) part_size = (part.maxaddr() - part.minaddr()) + 1 yield Region("bootloader", rom_start + start, part_size, False, filename) start += part_size if 'target.restrict_size' in target_overrides: new_size = int(target_overrides['target.restrict_size'], 0) yield Region("application", rom_start + start, new_size, True, None) start += new_size yield Region("post_application", rom_start +start, rom_size - start, False, None) else: yield Region("application", rom_start + start, rom_size - start, True, None) if start > rom_size: raise ConfigException("Not enough memory on device to fit all " "application regions")