Nicolas Borla
/
BBR_1Ebene
BBR 1 Ebene
mbed-os/tools/toolchains/iar.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 | import re |
borlanic | 0:fbdae7e6d805 | 18 | from os import remove |
borlanic | 0:fbdae7e6d805 | 19 | from os.path import join, splitext, exists |
borlanic | 0:fbdae7e6d805 | 20 | |
borlanic | 0:fbdae7e6d805 | 21 | from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS |
borlanic | 0:fbdae7e6d805 | 22 | from tools.hooks import hook_tool |
borlanic | 0:fbdae7e6d805 | 23 | |
borlanic | 0:fbdae7e6d805 | 24 | class IAR(mbedToolchain): |
borlanic | 0:fbdae7e6d805 | 25 | LIBRARY_EXT = '.a' |
borlanic | 0:fbdae7e6d805 | 26 | LINKER_EXT = '.icf' |
borlanic | 0:fbdae7e6d805 | 27 | STD_LIB_NAME = "%s.a" |
borlanic | 0:fbdae7e6d805 | 28 | |
borlanic | 0:fbdae7e6d805 | 29 | DIAGNOSTIC_PATTERN = re.compile('"(?P<file>[^"]+)",(?P<line>[\d]+)\s+(?P<severity>Warning|Error|Fatal error)(?P<message>.+)') |
borlanic | 0:fbdae7e6d805 | 30 | INDEX_PATTERN = re.compile('(?P<col>\s*)\^') |
borlanic | 0:fbdae7e6d805 | 31 | |
borlanic | 0:fbdae7e6d805 | 32 | @staticmethod |
borlanic | 0:fbdae7e6d805 | 33 | def check_executable(): |
borlanic | 0:fbdae7e6d805 | 34 | """Returns True if the executable (arm-none-eabi-gcc) location |
borlanic | 0:fbdae7e6d805 | 35 | specified by the user exists OR the executable can be found on the PATH. |
borlanic | 0:fbdae7e6d805 | 36 | Returns False otherwise.""" |
borlanic | 0:fbdae7e6d805 | 37 | return mbedToolchain.generic_check_executable("IAR", 'iccarm', 2, "bin") |
borlanic | 0:fbdae7e6d805 | 38 | |
borlanic | 0:fbdae7e6d805 | 39 | def __init__(self, target, notify=None, macros=None, build_profile=None, |
borlanic | 0:fbdae7e6d805 | 40 | build_dir=None): |
borlanic | 0:fbdae7e6d805 | 41 | mbedToolchain.__init__(self, target, notify, macros, build_dir=build_dir, |
borlanic | 0:fbdae7e6d805 | 42 | build_profile=build_profile) |
borlanic | 0:fbdae7e6d805 | 43 | if target.core == "Cortex-M7F" or target.core == "Cortex-M7FD": |
borlanic | 0:fbdae7e6d805 | 44 | cpuchoice = "Cortex-M7" |
borlanic | 0:fbdae7e6d805 | 45 | elif target.core.startswith("Cortex-M23"): |
borlanic | 0:fbdae7e6d805 | 46 | cpuchoice = "8-M.baseline" |
borlanic | 0:fbdae7e6d805 | 47 | elif target.core.startswith("Cortex-M33"): |
borlanic | 0:fbdae7e6d805 | 48 | cpuchoice = "8-M.mainline" |
borlanic | 0:fbdae7e6d805 | 49 | else: |
borlanic | 0:fbdae7e6d805 | 50 | cpuchoice = target.core |
borlanic | 0:fbdae7e6d805 | 51 | |
borlanic | 0:fbdae7e6d805 | 52 | # flags_cmd are used only by our scripts, the project files have them already defined, |
borlanic | 0:fbdae7e6d805 | 53 | # using this flags results in the errors (duplication) |
borlanic | 0:fbdae7e6d805 | 54 | # asm accepts --cpu Core or --fpu FPU, not like c/c++ --cpu=Core |
borlanic | 0:fbdae7e6d805 | 55 | asm_flags_cmd = ["--cpu", cpuchoice] |
borlanic | 0:fbdae7e6d805 | 56 | # custom c flags |
borlanic | 0:fbdae7e6d805 | 57 | c_flags_cmd = ["--cpu", cpuchoice] |
borlanic | 0:fbdae7e6d805 | 58 | |
borlanic | 0:fbdae7e6d805 | 59 | c_flags_cmd.extend([ |
borlanic | 0:fbdae7e6d805 | 60 | "--thumb", "--dlib_config", "DLib_Config_Full.h" |
borlanic | 0:fbdae7e6d805 | 61 | ]) |
borlanic | 0:fbdae7e6d805 | 62 | # custom c++ cmd flags |
borlanic | 0:fbdae7e6d805 | 63 | cxx_flags_cmd = [ |
borlanic | 0:fbdae7e6d805 | 64 | "--c++", "--no_rtti", "--no_exceptions" |
borlanic | 0:fbdae7e6d805 | 65 | ] |
borlanic | 0:fbdae7e6d805 | 66 | if target.core == "Cortex-M7FD": |
borlanic | 0:fbdae7e6d805 | 67 | asm_flags_cmd += ["--fpu", "VFPv5"] |
borlanic | 0:fbdae7e6d805 | 68 | c_flags_cmd.append("--fpu=VFPv5") |
borlanic | 0:fbdae7e6d805 | 69 | elif target.core == "Cortex-M7F": |
borlanic | 0:fbdae7e6d805 | 70 | asm_flags_cmd += ["--fpu", "VFPv5_sp"] |
borlanic | 0:fbdae7e6d805 | 71 | c_flags_cmd.append("--fpu=VFPv5_sp") |
borlanic | 0:fbdae7e6d805 | 72 | elif target.core == "Cortex-M23" or target.core == "Cortex-M33": |
borlanic | 0:fbdae7e6d805 | 73 | self.flags["asm"] += ["--cmse"] |
borlanic | 0:fbdae7e6d805 | 74 | self.flags["common"] += ["--cmse"] |
borlanic | 0:fbdae7e6d805 | 75 | |
borlanic | 0:fbdae7e6d805 | 76 | # Create Secure library |
borlanic | 0:fbdae7e6d805 | 77 | if target.core == "Cortex-M23" or self.target.core == "Cortex-M33": |
borlanic | 0:fbdae7e6d805 | 78 | secure_file = join(build_dir, "cmse_lib.o") |
borlanic | 0:fbdae7e6d805 | 79 | self.flags["ld"] += ["--import_cmse_lib_out=%s" % secure_file] |
borlanic | 0:fbdae7e6d805 | 80 | |
borlanic | 0:fbdae7e6d805 | 81 | IAR_BIN = join(TOOLCHAIN_PATHS['IAR'], "bin") |
borlanic | 0:fbdae7e6d805 | 82 | main_cc = join(IAR_BIN, "iccarm") |
borlanic | 0:fbdae7e6d805 | 83 | |
borlanic | 0:fbdae7e6d805 | 84 | self.asm = [join(IAR_BIN, "iasmarm")] + asm_flags_cmd + self.flags["asm"] |
borlanic | 0:fbdae7e6d805 | 85 | self.cc = [main_cc] |
borlanic | 0:fbdae7e6d805 | 86 | self.cppc = [main_cc] |
borlanic | 0:fbdae7e6d805 | 87 | self.cc += self.flags["common"] + c_flags_cmd + self.flags["c"] |
borlanic | 0:fbdae7e6d805 | 88 | self.cppc += self.flags["common"] + c_flags_cmd + cxx_flags_cmd + self.flags["cxx"] |
borlanic | 0:fbdae7e6d805 | 89 | |
borlanic | 0:fbdae7e6d805 | 90 | self.ld = [join(IAR_BIN, "ilinkarm")] + self.flags['ld'] |
borlanic | 0:fbdae7e6d805 | 91 | self.ar = join(IAR_BIN, "iarchive") |
borlanic | 0:fbdae7e6d805 | 92 | self.elf2bin = join(IAR_BIN, "ielftool") |
borlanic | 0:fbdae7e6d805 | 93 | |
borlanic | 0:fbdae7e6d805 | 94 | def parse_dependencies(self, dep_path): |
borlanic | 0:fbdae7e6d805 | 95 | return [(self.CHROOT if self.CHROOT else '')+path.strip() for path in open(dep_path).readlines() |
borlanic | 0:fbdae7e6d805 | 96 | if (path and not path.isspace())] |
borlanic | 0:fbdae7e6d805 | 97 | |
borlanic | 0:fbdae7e6d805 | 98 | def parse_output(self, output): |
borlanic | 0:fbdae7e6d805 | 99 | msg = None |
borlanic | 0:fbdae7e6d805 | 100 | for line in output.splitlines(): |
borlanic | 0:fbdae7e6d805 | 101 | match = IAR.DIAGNOSTIC_PATTERN.match(line) |
borlanic | 0:fbdae7e6d805 | 102 | if match is not None: |
borlanic | 0:fbdae7e6d805 | 103 | if msg is not None: |
borlanic | 0:fbdae7e6d805 | 104 | self.notify.cc_info(msg) |
borlanic | 0:fbdae7e6d805 | 105 | msg = None |
borlanic | 0:fbdae7e6d805 | 106 | msg = { |
borlanic | 0:fbdae7e6d805 | 107 | 'severity': match.group('severity').lower(), |
borlanic | 0:fbdae7e6d805 | 108 | 'file': match.group('file'), |
borlanic | 0:fbdae7e6d805 | 109 | 'line': match.group('line'), |
borlanic | 0:fbdae7e6d805 | 110 | 'col': 0, |
borlanic | 0:fbdae7e6d805 | 111 | 'message': match.group('message'), |
borlanic | 0:fbdae7e6d805 | 112 | 'text': '', |
borlanic | 0:fbdae7e6d805 | 113 | 'target_name': self.target.name, |
borlanic | 0:fbdae7e6d805 | 114 | 'toolchain_name': self.name |
borlanic | 0:fbdae7e6d805 | 115 | } |
borlanic | 0:fbdae7e6d805 | 116 | elif msg is not None: |
borlanic | 0:fbdae7e6d805 | 117 | # Determine the warning/error column by calculating the ^ position |
borlanic | 0:fbdae7e6d805 | 118 | match = IAR.INDEX_PATTERN.match(line) |
borlanic | 0:fbdae7e6d805 | 119 | if match is not None: |
borlanic | 0:fbdae7e6d805 | 120 | msg['col'] = len(match.group('col')) |
borlanic | 0:fbdae7e6d805 | 121 | self.notify.cc_info(msg) |
borlanic | 0:fbdae7e6d805 | 122 | msg = None |
borlanic | 0:fbdae7e6d805 | 123 | else: |
borlanic | 0:fbdae7e6d805 | 124 | msg['text'] += line+"\n" |
borlanic | 0:fbdae7e6d805 | 125 | |
borlanic | 0:fbdae7e6d805 | 126 | if msg is not None: |
borlanic | 0:fbdae7e6d805 | 127 | self.notify.cc_info(msg) |
borlanic | 0:fbdae7e6d805 | 128 | |
borlanic | 0:fbdae7e6d805 | 129 | def get_dep_option(self, object): |
borlanic | 0:fbdae7e6d805 | 130 | base, _ = splitext(object) |
borlanic | 0:fbdae7e6d805 | 131 | dep_path = base + '.d' |
borlanic | 0:fbdae7e6d805 | 132 | return ["--dependencies", dep_path] |
borlanic | 0:fbdae7e6d805 | 133 | |
borlanic | 0:fbdae7e6d805 | 134 | def cc_extra(self, object): |
borlanic | 0:fbdae7e6d805 | 135 | base, _ = splitext(object) |
borlanic | 0:fbdae7e6d805 | 136 | return ["-l", base + '.s.txt'] |
borlanic | 0:fbdae7e6d805 | 137 | |
borlanic | 0:fbdae7e6d805 | 138 | def get_config_option(self, config_header): |
borlanic | 0:fbdae7e6d805 | 139 | return ['--preinclude=' + config_header] |
borlanic | 0:fbdae7e6d805 | 140 | |
borlanic | 0:fbdae7e6d805 | 141 | def get_compile_options(self, defines, includes, for_asm=False): |
borlanic | 0:fbdae7e6d805 | 142 | opts = ['-D%s' % d for d in defines] |
borlanic | 0:fbdae7e6d805 | 143 | if for_asm : |
borlanic | 0:fbdae7e6d805 | 144 | return opts |
borlanic | 0:fbdae7e6d805 | 145 | if self.RESPONSE_FILES: |
borlanic | 0:fbdae7e6d805 | 146 | opts += ['-f', self.get_inc_file(includes)] |
borlanic | 0:fbdae7e6d805 | 147 | else: |
borlanic | 0:fbdae7e6d805 | 148 | opts += ["-I%s" % i for i in includes] |
borlanic | 0:fbdae7e6d805 | 149 | |
borlanic | 0:fbdae7e6d805 | 150 | config_header = self.get_config_header() |
borlanic | 0:fbdae7e6d805 | 151 | if config_header is not None: |
borlanic | 0:fbdae7e6d805 | 152 | opts = opts + self.get_config_option(config_header) |
borlanic | 0:fbdae7e6d805 | 153 | return opts |
borlanic | 0:fbdae7e6d805 | 154 | |
borlanic | 0:fbdae7e6d805 | 155 | @hook_tool |
borlanic | 0:fbdae7e6d805 | 156 | def assemble(self, source, object, includes): |
borlanic | 0:fbdae7e6d805 | 157 | # Build assemble command |
borlanic | 0:fbdae7e6d805 | 158 | cmd = self.asm + self.get_compile_options(self.get_symbols(True), includes, True) + ["-o", object, source] |
borlanic | 0:fbdae7e6d805 | 159 | |
borlanic | 0:fbdae7e6d805 | 160 | # Call cmdline hook |
borlanic | 0:fbdae7e6d805 | 161 | cmd = self.hook.get_cmdline_assembler(cmd) |
borlanic | 0:fbdae7e6d805 | 162 | |
borlanic | 0:fbdae7e6d805 | 163 | # Return command array, don't execute |
borlanic | 0:fbdae7e6d805 | 164 | return [cmd] |
borlanic | 0:fbdae7e6d805 | 165 | |
borlanic | 0:fbdae7e6d805 | 166 | @hook_tool |
borlanic | 0:fbdae7e6d805 | 167 | def compile(self, cc, source, object, includes): |
borlanic | 0:fbdae7e6d805 | 168 | # Build compile command |
borlanic | 0:fbdae7e6d805 | 169 | cmd = cc + self.get_compile_options(self.get_symbols(), includes) |
borlanic | 0:fbdae7e6d805 | 170 | |
borlanic | 0:fbdae7e6d805 | 171 | cmd.extend(self.get_dep_option(object)) |
borlanic | 0:fbdae7e6d805 | 172 | |
borlanic | 0:fbdae7e6d805 | 173 | cmd.extend(self.cc_extra(object)) |
borlanic | 0:fbdae7e6d805 | 174 | |
borlanic | 0:fbdae7e6d805 | 175 | cmd.extend(["-o", object, source]) |
borlanic | 0:fbdae7e6d805 | 176 | |
borlanic | 0:fbdae7e6d805 | 177 | # Call cmdline hook |
borlanic | 0:fbdae7e6d805 | 178 | cmd = self.hook.get_cmdline_compiler(cmd) |
borlanic | 0:fbdae7e6d805 | 179 | |
borlanic | 0:fbdae7e6d805 | 180 | return [cmd] |
borlanic | 0:fbdae7e6d805 | 181 | |
borlanic | 0:fbdae7e6d805 | 182 | def compile_c(self, source, object, includes): |
borlanic | 0:fbdae7e6d805 | 183 | return self.compile(self.cc, source, object, includes) |
borlanic | 0:fbdae7e6d805 | 184 | |
borlanic | 0:fbdae7e6d805 | 185 | def compile_cpp(self, source, object, includes): |
borlanic | 0:fbdae7e6d805 | 186 | return self.compile(self.cppc, source, object, includes) |
borlanic | 0:fbdae7e6d805 | 187 | |
borlanic | 0:fbdae7e6d805 | 188 | @hook_tool |
borlanic | 0:fbdae7e6d805 | 189 | def link(self, output, objects, libraries, lib_dirs, mem_map): |
borlanic | 0:fbdae7e6d805 | 190 | # Build linker command |
borlanic | 0:fbdae7e6d805 | 191 | map_file = splitext(output)[0] + ".map" |
borlanic | 0:fbdae7e6d805 | 192 | cmd = self.ld + [ "-o", output, "--map=%s" % map_file] + objects + libraries |
borlanic | 0:fbdae7e6d805 | 193 | |
borlanic | 0:fbdae7e6d805 | 194 | if mem_map: |
borlanic | 0:fbdae7e6d805 | 195 | cmd.extend(["--config", mem_map]) |
borlanic | 0:fbdae7e6d805 | 196 | |
borlanic | 0:fbdae7e6d805 | 197 | # Call cmdline hook |
borlanic | 0:fbdae7e6d805 | 198 | cmd = self.hook.get_cmdline_linker(cmd) |
borlanic | 0:fbdae7e6d805 | 199 | |
borlanic | 0:fbdae7e6d805 | 200 | if self.RESPONSE_FILES: |
borlanic | 0:fbdae7e6d805 | 201 | # Split link command to linker executable + response file |
borlanic | 0:fbdae7e6d805 | 202 | cmd_linker = cmd[0] |
borlanic | 0:fbdae7e6d805 | 203 | link_files = self.get_link_file(cmd[1:]) |
borlanic | 0:fbdae7e6d805 | 204 | cmd = [cmd_linker, '-f', link_files] |
borlanic | 0:fbdae7e6d805 | 205 | |
borlanic | 0:fbdae7e6d805 | 206 | # Exec command |
borlanic | 0:fbdae7e6d805 | 207 | self.notify.cc_verbose("Link: %s" % ' '.join(cmd)) |
borlanic | 0:fbdae7e6d805 | 208 | self.default_cmd(cmd) |
borlanic | 0:fbdae7e6d805 | 209 | |
borlanic | 0:fbdae7e6d805 | 210 | @hook_tool |
borlanic | 0:fbdae7e6d805 | 211 | def archive(self, objects, lib_path): |
borlanic | 0:fbdae7e6d805 | 212 | if self.RESPONSE_FILES: |
borlanic | 0:fbdae7e6d805 | 213 | param = ['-f', self.get_arch_file(objects)] |
borlanic | 0:fbdae7e6d805 | 214 | else: |
borlanic | 0:fbdae7e6d805 | 215 | param = objects |
borlanic | 0:fbdae7e6d805 | 216 | |
borlanic | 0:fbdae7e6d805 | 217 | if exists(lib_path): |
borlanic | 0:fbdae7e6d805 | 218 | remove(lib_path) |
borlanic | 0:fbdae7e6d805 | 219 | |
borlanic | 0:fbdae7e6d805 | 220 | self.default_cmd([self.ar, lib_path] + param) |
borlanic | 0:fbdae7e6d805 | 221 | |
borlanic | 0:fbdae7e6d805 | 222 | @hook_tool |
borlanic | 0:fbdae7e6d805 | 223 | def binary(self, resources, elf, bin): |
borlanic | 0:fbdae7e6d805 | 224 | _, fmt = splitext(bin) |
borlanic | 0:fbdae7e6d805 | 225 | bin_arg = {".bin": "--bin", ".hex": "--ihex"}[fmt] |
borlanic | 0:fbdae7e6d805 | 226 | # Build binary command |
borlanic | 0:fbdae7e6d805 | 227 | cmd = [self.elf2bin, bin_arg, elf, bin] |
borlanic | 0:fbdae7e6d805 | 228 | |
borlanic | 0:fbdae7e6d805 | 229 | # Call cmdline hook |
borlanic | 0:fbdae7e6d805 | 230 | cmd = self.hook.get_cmdline_binary(cmd) |
borlanic | 0:fbdae7e6d805 | 231 | |
borlanic | 0:fbdae7e6d805 | 232 | # Exec command |
borlanic | 0:fbdae7e6d805 | 233 | self.notify.cc_verbose("FromELF: %s" % ' '.join(cmd)) |
borlanic | 0:fbdae7e6d805 | 234 | self.default_cmd(cmd) |
borlanic | 0:fbdae7e6d805 | 235 | |
borlanic | 0:fbdae7e6d805 | 236 | @staticmethod |
borlanic | 0:fbdae7e6d805 | 237 | def name_mangle(name): |
borlanic | 0:fbdae7e6d805 | 238 | return "_Z%i%sv" % (len(name), name) |
borlanic | 0:fbdae7e6d805 | 239 | |
borlanic | 0:fbdae7e6d805 | 240 | @staticmethod |
borlanic | 0:fbdae7e6d805 | 241 | def make_ld_define(name, value): |
borlanic | 0:fbdae7e6d805 | 242 | return "--config_def %s=0x%x" % (name, value) |
borlanic | 0:fbdae7e6d805 | 243 | |
borlanic | 0:fbdae7e6d805 | 244 | @staticmethod |
borlanic | 0:fbdae7e6d805 | 245 | def redirect_symbol(source, sync, build_dir): |
borlanic | 0:fbdae7e6d805 | 246 | return "--redirect %s=%s" % (source, sync) |