From 7a85ae75e6a3083a52fc63b019d85f993dcdd9c4 Mon Sep 17 00:00:00 2001 From: "Andriy.Lishchynskyi" Date: Mon, 14 Jan 2019 17:02:29 +0200 Subject: [PATCH] Reworked launch configuration creation mechanism - switched to single template. Specific data comes from the JSON file --- tools/export/cdt/__init__.py | 63 +++++++++++++----- tools/export/cdt/cdt_definitions.json | 60 +++++++++++++++++ tools/export/cdt/pyocd_settings.tmpl | 38 +++++------ tools/export/cdt/pyocd_settings_debug.tmpl | 70 -------------------- tools/export/cdt/pyocd_settings_program.tmpl | 70 -------------------- 5 files changed, 127 insertions(+), 174 deletions(-) create mode 100644 tools/export/cdt/cdt_definitions.json delete mode 100644 tools/export/cdt/pyocd_settings_debug.tmpl delete mode 100644 tools/export/cdt/pyocd_settings_program.tmpl diff --git a/tools/export/cdt/__init__.py b/tools/export/cdt/__init__.py index 685b2413a9..fa51a1efe9 100644 --- a/tools/export/cdt/__init__.py +++ b/tools/export/cdt/__init__.py @@ -1,16 +1,49 @@ import re - +import os +import json +from collections import namedtuple +from tools.targets import TARGET_MAP from os.path import join, exists from os import makedirs, remove import shutil -from jinja2.exceptions import TemplateNotFound from tools.export.makefile import Makefile, GccArm, Armc5, IAR +_eclipse_defs = os.path.join( + os.path.dirname(os.path.abspath(__file__)), 'cdt_definitions.json') + +with open(_eclipse_defs, 'r') as f: + _CONFIGS_OPTIONS = json.load(f) + +supported_launches = ['debug', 'program'] + class Eclipse(Makefile): """Generic Eclipse project. Intended to be subclassed by classes that specify a type of Makefile. """ + def get_target_config(self, ctx, configuration): + """Retrieve info from cdt_definitions.json""" + tgt = TARGET_MAP[self.target] + defaults = _CONFIGS_OPTIONS['default'] + eclipse_config = defaults['generic'] + if configuration in defaults: + eclipse_config.update(defaults[configuration]) + + target_specific = _CONFIGS_OPTIONS['targets'] + if tgt.name in target_specific: + target_info = target_specific[tgt.name]['generic'] + if configuration in target_specific[tgt.name]: + target_info.update(target_specific[tgt.name][configuration]) + + eclipse_config.update(target_info) + + #special case for gdbClientOtherOptions param - in some cases it may contain dynamical values, fill in it here + eclipse_config['gdbClientOtherOptions'] = eclipse_config['gdbClientOtherOptions'].format( + elf_location=ctx['elf_location']) + + Eclipsedevice = namedtuple('Eclipsedevice', eclipse_config.keys()) + return Eclipsedevice(**eclipse_config) + def generate(self): """Generate Makefile, .cproject & .project Eclipse project file, py_ocd_settings launch file, and software link .p2f file @@ -26,22 +59,22 @@ class Eclipse(Makefile): 'include_paths': [starting_dot.sub('%s/' % self.project_name, inc) for inc in self.resources.inc_dirs], 'load_exe': str(self.LOAD_EXE).lower() } - + + launch_cfgs = {} + for launch_name in supported_launches: + launch = dict(ctx.items() + {'device': self.get_target_config(ctx, launch_name)}.items()) + launch_cfgs.update({launch_name: launch}) + if not exists(join(self.export_dir,'eclipse-extras')): makedirs(join(self.export_dir,'eclipse-extras')) - templates = ['%s.tmpl' % (self.target.lower())] + \ - ['%s.tmpl' % (label.lower()) for label - in self.toolchain.target.extra_labels] + \ - ['%s.tmpl' % 'pyocd_settings'] - - for templatefile in templates: - try: - self.gen_file('cdt/%s' % templatefile, ctx, join('eclipse-extras', - '{target}_{project}_{launch}.launch'.format(target=self.target, - project=self.project_name, launch=templatefile))) - except TemplateNotFound: - pass + for launch_name, ctx in launch_cfgs.items(): + self.gen_file('cdt/%s' % 'pyocd_settings.tmpl', ctx, join('eclipse-extras', + '{target}_{project}_{conf}_{launch}.launch'.format( + target=self.target, + project=self.project_name, + conf=launch_name, + launch='pyocd_settings'))) self.gen_file('cdt/necessary_software.tmpl', ctx, join('eclipse-extras','necessary_software.p2f')) diff --git a/tools/export/cdt/cdt_definitions.json b/tools/export/cdt/cdt_definitions.json new file mode 100644 index 0000000000..112d09adf7 --- /dev/null +++ b/tools/export/cdt/cdt_definitions.json @@ -0,0 +1,60 @@ +{ + "default": { + "generic": { + "doContinue": "true", + "doFirstReset": "true", + "doGdbServerAllocateSemihostingConsole": "true", + "doSecondReset": "true", + "enableSemihosting": "true", + "firstResetType": "init", + "gdbClientOtherCommands": "set mem inaccessible-by-default off", + "gdbClientOtherOptions": "", + "gdbServerBusSpeed": 1000000, + "gdbServerEnableSemihosting": "true", + "gdbServerFlashMode": 0, + "gdbServerGdbPortNumber": 3333, + "gdbServerHaltAtHardFault": "true", + "gdbServerOther": "", + "secondResetType": "halt", + "coreLoadImage": "true", + "coreLoadSymbols": "true", + "corePortNumber": 3333, + "setStopAt": "true" + }, + + "debug": { + }, + + "program": { + "doContinue": "false", + "doSecondReset": "false", + "gdbClientOtherCommands": "set mem inaccessible-by-default off target remote localhost:3333 mon reset halt load mon reset quit", + "gdbClientOtherOptions": "{elf_location}", + "coreLoadImage": "false", + "coreLoadSymbols": "false", + "setStopAt": "false" + } + }, + + "targets": { + "CY8CPROTO_062_4343W": { + "generic": { + "doFirstReset": "false", + "doGdbServerAllocateSemihostingConsole": "false", + "enableSemihosting": "false", + "firstResetType": "", + "gdbServerEnableSemihosting": "false", + "gdbServerFlashMode": 2, + "gdbServerGdbPortNumber": 3334, + "gdbServerHaltAtHardFault": "false", + "gdbServerOther": "-p 3333 --no-deprecation-warning", + "secondResetType": "", + "corePortNumber": 3334 + }, + + "program": { + "gdbClientOtherCommands": "set mem inaccessible-by-default off target remote localhost:3334 mon reset halt load mon reset quit" + } + } + } +} \ No newline at end of file diff --git a/tools/export/cdt/pyocd_settings.tmpl b/tools/export/cdt/pyocd_settings.tmpl index 67d0ed4fba..a59987a6cb 100644 --- a/tools/export/cdt/pyocd_settings.tmpl +++ b/tools/export/cdt/pyocd_settings.tmpl @@ -1,27 +1,27 @@ - + - + - - + + - - - - + + + + - + - + - - - + + + - + @@ -29,18 +29,18 @@ - + - - + + - + - + diff --git a/tools/export/cdt/pyocd_settings_debug.tmpl b/tools/export/cdt/pyocd_settings_debug.tmpl deleted file mode 100644 index 290338d3c7..0000000000 --- a/tools/export/cdt/pyocd_settings_debug.tmpl +++ /dev/null @@ -1,70 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/tools/export/cdt/pyocd_settings_program.tmpl b/tools/export/cdt/pyocd_settings_program.tmpl deleted file mode 100644 index dc6c0c34a2..0000000000 --- a/tools/export/cdt/pyocd_settings_program.tmpl +++ /dev/null @@ -1,70 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -