Refactor the build system to keep the information about a new target in a single class

pull/3/head
Emilio Monti 2013-04-18 15:43:29 +01:00
parent a607392724
commit 4e747af031
9 changed files with 158 additions and 104 deletions

View File

@ -13,6 +13,7 @@ from workspace_tools.client import request_test, get_muts
from workspace_tools.settings import *
from workspace_tools.paths import BUILD_DIR
from workspace_tools.utils import error
from workspace_tools.targets import TARGET_MAP
class TestServer:
@ -86,7 +87,8 @@ if __name__ == "__main__":
for toolchain in toolchains:
print '=== %s::%s ===' % (target, toolchain)
build_mbed_libs(target, toolchain)
T = TARGET_MAP[target]
build_mbed_libs(T, toolchain)
build_dir = join(BUILD_DIR, "test", target, toolchain)
@ -107,7 +109,7 @@ if __name__ == "__main__":
}
path = build_project(test.source_dir, join(build_dir, test_id),
target, toolchain, test.dependencies, clean=clean)
T, toolchain, test.dependencies, clean=clean)
test_result_cache = join(dirname(path), "test_result.json")
if not clean and exists(test_result_cache):

View File

@ -10,7 +10,8 @@ from os.path import join, abspath, dirname
ROOT = abspath(join(dirname(__file__), ".."))
sys.path.append(ROOT)
from workspace_tools.toolchains import TARGETS, TOOLCHAINS
from workspace_tools.toolchains import TOOLCHAINS
from workspace_tools.targets import TARGET_NAMES, TARGET_MAP
from workspace_tools.options import get_default_options_parser
from workspace_tools.build_api import build_mbed_libs, build_lib
@ -47,7 +48,7 @@ if __name__ == '__main__':
if options.mcu:
targets = [options.mcu]
else:
targets = TARGETS
targets = TARGET_NAMES
# Get toolchains list
if options.tool:
@ -83,9 +84,10 @@ if __name__ == '__main__':
for target in targets:
id = "%s::%s" % (toolchain, target)
try:
build_mbed_libs(target, toolchain, verbose=options.verbose)
mcu = TARGET_MAP[target]
build_mbed_libs(mcu, toolchain, verbose=options.verbose)
for lib_id in libraries:
build_lib(lib_id, target, toolchain, verbose=options.verbose)
build_lib(lib_id, mcu, toolchain, verbose=options.verbose)
successes.append(id)
except Exception, e:
failures.append(id)

View File

