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, basename, splitext
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
screamer 0:66f3b5499f7f 23 class GCC(mbedToolchain):
screamer 0:66f3b5499f7f 24 LINKER_EXT = '.ld'
screamer 0:66f3b5499f7f 25 LIBRARY_EXT = '.a'
screamer 0:66f3b5499f7f 26
screamer 0:66f3b5499f7f 27 STD_LIB_NAME = "lib%s.a"
The Other Jimmy 35:da9c89f8be7d 28 DIAGNOSTIC_PATTERN = re.compile('((?P<file>[^:]+):(?P<line>\d+):)(\d+:)? (?P<severity>warning|[eE]rror|fatal error): (?P<message>.+)')
screamer 21:4fdf0dd04f6f 29 INDEX_PATTERN = re.compile('(?P<col>\s*)\^')
screamer 0:66f3b5499f7f 30
The Other Jimmy 31:8ea194f6145b 31 def __init__(self, target, notify=None, macros=None,
The Other Jimmy 31:8ea194f6145b 32 silent=False, tool_path="", extra_verbose=False,
The Other Jimmy 31:8ea194f6145b 33 build_profile=None):
The Other Jimmy 31:8ea194f6145b 34 mbedToolchain.__init__(self, target, notify, macros, silent,
The Other Jimmy 31:8ea194f6145b 35 extra_verbose=extra_verbose,
The Other Jimmy 31:8ea194f6145b 36 build_profile=build_profile)
screamer 13:ab47a20b66f0 37
The Other Jimmy 31:8ea194f6145b 38 # Add flags for current size setting
The Other Jimmy 31:8ea194f6145b 39 default_lib = "std"
The Other Jimmy 31:8ea194f6145b 40 if hasattr(target, "default_lib"):
The Other Jimmy 31:8ea194f6145b 41 default_lib = target.default_lib
The Other Jimmy 31:8ea194f6145b 42 elif hasattr(target, "default_build"): # Legacy
The Other Jimmy 31:8ea194f6145b 43 default_lib = target.default_build
The Other Jimmy 31:8ea194f6145b 44
The Other Jimmy 31:8ea194f6145b 45 if default_lib == "small":
The Other Jimmy 31:8ea194f6145b 46 self.flags["common"].append("-DMBED_RTOS_SINGLE_THREAD")
The Other Jimmy 31:8ea194f6145b 47 self.flags["ld"].append("--specs=nano.specs")
screamer 0:66f3b5499f7f 48
screamer 0:66f3b5499f7f 49 if target.core == "Cortex-M0+":
screamer 0:66f3b5499f7f 50 cpu = "cortex-m0plus"
screamer 0:66f3b5499f7f 51 elif target.core == "Cortex-M4F":
screamer 0:66f3b5499f7f 52 cpu = "cortex-m4"
screamer 0:66f3b5499f7f 53 elif target.core == "Cortex-M7F":
screamer 0:66f3b5499f7f 54 cpu = "cortex-m7"
screamer 13:ab47a20b66f0 55 elif target.core == "Cortex-M7FD":
screamer 13:ab47a20b66f0 56 cpu = "cortex-m7"
screamer 0:66f3b5499f7f 57 else:
screamer 0:66f3b5499f7f 58 cpu = target.core.lower()
screamer 0:66f3b5499f7f 59
screamer 0:66f3b5499f7f 60 self.cpu = ["-mcpu=%s" % cpu]
screamer 0:66f3b5499f7f 61 if target.core.startswith("Cortex"):
screamer 0:66f3b5499f7f 62 self.cpu.append("-mthumb")
screamer 0:66f3b5499f7f 63
screamer 13:ab47a20b66f0 64 # FPU handling, M7 possibly to have double FPU
screamer 0:66f3b5499f7f 65 if target.core == "Cortex-M4F":
screamer 0:66f3b5499f7f 66 self.cpu.append("-mfpu=fpv4-sp-d16")
screamer 0:66f3b5499f7f 67 self.cpu.append("-mfloat-abi=softfp")
screamer 0:66f3b5499f7f 68 elif target.core == "Cortex-M7F":
screamer 13:ab47a20b66f0 69 self.cpu.append("-mfpu=fpv5-sp-d16")
screamer 13:ab47a20b66f0 70 self.cpu.append("-mfloat-abi=softfp")
screamer 13:ab47a20b66f0 71 elif target.core == "Cortex-M7FD":
screamer 0:66f3b5499f7f 72 self.cpu.append("-mfpu=fpv5-d16")
screamer 0:66f3b5499f7f 73 self.cpu.append("-mfloat-abi=softfp")
screamer 0:66f3b5499f7f 74
screamer 0:66f3b5499f7f 75 if target.core == "Cortex-A9":
screamer 0:66f3b5499f7f 76 self.cpu.append("-mthumb-interwork")
screamer 0:66f3b5499f7f 77 self.cpu.append("-marm")
screamer 0:66f3b5499f7f 78 self.cpu.append("-march=armv7-a")
screamer 0:66f3b5499f7f 79 self.cpu.append("-mfpu=vfpv3")
screamer 0:66f3b5499f7f 80 self.cpu.append("-mfloat-abi=hard")
screamer 0:66f3b5499f7f 81 self.cpu.append("-mno-unaligned-access")
screamer 0:66f3b5499f7f 82
screamer 13:ab47a20b66f0 83 self.flags["common"] += self.cpu
screamer 0:66f3b5499f7f 84
screamer 13:ab47a20b66f0 85 main_cc = join(tool_path, "arm-none-eabi-gcc")
screamer 13:ab47a20b66f0 86 main_cppc = join(tool_path, "arm-none-eabi-g++")
screamer 13:ab47a20b66f0 87 self.asm = [main_cc] + self.flags['asm'] + self.flags["common"]
screamer 21:4fdf0dd04f6f 88 self.cc = [main_cc]
screamer 21:4fdf0dd04f6f 89 self.cppc =[main_cppc]
screamer 13:ab47a20b66f0 90 self.cc += self.flags['c'] + self.flags['common']
screamer 13:ab47a20b66f0 91 self.cppc += self.flags['cxx'] + self.flags['common']
screamer 0:66f3b5499f7f 92
screamer 13:ab47a20b66f0 93 self.flags['ld'] += self.cpu
screamer 13:ab47a20b66f0 94 self.ld = [join(tool_path, "arm-none-eabi-gcc")] + self.flags['ld']
screamer 0:66f3b5499f7f 95 self.sys_libs = ["stdc++", "supc++", "m", "c", "gcc"]
screamer 0:66f3b5499f7f 96
screamer 0:66f3b5499f7f 97 self.ar = join(tool_path, "arm-none-eabi-ar")
screamer 0:66f3b5499f7f 98 self.elf2bin = join(tool_path, "arm-none-eabi-objcopy")
screamer 0:66f3b5499f7f 99
screamer 0:66f3b5499f7f 100 def parse_dependencies(self, dep_path):
screamer 0:66f3b5499f7f 101 dependencies = []
screamer 0:66f3b5499f7f 102 buff = open(dep_path).readlines()
screamer 0:66f3b5499f7f 103 buff[0] = re.sub('^(.*?)\: ', '', buff[0])
screamer 0:66f3b5499f7f 104 for line in buff:
screamer 0:66f3b5499f7f 105 file = line.replace('\\\n', '').strip()
screamer 0:66f3b5499f7f 106 if file:
screamer 0:66f3b5499f7f 107 # GCC might list more than one dependency on a single line, in this case
screamer 0:66f3b5499f7f 108 # the dependencies are separated by a space. However, a space might also
screamer 0:66f3b5499f7f 109 # indicate an actual space character in a dependency path, but in this case
screamer 0:66f3b5499f7f 110 # the space character is prefixed by a backslash.
screamer 0:66f3b5499f7f 111 # Temporary replace all '\ ' with a special char that is not used (\a in this
screamer 0:66f3b5499f7f 112 # case) to keep them from being interpreted by 'split' (they will be converted
screamer 0:66f3b5499f7f 113 # back later to a space char)
screamer 0:66f3b5499f7f 114 file = file.replace('\\ ', '\a')
screamer 0:66f3b5499f7f 115 if file.find(" ") == -1:
screamer 21:4fdf0dd04f6f 116 dependencies.append((self.CHROOT if self.CHROOT else '') + file.replace('\a', ' '))
screamer 0:66f3b5499f7f 117 else:
screamer 21:4fdf0dd04f6f 118 dependencies = dependencies + [(self.CHROOT if self.CHROOT else '') + f.replace('\a', ' ') for f in file.split(" ")]
screamer 0:66f3b5499f7f 119 return dependencies
screamer 0:66f3b5499f7f 120
screamer 0:66f3b5499f7f 121 def is_not_supported_error(self, output):
screamer 0:66f3b5499f7f 122 return "error: #error [NOT_SUPPORTED]" in output
screamer 0:66f3b5499f7f 123
screamer 0:66f3b5499f7f 124 def parse_output(self, output):
screamer 0:66f3b5499f7f 125 # The warning/error notification is multiline
screamer 21:4fdf0dd04f6f 126 msg = None
screamer 0:66f3b5499f7f 127 for line in output.splitlines():
The Other Jimmy 31:8ea194f6145b 128 match = GCC.DIAGNOSTIC_PATTERN.search(line)
screamer 13:ab47a20b66f0 129 if match is not None:
screamer 21:4fdf0dd04f6f 130 if msg is not None:
screamer 21:4fdf0dd04f6f 131 self.cc_info(msg)
The Other Jimmy 31:8ea194f6145b 132 msg = None
screamer 21:4fdf0dd04f6f 133 msg = {
screamer 21:4fdf0dd04f6f 134 'severity': match.group('severity').lower(),
screamer 21:4fdf0dd04f6f 135 'file': match.group('file'),
screamer 21:4fdf0dd04f6f 136 'line': match.group('line'),
screamer 21:4fdf0dd04f6f 137 'col': 0,
screamer 21:4fdf0dd04f6f 138 'message': match.group('message'),
screamer 21:4fdf0dd04f6f 139 'text': '',
screamer 21:4fdf0dd04f6f 140 'target_name': self.target.name,
screamer 21:4fdf0dd04f6f 141 'toolchain_name': self.name
screamer 21:4fdf0dd04f6f 142 }
screamer 21:4fdf0dd04f6f 143 elif msg is not None:
screamer 24:25bff2709c20 144 # Determine the warning/error column by calculating the ^ position
screamer 21:4fdf0dd04f6f 145 match = GCC.INDEX_PATTERN.match(line)
screamer 21:4fdf0dd04f6f 146 if match is not None:
screamer 21:4fdf0dd04f6f 147 msg['col'] = len(match.group('col'))
screamer 21:4fdf0dd04f6f 148 self.cc_info(msg)
screamer 21:4fdf0dd04f6f 149 msg = None
screamer 21:4fdf0dd04f6f 150 else:
screamer 21:4fdf0dd04f6f 151 msg['text'] += line+"\n"
screamer 0:66f3b5499f7f 152
The Other Jimmy 31:8ea194f6145b 153 if msg is not None:
The Other Jimmy 31:8ea194f6145b 154 self.cc_info(msg)
The Other Jimmy 31:8ea194f6145b 155
screamer 0:66f3b5499f7f 156 def get_dep_option(self, object):
screamer 0:66f3b5499f7f 157 base, _ = splitext(object)
screamer 0:66f3b5499f7f 158 dep_path = base + '.d'
screamer 0:66f3b5499f7f 159 return ["-MD", "-MF", dep_path]
screamer 0:66f3b5499f7f 160
screamer 13:ab47a20b66f0 161 def get_config_option(self, config_header):
screamer 13:ab47a20b66f0 162 return ['-include', config_header]
screamer 13:ab47a20b66f0 163
screamer 29:1210849dba19 164 def get_compile_options(self, defines, includes, for_asm=False):
screamer 21:4fdf0dd04f6f 165 opts = ['-D%s' % d for d in defines]
screamer 21:4fdf0dd04f6f 166 if self.RESPONSE_FILES:
screamer 21:4fdf0dd04f6f 167 opts += ['@%s' % self.get_inc_file(includes)]
screamer 21:4fdf0dd04f6f 168 else:
screamer 21:4fdf0dd04f6f 169 opts += ["-I%s" % i for i in includes]
screamer 21:4fdf0dd04f6f 170
screamer 29:1210849dba19 171 if not for_asm:
screamer 29:1210849dba19 172 config_header = self.get_config_header()
screamer 29:1210849dba19 173 if config_header is not None:
screamer 29:1210849dba19 174 opts = opts + self.get_config_option(config_header)
screamer 13:ab47a20b66f0 175 return opts
screamer 0:66f3b5499f7f 176
screamer 0:66f3b5499f7f 177 @hook_tool
screamer 0:66f3b5499f7f 178 def assemble(self, source, object, includes):
screamer 0:66f3b5499f7f 179 # Build assemble command
screamer 29:1210849dba19 180 cmd = self.asm + self.get_compile_options(self.get_symbols(True), includes) + ["-o", object, source]
screamer 0:66f3b5499f7f 181
screamer 0:66f3b5499f7f 182 # Call cmdline hook
screamer 0:66f3b5499f7f 183 cmd = self.hook.get_cmdline_assembler(cmd)
screamer 0:66f3b5499f7f 184
screamer 0:66f3b5499f7f 185 # Return command array, don't execute
screamer 0:66f3b5499f7f 186 return [cmd]
screamer 0:66f3b5499f7f 187
screamer 0:66f3b5499f7f 188 @hook_tool
screamer 0:66f3b5499f7f 189 def compile(self, cc, source, object, includes):
screamer 0:66f3b5499f7f 190 # Build compile command
screamer 0:66f3b5499f7f 191 cmd = cc + self.get_compile_options(self.get_symbols(), includes)
screamer 0:66f3b5499f7f 192
screamer 0:66f3b5499f7f 193 cmd.extend(self.get_dep_option(object))
screamer 0:66f3b5499f7f 194
screamer 0:66f3b5499f7f 195 cmd.extend(["-o", object, source])
screamer 13:ab47a20b66f0 196
screamer 0:66f3b5499f7f 197 # Call cmdline hook
screamer 0:66f3b5499f7f 198 cmd = self.hook.get_cmdline_compiler(cmd)
screamer 0:66f3b5499f7f 199
screamer 0:66f3b5499f7f 200 return [cmd]
screamer 0:66f3b5499f7f 201
screamer 0:66f3b5499f7f 202 def compile_c(self, source, object, includes):
screamer 0:66f3b5499f7f 203 return self.compile(self.cc, source, object, includes)
screamer 0:66f3b5499f7f 204
screamer 0:66f3b5499f7f 205 def compile_cpp(self, source, object, includes):
screamer 0:66f3b5499f7f 206 return self.compile(self.cppc, source, object, includes)
screamer 0:66f3b5499f7f 207
screamer 0:66f3b5499f7f 208 @hook_tool
screamer 0:66f3b5499f7f 209 def link(self, output, objects, libraries, lib_dirs, mem_map):
screamer 0:66f3b5499f7f 210 libs = []
screamer 0:66f3b5499f7f 211 for l in libraries:
screamer 0:66f3b5499f7f 212 name, _ = splitext(basename(l))
screamer 0:66f3b5499f7f 213 libs.append("-l%s" % name[3:])
screamer 0:66f3b5499f7f 214 libs.extend(["-l%s" % l for l in self.sys_libs])
screamer 0:66f3b5499f7f 215
screamer 0:66f3b5499f7f 216 # Build linker command
screamer 7:5af61d55adbe 217 map_file = splitext(output)[0] + ".map"
screamer 13:ab47a20b66f0 218 cmd = self.ld + ["-o", output, "-Wl,-Map=%s" % map_file] + objects + ["-Wl,--start-group"] + libs + ["-Wl,--end-group"]
screamer 0:66f3b5499f7f 219 if mem_map:
screamer 0:66f3b5499f7f 220 cmd.extend(['-T', mem_map])
screamer 13:ab47a20b66f0 221
screamer 0:66f3b5499f7f 222 for L in lib_dirs:
screamer 0:66f3b5499f7f 223 cmd.extend(['-L', L])
screamer 0:66f3b5499f7f 224 cmd.extend(libs)
screamer 0:66f3b5499f7f 225
screamer 0:66f3b5499f7f 226 # Call cmdline hook
screamer 0:66f3b5499f7f 227 cmd = self.hook.get_cmdline_linker(cmd)
screamer 0:66f3b5499f7f 228
screamer 21:4fdf0dd04f6f 229 if self.RESPONSE_FILES:
screamer 21:4fdf0dd04f6f 230 # Split link command to linker executable + response file
screamer 21:4fdf0dd04f6f 231 cmd_linker = cmd[0]
screamer 21:4fdf0dd04f6f 232 link_files = self.get_link_file(cmd[1:])
screamer 21:4fdf0dd04f6f 233 cmd = [cmd_linker, "@%s" % link_files]
screamer 0:66f3b5499f7f 234
screamer 0:66f3b5499f7f 235 # Exec command
screamer 21:4fdf0dd04f6f 236 self.cc_verbose("Link: %s" % ' '.join(cmd))
screamer 21:4fdf0dd04f6f 237 self.default_cmd(cmd)
screamer 0:66f3b5499f7f 238
screamer 0:66f3b5499f7f 239 @hook_tool
screamer 0:66f3b5499f7f 240 def archive(self, objects, lib_path):
screamer 21:4fdf0dd04f6f 241 if self.RESPONSE_FILES:
screamer 22:9e85236d8716 242 param = ["@%s" % self.get_arch_file(objects)]
screamer 21:4fdf0dd04f6f 243 else:
screamer 21:4fdf0dd04f6f 244 param = objects
screamer 0:66f3b5499f7f 245
screamer 0:66f3b5499f7f 246 # Exec command
screamer 21:4fdf0dd04f6f 247 self.default_cmd([self.ar, 'rcs', lib_path] + param)
screamer 0:66f3b5499f7f 248
screamer 0:66f3b5499f7f 249 @hook_tool
screamer 0:66f3b5499f7f 250 def binary(self, resources, elf, bin):
screamer 0:66f3b5499f7f 251 # Build binary command
screamer 0:66f3b5499f7f 252 cmd = [self.elf2bin, "-O", "binary", elf, bin]
screamer 0:66f3b5499f7f 253
screamer 0:66f3b5499f7f 254 # Call cmdline hook
screamer 0:66f3b5499f7f 255 cmd = self.hook.get_cmdline_binary(cmd)
screamer 0:66f3b5499f7f 256
screamer 0:66f3b5499f7f 257 # Exec command
screamer 21:4fdf0dd04f6f 258 self.cc_verbose("FromELF: %s" % ' '.join(cmd))
screamer 0:66f3b5499f7f 259 self.default_cmd(cmd)
screamer 0:66f3b5499f7f 260
screamer 0:66f3b5499f7f 261
screamer 0:66f3b5499f7f 262 class GCC_ARM(GCC):
The Other Jimmy 31:8ea194f6145b 263 @staticmethod
The Other Jimmy 31:8ea194f6145b 264 def check_executable():
The Other Jimmy 31:8ea194f6145b 265 """Returns True if the executable (arm-none-eabi-gcc) location
The Other Jimmy 31:8ea194f6145b 266 specified by the user exists OR the executable can be found on the PATH.
The Other Jimmy 31:8ea194f6145b 267 Returns False otherwise."""
The Other Jimmy 31:8ea194f6145b 268 return mbedToolchain.generic_check_executable("GCC_ARM", 'arm-none-eabi-gcc', 1)
screamer 0:66f3b5499f7f 269
The Other Jimmy 31:8ea194f6145b 270 def __init__(self, target, notify=None, macros=None,
The Other Jimmy 31:8ea194f6145b 271 silent=False, extra_verbose=False, build_profile=None):
The Other Jimmy 31:8ea194f6145b 272 GCC.__init__(self, target, notify, macros, silent,
The Other Jimmy 31:8ea194f6145b 273 TOOLCHAIN_PATHS['GCC_ARM'], extra_verbose=extra_verbose,
The Other Jimmy 31:8ea194f6145b 274 build_profile=build_profile)
screamer 13:ab47a20b66f0 275
screamer 0:66f3b5499f7f 276 self.sys_libs.append("nosys")
screamer 0:66f3b5499f7f 277
screamer 0:66f3b5499f7f 278
screamer 0:66f3b5499f7f 279 class GCC_CR(GCC):
The Other Jimmy 31:8ea194f6145b 280 @staticmethod
The Other Jimmy 31:8ea194f6145b 281 def check_executable():
The Other Jimmy 31:8ea194f6145b 282 """Returns True if the executable (arm-none-eabi-gcc) location
The Other Jimmy 31:8ea194f6145b 283 specified by the user exists OR the executable can be found on the PATH.
The Other Jimmy 31:8ea194f6145b 284 Returns False otherwise."""
The Other Jimmy 31:8ea194f6145b 285 return mbedToolchain.generic_check_executable("GCC_CR", 'arm-none-eabi-gcc', 1)
The Other Jimmy 31:8ea194f6145b 286
The Other Jimmy 31:8ea194f6145b 287 def __init__(self, target, notify=None, macros=None,
The Other Jimmy 31:8ea194f6145b 288 silent=False, extra_verbose=False, build_profile=None):
The Other Jimmy 31:8ea194f6145b 289 GCC.__init__(self, target, notify, macros, silent,
The Other Jimmy 31:8ea194f6145b 290 TOOLCHAIN_PATHS['GCC_CR'], extra_verbose=extra_verbose,
The Other Jimmy 31:8ea194f6145b 291 build_profile=build_profile)
screamer 0:66f3b5499f7f 292
screamer 0:66f3b5499f7f 293 additional_compiler_flags = [
screamer 0:66f3b5499f7f 294 "-D__NEWLIB__", "-D__CODE_RED", "-D__USE_CMSIS", "-DCPP_USE_HEAP",
screamer 0:66f3b5499f7f 295 ]
screamer 0:66f3b5499f7f 296 self.cc += additional_compiler_flags
screamer 0:66f3b5499f7f 297 self.cppc += additional_compiler_flags
screamer 0:66f3b5499f7f 298
screamer 0:66f3b5499f7f 299 # Use latest gcc nanolib
screamer 0:66f3b5499f7f 300 self.ld.append("--specs=nano.specs")
screamer 0:66f3b5499f7f 301 if target.name in ["LPC1768", "LPC4088", "LPC4088_DM", "LPC4330", "UBLOX_C027", "LPC2368"]:
screamer 0:66f3b5499f7f 302 self.ld.extend(["-u _printf_float", "-u _scanf_float"])
screamer 0:66f3b5499f7f 303 self.ld += ["-nostdlib"]