Backup 1

Committer:
borlanic
Date:
Tue Apr 24 11:45:18 2018 +0000
Revision:
0:02dd72d1d465
BaBoRo_test2 - backup 1

Who changed what in which revision?

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