Skip to content

Commit 7a85ae7

Browse files
author
Andriy.Lishchynskyi
committed
Reworked launch configuration creation mechanism - switched to single template. Specific data comes from the JSON file
1 parent 9fa2c75 commit 7a85ae7

File tree

5 files changed

+127
-174
lines changed

5 files changed

+127
-174
lines changed

tools/export/cdt/__init__.py

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,49 @@
11
import re
2-
2+
import os
3+
import json
4+
from collections import namedtuple
5+
from tools.targets import TARGET_MAP
36
from os.path import join, exists
47
from os import makedirs, remove
58
import shutil
6-
from jinja2.exceptions import TemplateNotFound
79

810
from tools.export.makefile import Makefile, GccArm, Armc5, IAR
911

12+
_eclipse_defs = os.path.join(
13+
os.path.dirname(os.path.abspath(__file__)), 'cdt_definitions.json')
14+
15+
with open(_eclipse_defs, 'r') as f:
16+
_CONFIGS_OPTIONS = json.load(f)
17+
18+
supported_launches = ['debug', 'program']
19+
1020
class Eclipse(Makefile):
1121
"""Generic Eclipse project. Intended to be subclassed by classes that
1222
specify a type of Makefile.
1323
"""
24+
def get_target_config(self, ctx, configuration):
25+
"""Retrieve info from cdt_definitions.json"""
26+
tgt = TARGET_MAP[self.target]
27+
defaults = _CONFIGS_OPTIONS['default']
28+
eclipse_config = defaults['generic']
29+
if configuration in defaults:
30+
eclipse_config.update(defaults[configuration])
31+
32+
target_specific = _CONFIGS_OPTIONS['targets']
33+
if tgt.name in target_specific:
34+
target_info = target_specific[tgt.name]['generic']
35+
if configuration in target_specific[tgt.name]:
36+
target_info.update(target_specific[tgt.name][configuration])
37+
38+
eclipse_config.update(target_info)
39+
40+
#special case for gdbClientOtherOptions param - in some cases it may contain dynamical values, fill in it here
41+
eclipse_config['gdbClientOtherOptions'] = eclipse_config['gdbClientOtherOptions'].format(
42+
elf_location=ctx['elf_location'])
43+
44+
Eclipsedevice = namedtuple('Eclipsedevice', eclipse_config.keys())
45+
return Eclipsedevice(**eclipse_config)
46+
1447
def generate(self):
1548
"""Generate Makefile, .cproject & .project Eclipse project file,
1649
py_ocd_settings launch file, and software link .p2f file
@@ -26,22 +59,22 @@ def generate(self):
2659
'include_paths': [starting_dot.sub('%s/' % self.project_name, inc) for inc in self.resources.inc_dirs],
2760
'load_exe': str(self.LOAD_EXE).lower()
2861
}
29-
62+
63+
launch_cfgs = {}
64+
for launch_name in supported_launches:
65+
launch = dict(ctx.items() + {'device': self.get_target_config(ctx, launch_name)}.items())
66+
launch_cfgs.update({launch_name: launch})
67+
3068
if not exists(join(self.export_dir,'eclipse-extras')):
3169
makedirs(join(self.export_dir,'eclipse-extras'))
3270

33-
templates = ['%s.tmpl' % (self.target.lower())] + \
34-
['%s.tmpl' % (label.lower()) for label
35-
in self.toolchain.target.extra_labels] + \
36-
['%s.tmpl' % 'pyocd_settings']
37-
38-
for templatefile in templates:
39-
try:
40-
self.gen_file('cdt/%s' % templatefile, ctx, join('eclipse-extras',
41-
'{target}_{project}_{launch}.launch'.format(target=self.target,
42-
project=self.project_name, launch=templatefile)))
43-
except TemplateNotFound:
44-
pass
71+
for launch_name, ctx in launch_cfgs.items():
72+
self.gen_file('cdt/%s' % 'pyocd_settings.tmpl', ctx, join('eclipse-extras',
73+
'{target}_{project}_{conf}_{launch}.launch'.format(
74+
target=self.target,
75+
project=self.project_name,
76+
conf=launch_name,
77+
launch='pyocd_settings')))
4578

4679
self.gen_file('cdt/necessary_software.tmpl', ctx,
4780
join('eclipse-extras','necessary_software.p2f'))

tools/export/cdt/cdt_definitions.json

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"default": {
3+
"generic": {
4+
"doContinue": "true",
5+
"doFirstReset": "true",
6+
"doGdbServerAllocateSemihostingConsole": "true",
7+
"doSecondReset": "true",
8+
"enableSemihosting": "true",
9+
"firstResetType": "init",
10+
"gdbClientOtherCommands": "set mem inaccessible-by-default off",
11+
"gdbClientOtherOptions": "",
12+
"gdbServerBusSpeed": 1000000,
13+
"gdbServerEnableSemihosting": "true",
14+
"gdbServerFlashMode": 0,
15+
"gdbServerGdbPortNumber": 3333,
16+
"gdbServerHaltAtHardFault": "true",
17+
"gdbServerOther": "",
18+
"secondResetType": "halt",
19+
"coreLoadImage": "true",
20+
"coreLoadSymbols": "true",
21+
"corePortNumber": 3333,
22+
"setStopAt": "true"
23+
},
24+
25+
"debug": {
26+
},
27+
28+
"program": {
29+
"doContinue": "false",
30+
"doSecondReset": "false",
31+
"gdbClientOtherCommands": "set mem inaccessible-by-default off
target remote localhost:3333
mon reset halt
load
mon reset
quit",
32+
"gdbClientOtherOptions": "{elf_location}",
33+
"coreLoadImage": "false",
34+
"coreLoadSymbols": "false",
35+
"setStopAt": "false"
36+
}
37+
},
38+
39+
"targets": {
40+
"CY8CPROTO_062_4343W": {
41+
"generic": {
42+
"doFirstReset": "false",
43+
"doGdbServerAllocateSemihostingConsole": "false",
44+
"enableSemihosting": "false",
45+
"firstResetType": "",
46+
"gdbServerEnableSemihosting": "false",
47+
"gdbServerFlashMode": 2,
48+
"gdbServerGdbPortNumber": 3334,
49+
"gdbServerHaltAtHardFault": "false",
50+
"gdbServerOther": "-p 3333
--no-deprecation-warning",
51+
"secondResetType": "",
52+
"corePortNumber": 3334
53+
},
54+
55+
"program": {
56+
"gdbClientOtherCommands": "set mem inaccessible-by-default off
target remote localhost:3334
mon reset halt
load
mon reset
quit"
57+
}
58+
}
59+
}
60+
}

tools/export/cdt/pyocd_settings.tmpl

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,46 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
22
<launchConfiguration type="ilg.gnuarmeclipse.debug.gdbjtag.pyocd.launchConfigurationType">
3-
<booleanAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.pyocd.doContinue" value="true"/>
3+
<booleanAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.pyocd.doContinue" value="{{device.doContinue}}"/>
44
<booleanAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.pyocd.doDebugInRam" value="false"/>
5-
<booleanAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.pyocd.doFirstReset" value="true"/>
5+
<booleanAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.pyocd.doFirstReset" value="{{device.doFirstReset}}"/>
66
<booleanAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.pyocd.doGdbServerAllocateConsole" value="true"/>
7-
<booleanAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.pyocd.doGdbServerAllocateSemihostingConsole" value="true"/>
8-
<booleanAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.pyocd.doSecondReset" value="true"/>
7+
<booleanAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.pyocd.doGdbServerAllocateSemihostingConsole" value="{{device.doGdbServerAllocateSemihostingConsole}}"/>
8+
<booleanAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.pyocd.doSecondReset" value="{{device.doSecondReset}}"/>
99
<booleanAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.pyocd.doStartGdbServer" value="true"/>
10-
<booleanAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.pyocd.enableSemihosting" value="true"/>
11-
<stringAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.pyocd.firstResetType" value="init"/>
12-
<stringAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.pyocd.gdbClientOtherCommands" value="set mem inaccessible-by-default off"/>
13-
<stringAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.pyocd.gdbClientOtherOptions" value=""/>
10+
<booleanAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.pyocd.enableSemihosting" value="{{device.enableSemihosting}}"/>
11+
<stringAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.pyocd.firstResetType" value="{{device.firstResetType}}"/>
12+
<stringAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.pyocd.gdbClientOtherCommands" value="{{device.gdbClientOtherCommands}}"/>
13+
<stringAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.pyocd.gdbClientOtherOptions" value="{{device.gdbClientOtherOptions}}"/>
1414
<stringAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.pyocd.gdbServerBoardId" value=""/>
15-
<intAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.pyocd.gdbServerBusSpeed" value="1000000"/>
15+
<intAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.pyocd.gdbServerBusSpeed" value="{{device.gdbServerBusSpeed}}"/>
1616
<stringAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.pyocd.gdbServerConnectionAddress" value=""/>
17-
<booleanAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.pyocd.gdbServerEnableSemihosting" value="true"/>
17+
<booleanAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.pyocd.gdbServerEnableSemihosting" value="{{device.gdbServerEnableSemihosting}}"/>
1818
<stringAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.pyocd.gdbServerExecutable" value="${pyocd_path}/${pyocd_executable}"/>
1919
<booleanAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.pyocd.gdbServerFlashFastVerify" value="false"/>
20-
<intAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.pyocd.gdbServerFlashMode" value="0"/>
21-
<intAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.pyocd.gdbServerGdbPortNumber" value="3333"/>
22-
<booleanAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.pyocd.gdbServerHaltAtHardFault" value="true"/>
20+
<intAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.pyocd.gdbServerFlashMode" value="{{device.gdbServerFlashMode}}"/>
21+
<intAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.pyocd.gdbServerGdbPortNumber" value="{{device.gdbServerGdbPortNumber}}"/>
22+
<booleanAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.pyocd.gdbServerHaltAtHardFault" value="{{device.gdbServerHaltAtHardFault}}"/>
2323
<stringAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.pyocd.gdbServerLog" value=""/>
24-
<stringAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.pyocd.gdbServerOther" value=""/>
24+
<stringAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.pyocd.gdbServerOther" value="{{device.gdbServerOther}}"/>
2525
<booleanAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.pyocd.gdbServerOverrideTarget" value="false"/>
2626
<booleanAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.pyocd.gdbServerStepIntoInterrutps" value="false"/>
2727
<stringAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.pyocd.gdbServerTargetName" value=""/>
2828
<intAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.pyocd.gdbServerTelnetPortNumber" value="4444"/>
2929
<booleanAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.pyocd.gdbServerUseGdbSyscalls" value="false"/>
3030
<stringAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.pyocd.otherInitCommands" value=""/>
3131
<stringAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.pyocd.otherRunCommands" value=""/>
32-
<stringAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.pyocd.secondResetType" value="halt"/>
32+
<stringAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.pyocd.secondResetType" value="{{device.secondResetType}}"/>
3333
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.imageFileName" value=""/>
3434
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.imageOffset" value=""/>
3535
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.ipAddress" value="localhost"/>
3636
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.jtagDevice" value="GNU ARM PyOCD"/>
37-
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.loadImage" value="{{load_exe}}"/>
38-
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.loadSymbols" value="{{load_exe}}"/>
37+
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.loadImage" value="{% if load_exe == device.coreLoadImage %}{{load_exe}}{% else %}{{device.coreLoadImage}}{% endif %}"/>
38+
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.loadSymbols" value="{% if load_exe == device.coreLoadSymbols %}{{load_exe}}{% else %}{{device.coreLoadSymbols}}{% endif %}"/>
3939
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.pcRegister" value=""/>
40-
<intAttribute key="org.eclipse.cdt.debug.gdbjtag.core.portNumber" value="3333"/>
40+
<intAttribute key="org.eclipse.cdt.debug.gdbjtag.core.portNumber" value="{{device.corePortNumber}}"/>
4141
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setPcRegister" value="false"/>
4242
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setResume" value="false"/>
43-
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setStopAt" value="true"/>
43+
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setStopAt" value="{{device.setStopAt}}"/>
4444
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.stopAt" value="main"/>
4545
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.symbolsFileName" value=""/>
4646
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.symbolsOffset" value=""/>

tools/export/cdt/pyocd_settings_debug.tmpl

Lines changed: 0 additions & 70 deletions
This file was deleted.

0 commit comments

Comments
 (0)