Clone of official tools

Committer:
theotherjimmy
Date:
Tue Oct 10 16:56:30 2017 -0500
Revision:
40:7d3fa6b99b2b
Parent:
36:96847d42f010
Child:
41:2a77626a4c21
Update to tools release 5.6.1

Who changed what in which revision?

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