Skip to content

Commit 94b67de

Browse files
authored
Merge pull request #4202 from theotherjimmy/rom-size-injection
Add support for Unmanaged Bootloader
2 parents 8e8174a + 2821fd5 commit 94b67de

File tree

3 files changed

+53
-5
lines changed

3 files changed

+53
-5
lines changed

tools/config/__init__.py

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,8 @@ class Config(object):
362362
"artifact_name": str}
363363
}
364364

365-
__unused_overrides = set(["target.bootloader_img", "target.restrict_size"])
365+
__unused_overrides = set(["target.bootloader_img", "target.restrict_size",
366+
"target.mbed_app_start", "target.mbed_app_size"])
366367

367368
# Allowed features in configurations
368369
__allowed_features = [
@@ -485,7 +486,9 @@ def has_regions(self):
485486
target_overrides = self.app_config_data['target_overrides'].get(
486487
self.target.name, {})
487488
return ('target.bootloader_img' in target_overrides or
488-
'target.restrict_size' in target_overrides)
489+
'target.restrict_size' in target_overrides or
490+
'target.mbed_app_start' in target_overrides or
491+
'target.mbed_app_size' in target_overrides)
489492
else:
490493
return False
491494

@@ -495,15 +498,37 @@ def regions(self):
495498
if not self.target.bootloader_supported:
496499
raise ConfigException("Bootloader not supported on this target.")
497500
cmsis_part = Cache(False, False).index[self.target.device_name]
498-
start = 0
499501
target_overrides = self.app_config_data['target_overrides'].get(
500502
self.target.name, {})
503+
if (('target.bootloader_img' in target_overrides or
504+
'target.restrict_size' in target_overrides) and
505+
('target.mbed_app_start' in target_overrides or
506+
'target.mbed_app_size' in target_overrides)):
507+
raise ConfigException(
508+
"target.bootloader_img and target.restirct_size are "
509+
"incompatible with target.mbed_app_start and "
510+
"target.mbed_app_size")
501511
try:
502512
rom_size = int(cmsis_part['memory']['IROM1']['size'], 0)
503513
rom_start = int(cmsis_part['memory']['IROM1']['start'], 0)
504514
except KeyError:
505515
raise ConfigException("Not enough information in CMSIS packs to "
506516
"build a bootloader project")
517+
if ('target.bootloader_img' in target_overrides or
518+
'target.restrict_size' in target_overrides):
519+
return self._generate_booloader_build(target_overrides,
520+
rom_size, rom_size)
521+
elif ('target.mbed_app_start' in target_overrides or
522+
'target.mbed_app_size' in target_overrides):
523+
return self._generate_linker_overrides(target_overrides,
524+
rom_start, rom_size)
525+
else:
526+
raise ConfigException(
527+
"Bootloader build requested but no bootlader configuration")
528+
529+
@staticmethod
530+
def _generate_booloader_build(target_overrides, rom_start, rom_size):
531+
start = 0
507532
if 'target.bootloader_img' in target_overrides:
508533
filename = target_overrides['target.bootloader_img']
509534
if not exists(filename):
@@ -534,6 +559,22 @@ def report(self):
534559
return {'app_config': self.app_config_location,
535560
'library_configs': map(relpath, self.processed_configs.keys())}
536561

562+
@staticmethod
563+
def _generate_linker_overrides(target_overrides, rom_start, rom_size):
564+
if 'target.mbed_app_start' in target_overrides:
565+
start = int(target_overrides['target.mbed_app_start'], 0)
566+
else:
567+
start = rom_start
568+
if 'target.mbed_app_size' in target_overrides:
569+
size = int(target_overrides['target.mbed_app_size'], 0)
570+
else:
571+
size = (rom_size + rom_start) - start
572+
if start < rom_start:
573+
raise ConfigException("Application starts before ROM")
574+
if size + start > rom_size + rom_start:
575+
raise ConfigException("Application ends after ROM")
576+
yield Region("application", start, size, True, None)
577+
537578
def _process_config_and_overrides(self, data, params, unit_name, unit_kind):
538579
"""Process "config_parameters" and "target_config_overrides" into a
539580
given dictionary

tools/test/toolchains/api.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def test_toolchain_profile_c(profile, source_file):
4242
toolchain = tc_class(TARGET_MAP["K64F"], build_profile=profile)
4343
toolchain.inc_md5 = ""
4444
toolchain.build_dir = ""
45+
toolchain.config = MagicMock(app_config_locaiton=None)
4546
compile_command = toolchain.compile_command(to_compile,
4647
to_compile + ".o", [])
4748
for parameter in profile['c'] + profile['common']:
@@ -67,6 +68,7 @@ def test_toolchain_profile_cpp(profile, source_file):
6768
toolchain = tc_class(TARGET_MAP["K64F"], build_profile=profile)
6869
toolchain.inc_md5 = ""
6970
toolchain.build_dir = ""
71+
toolchain.config = MagicMock(app_config_locaiton=None)
7072
compile_command = toolchain.compile_command(to_compile,
7173
to_compile + ".o", [])
7274
for parameter in profile['cxx'] + profile['common']:

tools/toolchains/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,9 @@ def compile_command(self, source, object, includes):
909909
deps = self.parse_dependencies(dep_path) if (exists(dep_path)) else []
910910
except IOError, IndexError:
911911
deps = []
912-
if len(deps) == 0 or self.need_update(object, deps):
912+
config_file = ([self.config.app_config_location]
913+
if self.config.app_config_location else [])
914+
if len(deps) == 0 or self.need_update(object, deps + config_file):
913915
if ext == '.cpp' or self.COMPILE_C_AS_CPP:
914916
return self.compile_cpp(source, object, includes)
915917
else:
@@ -1008,7 +1010,10 @@ def link_program(self, r, tmp_path, name):
10081010
map = join(tmp_path, name + '.map')
10091011

10101012
r.objects = sorted(set(r.objects))
1011-
if self.need_update(elf, r.objects + r.libraries + [r.linker_script]):
1013+
config_file = ([self.config.app_config_location]
1014+
if self.config.app_config_location else [])
1015+
if self.need_update(elf, r.objects + r.libraries + [r.linker_script] +
1016+
config_file):
10121017
needed_update = True
10131018
self.progress("link", name)
10141019
self.link(elf, r.objects, r.libraries, r.lib_dirs, r.linker_script)

0 commit comments

Comments
 (0)