mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #5909 from theotherjimmy/bl-as-config
Let libraries, targets configure bootloaderpull/5996/head
commit
bf3693fef4
|
@ -284,31 +284,6 @@ def get_mbed_official_release(version):
|
||||||
|
|
||||||
return mbed_official_release
|
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,
|
def prepare_toolchain(src_paths, build_dir, target, toolchain_name,
|
||||||
macros=None, clean=False, jobs=1,
|
macros=None, clean=False, jobs=1,
|
||||||
|
@ -352,9 +327,6 @@ def prepare_toolchain(src_paths, build_dir, target, toolchain_name,
|
||||||
for key in profile:
|
for key in profile:
|
||||||
profile[key].extend(contents[toolchain_name][key])
|
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,
|
toolchain = cur_tc(target, notify, macros, silent, build_dir=build_dir,
|
||||||
extra_verbose=extra_verbose, build_profile=profile)
|
extra_verbose=extra_verbose, build_profile=profile)
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ limitations under the License.
|
||||||
|
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
import os
|
import os
|
||||||
from os.path import dirname, abspath, exists, join
|
from os.path import dirname, abspath, exists, join, isabs
|
||||||
import sys
|
import sys
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from os.path import splitext, relpath
|
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, \
|
from tools.targets import CUMULATIVE_ATTRIBUTES, TARGET_MAP, \
|
||||||
generate_py_target, get_resolution_order
|
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
|
# Base class for all configuration exceptions
|
||||||
class ConfigException(Exception):
|
class ConfigException(Exception):
|
||||||
"""Config system only exception. Makes it easier to distinguish config
|
"""Config system only exception. Makes it easier to distinguish config
|
||||||
|
@ -84,6 +88,8 @@ class ConfigParameter(object):
|
||||||
else:
|
else:
|
||||||
prefix = unit_name + '.'
|
prefix = unit_name + '.'
|
||||||
return prefix + name
|
return prefix + name
|
||||||
|
if name in BOOTLOADER_OVERRIDES:
|
||||||
|
return name
|
||||||
# The name has a prefix, so check if it is valid
|
# The name has a prefix, so check if it is valid
|
||||||
if not allow_prefix:
|
if not allow_prefix:
|
||||||
raise ConfigException("Invalid parameter name '%s' in '%s'" %
|
raise ConfigException("Invalid parameter name '%s' in '%s'" %
|
||||||
|
@ -362,8 +368,6 @@ class Config(object):
|
||||||
"artifact_name": str}
|
"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 in configurations
|
||||||
__allowed_features = [
|
__allowed_features = [
|
||||||
|
@ -441,6 +445,9 @@ class Config(object):
|
||||||
self.target = tgt
|
self.target = tgt
|
||||||
self.target = deepcopy(self.target)
|
self.target = deepcopy(self.target)
|
||||||
self.target_labels = self.target.labels
|
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)
|
self.cumulative_overrides = {key: ConfigCumulativeOverride(key)
|
||||||
for key in CUMULATIVE_ATTRIBUTES}
|
for key in CUMULATIVE_ATTRIBUTES}
|
||||||
|
@ -488,15 +495,11 @@ class Config(object):
|
||||||
@property
|
@property
|
||||||
def has_regions(self):
|
def has_regions(self):
|
||||||
"""Does this config have regions defined?"""
|
"""Does this config have regions defined?"""
|
||||||
if 'target_overrides' in self.app_config_data:
|
for override in BOOTLOADER_OVERRIDES:
|
||||||
target_overrides = self.app_config_data['target_overrides'].get(
|
_, attr = override.split(".")
|
||||||
self.target.name, {})
|
if getattr(self.target, attr, None):
|
||||||
return ('target.bootloader_img' in target_overrides or
|
return True
|
||||||
'target.restrict_size' in target_overrides or
|
return False
|
||||||
'target.mbed_app_start' in target_overrides or
|
|
||||||
'target.mbed_app_size' in target_overrides)
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def sectors(self):
|
def sectors(self):
|
||||||
|
@ -526,12 +529,8 @@ class Config(object):
|
||||||
"targets.json `device_name` not found in "
|
"targets.json `device_name` not found in "
|
||||||
"arm_pack_manager index.")
|
"arm_pack_manager index.")
|
||||||
cmsis_part = cache.index[self.target.device_name]
|
cmsis_part = cache.index[self.target.device_name]
|
||||||
target_overrides = self.app_config_data['target_overrides'].get(
|
if ((self.target.bootloader_img or self.target.restrict_size) and
|
||||||
self.target.name, {})
|
(self.target.mbed_app_start or self.target.mbed_app_size)):
|
||||||
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)):
|
|
||||||
raise ConfigException(
|
raise ConfigException(
|
||||||
"target.bootloader_img and target.restirct_size are "
|
"target.bootloader_img and target.restirct_size are "
|
||||||
"incompatible with target.mbed_app_start and "
|
"incompatible with target.mbed_app_start and "
|
||||||
|
@ -546,23 +545,22 @@ class Config(object):
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise ConfigException("Not enough information in CMSIS packs to "
|
raise ConfigException("Not enough information in CMSIS packs to "
|
||||||
"build a bootloader project")
|
"build a bootloader project")
|
||||||
if ('target.bootloader_img' in target_overrides or
|
if self.target.bootloader_img or self.target.restrict_size:
|
||||||
'target.restrict_size' in target_overrides):
|
return self._generate_bootloader_build(rom_start, rom_size)
|
||||||
return self._generate_bootloader_build(target_overrides,
|
elif self.target.mbed_app_start or self.target.mbed_app_size:
|
||||||
rom_start, rom_size)
|
return self._generate_linker_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)
|
|
||||||
else:
|
else:
|
||||||
raise ConfigException(
|
raise ConfigException(
|
||||||
"Bootloader build requested but no bootlader configuration")
|
"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
|
start = rom_start
|
||||||
if 'target.bootloader_img' in target_overrides:
|
if self.target.bootloader_img:
|
||||||
basedir = abspath(dirname(self.app_config_location))
|
if isabs(self.target.bootloader_img):
|
||||||
filename = join(basedir, target_overrides['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):
|
if not exists(filename):
|
||||||
raise ConfigException("Bootloader %s not found" % filename)
|
raise ConfigException("Bootloader %s not found" % filename)
|
||||||
part = intelhex_offset(filename, offset=rom_start)
|
part = intelhex_offset(filename, offset=rom_start)
|
||||||
|
@ -574,8 +572,8 @@ class Config(object):
|
||||||
yield Region("bootloader", rom_start, part_size, False,
|
yield Region("bootloader", rom_start, part_size, False,
|
||||||
filename)
|
filename)
|
||||||
start = rom_start + part_size
|
start = rom_start + part_size
|
||||||
if 'target.restrict_size' in target_overrides:
|
if self.target.restrict_size is not None:
|
||||||
new_size = int(target_overrides['target.restrict_size'], 0)
|
new_size = int(self.target.restrict_size, 0)
|
||||||
new_size = Config._align_floor(start + new_size, self.sectors) - start
|
new_size = Config._align_floor(start + new_size, self.sectors) - start
|
||||||
yield Region("application", start, new_size, True, None)
|
yield Region("application", start, new_size, True, None)
|
||||||
start += new_size
|
start += new_size
|
||||||
|
@ -618,14 +616,13 @@ class Config(object):
|
||||||
return {'app_config': self.app_config_location,
|
return {'app_config': self.app_config_location,
|
||||||
'library_configs': map(relpath, self.processed_configs.keys())}
|
'library_configs': map(relpath, self.processed_configs.keys())}
|
||||||
|
|
||||||
@staticmethod
|
def _generate_linker_overrides(self, rom_start, rom_size):
|
||||||
def _generate_linker_overrides(target_overrides, rom_start, rom_size):
|
if self.target.mbed_app_start is not None:
|
||||||
if 'target.mbed_app_start' in target_overrides:
|
start = int(self.target.mbed_app_start, 0)
|
||||||
start = int(target_overrides['target.mbed_app_start'], 0)
|
|
||||||
else:
|
else:
|
||||||
start = rom_start
|
start = rom_start
|
||||||
if 'target.mbed_app_size' in target_overrides:
|
if self.target.mbed_app_size is not None:
|
||||||
size = int(target_overrides['target.mbed_app_size'], 0)
|
size = int(self.target.mbed_app_size, 0)
|
||||||
else:
|
else:
|
||||||
size = (rom_size + rom_start) - start
|
size = (rom_size + rom_start) - start
|
||||||
if start < rom_start:
|
if start < rom_start:
|
||||||
|
@ -695,18 +692,22 @@ class Config(object):
|
||||||
|
|
||||||
# Consider the others as overrides
|
# Consider the others as overrides
|
||||||
for name, val in overrides.items():
|
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
|
# Get the full name of the parameter
|
||||||
full_name = ConfigParameter.get_full_name(name, unit_name,
|
full_name = ConfigParameter.get_full_name(name, unit_name,
|
||||||
unit_kind, label)
|
unit_kind, label)
|
||||||
if full_name in params:
|
if full_name in params:
|
||||||
params[full_name].set_value(val, unit_name, unit_kind,
|
params[full_name].set_value(val, unit_name, unit_kind,
|
||||||
label)
|
label)
|
||||||
elif name in self.__unused_overrides:
|
|
||||||
pass
|
|
||||||
elif (name.startswith("target.") and
|
elif (name.startswith("target.") and
|
||||||
unit_kind is "application"):
|
(unit_kind is "application" or
|
||||||
|
name in BOOTLOADER_OVERRIDES)):
|
||||||
_, attribute = name.split(".")
|
_, attribute = name.split(".")
|
||||||
setattr(self.target, attribute, val)
|
setattr(self.target, attribute, val)
|
||||||
|
continue
|
||||||
else:
|
else:
|
||||||
self.config_errors.append(
|
self.config_errors.append(
|
||||||
ConfigException(
|
ConfigException(
|
||||||
|
@ -759,7 +760,7 @@ class Config(object):
|
||||||
rel_names = [tgt for tgt, _ in
|
rel_names = [tgt for tgt, _ in
|
||||||
get_resolution_order(self.target.json_data, tname,
|
get_resolution_order(self.target.json_data, tname,
|
||||||
[])]
|
[])]
|
||||||
if full_name in self.__unused_overrides:
|
if full_name in BOOTLOADER_OVERRIDES:
|
||||||
continue
|
continue
|
||||||
if (full_name not in params) or \
|
if (full_name not in params) or \
|
||||||
(params[full_name].defined_by[7:] not in rel_names):
|
(params[full_name].defined_by[7:] not in rel_names):
|
||||||
|
|
|
@ -210,6 +210,8 @@ class GNUARMEclipse(Exporter):
|
||||||
|
|
||||||
# Hack to fill in build_dir
|
# Hack to fill in build_dir
|
||||||
toolchain.build_dir = self.toolchain.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)
|
flags = self.toolchain_flags(toolchain)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"name": "bl",
|
||||||
|
"target_overrides": {
|
||||||
|
"LPC1768": {
|
||||||
|
"target.bootloader_img": "does_not_exists.bin",
|
||||||
|
"target.restrict_size": "0xFFFFF"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,7 +1,8 @@
|
||||||
{
|
{
|
||||||
"target_overrides": {
|
"target_overrides": {
|
||||||
"K64F": {
|
"K64F": {
|
||||||
"target.bootloader_img": "does_not_exists.bin"
|
"target.bootloader_img": "does_not_exists.bin",
|
||||||
|
"target.restrict_size": "0xFFFFF"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
{
|
{
|
||||||
"K64F": {
|
"K64F": {
|
||||||
"exception_msg": "not found"
|
"exception_msg": "not found"
|
||||||
|
},
|
||||||
|
"LPC1768": {
|
||||||
|
"exception_msg": "not found"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1231,9 +1231,31 @@ class mbedToolchain:
|
||||||
|
|
||||||
return None
|
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
|
# Set the configuration data
|
||||||
def set_config_data(self, config_data):
|
def set_config_data(self, config_data):
|
||||||
self.config_data = config_data
|
self.config_data = config_data
|
||||||
|
if self.config.has_regions:
|
||||||
|
self.add_regions()
|
||||||
|
|
||||||
# Creates the configuration header if needed:
|
# Creates the configuration header if needed:
|
||||||
# - if there is no configuration data, "mbed_config.h" is not create (or deleted if it exists).
|
# - if there is no configuration data, "mbed_config.h" is not create (or deleted if it exists).
|
||||||
|
|
Loading…
Reference in New Issue