Clone of official tools

Committer:
The Other Jimmy
Date:
Wed Feb 15 13:53:18 2017 -0600
Revision:
35:da9c89f8be7d
Parent:
31:8ea194f6145b
Child:
36:96847d42f010
Update tools to mbed-os 5.3.5

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
The Other Jimmy 31:8ea194f6145b 18 from os.path import join, dirname, splitext, basename
screamer 0:66f3b5499f7f 19
screamer 20:835f6355470d 20 from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS
screamer 0:66f3b5499f7f 21 from tools.hooks import hook_tool
screamer 0:66f3b5499f7f 22 from tools.utils import mkdir
screamer 0:66f3b5499f7f 23
screamer 0:66f3b5499f7f 24 class ARM(mbedToolchain):
screamer 0:66f3b5499f7f 25 LINKER_EXT = '.sct'
screamer 0:66f3b5499f7f 26 LIBRARY_EXT = '.ar'
screamer 0:66f3b5499f7f 27
screamer 0:66f3b5499f7f 28 STD_LIB_NAME = "%s.ar"
The Other Jimmy 35:da9c89f8be7d 29 DIAGNOSTIC_PATTERN = re.compile('"(?P<file>[^"]+)", line (?P<line>\d+)( \(column (?P<column>\d+)\)|): (?P<severity>Warning|Error|Fatal error): (?P<message>.+)')
screamer 21:4fdf0dd04f6f 30 INDEX_PATTERN = re.compile('(?P<col>\s*)\^')
screamer 0:66f3b5499f7f 31 DEP_PATTERN = re.compile('\S+:\s(?P<file>.+)\n')
screamer 0:66f3b5499f7f 32
The Other Jimmy 31:8ea194f6145b 33 @staticmethod
The Other Jimmy 31:8ea194f6145b 34 def check_executable():
The Other Jimmy 31:8ea194f6145b 35 """Returns True if the executable (armcc) location specified by the
The Other Jimmy 31:8ea194f6145b 36 user exists OR the executable can be found on the PATH.
The Other Jimmy 31:8ea194f6145b 37 Returns False otherwise."""
The Other Jimmy 31:8ea194f6145b 38 return mbedToolchain.generic_check_executable("ARM", 'armcc', 2, 'bin')
screamer 13:ab47a20b66f0 39
The Other Jimmy 31:8ea194f6145b 40 def __init__(self, target, notify=None, macros=None,
The Other Jimmy 31:8ea194f6145b 41 silent=False, extra_verbose=False, build_profile=None):
The Other Jimmy 31:8ea194f6145b 42 mbedToolchain.__init__(self, target, notify, macros, silent,
The Other Jimmy 31:8ea194f6145b 43 extra_verbose=extra_verbose,
The Other Jimmy 31:8ea194f6145b 44 build_profile=build_profile)
screamer 0:66f3b5499f7f 45
screamer 0:66f3b5499f7f 46 if target.core == "Cortex-M0+":
screamer 0:66f3b5499f7f 47 cpu = "Cortex-M0"
screamer 0:66f3b5499f7f 48 elif target.core == "Cortex-M4F":
screamer 0:66f3b5499f7f 49 cpu = "Cortex-M4.fp"
screamer 13:ab47a20b66f0 50 elif target.core == "Cortex-M7FD":
screamer 13:ab47a20b66f0 51 cpu = "Cortex-M7.fp.dp"
screamer 0:66f3b5499f7f 52 elif target.core == "Cortex-M7F":
screamer 0:66f3b5499f7f 53 cpu = "Cortex-M7.fp.sp"
screamer 0:66f3b5499f7f 54 else:
screamer 0:66f3b5499f7f 55 cpu = target.core
screamer 0:66f3b5499f7f 56
screamer 20:835f6355470d 57 ARM_BIN = join(TOOLCHAIN_PATHS['ARM'], "bin")
screamer 20:835f6355470d 58 ARM_INC = join(TOOLCHAIN_PATHS['ARM'], "include")
screamer 20:835f6355470d 59
screamer 0:66f3b5499f7f 60 main_cc = join(ARM_BIN, "armcc")
screamer 0:66f3b5499f7f 61
screamer 13:ab47a20b66f0 62 self.flags['common'] += ["--cpu=%s" % cpu]
screamer 0:66f3b5499f7f 63
The Other Jimmy 31:8ea194f6145b 64 self.asm = [main_cc] + self.flags['common'] + self.flags['asm']
The Other Jimmy 31:8ea194f6145b 65 self.cc = [main_cc] + self.flags['common'] + self.flags['c']
The Other Jimmy 31:8ea194f6145b 66 self.cppc = [main_cc] + self.flags['common'] + self.flags['c'] + self.flags['cxx']
screamer 0:66f3b5499f7f 67
screamer 13:ab47a20b66f0 68 self.ld = [join(ARM_BIN, "armlink")]
screamer 0:66f3b5499f7f 69
screamer 0:66f3b5499f7f 70 self.ar = join(ARM_BIN, "armar")
screamer 0:66f3b5499f7f 71 self.elf2bin = join(ARM_BIN, "fromelf")
screamer 0:66f3b5499f7f 72
screamer 0:66f3b5499f7f 73 def parse_dependencies(self, dep_path):
screamer 0:66f3b5499f7f 74 dependencies = []
screamer 0:66f3b5499f7f 75 for line in open(dep_path).readlines():
screamer 0:66f3b5499f7f 76 match = ARM.DEP_PATTERN.match(line)
screamer 0:66f3b5499f7f 77 if match is not None:
screamer 21:4fdf0dd04f6f 78 #we need to append chroot, because when the .d files are generated the compiler is chrooted
screamer 21:4fdf0dd04f6f 79 dependencies.append((self.CHROOT if self.CHROOT else '') + match.group('file'))
screamer 0:66f3b5499f7f 80 return dependencies
screamer 21:4fdf0dd04f6f 81
screamer 0:66f3b5499f7f 82 def parse_output(self, output):
screamer 21:4fdf0dd04f6f 83 msg = None
screamer 0:66f3b5499f7f 84 for line in output.splitlines():
screamer 0:66f3b5499f7f 85 match = ARM.DIAGNOSTIC_PATTERN.match(line)
screamer 0:66f3b5499f7f 86 if match is not None:
screamer 21:4fdf0dd04f6f 87 if msg is not None:
screamer 21:4fdf0dd04f6f 88 self.cc_info(msg)
The Other Jimmy 31:8ea194f6145b 89 msg = None
screamer 21:4fdf0dd04f6f 90 msg = {
screamer 21:4fdf0dd04f6f 91 'severity': match.group('severity').lower(),
screamer 21:4fdf0dd04f6f 92 'file': match.group('file'),
screamer 21:4fdf0dd04f6f 93 'line': match.group('line'),
screamer 21:4fdf0dd04f6f 94 'col': match.group('column') if match.group('column') else 0,
screamer 21:4fdf0dd04f6f 95 'message': match.group('message'),
screamer 21:4fdf0dd04f6f 96 'text': '',
screamer 21:4fdf0dd04f6f 97 'target_name': self.target.name,
screamer 21:4fdf0dd04f6f 98 'toolchain_name': self.name
screamer 21:4fdf0dd04f6f 99 }
screamer 21:4fdf0dd04f6f 100 elif msg is not None:
screamer 24:25bff2709c20 101 # Determine the warning/error column by calculating the ^ position
screamer 21:4fdf0dd04f6f 102 match = ARM.INDEX_PATTERN.match(line)
screamer 21:4fdf0dd04f6f 103 if match is not None:
screamer 21:4fdf0dd04f6f 104 msg['col'] = len(match.group('col'))
screamer 21:4fdf0dd04f6f 105 self.cc_info(msg)
screamer 21:4fdf0dd04f6f 106 msg = None
screamer 21:4fdf0dd04f6f 107 else:
screamer 21:4fdf0dd04f6f 108 msg['text'] += line+"\n"
screamer 21:4fdf0dd04f6f 109
screamer 21:4fdf0dd04f6f 110 if msg is not None:
screamer 21:4fdf0dd04f6f 111 self.cc_info(msg)
screamer 0:66f3b5499f7f 112
screamer 0:66f3b5499f7f 113 def get_dep_option(self, object):
screamer 0:66f3b5499f7f 114 base, _ = splitext(object)
screamer 0:66f3b5499f7f 115 dep_path = base + '.d'
screamer 0:66f3b5499f7f 116 return ["--depend", dep_path]
screamer 0:66f3b5499f7f 117
screamer 20:835f6355470d 118 def get_config_option(self, config_header):
screamer 13:ab47a20b66f0 119 return ['--preinclude=' + config_header]
screamer 13:ab47a20b66f0 120
screamer 29:1210849dba19 121 def get_compile_options(self, defines, includes, for_asm=False):
screamer 21:4fdf0dd04f6f 122 opts = ['-D%s' % d for d in defines]
screamer 21:4fdf0dd04f6f 123 if self.RESPONSE_FILES:
screamer 21:4fdf0dd04f6f 124 opts += ['--via', self.get_inc_file(includes)]
screamer 21:4fdf0dd04f6f 125 else:
screamer 21:4fdf0dd04f6f 126 opts += ["-I%s" % i for i in includes]
screamer 21:4fdf0dd04f6f 127
screamer 29:1210849dba19 128 if not for_asm:
screamer 29:1210849dba19 129 config_header = self.get_config_header()
screamer 29:1210849dba19 130 if config_header is not None:
screamer 29:1210849dba19 131 opts = opts + self.get_config_option(config_header)
screamer 13:ab47a20b66f0 132 return opts
screamer 0:66f3b5499f7f 133
screamer 0:66f3b5499f7f 134 @hook_tool
screamer 0:66f3b5499f7f 135 def assemble(self, source, object, includes):
screamer 0:66f3b5499f7f 136 # Preprocess first, then assemble
screamer 0:66f3b5499f7f 137 dir = join(dirname(object), '.temp')
screamer 0:66f3b5499f7f 138 mkdir(dir)
screamer 0:66f3b5499f7f 139 tempfile = join(dir, basename(object) + '.E.s')
screamer 0:66f3b5499f7f 140
screamer 0:66f3b5499f7f 141 # Build preprocess assemble command
screamer 29:1210849dba19 142 cmd_pre = self.asm + self.get_compile_options(self.get_symbols(True), includes) + ["-E", "-o", tempfile, source]
screamer 0:66f3b5499f7f 143
screamer 0:66f3b5499f7f 144 # Build main assemble command
screamer 0:66f3b5499f7f 145 cmd = self.asm + ["-o", object, tempfile]
screamer 0:66f3b5499f7f 146
screamer 0:66f3b5499f7f 147 # Call cmdline hook
screamer 0:66f3b5499f7f 148 cmd_pre = self.hook.get_cmdline_assembler(cmd_pre)
screamer 0:66f3b5499f7f 149 cmd = self.hook.get_cmdline_assembler(cmd)
screamer 0:66f3b5499f7f 150
screamer 0:66f3b5499f7f 151 # Return command array, don't execute
screamer 0:66f3b5499f7f 152 return [cmd_pre, cmd]
screamer 0:66f3b5499f7f 153
screamer 0:66f3b5499f7f 154 @hook_tool
screamer 0:66f3b5499f7f 155 def compile(self, cc, source, object, includes):
screamer 0:66f3b5499f7f 156 # Build compile command
screamer 0:66f3b5499f7f 157 cmd = cc + self.get_compile_options(self.get_symbols(), includes)
screamer 0:66f3b5499f7f 158
screamer 0:66f3b5499f7f 159 cmd.extend(self.get_dep_option(object))
screamer 0:66f3b5499f7f 160
screamer 0:66f3b5499f7f 161 cmd.extend(["-o", object, source])
screamer 0:66f3b5499f7f 162
screamer 0:66f3b5499f7f 163 # Call cmdline hook
screamer 0:66f3b5499f7f 164 cmd = self.hook.get_cmdline_compiler(cmd)
screamer 0:66f3b5499f7f 165
screamer 0:66f3b5499f7f 166 return [cmd]
screamer 0:66f3b5499f7f 167
screamer 0:66f3b5499f7f 168 def compile_c(self, source, object, includes):
screamer 0:66f3b5499f7f 169 return self.compile(self.cc, source, object, includes)
screamer 0:66f3b5499f7f 170
screamer 0:66f3b5499f7f 171 def compile_cpp(self, source, object, includes):
screamer 0:66f3b5499f7f 172 return self.compile(self.cppc, source, object, includes)
screamer 0:66f3b5499f7f 173
screamer 0:66f3b5499f7f 174 @hook_tool
screamer 0:66f3b5499f7f 175 def link(self, output, objects, libraries, lib_dirs, mem_map):
screamer 7:5af61d55adbe 176 map_file = splitext(output)[0] + ".map"
screamer 0:66f3b5499f7f 177 if len(lib_dirs):
screamer 7:5af61d55adbe 178 args = ["-o", output, "--userlibpath", ",".join(lib_dirs), "--info=totals", "--map", "--list=%s" % map_file]
screamer 0:66f3b5499f7f 179 else:
screamer 7:5af61d55adbe 180 args = ["-o", output, "--info=totals", "--map", "--list=%s" % map_file]
screamer 0:66f3b5499f7f 181
screamer 0:66f3b5499f7f 182 if mem_map:
screamer 0:66f3b5499f7f 183 args.extend(["--scatter", mem_map])
screamer 0:66f3b5499f7f 184
screamer 0:66f3b5499f7f 185 # Build linker command
screamer 0:66f3b5499f7f 186 cmd = self.ld + args + objects + libraries + self.sys_libs
screamer 0:66f3b5499f7f 187
screamer 0:66f3b5499f7f 188 # Call cmdline hook
screamer 0:66f3b5499f7f 189 cmd = self.hook.get_cmdline_linker(cmd)
screamer 0:66f3b5499f7f 190
screamer 21:4fdf0dd04f6f 191 if self.RESPONSE_FILES:
screamer 21:4fdf0dd04f6f 192 # Split link command to linker executable + response file
screamer 21:4fdf0dd04f6f 193 cmd_linker = cmd[0]
screamer 21:4fdf0dd04f6f 194 link_files = self.get_link_file(cmd[1:])
screamer 21:4fdf0dd04f6f 195 cmd = [cmd_linker, '--via', link_files]
screamer 0:66f3b5499f7f 196
screamer 0:66f3b5499f7f 197 # Exec command
screamer 21:4fdf0dd04f6f 198 self.cc_verbose("Link: %s" % ' '.join(cmd))
screamer 21:4fdf0dd04f6f 199 self.default_cmd(cmd)
screamer 0:66f3b5499f7f 200
screamer 0:66f3b5499f7f 201 @hook_tool
screamer 0:66f3b5499f7f 202 def archive(self, objects, lib_path):
screamer 21:4fdf0dd04f6f 203 if self.RESPONSE_FILES:
screamer 22:9e85236d8716 204 param = ['--via', self.get_arch_file(objects)]
screamer 21:4fdf0dd04f6f 205 else:
screamer 21:4fdf0dd04f6f 206 param = objects
screamer 0:66f3b5499f7f 207
screamer 0:66f3b5499f7f 208 # Exec command
screamer 21:4fdf0dd04f6f 209 self.default_cmd([self.ar, '-r', lib_path] + param)
screamer 0:66f3b5499f7f 210
screamer 0:66f3b5499f7f 211 @hook_tool
screamer 0:66f3b5499f7f 212 def binary(self, resources, elf, bin):
screamer 0:66f3b5499f7f 213 # Build binary command
screamer 0:66f3b5499f7f 214 cmd = [self.elf2bin, '--bin', '-o', bin, elf]
screamer 0:66f3b5499f7f 215
screamer 0:66f3b5499f7f 216 # Call cmdline hook
screamer 0:66f3b5499f7f 217 cmd = self.hook.get_cmdline_binary(cmd)
screamer 0:66f3b5499f7f 218
screamer 0:66f3b5499f7f 219 # Exec command
screamer 21:4fdf0dd04f6f 220 self.cc_verbose("FromELF: %s" % ' '.join(cmd))
screamer 0:66f3b5499f7f 221 self.default_cmd(cmd)
screamer 0:66f3b5499f7f 222
screamer 0:66f3b5499f7f 223
screamer 0:66f3b5499f7f 224 class ARM_STD(ARM):
The Other Jimmy 31:8ea194f6145b 225 pass
screamer 0:66f3b5499f7f 226
screamer 0:66f3b5499f7f 227
screamer 0:66f3b5499f7f 228 class ARM_MICRO(ARM):
screamer 0:66f3b5499f7f 229 PATCHED_LIBRARY = False