@ -17,7 +17,7 @@ clean: Rebuild everything if True
notify: Notify function for logs
verbose: Write the actual tools command lines if True
"""
def build_library(src_paths, build_path, target='LPC1768', toolchain_name='ARM',
def build_library(src_paths, build_path, target, toolchain_name,
libraries_paths=None, name=None, clean=False, notify=None, verbose=False):
if type(src_paths) != ListType: src_paths = [src_paths]
@ -50,7 +50,7 @@ def build_library(src_paths, build_path, target='LPC1768', toolchain_name='ARM',
else:
name = basename(main_src)
toolchain.info("\n>>> BUILD LIBRARY %s (%s, %s)" % (name.upper(), target, toolchain_name))
toolchain.info("\n>>> BUILD LIBRARY %s (%s, %s)" % (name.upper(), target.name, toolchain_name))
# Scan Resources
resources = []
@ -99,7 +99,7 @@ def build_library(src_paths, build_path, target='LPC1768', toolchain_name='ARM',
toolchain.build_library(objects, bin_path, name)
def build_project(src_path, build_path, target='LPC1768', toolchain_name='ARM',
def build_project(src_path, build_path, target, toolchain_name,
libraries_paths=None, clean=False, notify=None, verbose=False, name=None):
# Toolchain instance
toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, notify)
@ -108,7 +108,7 @@ def build_project(src_path, build_path, target='LPC1768', toolchain_name='ARM',
if name is None:
name = basename(src_path)
toolchain.info("\n>>> BUILD PROJECT: %s (%s, %s)" % (name.upper(), target, toolchain_name))
toolchain.info("\n>>> BUILD PROJECT: %s (%s, %s)" % (name.upper(), target.name, toolchain_name))
# Scan src_path and libraries_paths for resources
resources = toolchain.scan_resources(src_path)
@ -135,19 +135,9 @@ def build_lib(lib_id, target, toolchain, verbose=False):
if lib.is_supported(target, toolchain):
build_library(lib.source_dir, lib.build_dir, target, toolchain, lib.dependencies, lib.name, verbose=verbose)
else:
print '\n\nLibrary "%s" is not yet supported on target %s with toolchain %s' % (lib_id, target, toolchain)
print '\n\nLibrary "%s" is not yet supported on target %s with toolchain %s' % (lib_id, target.name, toolchain)
CHIP_VENDOR = {
"LPC2368" : "nxp",
"LPC1768" : "nxp",
"LPC11U24": "nxp",
"LPC812" : "nxp",
"KL25Z" : "freescale",
}
def build_mbed_libs(target, toolchain, verbose=False):
vendor = CHIP_VENDOR[target]
for lib_name in ["%s_cmsis"%vendor, "%s_mbed"%vendor]:
for lib_name in ["%s_cmsis" % target.vendor, "%s_mbed" % target.vendor]:
build_lib(lib_name, target, toolchain, verbose=verbose)

View File

@ -1,13 +1,11 @@
DEFAULT_SUPPORT = {
"LPC1768" : ["ARM", "GCC_ARM", "GCC_CS", "GCC_CR", "IAR"],
"LPC11U24": ["ARM", "uARM"],
"LPC2368" : ["ARM"],
"KL25Z" : ["ARM", "GCC_CW"],
"LPC812" : ["uARM"],
}
CORTEX_ARM_SUPPORT = {
"LPC1768" : ["ARM"],
"LPC11U24": ["ARM", "uARM"],
"KL25Z" : ["ARM"],
"LPC812" : ["uARM"],
}
from workspace_tools.targets import TARGETS
DEFAULT_SUPPORT = {}
CORTEX_ARM_SUPPORT = {}
for target in TARGETS:
DEFAULT_SUPPORT[target.name] = target.supported_toolchains
if target.core.startswith('Cortex'):
CORTEX_ARM_SUPPORT[target.name] = [t for t in target.supported_toolchains
if (t=='ARM' or t=='uARM')]

View File

@ -119,4 +119,4 @@ class Library:
def is_supported(self, target, toolchain):
if not hasattr(self, 'supported'):
return True
return (target in self.supported) and (toolchain in self.supported[target])
return (target.name in self.supported) and (toolchain in self.supported[target.name])

View File

@ -16,6 +16,7 @@ from workspace_tools.options import get_default_options_parser
from workspace_tools.build_api import build_project
from workspace_tools.tests import TESTS, Test, TEST_MAP
from workspace_tools.paths import BUILD_DIR, RTOS_LIBRARIES
from workspace_tools.targets import TARGET_MAP
def args_error(parser, message):
@ -78,8 +79,9 @@ if __name__ == '__main__':
build_dir = join(BUILD_DIR, "test", mcu, toolchain, test.id)
target = TARGET_MAP[mcu]
try:
bin = build_project(test.source_dir, build_dir, mcu, toolchain,
bin = build_project(test.source_dir, build_dir, target, toolchain,
test.dependencies, clean=options.clean, verbose=options.verbose)
print 'Image: %s' % bin
@ -88,15 +90,7 @@ if __name__ == '__main__':
copy(bin, options.disk)
if options.serial:
if options.mcu in ["KL25Z", "LPC812"]:
# We do not have a flash disk where to store the image, we write
# it directly on the target chip, therefore we need to
# disconnect the interface: wait for the device to enumerate
# again
copy_time = 4
else:
copy_time = 1.5
sleep(copy_time)
sleep(target.program_cycle_s)
serial = Serial(options.serial, timeout = 1)
if options.baud:
serial.setBaudrate(options.baud)

View File

@ -1,22 +1,14 @@
from optparse import OptionParser
from workspace_tools.toolchains import *
from workspace_tools.toolchains import TOOLCHAINS
from workspace_tools.targets import TARGET_NAMES
# Targets and Toolchains
TARGETS = (
"LPC2368",
"LPC1768",
"LPC11U24",
"KL25Z",
"LPC812"
)
def get_default_options_parser():
parser = OptionParser()
parser.add_option("-m", "--mcu", dest="mcu",
help="build for the given MCU (%s)" % ', '.join(TARGETS),
help="build for the given MCU (%s)" % ', '.join(TARGET_NAMES),
metavar="MCU")
parser.add_option("-t", "--tool", dest="tool",

View File

@ -0,0 +1,88 @@
class Target:
def __init__(self):
# ARM Core
self.core = None
# The silicon vendor of this chip
self.vendor = None
# How much time (in seconds) it takes to the interface chip to flash a
# new image and reset the target chip
self.program_cycle_s = 1.5
# list of toolchains that are supported by the mbed SDK for this target
self.supported_toolchains = None
self.name = self.__class__.__name__
class LPC2368(Target):
def __init__(self):
Target.__init__(self)
self.core = "ARM7TDMI-S"
self.vendor = "nxp"
self.supported_toolchains = ["ARM"]
class LPC1768(Target):
def __init__(self):
Target.__init__(self)
self.core = "Cortex-M3"
self.vendor = "nxp"
self.supported_toolchains = ["ARM", "GCC_ARM", "GCC_CS", "GCC_CR", "IAR"]
class LPC11U24(Target):
def __init__(self):
Target.__init__(self)
self.core = "Cortex-M0"
self.vendor = "nxp"
self.supported_toolchains = ["ARM", "uARM"]
class KL25Z(Target):
def __init__(self):
Target.__init__(self)
self.core = "Cortex-M0+"
self.vendor = "freescale"
self.supported_toolchains = ["ARM", "GCC_CW"]
self.program_cycle_s = 4
class LPC812(Target):
def __init__(self):
Target.__init__(self)
self.core = "Cortex-M0+"
self.vendor = "nxp"
self.supported_toolchains = ["uARM"]
self.program_cycle_s = 4
# Get a single instance for each target
TARGETS = [
LPC2368(),
LPC1768(),
LPC11U24(),
KL25Z(),
LPC812()
]
# Map each target name to its unique instance
TARGET_MAP = {}
for t in TARGETS:
TARGET_MAP[t.name] = t
TARGET_NAMES = TARGET_MAP.keys()

View File

@ -8,6 +8,7 @@ import re
from workspace_tools.settings import *
from workspace_tools.utils import run_cmd, mkdir, rel_path, ToolException, split_path
from workspace_tools.patch import patch
from workspace_tools.targets import TARGET_NAMES
"""
We made the unfortunate choice of calling the ARM standard library toolchain "ARM"
@ -24,9 +25,7 @@ type directory, because it would get confused with the legacy "ARM" toolchain.
* ARM -> ARM_STD
* uARM -> ARM_MICRO
"""
TARGETS = set(['LPC1768', 'LPC11U24', 'LPC2368', 'KL25Z', 'LPC812'])
TOOLCHAINS = set(['ARM', 'uARM', 'GCC_ARM', 'GCC_CS', 'GCC_CR', 'GCC_CW', 'IAR'])
TYPES = set(['GCC'])
# List of ignored directories (all the hidden directories are ignored by default)
IGNORE_DIRECTORIES = set(['CVS'])
@ -126,10 +125,9 @@ class mbedToolchain:
VERBOSE = True
CORTEX_SYMBOLS = {
"LPC1768" : ["__CORTEX_M3", "ARM_MATH_CM3"],
"LPC11U24": ["__CORTEX_M0", "ARM_MATH_CM0"],
"KL25Z" : ["__CORTEX_M0", "ARM_MATH_CM0"],
"LPC812" : ["__CORTEX_M0", "ARM_MATH_CM0"],
"Cortex-M3" : ["__CORTEX_M3", "ARM_MATH_CM3"],
"Cortex-M0" : ["__CORTEX_M0", "ARM_MATH_CM0"],
"Cortex-M0+": ["__CORTEX_M0", "ARM_MATH_CM0"],
}
def __init__(self, target, notify=None):
@ -142,19 +140,19 @@ class mbedToolchain:
self.COMPILE_C_AS_CPP = False
self.CHROOT = None
bin_tuple = (target, self.NAME)
bin_tuple = (target.name, self.NAME)
self.obj_path = join(*bin_tuple)
self.IGNORE_DIR = (IGNORE_DIRECTORIES | TARGETS | TOOLCHAINS | TYPES) - set(bin_tuple)
self.IGNORE_DIR = (IGNORE_DIRECTORIES | set(TARGET_NAMES) | TOOLCHAINS) - set(bin_tuple)
# Target and Toolchain symbols
self.symbols = [
"TARGET_" + target, "TOOLCHAIN_" + self.NAME,
"TARGET_" + target.name, "TOOLCHAIN_" + self.NAME,
]
# Cortex CPU symbols
if target in mbedToolchain.CORTEX_SYMBOLS:
self.symbols.extend(mbedToolchain.CORTEX_SYMBOLS[target])
if target.core in mbedToolchain.CORTEX_SYMBOLS:
self.symbols.extend(mbedToolchain.CORTEX_SYMBOLS[target.core])
self.IGNORE_FILES = []
@ -197,8 +195,8 @@ class mbedToolchain:
self.remove_option(option)
# Target specific options
if self.target in options:
to = options[self.target]
if self.target.name in options:
to = options[self.target.name]
if 'ignore_files' in to:
self.IGNORE_FILES.extend(to['ignore_files'])
@ -247,7 +245,7 @@ class mbedToolchain:
if self.NAME == 'ARM': # Legacy default toolchain
self.mbed_libs = True
else:
self.mbed_libs = exists(join(root, self.target, self.NAME))
self.mbed_libs = exists(join(root, self.target.name, self.NAME))
elif ext == '.o':
resources.objects.append(file_path)
@ -363,9 +361,9 @@ class mbedToolchain:
self.progress("elf2bin", name)
self.binary(elf, bin)
if self.target in ['LPC1768', 'LPC11U24', 'LPC2368', 'LPC812']:
if self.target.vendor == 'nxp':
self.debug("LPC Patch %s" % (name + '.bin'))
patch(bin)
patch(bin)
self.var("compile_succeded", True)
self.var("binary", name+'.bin')
@ -408,14 +406,6 @@ class ARM(mbedToolchain):
LINKER_EXT = '.sct'
LIBRARY_EXT = '.ar'
CPU = {
"LPC1768" : "Cortex-M3",
"LPC2368" : "ARM7TDMI-S",
"LPC11U24": "Cortex-M0",
"KL25Z" : "Cortex-M0",
"LPC812" : "Cortex-M0",
}
STD_LIB_NAME = "%s.ar"
DIAGNOSTIC_PATTERN = re.compile('"(?P<file>[^"]+)", line (?P<line>\d+): (?P<severity>Warning|Error): (?P<message>.+)')
DEP_PATTERN = re.compile('\S+:\s(?P<file>.+)\n')
@ -423,10 +413,13 @@ class ARM(mbedToolchain):
def __init__(self, target, notify):
mbedToolchain.__init__(self, target, notify)
# self.IGNORE_DIR.remove('ARM')
if target.core == "Cortex-M0+":
cpu = "Cortex-M0"
else:
cpu = target.core
common = [join(ARM_BIN, "armcc"), "-c",
"--cpu=%s" % ARM.CPU[target], "--gnu",
"--cpu=%s" % cpu, "--gnu",
"-Ospace", "--split_sections", "--apcs=interwork",
"--brief_diagnostics"
]
@ -507,10 +500,10 @@ class ARM_MICRO(ARM):
# System Libraries
self.sys_libs.extend([join(MY_ARM_CLIB, lib+".l") for lib in ["mc_p", "mf_p", "m_ps"]])
if target == "LPC1768":
if target.core == "Cortex-M3":
self.sys_libs.extend([join(ARM_CPPLIB, lib+".l") for lib in ["cpp_ws", "cpprt_w"]])
elif target in ["LPC11U24", "KL25Z", "LPC812"]:
elif target.core in ["Cortex-M0", "Cortex-M0+"]:
self.sys_libs.extend([join(ARM_CPPLIB, lib+".l") for lib in ["cpp_ps", "cpprt_p"]])
@ -518,23 +511,20 @@ class GCC(mbedToolchain):
LINKER_EXT = '.ld'
LIBRARY_EXT = '.a'
CPU = {
"LPC1768": "cortex-m3",
"LPC2368": "arm7tdmi-s",
"LPC11U24": "cortex-m0",
"KL25Z": "cortex-m0",
"LPC812" : "cortex-m0",
}
STD_LIB_NAME = "lib%s.a"
CIRCULAR_DEPENDENCIES = True
DIAGNOSTIC_PATTERN = re.compile('((?P<line>\d+):)(\d+:)? (?P<severity>warning|error): (?P<message>.+)')
def __init__(self, target, notify, tool_path):
mbedToolchain.__init__(self, target, notify)
self.IGNORE_DIR.remove('GCC')
self.cpu = ["-mcpu=%s" % GCC.CPU[target]]
if target in ["LPC1768", "LPC11U24", "KL25Z", "LPC812"]:
if target.core == "Cortex-M0+":
cpu = "cortex-m0"
else:
cpu = target.core.lower()
self.cpu = ["-mcpu=%s" % cpu]
if target.core.startswith("Cortex"):
self.cpu.append("-mthumb")
# Note: We are using "-O2" instead of "-Os" to avoid this known GCC bug:
@ -659,7 +649,7 @@ class GCC_CW(GCC):
NAME = 'GCC_CW'
ARCH_LIB = {
"KL25Z": "armv6-m",
"Cortex-M0+": "armv6-m",
}
def __init__(self, target, notify=None):
@ -667,7 +657,7 @@ class GCC_CW(GCC):
GCC.__init__(self, target, notify, tool_path)
self.CIRCULAR_DEPENDENCIES = False
lib_path = join(GCC_CW_PATH, "MCU/ARM_GCC_Support/ewl/lib", GCC_CW.ARCH_LIB[target])
lib_path = join(GCC_CW_PATH, "MCU/ARM_GCC_Support/ewl/lib", GCC_CW.ARCH_LIB[target.core])
self.sys_libs = []
self.ld = [join(tool_path, "arm-none-eabi-g++"),
"-Xlinker", "--gc-sections",
@ -683,9 +673,7 @@ class IAR(mbedToolchain):
LIBRARY_EXT = '.a'
LINKER_EXT = '.icf'
STD_LIB_NAME = "%s.a"
CPU = {
"LPC1768" : "Cortex-M3",
}
DIAGNOSTIC_PATTERN = re.compile('"(?P<file>[^"]+)",(?P<line>[\d]+)\s+(?P<severity>Warning|Error)(?P<message>.+)')
def __init__(self, target, notify=None):
@ -693,7 +681,7 @@ class IAR(mbedToolchain):
c_flags = [
"-Oh",
"--cpu=%s" % IAR.CPU[target], "--thumb",
"--cpu=%s" % target.core, "--thumb",
"--dlib_config", join(IAR_PATH, "inc", "c", "DLib_Config_Full.h"),
"-e", # Enable IAR language extension
"--no_wrap_diagnostics",
@ -705,7 +693,7 @@ class IAR(mbedToolchain):
]
IAR_BIN = join(IAR_PATH, "bin")
self.asm = [join(IAR_BIN, "iasmarm")] + ["--cpu", IAR.CPU[target]]
self.asm = [join(IAR_BIN, "iasmarm")] + ["--cpu", target.core]
self.cc = [join(IAR_BIN, "iccarm")] + c_flags
self.cppc = [join(IAR_BIN, "iccarm"), "--c++", "--no_rtti", "--no_exceptions"] + c_flags