Skip to content

Commit 83127db

Browse files
committed
export: Sw4STM32 inherits GNUARMEclipse
Sw4STM32 is using methods from GNUARMEclipse class to handle flags. Flags are also passed to cproject file.
1 parent dbf20fc commit 83127db

File tree

4 files changed

+369
-225
lines changed

4 files changed

+369
-225
lines changed

tools/export/sw4stm32/__init__.py

Lines changed: 147 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
mbed SDK
3-
Copyright (c) 2011-2016 ARM Limited
3+
Copyright (c) 2011-2017 ARM Limited
44
55
Licensed under the Apache License, Version 2.0 (the "License");
66
you may not use this file except in compliance with the License.
@@ -21,10 +21,16 @@
2121
from os.path import splitext, basename, join, dirname, relpath
2222
from random import randint
2323
from tools.utils import mkdir
24-
from tools.export.exporters import Exporter
24+
from tools.export.gnuarmeclipse import GNUARMEclipse
25+
from tools.export.gnuarmeclipse import UID
26+
from tools.build_api import prepare_toolchain
27+
from sys import flags
2528

29+
# Global random number generator instance.
30+
u = UID()
2631

27-
class Sw4STM32(Exporter):
32+
33+
class Sw4STM32(GNUARMEclipse):
2834
"""
2935
Sw4STM32 class
3036
"""
@@ -258,24 +264,6 @@ def __gen_dir(self, dir_name):
258264
settings = join(self.export_dir, dir_name)
259265
mkdir(settings)
260266

