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