BBR 1 Ebene

Committer:
borlanic
Date:
Mon May 14 11:29:06 2018 +0000
Revision:
0:fbdae7e6d805
BBR

Who changed what in which revision?

UserRevisionLine numberNew 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.path import join, basename, splitext, dirname, exists
borlanic 0:fbdae7e6d805 19 from distutils.spawn import find_executable
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 GCC(mbedToolchain):
borlanic 0:fbdae7e6d805 25 LINKER_EXT = '.ld'
borlanic 0:fbdae7e6d805 26 LIBRARY_EXT = '.a'
borlanic 0:fbdae7e6d805 27
borlanic 0:fbdae7e6d805 28 STD_LIB_NAME = "lib%s.a"
borlanic 0:fbdae7e6d805 29 DIAGNOSTIC_PATTERN = re.compile('((?P<file>[^:]+):(?P<line>\d+):)(?P<col>\d+):? (?P<severity>warning|[eE]rror|fatal error): (?P<message>.+)')
borlanic 0:fbdae7e6d805 30
borlanic 0:fbdae7e6d805 31 def __init__(self, target, notify=None, macros=None, build_profile=None,
borlanic 0:fbdae7e6d805 32 build_dir=None):
borlanic 0:fbdae7e6d805 33 mbedToolchain.__init__(self, target, notify, macros,
borlanic 0:fbdae7e6d805 34 build_profile=build_profile, build_dir=build_dir)
borlanic 0:fbdae7e6d805 35
borlanic 0:fbdae7e6d805 36 tool_path=TOOLCHAIN_PATHS['GCC_ARM']
borlanic 0:fbdae7e6d805 37 # Add flags for current size setting
borlanic 0:fbdae7e6d805 38 default_lib = "std"
borlanic 0:fbdae7e6d805 39 if hasattr(target, "default_lib"):
borlanic 0:fbdae7e6d805 40 default_lib = target.default_lib
borlanic 0:fbdae7e6d805 41 elif hasattr(target, "default_build"): # Legacy
borlanic 0:fbdae7e6d805 42 default_lib = target.default_build
borlanic 0:fbdae7e6d805 43
borlanic 0:fbdae7e6d805 44 if default_lib == "small":
borlanic 0:fbdae7e6d805 45 self.flags["common"].append("-DMBED_RTOS_SINGLE_THREAD")
borlanic 0:fbdae7e6d805 46 self.flags["ld"].append("--specs=nano.specs")
borlanic 0:fbdae7e6d805 47
borlanic 0:fbdae7e6d805 48 if target.core == "Cortex-M0+":
borlanic 0:fbdae7e6d805 49 self.cpu = ["-mcpu=cortex-m0plus"]
borlanic 0:fbdae7e6d805 50 elif target.core.startswith("Cortex-M4"):
borlanic 0:fbdae7e6d805 51 self.cpu = ["-mcpu=cortex-m4"]
borlanic 0:fbdae7e6d805 52 elif target.core.startswith("Cortex-M7"):
borlanic 0:fbdae7e6d805 53 self.cpu = ["-mcpu=cortex-m7"]
borlanic 0:fbdae7e6d805 54 elif target.core.startswith("Cortex-M23"):
borlanic 0:fbdae7e6d805 55 self.cpu = ["-mcpu=cortex-m23"]
borlanic 0:fbdae7e6d805 56 elif target.core.startswith("Cortex-M33F"):
borlanic 0:fbdae7e6d805 57 self.cpu = ["-mcpu=cortex-m33"]
borlanic 0:fbdae7e6d805 58 elif target.core.startswith("Cortex-M33"):
borlanic 0:fbdae7e6d805 59 self.cpu = ["-march=armv8-m.main"]
borlanic 0:fbdae7e6d805 60 else:
borlanic 0:fbdae7e6d805 61 self.cpu = ["-mcpu={}".format(target.core.lower())]
borlanic 0:fbdae7e6d805 62
borlanic 0:fbdae7e6d805 63 if target.core.startswith("Cortex-M"):
borlanic 0:fbdae7e6d805 64 self.cpu.append("-mthumb")
borlanic 0:fbdae7e6d805 65
borlanic 0:fbdae7e6d805 66 # FPU handling, M7 possibly to have double FPU
borlanic 0:fbdae7e6d805 67 if target.core == "Cortex-M4F":
borlanic 0:fbdae7e6d805 68 self.cpu.append("-mfpu=fpv4-sp-d16")
borlanic 0:fbdae7e6d805 69 self.cpu.append("-mfloat-abi=softfp")
borlanic 0:fbdae7e6d805 70 elif target.core == "Cortex-M7F":
borlanic 0:fbdae7e6d805 71 self.cpu.append("-mfpu=fpv5-sp-d16")
borlanic 0:fbdae7e6d805 72 self.cpu.append("-mfloat-abi=softfp")
borlanic 0:fbdae7e6d805 73 elif target.core == "Cortex-M7FD":
borlanic 0:fbdae7e6d805 74 self.cpu.append("-mfpu=fpv5-d16")
borlanic 0:fbdae7e6d805 75 self.cpu.append("-mfloat-abi=softfp")
borlanic 0:fbdae7e6d805 76
borlanic 0:fbdae7e6d805 77 if target.core == "Cortex-A9":
borlanic 0:fbdae7e6d805 78 self.cpu.append("-mthumb-interwork")
borlanic 0:fbdae7e6d805 79 self.cpu.append("-marm")
borlanic 0:fbdae7e6d805 80 self.cpu.append("-march=armv7-a")
borlanic 0:fbdae7e6d805 81 self.cpu.append("-mfpu=vfpv3")
borlanic 0:fbdae7e6d805 82 self.cpu.append("-mfloat-abi=hard")
borlanic 0:fbdae7e6d805 83 self.cpu.append("-mno-unaligned-access")
borlanic 0:fbdae7e6d805 84
borlanic 0:fbdae7e6d805 85 if ((target.core.startswith("Cortex-M23") or
borlanic 0:fbdae7e6d805 86 target.core.startswith("Cortex-M33")) and
borlanic 0:fbdae7e6d805 87 not target.core.endswith("-NS")):
borlanic 0:fbdae7e6d805 88 self.cpu.append("-mcmse")
borlanic 0:fbdae7e6d805 89 elif target.core == "Cortex-M23-NS" or target.core == "Cortex-M33-NS":
borlanic 0:fbdae7e6d805 90 self.flags["ld"].append("-D__DOMAIN_NS=1")
borlanic 0:fbdae7e6d805 91
borlanic 0:fbdae7e6d805 92 self.flags["common"] += self.cpu
borlanic 0:fbdae7e6d805 93
borlanic 0:fbdae7e6d805 94 main_cc = join(tool_path, "arm-none-eabi-gcc")
borlanic 0:fbdae7e6d805 95 main_cppc = join(tool_path, "arm-none-eabi-g++")
borlanic 0:fbdae7e6d805 96 self.asm = [main_cc] + self.flags['asm'] + self.flags["common"]
borlanic 0:fbdae7e6d805 97 self.cc = [main_cc]
borlanic 0:fbdae7e6d805 98 self.cppc =[main_cppc]
borlanic 0:fbdae7e6d805 99 self.cc += self.flags['c'] + self.flags['common']
borlanic 0:fbdae7e6d805 100 self.cppc += self.flags['cxx'] + self.flags['common']
borlanic 0:fbdae7e6d805 101
borlanic 0:fbdae7e6d805 102 self.flags['ld'] += self.cpu
borlanic 0:fbdae7e6d805 103 self.ld = [join(tool_path, "arm-none-eabi-gcc")] + self.flags['ld']
borlanic 0:fbdae7e6d805 104 self.sys_libs = ["stdc++", "supc++", "m", "c", "gcc", "nosys"]
borlanic 0:fbdae7e6d805 105 self.preproc = [join(tool_path, "arm-none-eabi-cpp"), "-E", "-P"]
borlanic 0:fbdae7e6d805 106
borlanic 0:fbdae7e6d805 107 self.ar = join(tool_path, "arm-none-eabi-ar")
borlanic 0:fbdae7e6d805 108 self.elf2bin = join(tool_path, "arm-none-eabi-objcopy")
borlanic 0:fbdae7e6d805 109
borlanic 0:fbdae7e6d805 110 def is_not_supported_error(self, output):
borlanic 0:fbdae7e6d805 111 return "error: #error [NOT_SUPPORTED]" in output
borlanic 0:fbdae7e6d805 112
borlanic 0:fbdae7e6d805 113 def parse_output(self, output):
borlanic 0:fbdae7e6d805 114 # The warning/error notification is multiline
borlanic 0:fbdae7e6d805 115 msg = None
borlanic 0:fbdae7e6d805 116 for line in output.splitlines():
borlanic 0:fbdae7e6d805 117 match = self.DIAGNOSTIC_PATTERN.search(line)
borlanic 0:fbdae7e6d805 118 if match is not None:
borlanic 0:fbdae7e6d805 119 if msg is not None:
borlanic 0:fbdae7e6d805 120 self.notify.cc_info(msg)
borlanic 0:fbdae7e6d805 121 msg = None
borlanic 0:fbdae7e6d805 122 msg = {
borlanic 0:fbdae7e6d805 123 'severity': match.group('severity').lower(),
borlanic 0:fbdae7e6d805 124 'file': match.group('file'),
borlanic 0:fbdae7e6d805 125 'line': match.group('line'),
borlanic 0:fbdae7e6d805 126 'col': match.group('col'),
borlanic 0:fbdae7e6d805 127 'message': match.group('message'),
borlanic 0:fbdae7e6d805 128 'text': '',
borlanic 0:fbdae7e6d805 129 'target_name': self.target.name,
borlanic 0:fbdae7e6d805 130 'toolchain_name': self.name
borlanic 0:fbdae7e6d805 131 }
borlanic 0:fbdae7e6d805 132
borlanic 0:fbdae7e6d805 133 if msg is not None:
borlanic 0:fbdae7e6d805 134 self.notify.cc_info(msg)
borlanic 0:fbdae7e6d805 135
borlanic 0:fbdae7e6d805 136 def get_dep_option(self, object):
borlanic 0:fbdae7e6d805 137 base, _ = splitext(object)
borlanic 0:fbdae7e6d805 138 dep_path = base + '.d'
borlanic 0:fbdae7e6d805 139 return ["-MD", "-MF", dep_path]
borlanic 0:fbdae7e6d805 140
borlanic 0:fbdae7e6d805 141 def get_config_option(self, config_header):
borlanic 0:fbdae7e6d805 142 return ['-include', config_header]
borlanic 0:fbdae7e6d805 143
borlanic 0:fbdae7e6d805 144 def get_compile_options(self, defines, includes, for_asm=False):
borlanic 0:fbdae7e6d805 145 opts = ['-D%s' % d for d in defines]
borlanic 0:fbdae7e6d805 146 if self.RESPONSE_FILES:
borlanic 0:fbdae7e6d805 147 opts += ['@%s' % self.get_inc_file(includes)]
borlanic 0:fbdae7e6d805 148 else:
borlanic 0:fbdae7e6d805 149 opts += ["-I%s" % i for i in includes]
borlanic 0:fbdae7e6d805 150
borlanic 0:fbdae7e6d805 151 if not for_asm:
borlanic 0:fbdae7e6d805 152 config_header = self.get_config_header()
borlanic 0:fbdae7e6d805 153 if config_header is not None:
borlanic 0:fbdae7e6d805 154 opts = opts + self.get_config_option(config_header)
borlanic 0:fbdae7e6d805 155 return opts
borlanic 0:fbdae7e6d805 156
borlanic 0:fbdae7e6d805 157 @hook_tool
borlanic 0:fbdae7e6d805 158 def assemble(self, source, object, includes):
borlanic 0:fbdae7e6d805 159 # Build assemble command
borlanic 0:fbdae7e6d805 160 cmd = self.asm + self.get_compile_options(self.get_symbols(True), includes) + ["-o", object, source]
borlanic 0:fbdae7e6d805 161
borlanic 0:fbdae7e6d805 162 # Call cmdline hook
borlanic 0:fbdae7e6d805 163 cmd = self.hook.get_cmdline_assembler(cmd)
borlanic 0:fbdae7e6d805 164
borlanic 0:fbdae7e6d805 165 # Return command array, don't execute
borlanic 0:fbdae7e6d805 166 return [cmd]
borlanic 0:fbdae7e6d805 167
borlanic 0:fbdae7e6d805 168 @hook_tool
borlanic 0:fbdae7e6d805 169 def compile(self, cc, source, object, includes):
borlanic 0:fbdae7e6d805 170 # Build compile command
borlanic 0:fbdae7e6d805 171 cmd = cc + self.get_compile_options(self.get_symbols(), includes)
borlanic 0:fbdae7e6d805 172
borlanic 0:fbdae7e6d805 173 cmd.extend(self.get_dep_option(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 libs = []
borlanic 0:fbdae7e6d805 191 for l in libraries:
borlanic 0:fbdae7e6d805 192 name, _ = splitext(basename(l))
borlanic 0:fbdae7e6d805 193 libs.append("-l%s" % name[3:])
borlanic 0:fbdae7e6d805 194 libs.extend(["-l%s" % l for l in self.sys_libs])
borlanic 0:fbdae7e6d805 195
borlanic 0:fbdae7e6d805 196 # Preprocess
borlanic 0:fbdae7e6d805 197 if mem_map:
borlanic 0:fbdae7e6d805 198 preproc_output = join(dirname(output), ".link_script.ld")
borlanic 0:fbdae7e6d805 199 cmd = (self.preproc + [mem_map] + self.ld[1:] +
borlanic 0:fbdae7e6d805 200 [ "-o", preproc_output])
borlanic 0:fbdae7e6d805 201 self.notify.cc_verbose("Preproc: %s" % ' '.join(cmd))
borlanic 0:fbdae7e6d805 202 self.default_cmd(cmd)
borlanic 0:fbdae7e6d805 203 mem_map = preproc_output
borlanic 0:fbdae7e6d805 204
borlanic 0:fbdae7e6d805 205 # Build linker command
borlanic 0:fbdae7e6d805 206 map_file = splitext(output)[0] + ".map"
borlanic 0:fbdae7e6d805 207 cmd = self.ld + ["-o", output, "-Wl,-Map=%s" % map_file] + objects + ["-Wl,--start-group"] + libs + ["-Wl,--end-group"]
borlanic 0:fbdae7e6d805 208 # Create Secure library
borlanic 0:fbdae7e6d805 209 if self.target.core == "Cortex-M23" or self.target.core == "Cortex-M33":
borlanic 0:fbdae7e6d805 210 secure_file = join(dirname(output), "cmse_lib.o")
borlanic 0:fbdae7e6d805 211 cmd.extend(["-Wl,--cmse-implib"])
borlanic 0:fbdae7e6d805 212 cmd.extend(["-Wl,--out-implib=%s" % secure_file])
borlanic 0:fbdae7e6d805 213
borlanic 0:fbdae7e6d805 214 if mem_map:
borlanic 0:fbdae7e6d805 215 cmd.extend(['-T', mem_map])
borlanic 0:fbdae7e6d805 216
borlanic 0:fbdae7e6d805 217 for L in lib_dirs:
borlanic 0:fbdae7e6d805 218 cmd.extend(['-L', L])
borlanic 0:fbdae7e6d805 219 cmd.extend(libs)
borlanic 0:fbdae7e6d805 220
borlanic 0:fbdae7e6d805 221 # Call cmdline hook
borlanic 0:fbdae7e6d805 222 cmd = self.hook.get_cmdline_linker(cmd)
borlanic 0:fbdae7e6d805 223
borlanic 0:fbdae7e6d805 224 if self.RESPONSE_FILES:
borlanic 0:fbdae7e6d805 225 # Split link command to linker executable + response file
borlanic 0:fbdae7e6d805 226 cmd_linker = cmd[0]
borlanic 0:fbdae7e6d805 227 link_files = self.get_link_file(cmd[1:])
borlanic 0:fbdae7e6d805 228 cmd = [cmd_linker, "@%s" % link_files]
borlanic 0:fbdae7e6d805 229
borlanic 0:fbdae7e6d805 230 # Exec command
borlanic 0:fbdae7e6d805 231 self.notify.cc_verbose("Link: %s" % ' '.join(cmd))
borlanic 0:fbdae7e6d805 232 self.default_cmd(cmd)
borlanic 0:fbdae7e6d805 233 if self.target.core == "Cortex-M23" or self.target.core == "Cortex-M33":
borlanic 0:fbdae7e6d805 234 self.notify.info("Secure Library Object %s" %secure_file)
borlanic 0:fbdae7e6d805 235
borlanic 0:fbdae7e6d805 236 @hook_tool
borlanic 0:fbdae7e6d805 237 def archive(self, objects, lib_path):
borlanic 0:fbdae7e6d805 238 if self.RESPONSE_FILES:
borlanic 0:fbdae7e6d805 239 param = ["@%s" % self.get_arch_file(objects)]
borlanic 0:fbdae7e6d805 240 else:
borlanic 0:fbdae7e6d805 241 param = objects
borlanic 0:fbdae7e6d805 242
borlanic 0:fbdae7e6d805 243 # Exec command
borlanic 0:fbdae7e6d805 244 self.default_cmd([self.ar, 'rcs', lib_path] + param)
borlanic 0:fbdae7e6d805 245
borlanic 0:fbdae7e6d805 246 @hook_tool
borlanic 0:fbdae7e6d805 247 def binary(self, resources, elf, bin):
borlanic 0:fbdae7e6d805 248 # Build binary command
borlanic 0:fbdae7e6d805 249 _, fmt = splitext(bin)
borlanic 0:fbdae7e6d805 250 bin_arg = {'.bin': 'binary', '.hex': 'ihex'}[fmt]
borlanic 0:fbdae7e6d805 251 cmd = [self.elf2bin, "-O", bin_arg, elf, bin]
borlanic 0:fbdae7e6d805 252
borlanic 0:fbdae7e6d805 253 # Call cmdline hook
borlanic 0:fbdae7e6d805 254 cmd = self.hook.get_cmdline_binary(cmd)
borlanic 0:fbdae7e6d805 255
borlanic 0:fbdae7e6d805 256 # Exec command
borlanic 0:fbdae7e6d805 257 self.notify.cc_verbose("FromELF: %s" % ' '.join(cmd))
borlanic 0:fbdae7e6d805 258 self.default_cmd(cmd)
borlanic 0:fbdae7e6d805 259
borlanic 0:fbdae7e6d805 260 @staticmethod
borlanic 0:fbdae7e6d805 261 def name_mangle(name):
borlanic 0:fbdae7e6d805 262 return "_Z%i%sv" % (len(name), name)
borlanic 0:fbdae7e6d805 263
borlanic 0:fbdae7e6d805 264 @staticmethod
borlanic 0:fbdae7e6d805 265 def make_ld_define(name, value):
borlanic 0:fbdae7e6d805 266 return "-D%s=0x%x" % (name, value)
borlanic 0:fbdae7e6d805 267
borlanic 0:fbdae7e6d805 268 @staticmethod
borlanic 0:fbdae7e6d805 269 def redirect_symbol(source, sync, build_dir):
borlanic 0:fbdae7e6d805 270 return "-Wl,--defsym=%s=%s" % (source, sync)
borlanic 0:fbdae7e6d805 271
borlanic 0:fbdae7e6d805 272 @staticmethod
borlanic 0:fbdae7e6d805 273 def check_executable():
borlanic 0:fbdae7e6d805 274 """Returns True if the executable (arm-none-eabi-gcc) location
borlanic 0:fbdae7e6d805 275 specified by the user exists OR the executable can be found on the PATH.
borlanic 0:fbdae7e6d805 276 Returns False otherwise."""
borlanic 0:fbdae7e6d805 277 if not TOOLCHAIN_PATHS['GCC_ARM'] or not exists(TOOLCHAIN_PATHS['GCC_ARM']):
borlanic 0:fbdae7e6d805 278 if find_executable('arm-none-eabi-gcc'):
borlanic 0:fbdae7e6d805 279 TOOLCHAIN_PATHS['GCC_ARM'] = ''
borlanic 0:fbdae7e6d805 280 return True
borlanic 0:fbdae7e6d805 281 else:
borlanic 0:fbdae7e6d805 282 return False
borlanic 0:fbdae7e6d805 283 else:
borlanic 0:fbdae7e6d805 284 exec_name = join(TOOLCHAIN_PATHS['GCC_ARM'], 'arm-none-eabi-gcc')
borlanic 0:fbdae7e6d805 285 return exists(exec_name) or exists(exec_name + '.exe')
borlanic 0:fbdae7e6d805 286
borlanic 0:fbdae7e6d805 287 class GCC_ARM(GCC):
borlanic 0:fbdae7e6d805 288 pass