BA
/
BaBoRo_test2
Backup 1
mbed-os/tools/toolchains/arm.py@0:02dd72d1d465, 2018-04-24 (annotated)
- Committer:
- borlanic
- Date:
- Tue Apr 24 11:45:18 2018 +0000
- Revision:
- 0:02dd72d1d465
BaBoRo_test2 - backup 1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
borlanic | 0:02dd72d1d465 | 1 | """ |
borlanic | 0:02dd72d1d465 | 2 | mbed SDK |
borlanic | 0:02dd72d1d465 | 3 | Copyright (c) 2011-2013 ARM Limited |
borlanic | 0:02dd72d1d465 | 4 | |
borlanic | 0:02dd72d1d465 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); |
borlanic | 0:02dd72d1d465 | 6 | you may not use this file except in compliance with the License. |
borlanic | 0:02dd72d1d465 | 7 | You may obtain a copy of the License at |
borlanic | 0:02dd72d1d465 | 8 | |
borlanic | 0:02dd72d1d465 | 9 | http://www.apache.org/licenses/LICENSE-2.0 |
borlanic | 0:02dd72d1d465 | 10 | |
borlanic | 0:02dd72d1d465 | 11 | Unless required by applicable law or agreed to in writing, software |
borlanic | 0:02dd72d1d465 | 12 | distributed under the License is distributed on an "AS IS" BASIS, |
borlanic | 0:02dd72d1d465 | 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
borlanic | 0:02dd72d1d465 | 14 | See the License for the specific language governing permissions and |
borlanic | 0:02dd72d1d465 | 15 | limitations under the License. |
borlanic | 0:02dd72d1d465 | 16 | """ |
borlanic | 0:02dd72d1d465 | 17 | from __future__ import print_function, absolute_import |
borlanic | 0:02dd72d1d465 | 18 | from builtins import str |
borlanic | 0:02dd72d1d465 | 19 | |
borlanic | 0:02dd72d1d465 | 20 | import re |
borlanic | 0:02dd72d1d465 | 21 | from copy import copy |
borlanic | 0:02dd72d1d465 | 22 | from os.path import join, dirname, splitext, basename, exists, relpath, isfile |
borlanic | 0:02dd72d1d465 | 23 | from os import makedirs, write, curdir, remove |
borlanic | 0:02dd72d1d465 | 24 | from tempfile import mkstemp |
borlanic | 0:02dd72d1d465 | 25 | from shutil import rmtree |
borlanic | 0:02dd72d1d465 | 26 | |
borlanic | 0:02dd72d1d465 | 27 | from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS |
borlanic | 0:02dd72d1d465 | 28 | from tools.hooks import hook_tool |
borlanic | 0:02dd72d1d465 | 29 | from tools.utils import mkdir, NotSupportedException |
borlanic | 0:02dd72d1d465 | 30 | |
borlanic | 0:02dd72d1d465 | 31 | class ARM(mbedToolchain): |
borlanic | 0:02dd72d1d465 | 32 | LINKER_EXT = '.sct' |
borlanic | 0:02dd72d1d465 | 33 | LIBRARY_EXT = '.ar' |
borlanic | 0:02dd72d1d465 | 34 | |
borlanic | 0:02dd72d1d465 | 35 | STD_LIB_NAME = "%s.ar" |
borlanic | 0:02dd72d1d465 | 36 | DIAGNOSTIC_PATTERN = re.compile('"(?P<file>[^"]+)", line (?P<line>\d+)( \(column (?P<column>\d+)\)|): (?P<severity>Warning|Error|Fatal error): (?P<message>.+)') |
borlanic | 0:02dd72d1d465 | 37 | INDEX_PATTERN = re.compile('(?P<col>\s*)\^') |
borlanic | 0:02dd72d1d465 | 38 | DEP_PATTERN = re.compile('\S+:\s(?P<file>.+)\n') |
borlanic | 0:02dd72d1d465 | 39 | SHEBANG = "#! armcc -E" |
borlanic | 0:02dd72d1d465 | 40 | SUPPORTED_CORES = ["Cortex-M0", "Cortex-M0+", "Cortex-M3", "Cortex-M4", |
borlanic | 0:02dd72d1d465 | 41 | "Cortex-M4F", "Cortex-M7", "Cortex-M7F", "Cortex-M7FD", "Cortex-A9"] |
borlanic | 0:02dd72d1d465 | 42 | |
borlanic | 0:02dd72d1d465 | 43 | @staticmethod |
borlanic | 0:02dd72d1d465 | 44 | def check_executable(): |
borlanic | 0:02dd72d1d465 | 45 | """Returns True if the executable (armcc) location specified by the |
borlanic | 0:02dd72d1d465 | 46 | user exists OR the executable can be found on the PATH. |
borlanic | 0:02dd72d1d465 | 47 | Returns False otherwise.""" |
borlanic | 0:02dd72d1d465 | 48 | return mbedToolchain.generic_check_executable("ARM", 'armcc', 2, 'bin') |
borlanic | 0:02dd72d1d465 | 49 | |
borlanic | 0:02dd72d1d465 | 50 | def __init__(self, target, notify=None, macros=None, |
borlanic | 0:02dd72d1d465 | 51 | silent=False, extra_verbose=False, build_profile=None, |
borlanic | 0:02dd72d1d465 | 52 | build_dir=None): |
borlanic | 0:02dd72d1d465 | 53 | mbedToolchain.__init__(self, target, notify, macros, silent, |
borlanic | 0:02dd72d1d465 | 54 | build_dir=build_dir, |
borlanic | 0:02dd72d1d465 | 55 | extra_verbose=extra_verbose, |
borlanic | 0:02dd72d1d465 | 56 | build_profile=build_profile) |
borlanic | 0:02dd72d1d465 | 57 | if target.core not in self.SUPPORTED_CORES: |
borlanic | 0:02dd72d1d465 | 58 | raise NotSupportedException( |
borlanic | 0:02dd72d1d465 | 59 | "this compiler does not support the core %s" % target.core) |
borlanic | 0:02dd72d1d465 | 60 | |
borlanic | 0:02dd72d1d465 | 61 | if target.core == "Cortex-M0+": |
borlanic | 0:02dd72d1d465 | 62 | cpu = "Cortex-M0" |
borlanic | 0:02dd72d1d465 | 63 | elif target.core == "Cortex-M4F": |
borlanic | 0:02dd72d1d465 | 64 | cpu = "Cortex-M4.fp" |
borlanic | 0:02dd72d1d465 | 65 | elif target.core == "Cortex-M7FD": |
borlanic | 0:02dd72d1d465 | 66 | cpu = "Cortex-M7.fp.dp" |
borlanic | 0:02dd72d1d465 | 67 | elif target.core == "Cortex-M7F": |
borlanic | 0:02dd72d1d465 | 68 | cpu = "Cortex-M7.fp.sp" |
borlanic | 0:02dd72d1d465 | 69 | else: |
borlanic | 0:02dd72d1d465 | 70 | cpu = target.core |
borlanic | 0:02dd72d1d465 | 71 | |
borlanic | 0:02dd72d1d465 | 72 | ARM_BIN = join(TOOLCHAIN_PATHS['ARM'], "bin") |
borlanic | 0:02dd72d1d465 | 73 | ARM_INC = join(TOOLCHAIN_PATHS['ARM'], "include") |
borlanic | 0:02dd72d1d465 | 74 | |
borlanic | 0:02dd72d1d465 | 75 | main_cc = join(ARM_BIN, "armcc") |
borlanic | 0:02dd72d1d465 | 76 | |
borlanic | 0:02dd72d1d465 | 77 | self.flags['common'] += ["--cpu=%s" % cpu] |
borlanic | 0:02dd72d1d465 | 78 | |
borlanic | 0:02dd72d1d465 | 79 | self.asm = [main_cc] + self.flags['common'] + self.flags['asm'] |
borlanic | 0:02dd72d1d465 | 80 | self.cc = [main_cc] + self.flags['common'] + self.flags['c'] |
borlanic | 0:02dd72d1d465 | 81 | self.cppc = [main_cc] + self.flags['common'] + self.flags['c'] + self.flags['cxx'] |
borlanic | 0:02dd72d1d465 | 82 | |
borlanic | 0:02dd72d1d465 | 83 | self.ld = [join(ARM_BIN, "armlink")] + self.flags['ld'] |
borlanic | 0:02dd72d1d465 | 84 | |
borlanic | 0:02dd72d1d465 | 85 | self.ar = join(ARM_BIN, "armar") |
borlanic | 0:02dd72d1d465 | 86 | self.elf2bin = join(ARM_BIN, "fromelf") |
borlanic | 0:02dd72d1d465 | 87 | |
borlanic | 0:02dd72d1d465 | 88 | self.SHEBANG += " --cpu=%s" % cpu |
borlanic | 0:02dd72d1d465 | 89 | |
borlanic | 0:02dd72d1d465 | 90 | def parse_dependencies(self, dep_path): |
borlanic | 0:02dd72d1d465 | 91 | dependencies = [] |
borlanic | 0:02dd72d1d465 | 92 | for line in open(dep_path).readlines(): |
borlanic | 0:02dd72d1d465 | 93 | match = ARM.DEP_PATTERN.match(line) |
borlanic | 0:02dd72d1d465 | 94 | if match is not None: |
borlanic | 0:02dd72d1d465 | 95 | #we need to append chroot, because when the .d files are generated the compiler is chrooted |
borlanic | 0:02dd72d1d465 | 96 | dependencies.append((self.CHROOT if self.CHROOT else '') + match.group('file')) |
borlanic | 0:02dd72d1d465 | 97 | return dependencies |
borlanic | 0:02dd72d1d465 | 98 | |
borlanic | 0:02dd72d1d465 | 99 | def parse_output(self, output): |
borlanic | 0:02dd72d1d465 | 100 | msg = None |
borlanic | 0:02dd72d1d465 | 101 | for line in output.splitlines(): |
borlanic | 0:02dd72d1d465 | 102 | match = ARM.DIAGNOSTIC_PATTERN.match(line) |
borlanic | 0:02dd72d1d465 | 103 | if match is not None: |
borlanic | 0:02dd72d1d465 | 104 | if msg is not None: |
borlanic | 0:02dd72d1d465 | 105 | self.cc_info(msg) |
borlanic | 0:02dd72d1d465 | 106 | msg = None |
borlanic | 0:02dd72d1d465 | 107 | msg = { |
borlanic | 0:02dd72d1d465 | 108 | 'severity': match.group('severity').lower(), |
borlanic | 0:02dd72d1d465 | 109 | 'file': match.group('file'), |
borlanic | 0:02dd72d1d465 | 110 | 'line': match.group('line'), |
borlanic | 0:02dd72d1d465 | 111 | 'col': match.group('column') if match.group('column') else 0, |
borlanic | 0:02dd72d1d465 | 112 | 'message': match.group('message'), |
borlanic | 0:02dd72d1d465 | 113 | 'text': '', |
borlanic | 0:02dd72d1d465 | 114 | 'target_name': self.target.name, |
borlanic | 0:02dd72d1d465 | 115 | 'toolchain_name': self.name |
borlanic | 0:02dd72d1d465 | 116 | } |
borlanic | 0:02dd72d1d465 | 117 | elif msg is not None: |
borlanic | 0:02dd72d1d465 | 118 | # Determine the warning/error column by calculating the ^ position |
borlanic | 0:02dd72d1d465 | 119 | match = ARM.INDEX_PATTERN.match(line) |
borlanic | 0:02dd72d1d465 | 120 | if match is not None: |
borlanic | 0:02dd72d1d465 | 121 | msg['col'] = len(match.group('col')) |
borlanic | 0:02dd72d1d465 | 122 | self.cc_info(msg) |
borlanic | 0:02dd72d1d465 | 123 | msg = None |
borlanic | 0:02dd72d1d465 | 124 | else: |
borlanic | 0:02dd72d1d465 | 125 | msg['text'] += line+"\n" |
borlanic | 0:02dd72d1d465 | 126 | |
borlanic | 0:02dd72d1d465 | 127 | if msg is not None: |
borlanic | 0:02dd72d1d465 | 128 | self.cc_info(msg) |
borlanic | 0:02dd72d1d465 | 129 | |
borlanic | 0:02dd72d1d465 | 130 | def get_dep_option(self, object): |
borlanic | 0:02dd72d1d465 | 131 | base, _ = splitext(object) |
borlanic | 0:02dd72d1d465 | 132 | dep_path = base + '.d' |
borlanic | 0:02dd72d1d465 | 133 | return ["--depend", dep_path] |
borlanic | 0:02dd72d1d465 | 134 | |
borlanic | 0:02dd72d1d465 | 135 | def get_config_option(self, config_header): |
borlanic | 0:02dd72d1d465 | 136 | return ['--preinclude=' + config_header] |
borlanic | 0:02dd72d1d465 | 137 | |
borlanic | 0:02dd72d1d465 | 138 | def get_compile_options(self, defines, includes, for_asm=False): |
borlanic | 0:02dd72d1d465 | 139 | opts = ['-D%s' % d for d in defines] |
borlanic | 0:02dd72d1d465 | 140 | if self.RESPONSE_FILES: |
borlanic | 0:02dd72d1d465 | 141 | opts += ['--via', self.get_inc_file(includes)] |
borlanic | 0:02dd72d1d465 | 142 | else: |
borlanic | 0:02dd72d1d465 | 143 | opts += ["-I%s" % i for i in includes] |
borlanic | 0:02dd72d1d465 | 144 | |
borlanic | 0:02dd72d1d465 | 145 | if not for_asm: |
borlanic | 0:02dd72d1d465 | 146 | config_header = self.get_config_header() |
borlanic | 0:02dd72d1d465 | 147 | if config_header is not None: |
borlanic | 0:02dd72d1d465 | 148 | opts = opts + self.get_config_option(config_header) |
borlanic | 0:02dd72d1d465 | 149 | return opts |
borlanic | 0:02dd72d1d465 | 150 | |
borlanic | 0:02dd72d1d465 | 151 | @hook_tool |
borlanic | 0:02dd72d1d465 | 152 | def assemble(self, source, object, includes): |
borlanic | 0:02dd72d1d465 | 153 | # Preprocess first, then assemble |
borlanic | 0:02dd72d1d465 | 154 | dir = join(dirname(object), '.temp') |
borlanic | 0:02dd72d1d465 | 155 | mkdir(dir) |
borlanic | 0:02dd72d1d465 | 156 | tempfile = join(dir, basename(object) + '.E.s') |
borlanic | 0:02dd72d1d465 | 157 | |
borlanic | 0:02dd72d1d465 | 158 | # Build preprocess assemble command |
borlanic | 0:02dd72d1d465 | 159 | cmd_pre = self.asm + self.get_compile_options(self.get_symbols(True), includes) + ["-E", "-o", tempfile, source] |
borlanic | 0:02dd72d1d465 | 160 | |
borlanic | 0:02dd72d1d465 | 161 | # Build main assemble command |
borlanic | 0:02dd72d1d465 | 162 | cmd = self.asm + ["-o", object, tempfile] |
borlanic | 0:02dd72d1d465 | 163 | |
borlanic | 0:02dd72d1d465 | 164 | # Call cmdline hook |
borlanic | 0:02dd72d1d465 | 165 | cmd_pre = self.hook.get_cmdline_assembler(cmd_pre) |
borlanic | 0:02dd72d1d465 | 166 | cmd = self.hook.get_cmdline_assembler(cmd) |
borlanic | 0:02dd72d1d465 | 167 | |
borlanic | 0:02dd72d1d465 | 168 | # Return command array, don't execute |
borlanic | 0:02dd72d1d465 | 169 | return [cmd_pre, cmd] |
borlanic | 0:02dd72d1d465 | 170 | |
borlanic | 0:02dd72d1d465 | 171 | @hook_tool |
borlanic | 0:02dd72d1d465 | 172 | def compile(self, cc, source, object, includes): |
borlanic | 0:02dd72d1d465 | 173 | # Build compile command |
borlanic | 0:02dd72d1d465 | 174 | cmd = cc + self.get_compile_options(self.get_symbols(), includes) |
borlanic | 0:02dd72d1d465 | 175 | |
borlanic | 0:02dd72d1d465 | 176 | cmd.extend(self.get_dep_option(object)) |
borlanic | 0:02dd72d1d465 | 177 | |
borlanic | 0:02dd72d1d465 | 178 | cmd.extend(["-o", object, source]) |
borlanic | 0:02dd72d1d465 | 179 | |
borlanic | 0:02dd72d1d465 | 180 | # Call cmdline hook |
borlanic | 0:02dd72d1d465 | 181 | cmd = self.hook.get_cmdline_compiler(cmd) |
borlanic | 0:02dd72d1d465 | 182 | |
borlanic | 0:02dd72d1d465 | 183 | return [cmd] |
borlanic | 0:02dd72d1d465 | 184 | |
borlanic | 0:02dd72d1d465 | 185 | def compile_c(self, source, object, includes): |
borlanic | 0:02dd72d1d465 | 186 | return self.compile(self.cc, source, object, includes) |
borlanic | 0:02dd72d1d465 | 187 | |
borlanic | 0:02dd72d1d465 | 188 | def compile_cpp(self, source, object, includes): |
borlanic | 0:02dd72d1d465 | 189 | return self.compile(self.cppc, source, object, includes) |
borlanic | 0:02dd72d1d465 | 190 | |
borlanic | 0:02dd72d1d465 | 191 | def correct_scatter_shebang(self, scatter_file, base_path=curdir): |
borlanic | 0:02dd72d1d465 | 192 | """Correct the shebang at the top of a scatter file. |
borlanic | 0:02dd72d1d465 | 193 | |
borlanic | 0:02dd72d1d465 | 194 | Positional arguments: |
borlanic | 0:02dd72d1d465 | 195 | scatter_file -- the scatter file to correct |
borlanic | 0:02dd72d1d465 | 196 | |
borlanic | 0:02dd72d1d465 | 197 | Return: |
borlanic | 0:02dd72d1d465 | 198 | The location of the correct scatter file |
borlanic | 0:02dd72d1d465 | 199 | |
borlanic | 0:02dd72d1d465 | 200 | Side Effects: |
borlanic | 0:02dd72d1d465 | 201 | This method MAY write a new scatter file to disk |
borlanic | 0:02dd72d1d465 | 202 | """ |
borlanic | 0:02dd72d1d465 | 203 | with open(scatter_file, "r") as input: |
borlanic | 0:02dd72d1d465 | 204 | lines = input.readlines() |
borlanic | 0:02dd72d1d465 | 205 | if (lines[0].startswith(self.SHEBANG) or |
borlanic | 0:02dd72d1d465 | 206 | not lines[0].startswith("#!")): |
borlanic | 0:02dd72d1d465 | 207 | return scatter_file |
borlanic | 0:02dd72d1d465 | 208 | else: |
borlanic | 0:02dd72d1d465 | 209 | new_scatter = join(self.build_dir, ".link_script.sct") |
borlanic | 0:02dd72d1d465 | 210 | self.SHEBANG += " -I %s" % relpath(dirname(scatter_file), |
borlanic | 0:02dd72d1d465 | 211 | base_path) |
borlanic | 0:02dd72d1d465 | 212 | if self.need_update(new_scatter, [scatter_file]): |
borlanic | 0:02dd72d1d465 | 213 | with open(new_scatter, "w") as out: |
borlanic | 0:02dd72d1d465 | 214 | out.write(self.SHEBANG) |
borlanic | 0:02dd72d1d465 | 215 | out.write("\n") |
borlanic | 0:02dd72d1d465 | 216 | out.write("".join(lines[1:])) |
borlanic | 0:02dd72d1d465 | 217 | |
borlanic | 0:02dd72d1d465 | 218 | return new_scatter |
borlanic | 0:02dd72d1d465 | 219 | |
borlanic | 0:02dd72d1d465 | 220 | @hook_tool |
borlanic | 0:02dd72d1d465 | 221 | def link(self, output, objects, libraries, lib_dirs, scatter_file): |
borlanic | 0:02dd72d1d465 | 222 | base, _ = splitext(output) |
borlanic | 0:02dd72d1d465 | 223 | map_file = base + ".map" |
borlanic | 0:02dd72d1d465 | 224 | args = ["-o", output, "--info=totals", "--map", "--list=%s" % map_file] |
borlanic | 0:02dd72d1d465 | 225 | args.extend(objects) |
borlanic | 0:02dd72d1d465 | 226 | args.extend(libraries) |
borlanic | 0:02dd72d1d465 | 227 | if lib_dirs: |
borlanic | 0:02dd72d1d465 | 228 | args.extend(["--userlibpath", ",".join(lib_dirs)]) |
borlanic | 0:02dd72d1d465 | 229 | if scatter_file: |
borlanic | 0:02dd72d1d465 | 230 | new_scatter = self.correct_scatter_shebang(scatter_file) |
borlanic | 0:02dd72d1d465 | 231 | args.extend(["--scatter", new_scatter]) |
borlanic | 0:02dd72d1d465 | 232 | |
borlanic | 0:02dd72d1d465 | 233 | cmd_pre = self.ld + args |
borlanic | 0:02dd72d1d465 | 234 | cmd = self.hook.get_cmdline_linker(cmd_pre) |
borlanic | 0:02dd72d1d465 | 235 | |
borlanic | 0:02dd72d1d465 | 236 | if self.RESPONSE_FILES: |
borlanic | 0:02dd72d1d465 | 237 | cmd_linker = cmd[0] |
borlanic | 0:02dd72d1d465 | 238 | link_files = self.get_link_file(cmd[1:]) |
borlanic | 0:02dd72d1d465 | 239 | cmd = [cmd_linker, '--via', link_files] |
borlanic | 0:02dd72d1d465 | 240 | |
borlanic | 0:02dd72d1d465 | 241 | self.cc_verbose("Link: %s" % ' '.join(cmd)) |
borlanic | 0:02dd72d1d465 | 242 | self.default_cmd(cmd) |
borlanic | 0:02dd72d1d465 | 243 | |
borlanic | 0:02dd72d1d465 | 244 | @hook_tool |
borlanic | 0:02dd72d1d465 | 245 | def archive(self, objects, lib_path): |
borlanic | 0:02dd72d1d465 | 246 | if self.RESPONSE_FILES: |
borlanic | 0:02dd72d1d465 | 247 | param = ['--via', self.get_arch_file(objects)] |
borlanic | 0:02dd72d1d465 | 248 | else: |
borlanic | 0:02dd72d1d465 | 249 | param = objects |
borlanic | 0:02dd72d1d465 | 250 | self.default_cmd([self.ar, '-r', lib_path] + param) |
borlanic | 0:02dd72d1d465 | 251 | |
borlanic | 0:02dd72d1d465 | 252 | @hook_tool |
borlanic | 0:02dd72d1d465 | 253 | def binary(self, resources, elf, bin): |
borlanic | 0:02dd72d1d465 | 254 | _, fmt = splitext(bin) |
borlanic | 0:02dd72d1d465 | 255 | bin_arg = {".bin": "--bin", ".hex": "--i32"}[fmt] |
borlanic | 0:02dd72d1d465 | 256 | cmd = [self.elf2bin, bin_arg, '-o', bin, elf] |
borlanic | 0:02dd72d1d465 | 257 | cmd = self.hook.get_cmdline_binary(cmd) |
borlanic | 0:02dd72d1d465 | 258 | |
borlanic | 0:02dd72d1d465 | 259 | # remove target binary file/path |
borlanic | 0:02dd72d1d465 | 260 | if exists(bin): |
borlanic | 0:02dd72d1d465 | 261 | if isfile(bin): |
borlanic | 0:02dd72d1d465 | 262 | remove(bin) |
borlanic | 0:02dd72d1d465 | 263 | else: |
borlanic | 0:02dd72d1d465 | 264 | rmtree(bin) |
borlanic | 0:02dd72d1d465 | 265 | |
borlanic | 0:02dd72d1d465 | 266 | self.cc_verbose("FromELF: %s" % ' '.join(cmd)) |
borlanic | 0:02dd72d1d465 | 267 | self.default_cmd(cmd) |
borlanic | 0:02dd72d1d465 | 268 | |
borlanic | 0:02dd72d1d465 | 269 | @staticmethod |
borlanic | 0:02dd72d1d465 | 270 | def name_mangle(name): |
borlanic | 0:02dd72d1d465 | 271 | return "_Z%i%sv" % (len(name), name) |
borlanic | 0:02dd72d1d465 | 272 | |
borlanic | 0:02dd72d1d465 | 273 | @staticmethod |
borlanic | 0:02dd72d1d465 | 274 | def make_ld_define(name, value): |
borlanic | 0:02dd72d1d465 | 275 | return "--predefine=\"-D%s=0x%x\"" % (name, value) |
borlanic | 0:02dd72d1d465 | 276 | |
borlanic | 0:02dd72d1d465 | 277 | @staticmethod |
borlanic | 0:02dd72d1d465 | 278 | def redirect_symbol(source, sync, build_dir): |
borlanic | 0:02dd72d1d465 | 279 | if not exists(build_dir): |
borlanic | 0:02dd72d1d465 | 280 | makedirs(build_dir) |
borlanic | 0:02dd72d1d465 | 281 | handle, filename = mkstemp(prefix=".redirect-symbol.", dir=build_dir) |
borlanic | 0:02dd72d1d465 | 282 | write(handle, "RESOLVE %s AS %s\n" % (source, sync)) |
borlanic | 0:02dd72d1d465 | 283 | return "--edit=%s" % filename |
borlanic | 0:02dd72d1d465 | 284 | |
borlanic | 0:02dd72d1d465 | 285 | |
borlanic | 0:02dd72d1d465 | 286 | class ARM_STD(ARM): |
borlanic | 0:02dd72d1d465 | 287 | def __init__(self, target, notify=None, macros=None, |
borlanic | 0:02dd72d1d465 | 288 | silent=False, extra_verbose=False, build_profile=None, |
borlanic | 0:02dd72d1d465 | 289 | build_dir=None): |
borlanic | 0:02dd72d1d465 | 290 | ARM.__init__(self, target, notify, macros, silent, |
borlanic | 0:02dd72d1d465 | 291 | build_dir=build_dir, extra_verbose=extra_verbose, |
borlanic | 0:02dd72d1d465 | 292 | build_profile=build_profile) |
borlanic | 0:02dd72d1d465 | 293 | if "ARM" not in target.supported_toolchains: |
borlanic | 0:02dd72d1d465 | 294 | raise NotSupportedException("ARM compiler support is required for ARM build") |
borlanic | 0:02dd72d1d465 | 295 | |
borlanic | 0:02dd72d1d465 | 296 | |
borlanic | 0:02dd72d1d465 | 297 | class ARM_MICRO(ARM): |
borlanic | 0:02dd72d1d465 | 298 | PATCHED_LIBRARY = False |
borlanic | 0:02dd72d1d465 | 299 | def __init__(self, target, notify=None, macros=None, |
borlanic | 0:02dd72d1d465 | 300 | silent=False, extra_verbose=False, build_profile=None, |
borlanic | 0:02dd72d1d465 | 301 | build_dir=None): |
borlanic | 0:02dd72d1d465 | 302 | ARM.__init__(self, target, notify, macros, silent, |
borlanic | 0:02dd72d1d465 | 303 | build_dir=build_dir, extra_verbose=extra_verbose, |
borlanic | 0:02dd72d1d465 | 304 | build_profile=build_profile) |
borlanic | 0:02dd72d1d465 | 305 | if not set(("ARM", "uARM")).intersection(set(target.supported_toolchains)): |
borlanic | 0:02dd72d1d465 | 306 | raise NotSupportedException("ARM/uARM compiler support is required for ARM build") |
borlanic | 0:02dd72d1d465 | 307 | |
borlanic | 0:02dd72d1d465 | 308 | class ARMC6(ARM_STD): |
borlanic | 0:02dd72d1d465 | 309 | SHEBANG = "#! armclang -E --target=arm-arm-none-eabi -x c" |
borlanic | 0:02dd72d1d465 | 310 | SUPPORTED_CORES = ["Cortex-M0", "Cortex-M0+", "Cortex-M3", "Cortex-M4", |
borlanic | 0:02dd72d1d465 | 311 | "Cortex-M4F", "Cortex-M7", "Cortex-M7F", "Cortex-M7FD", |
borlanic | 0:02dd72d1d465 | 312 | "Cortex-M23", "Cortex-M23-NS", "Cortex-M33", |
borlanic | 0:02dd72d1d465 | 313 | "CortexM33-NS", "Cortex-A9"] |
borlanic | 0:02dd72d1d465 | 314 | @staticmethod |
borlanic | 0:02dd72d1d465 | 315 | def check_executable(): |
borlanic | 0:02dd72d1d465 | 316 | return mbedToolchain.generic_check_executable("ARMC6", "armclang", 1) |
borlanic | 0:02dd72d1d465 | 317 | |
borlanic | 0:02dd72d1d465 | 318 | def __init__(self, target, *args, **kwargs): |
borlanic | 0:02dd72d1d465 | 319 | mbedToolchain.__init__(self, target, *args, **kwargs) |
borlanic | 0:02dd72d1d465 | 320 | if target.core not in self.SUPPORTED_CORES: |
borlanic | 0:02dd72d1d465 | 321 | raise NotSupportedException( |
borlanic | 0:02dd72d1d465 | 322 | "this compiler does not support the core %s" % target.core) |
borlanic | 0:02dd72d1d465 | 323 | |
borlanic | 0:02dd72d1d465 | 324 | if not set(("ARM", "ARMC6")).intersection(set(target.supported_toolchains)): |
borlanic | 0:02dd72d1d465 | 325 | raise NotSupportedException("ARM/ARMC6 compiler support is required for ARMC6 build") |
borlanic | 0:02dd72d1d465 | 326 | |
borlanic | 0:02dd72d1d465 | 327 | if target.core.lower().endswith("fd"): |
borlanic | 0:02dd72d1d465 | 328 | self.flags['common'].append("-mcpu=%s" % target.core.lower()[:-2]) |
borlanic | 0:02dd72d1d465 | 329 | self.flags['ld'].append("--cpu=%s" % target.core.lower()[:-2]) |
borlanic | 0:02dd72d1d465 | 330 | self.SHEBANG += " -mcpu=%s" % target.core.lower()[:-2] |
borlanic | 0:02dd72d1d465 | 331 | elif target.core.lower().endswith("f"): |
borlanic | 0:02dd72d1d465 | 332 | self.flags['common'].append("-mcpu=%s" % target.core.lower()[:-1]) |
borlanic | 0:02dd72d1d465 | 333 | self.flags['ld'].append("--cpu=%s" % target.core.lower()[:-1]) |
borlanic | 0:02dd72d1d465 | 334 | self.SHEBANG += " -mcpu=%s" % target.core.lower()[:-1] |
borlanic | 0:02dd72d1d465 | 335 | elif target.core.lower().endswith("ns"): |
borlanic | 0:02dd72d1d465 | 336 | self.flags['common'].append("-mcpu=%s" % target.core.lower()[:-3]) |
borlanic | 0:02dd72d1d465 | 337 | self.flags['ld'].append("--cpu=%s" % target.core.lower()[:-3]) |
borlanic | 0:02dd72d1d465 | 338 | self.SHEBANG += " -mcpu=%s" % target.core.lower()[:-3] |
borlanic | 0:02dd72d1d465 | 339 | else: |
borlanic | 0:02dd72d1d465 | 340 | self.flags['common'].append("-mcpu=%s" % target.core.lower()) |
borlanic | 0:02dd72d1d465 | 341 | self.flags['ld'].append("--cpu=%s" % target.core.lower()) |
borlanic | 0:02dd72d1d465 | 342 | self.SHEBANG += " -mcpu=%s" % target.core.lower() |
borlanic | 0:02dd72d1d465 | 343 | |
borlanic | 0:02dd72d1d465 | 344 | if target.core == "Cortex-M4F": |
borlanic | 0:02dd72d1d465 | 345 | self.flags['common'].append("-mfpu=fpv4-sp-d16") |
borlanic | 0:02dd72d1d465 | 346 | self.flags['common'].append("-mfloat-abi=hard") |
borlanic | 0:02dd72d1d465 | 347 | elif target.core == "Cortex-M7F": |
borlanic | 0:02dd72d1d465 | 348 | self.flags['common'].append("-mfpu=fpv5-sp-d16") |
borlanic | 0:02dd72d1d465 | 349 | self.flags['common'].append("-mfloat-abi=softfp") |
borlanic | 0:02dd72d1d465 | 350 | elif target.core == "Cortex-M7FD": |
borlanic | 0:02dd72d1d465 | 351 | self.flags['common'].append("-mfpu=fpv5-d16") |
borlanic | 0:02dd72d1d465 | 352 | self.flags['common'].append("-mfloat-abi=softfp") |
borlanic | 0:02dd72d1d465 | 353 | elif target.core.startswith("Cortex-M23"): |
borlanic | 0:02dd72d1d465 | 354 | self.flags['common'].append("-march=armv8-m.base") |
borlanic | 0:02dd72d1d465 | 355 | elif target.core.startswith("Cortex-M33"): |
borlanic | 0:02dd72d1d465 | 356 | self.flags['common'].append("-march=armv8-m.main") |
borlanic | 0:02dd72d1d465 | 357 | |
borlanic | 0:02dd72d1d465 | 358 | if target.core == "Cortex-M23" or target.core == "Cortex-M33": |
borlanic | 0:02dd72d1d465 | 359 | self.flags['common'].append("-mcmse") |
borlanic | 0:02dd72d1d465 | 360 | |
borlanic | 0:02dd72d1d465 | 361 | # Create Secure library |
borlanic | 0:02dd72d1d465 | 362 | if target.core == "Cortex-M23" or self.target.core == "Cortex-M33": |
borlanic | 0:02dd72d1d465 | 363 | build_dir = kwargs['build_dir'] |
borlanic | 0:02dd72d1d465 | 364 | secure_file = join(build_dir, "cmse_lib.o") |
borlanic | 0:02dd72d1d465 | 365 | self.flags["ld"] += ["--import_cmse_lib_out=%s" % secure_file] |
borlanic | 0:02dd72d1d465 | 366 | |
borlanic | 0:02dd72d1d465 | 367 | asm_cpu = { |
borlanic | 0:02dd72d1d465 | 368 | "Cortex-M0+": "Cortex-M0", |
borlanic | 0:02dd72d1d465 | 369 | "Cortex-M4F": "Cortex-M4.fp", |
borlanic | 0:02dd72d1d465 | 370 | "Cortex-M7F": "Cortex-M7.fp.sp", |
borlanic | 0:02dd72d1d465 | 371 | "Cortex-M7FD": "Cortex-M7.fp.dp", |
borlanic | 0:02dd72d1d465 | 372 | "Cortex-M23-NS": "Cortex-M23", |
borlanic | 0:02dd72d1d465 | 373 | "Cortex-M33-NS": "Cortex-M33" }.get(target.core, target.core) |
borlanic | 0:02dd72d1d465 | 374 | |
borlanic | 0:02dd72d1d465 | 375 | self.flags['asm'].append("--cpu=%s" % asm_cpu) |
borlanic | 0:02dd72d1d465 | 376 | |
borlanic | 0:02dd72d1d465 | 377 | self.cc = ([join(TOOLCHAIN_PATHS["ARMC6"], "armclang")] + |
borlanic | 0:02dd72d1d465 | 378 | self.flags['common'] + self.flags['c']) |
borlanic | 0:02dd72d1d465 | 379 | self.cppc = ([join(TOOLCHAIN_PATHS["ARMC6"], "armclang")] + |
borlanic | 0:02dd72d1d465 | 380 | self.flags['common'] + self.flags['cxx']) |
borlanic | 0:02dd72d1d465 | 381 | self.asm = [join(TOOLCHAIN_PATHS["ARMC6"], "armasm")] + self.flags['asm'] |
borlanic | 0:02dd72d1d465 | 382 | self.ld = [join(TOOLCHAIN_PATHS["ARMC6"], "armlink")] + self.flags['ld'] |
borlanic | 0:02dd72d1d465 | 383 | self.ar = [join(TOOLCHAIN_PATHS["ARMC6"], "armar")] |
borlanic | 0:02dd72d1d465 | 384 | self.elf2bin = join(TOOLCHAIN_PATHS["ARMC6"], "fromelf") |
borlanic | 0:02dd72d1d465 | 385 | |
borlanic | 0:02dd72d1d465 | 386 | def parse_dependencies(self, dep_path): |
borlanic | 0:02dd72d1d465 | 387 | return mbedToolchain.parse_dependencies(self, dep_path) |
borlanic | 0:02dd72d1d465 | 388 | |
borlanic | 0:02dd72d1d465 | 389 | def is_not_supported_error(self, output): |
borlanic | 0:02dd72d1d465 | 390 | return "#error [NOT_SUPPORTED]" in output |
borlanic | 0:02dd72d1d465 | 391 | |
borlanic | 0:02dd72d1d465 | 392 | def parse_output(self, output): |
borlanic | 0:02dd72d1d465 | 393 | pass |
borlanic | 0:02dd72d1d465 | 394 | |
borlanic | 0:02dd72d1d465 | 395 | def get_config_option(self, config_header): |
borlanic | 0:02dd72d1d465 | 396 | return ["-include", config_header] |
borlanic | 0:02dd72d1d465 | 397 | |
borlanic | 0:02dd72d1d465 | 398 | def get_compile_options(self, defines, includes, for_asm=False): |
borlanic | 0:02dd72d1d465 | 399 | opts = ['-D%s' % d for d in defines] |
borlanic | 0:02dd72d1d465 | 400 | opts.extend(["-I%s" % i for i in includes]) |
borlanic | 0:02dd72d1d465 | 401 | if for_asm: |
borlanic | 0:02dd72d1d465 | 402 | return ["--cpreproc", |
borlanic | 0:02dd72d1d465 | 403 | "--cpreproc_opts=%s" % ",".join(self.flags['common'] + opts)] |
borlanic | 0:02dd72d1d465 | 404 | else: |
borlanic | 0:02dd72d1d465 | 405 | config_header = self.get_config_header() |
borlanic | 0:02dd72d1d465 | 406 | if config_header: |
borlanic | 0:02dd72d1d465 | 407 | opts.extend(self.get_config_option(config_header)) |
borlanic | 0:02dd72d1d465 | 408 | return opts |
borlanic | 0:02dd72d1d465 | 409 | |
borlanic | 0:02dd72d1d465 | 410 | @hook_tool |
borlanic | 0:02dd72d1d465 | 411 | def assemble(self, source, object, includes): |
borlanic | 0:02dd72d1d465 | 412 | cmd_pre = copy(self.asm) |
borlanic | 0:02dd72d1d465 | 413 | cmd_pre.extend(self.get_compile_options( |
borlanic | 0:02dd72d1d465 | 414 | self.get_symbols(True), includes, for_asm=True)) |
borlanic | 0:02dd72d1d465 | 415 | cmd_pre.extend(["-o", object, source]) |
borlanic | 0:02dd72d1d465 | 416 | return [self.hook.get_cmdline_assembler(cmd_pre)] |
borlanic | 0:02dd72d1d465 | 417 | |
borlanic | 0:02dd72d1d465 | 418 | @hook_tool |
borlanic | 0:02dd72d1d465 | 419 | def compile(self, cc, source, object, includes): |
borlanic | 0:02dd72d1d465 | 420 | cmd = copy(cc) |
borlanic | 0:02dd72d1d465 | 421 | cmd.extend(self.get_compile_options(self.get_symbols(), includes)) |
borlanic | 0:02dd72d1d465 | 422 | cmd.extend(["-o", object, source]) |
borlanic | 0:02dd72d1d465 | 423 | cmd = self.hook.get_cmdline_compiler(cmd) |
borlanic | 0:02dd72d1d465 | 424 | return [cmd] |