261-
def __generate_uid(self):
262-
"""
263-
Method to create random int
264-
"""
265-
return "%0.9u" % randint(0, 999999999)
266-
267-
@staticmethod
268-
def filter_dot(path):
269-
"""
270-
This function removes ./ from str.
271-
str must be converted with win_to_unix() before using this function.
272-
"""
273-
if not path:
274-
return path
275-
if path.startswith('./'):
276-
return path[2:]
277-
return path
278-
279267
def build_excludelist(self):
280268
"""
281269
This method creates list for excluded directories.
@@ -314,11 +302,65 @@ def remove_unused(self, path):
314302
if needtoadd:
315303
self.exclude_dirs.append(path)
316304

305+
def get_fpu_hardware(self, fpu_unit):
306+
"""
307+
Convert fpu unit name into hardware name.
308+
"""
309+
hw = ''
310+
fpus = {
311+
'fpv4spd16': 'fpv4-sp-d16',
312+
'fpv5d16': 'fpv5-d16',
313+
'fpv5spd16': 'fpv5-sp-d16'
314+
}
315+
if fpu_unit in fpus:
316+
hw = fpus[fpu_unit]
317+
return hw
318+
319+
def process_sw_options(self, opts, flags_in):
320+
"""
321+
Process System Workbench specific options.
322+
323+
System Workbench for STM32 has some compile options, which are not recognized by the GNUARMEclipse exporter.
324+
Those are handled in this method.
325+
"""
326+
opts['c']['preprocess'] = False
327+
if '-E' in flags_in['c_flags']:
328+
opts['c']['preprocess'] = True
329+
opts['cpp']['preprocess'] = False
330+
if '-E' in flags_in['cxx_flags']:
331+
opts['cpp']['preprocess'] = True
332+
opts['ld']['strip'] = False
333+
if '-s' in flags_in['ld_flags']:
334+
opts['ld']['strip'] = True
335+
opts['ld']['shared'] = False
336+
if '-shared' in flags_in['ld_flags']:
337+
opts['ld']['shared'] = True
338+
opts['ld']['soname'] = ''
339+
opts['ld']['implname'] = ''
340+
opts['ld']['defname'] = ''
341+
for item in flags_in['ld_flags']:
342+
if item.startswith('-Wl,-soname='):
343+
opts['ld']['soname'] = item[len('-Wl,-soname='):]
344+
if item.startswith('-Wl,--out-implib='):
345+
opts['ld']['implname'] = item[len('-Wl,--out-implib='):]
346+
if item.startswith('-Wl,--output-def='):
347+
opts['ld']['defname'] = item[len('-Wl,--output-def='):]
348+
opts['common']['arm.target.fpu.hardware'] = self.get_fpu_hardware(
349+
opts['common']['arm.target.fpu.unit'])
350+
opts['common']['debugging.codecov'] = False
351+
if '-fprofile-arcs' in flags_in['common_flags'] and '-ftest-coverage' in flags_in['common_flags']:
352+
opts['common']['debugging.codecov'] = True
353+
# Passing linker options to linker with '-Wl,'-prefix.
354+
for index in range(len(opts['ld']['flags'])):
355+
item = opts['ld']['flags'][index]
356+
if not item.startswith('-Wl,'):
357+
opts['ld']['flags'][index] = '-Wl,' + item
358+
317359
def generate(self):
318360
"""
319361
Generate the .project and .cproject files.
320362
"""
321-
opts = {}
363+
options = {}
322364

323365
if not self.resources.linker_script:
324366
raise NotSupportedException("No linker script found.")
@@ -330,25 +372,24 @@ def generate(self):
330372

331373
self.resources.win_to_unix()
332374

333-
fp_hardware = "no"
334-
fp_abi = "soft"
335-
core = self.toolchain.target.core
336-
if core == "Cortex-M4F" or core == "Cortex-M7F":
337-
fp_hardware = "fpv4-sp-d16"
338-
fp_abi = "softfp"
339-
elif core == "Cortex-M7FD":
340-
fp_hardware = "fpv5-d16"
341-
fp_abi = "softfp"
342-
343375
config_header = self.filter_dot(self.toolchain.get_config_header())
344376

345-
self.resources.win_to_unix()
346-
347377
libraries = []
348378
for lib in self.resources.libraries:
349379
library, _ = splitext(basename(lib))
350380
libraries.append(library[3:])
351381

382+
self.system_libraries = [
383+
'stdc++', 'supc++', 'm', 'c', 'gcc', 'nosys'
384+
]
385+
386+
profiles = self.get_all_profiles()
387+
388+
self.as_defines = self.toolchain.get_symbols(True)
389+
self.c_defines = self.toolchain.get_symbols()
390+
self.cpp_defines = self.c_defines
391+
print 'Symbols: {0}'.format(len(self.c_defines))
392+
352393
self.include_path = [self.filter_dot(s)
353394
for s in self.resources.inc_dirs]
354395
print ('Include folders: {0}'.format(len(self.include_path)))
@@ -367,34 +408,92 @@ def generate(self):
367408

368409
symbols = [s.replace('"', '"')
369410
for s in self.toolchain.get_symbols()]
370-
# TODO: We need to fetch all flags from CDT
371-
opts['ld'] = {}
372-
opts['ld']['extra_flags'] = ''
411+
412+
for id in ['debug', 'release']:
413+
opts = {}
414+
opts['common'] = {}
415+
opts['as'] = {}
416+
opts['c'] = {}
417+
opts['cpp'] = {}
418+
opts['ld'] = {}
419+
420+
opts['id'] = id
421+
opts['name'] = opts['id'].capitalize()
422+
423+
# TODO: Add prints to log or console in verbose mode.
424+
#print ('\nBuild configuration: {0}'.format(opts['name']))
425+
426+
profile = profiles[id]
427+
428+
# A small hack, do not bother with src_path again,
429+
# pass an empty string to avoid crashing.
430+
src_paths = ['']
431+
toolchain = prepare_toolchain(
432+
src_paths, "", self.toolchain.target.name, self.TOOLCHAIN, build_profile=[profile])
433+
434+
# Hack to fill in build_dir
435+
toolchain.build_dir = self.toolchain.build_dir
436+
437+
flags = self.toolchain_flags(toolchain)
438+
439+
# TODO: Add prints to log or console in verbose mode.
440+
# print 'Common flags:', ' '.join(flags['common_flags'])
441+
# print 'C++ flags:', ' '.join(flags['cxx_flags'])
442+
# print 'C flags:', ' '.join(flags['c_flags'])
443+
# print 'ASM flags:', ' '.join(flags['asm_flags'])
444+
# print 'Linker flags:', ' '.join(flags['ld_flags'])
445+
446+
# Most GNU ARM Eclipse options have a parent,
447+
# either debug or release.
448+
if '-O0' in flags['common_flags'] or '-Og' in flags['common_flags']:
449+
opts['parent_id'] = 'debug'
450+
else:
451+
opts['parent_id'] = 'release'
452+
453+
self.process_options(opts, flags)
454+
455+
self.process_sw_options(opts, flags)
456+
457+
opts['as']['defines'] = self.as_defines
458+
opts['c']['defines'] = self.c_defines
459+
opts['cpp']['defines'] = self.cpp_defines
460+
461+
opts['ld']['library_paths'] = [
462+
self.filter_dot(s) for s in self.resources.lib_dirs]
463+
464+
opts['ld']['user_libraries'] = libraries
465+
opts['ld']['system_libraries'] = self.system_libraries
466+
opts['ld']['script'] = "linker-script-" + id + ".ld"
467+
468+
# Unique IDs used in multiple places.
469+
uid = {}
470+
uid['config'] = u.id
471+
uid['tool_c_compiler'] = u.id
472+
uid['tool_c_compiler_input'] = u.id
473+
uid['tool_cpp_compiler'] = u.id
474+
uid['tool_cpp_compiler_input'] = u.id
475+
476+
opts['uid'] = uid
477+
478+
options[id] = opts
373479

374480
ctx = {
375481
'name': self.project_name,
376482
'include_paths': self.include_path,
377483
'config_header': config_header,
378484
'exclude_paths': self.exclude_dirs,
379485
'ld_script': ld_script,
380-
'linker_script': 'linker-script-' + self.toolchain.target.name + '.ld',
381486
'library_paths': lib_dirs,
382487
'object_files': self.resources.objects,
383488
'libraries': libraries,
384489
'symbols': symbols,
385490
'board_name': self.BOARDS[self.target.upper()]['name'],
386491
'mcu_name': self.BOARDS[self.target.upper()]['mcuId'],
387-
'debug_config_uid': self.__generate_uid(),
388-
'debug_tool_compiler_uid': self.__generate_uid(),
389-
'debug_tool_compiler_input_uid': self.__generate_uid(),
390-
'release_config_uid': self.__generate_uid(),
391-
'release_tool_compiler_uid': self.__generate_uid(),
392-
'release_tool_compiler_input_uid': self.__generate_uid(),
393-
'uid': self.__generate_uid(),
394-
'floating_point_hardware': fp_hardware,
395-
'floating_point_abi': fp_abi,
396492
'cpp_cmd': " ".join(self.toolchain.preproc),
397-
'options': opts
493+
'options': options,
494+
# id property of 'u' will generate new random identifier every time
495+
# when called.
496+
'u': u
398497
}
399498

400499
self.__gen_dir('.settings')

0 commit comments

Comments
 (0)