diff --git a/tools/build_api.py b/tools/build_api.py index 23a5259bd4..147009cc12 100644 --- a/tools/build_api.py +++ b/tools/build_api.py @@ -284,31 +284,6 @@ def get_mbed_official_release(version): return mbed_official_release -def add_regions_to_profile(profile, config, toolchain_class): - """Add regions to the build profile, if there are any. - - Positional Arguments: - profile - the profile to update - config - the configuration object that owns the region - toolchain_class - the class of the toolchain being used - """ - if not profile: - return - regions = list(config.regions) - for region in regions: - for define in [(region.name.upper() + "_ADDR", region.start), - (region.name.upper() + "_SIZE", region.size)]: - profile["common"].append("-D%s=0x%x" % define) - active_region = [r for r in regions if r.active][0] - for define in [("MBED_APP_START", active_region.start), - ("MBED_APP_SIZE", active_region.size)]: - profile["ld"].append(toolchain_class.make_ld_define(*define)) - - print("Using regions in this build:") - for region in regions: - print(" Region %s size 0x%x, offset 0x%x" - % (region.name, region.size, region.start)) - def prepare_toolchain(src_paths, build_dir, target, toolchain_name, macros=None, clean=False, jobs=1, @@ -352,9 +327,6 @@ def prepare_toolchain(src_paths, build_dir, target, toolchain_name, for key in profile: profile[key].extend(contents[toolchain_name][key]) - if config.has_regions: - add_regions_to_profile(profile, config, cur_tc) - toolchain = cur_tc(target, notify, macros, silent, build_dir=build_dir, extra_verbose=extra_verbose, build_profile=profile) diff --git a/tools/config/__init__.py b/tools/config/__init__.py index f1de54e020..249afb4c8a 100644 --- a/tools/config/__init__.py +++ b/tools/config/__init__.py @@ -17,7 +17,7 @@ limitations under the License. from copy import deepcopy import os -from os.path import dirname, abspath, exists, join +from os.path import dirname, abspath, exists, join, isabs import sys from collections import namedtuple from os.path import splitext, relpath @@ -30,6 +30,10 @@ from tools.arm_pack_manager import Cache from tools.targets import CUMULATIVE_ATTRIBUTES, TARGET_MAP, \ generate_py_target, get_resolution_order +PATH_OVERRIDES = set(["target.bootloader_img"]) +BOOTLOADER_OVERRIDES = set(["target.bootloader_img", "target.restrict_size", + "target.mbed_app_start", "target.mbed_app_size"]) + # Base class for all configuration exceptions class ConfigException(Exception): """Config system only exception. Makes it easier to distinguish config @@ -84,6 +88,8 @@ class ConfigParameter(object): else: prefix = unit_name + '.' return prefix + name + if name in BOOTLOADER_OVERRIDES: + return name # The name has a prefix, so check if it is valid if not allow_prefix: raise ConfigException("Invalid parameter name '%s' in '%s'" % @@ -362,8 +368,6 @@ class Config(object): "artifact_name": str} } - __unused_overrides = set(["target.bootloader_img", "target.restrict_size", - "target.mbed_app_start", "target.mbed_app_size"]) # Allowed features in configurations __allowed_features = [ @@ -441,6 +445,9 @@ class Config(object): self.target = tgt self.target = deepcopy(self.target) self.target_labels = self.target.labels + for override in BOOTLOADER_OVERRIDES: + _, attr = override.split(".") + setattr(self.target, attr, None) self.cumulative_overrides = {key: ConfigCumulativeOverride(key) for key in CUMULATIVE_ATTRIBUTES} @@ -488,15 +495,11 @@ class Config(object): @property def has_regions(self): """Does this config have regions defined?""" - if 'target_overrides' in self.app_config_data: - target_overrides = self.app_config_data['target_overrides'].get( - self.target.name, {}) - return ('target.bootloader_img' in target_overrides or - 'target.restrict_size' in target_overrides or - 'target.mbed_app_start' in target_overrides or - 'target.mbed_app_size' in target_overrides) - else: - return False + for override in BOOTLOADER_OVERRIDES: + _, attr = override.split(".") + if getattr(self.target, attr, None): + return True + return False @property def sectors(self): @@ -526,12 +529,8 @@ class Config(object): "targets.json `device_name` not found in " "arm_pack_manager index.") cmsis_part = cache.index[self.target.device_name] - target_overrides = self.app_config_data['target_overrides'].get( - self.target.name, {}) - if (('target.bootloader_img' in target_overrides or - 'target.restrict_size' in target_overrides) and - ('target.mbed_app_start' in target_overrides or - 'target.mbed_app_size' in target_overrides)): + if ((self.target.bootloader_img or self.target.restrict_size) and + (self.target.mbed_app_start or self.target.mbed_app_size)): raise ConfigException( "target.bootloader_img and target.restirct_size are " "incompatible with target.mbed_app_start and " @@ -546,23 +545,22 @@ class Config(object): except KeyError: raise ConfigException("Not enough information in CMSIS packs to " "build a bootloader project") - if ('target.bootloader_img' in target_overrides or - 'target.restrict_size' in target_overrides): - return self._generate_bootloader_build(target_overrides, - rom_start, rom_size) - elif ('target.mbed_app_start' in target_overrides or - 'target.mbed_app_size' in target_overrides): - return self._generate_linker_overrides(target_overrides, - rom_start, rom_size) + if self.target.bootloader_img or self.target.restrict_size: + return self._generate_bootloader_build(rom_start, rom_size) + elif self.target.mbed_app_start or self.target.mbed_app_size: + return self._generate_linker_overrides(rom_start, rom_size) else: raise ConfigException( "Bootloader build requested but no bootlader configuration") - def _generate_bootloader_build(self, target_overrides, rom_start, rom_size): + def _generate_bootloader_build(self, rom_start, rom_size): start = rom_start - if 'target.bootloader_img' in target_overrides: - basedir = abspath(dirname(self.app_config_location)) - filename = join(basedir, target_overrides['target.bootloader_img']) + 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) @@ -574,8 +572,8 @@ class Config(object): yield Region("bootloader", rom_start, part_size, False, filename) start = rom_start + part_size - if 'target.restrict_size' in target_overrides: - new_size = int(target_overrides['target.restrict_size'], 0) + 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 @@ -618,14 +616,13 @@ class Config(object): return {'app_config': self.app_config_location, 'library_configs': map(relpath, self.processed_configs.keys())} - @staticmethod - def _generate_linker_overrides(target_overrides, rom_start, rom_size): - if 'target.mbed_app_start' in target_overrides: - start = int(target_overrides['target.mbed_app_start'], 0) + def _generate_linker_overrides(self, rom_start, rom_size): + if self.target.mbed_app_start is not None: + start = int(self.target.mbed_app_start, 0) else: start = rom_start - if 'target.mbed_app_size' in target_overrides: - size = int(target_overrides['target.mbed_app_size'], 0) + if self.target.mbed_app_size is not None: + size = int(self.target.mbed_app_size, 0) else: size = (rom_size + rom_start) - start if start < rom_start: @@ -695,18 +692,22 @@ class Config(object): # Consider the others as overrides for name, val in overrides.items(): + if (name in PATH_OVERRIDES and "__config_path" in data): + val = os.path.join( + os.path.dirname(data["__config_path"]), val) + # Get the full name of the parameter full_name = ConfigParameter.get_full_name(name, unit_name, unit_kind, label) if full_name in params: params[full_name].set_value(val, unit_name, unit_kind, label) - elif name in self.__unused_overrides: - pass elif (name.startswith("target.") and - unit_kind is "application"): + (unit_kind is "application" or + name in BOOTLOADER_OVERRIDES)): _, attribute = name.split(".") setattr(self.target, attribute, val) + continue else: self.config_errors.append( ConfigException( @@ -759,7 +760,7 @@ class Config(object): rel_names = [tgt for tgt, _ in get_resolution_order(self.target.json_data, tname, [])] - if full_name in self.__unused_overrides: + if full_name in BOOTLOADER_OVERRIDES: continue if (full_name not in params) or \ (params[full_name].defined_by[7:] not in rel_names): diff --git a/tools/export/gnuarmeclipse/__init__.py b/tools/export/gnuarmeclipse/__init__.py index 5d4dcc8b7d..f06831978c 100644 --- a/tools/export/gnuarmeclipse/__init__.py +++ b/tools/export/gnuarmeclipse/__init__.py @@ -210,6 +210,8 @@ class GNUARMEclipse(Exporter): # Hack to fill in build_dir toolchain.build_dir = self.toolchain.build_dir + toolchain.config = self.toolchain.config + toolchain.set_config_data(self.toolchain.config.get_config_data()) flags = self.toolchain_flags(toolchain) diff --git a/tools/test/config/bootloader_missing/bootloaders/mbed_lib.json b/tools/test/config/bootloader_missing/bootloaders/mbed_lib.json new file mode 100644 index 0000000000..4120ac867c --- /dev/null +++ b/tools/test/config/bootloader_missing/bootloaders/mbed_lib.json @@ -0,0 +1,9 @@ +{ + "name": "bl", + "target_overrides": { + "LPC1768": { + "target.bootloader_img": "does_not_exists.bin", + "target.restrict_size": "0xFFFFF" + } + } +} diff --git a/tools/test/config/bootloader_missing/mbed_app.json b/tools/test/config/bootloader_missing/mbed_app.json index c2ba944b9d..f1d47d66bf 100644 --- a/tools/test/config/bootloader_missing/mbed_app.json +++ b/tools/test/config/bootloader_missing/mbed_app.json @@ -1,7 +1,8 @@ { "target_overrides": { "K64F": { - "target.bootloader_img": "does_not_exists.bin" + "target.bootloader_img": "does_not_exists.bin", + "target.restrict_size": "0xFFFFF" } } } diff --git a/tools/test/config/bootloader_missing/test_data.json b/tools/test/config/bootloader_missing/test_data.json index 8159285864..2835b8ead8 100644 --- a/tools/test/config/bootloader_missing/test_data.json +++ b/tools/test/config/bootloader_missing/test_data.json @@ -1,5 +1,8 @@ { "K64F": { "exception_msg": "not found" + }, + "LPC1768": { + "exception_msg": "not found" } } diff --git a/tools/toolchains/__init__.py b/tools/toolchains/__init__.py index e8f7549eaa..7bb04d9000 100644 --- a/tools/toolchains/__init__.py +++ b/tools/toolchains/__init__.py @@ -1231,9 +1231,31 @@ class mbedToolchain: return None + def add_regions(self): + """Add regions to the build profile, if there are any. + """ + print("Using regions in this build:") + for region in self.config.regions: + for define in [(region.name.upper() + "_ADDR", region.start), + (region.name.upper() + "_SIZE", region.size)]: + define_string = "-D%s=0x%x" % define + self.cc.append(define_string) + self.cppc.append(define_string) + self.flags["common"].append(define_string) + if region.active: + for define in [("MBED_APP_START", region.start), + ("MBED_APP_SIZE", region.size)]: + define_string = self.make_ld_define(*define) + self.ld.append(define_string) + self.flags["ld"].append(define_string) + print(" Region %s size 0x%x, offset 0x%x" + % (region.name, region.size, region.start)) + # Set the configuration data def set_config_data(self, config_data): self.config_data = config_data + if self.config.has_regions: + self.add_regions() # Creates the configuration header if needed: # - if there is no configuration data, "mbed_config.h" is not create (or deleted if it exists).