Color Oled(SSD1331) connect to STMicroelectronics Nucleo-F466

Dependencies:   ssd1331

Committer:
kadonotakashi
Date:
Wed Oct 10 00:33:53 2018 +0000
Revision:
0:8fdf9a60065b
how to make mbed librry

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kadonotakashi 0:8fdf9a60065b 1 """
kadonotakashi 0:8fdf9a60065b 2 mbed SDK
kadonotakashi 0:8fdf9a60065b 3 Copyright (c) 2011-2013 ARM Limited
kadonotakashi 0:8fdf9a60065b 4
kadonotakashi 0:8fdf9a60065b 5 Licensed under the Apache License, Version 2.0 (the "License");
kadonotakashi 0:8fdf9a60065b 6 you may not use this file except in compliance with the License.
kadonotakashi 0:8fdf9a60065b 7 You may obtain a copy of the License at
kadonotakashi 0:8fdf9a60065b 8
kadonotakashi 0:8fdf9a60065b 9 http://www.apache.org/licenses/LICENSE-2.0
kadonotakashi 0:8fdf9a60065b 10
kadonotakashi 0:8fdf9a60065b 11 Unless required by applicable law or agreed to in writing, software
kadonotakashi 0:8fdf9a60065b 12 distributed under the License is distributed on an "AS IS" BASIS,
kadonotakashi 0:8fdf9a60065b 13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
kadonotakashi 0:8fdf9a60065b 14 See the License for the specific language governing permissions and
kadonotakashi 0:8fdf9a60065b 15 limitations under the License.
kadonotakashi 0:8fdf9a60065b 16 """
kadonotakashi 0:8fdf9a60065b 17 from __future__ import print_function, absolute_import
kadonotakashi 0:8fdf9a60065b 18 from builtins import str
kadonotakashi 0:8fdf9a60065b 19
kadonotakashi 0:8fdf9a60065b 20 import re
kadonotakashi 0:8fdf9a60065b 21 from copy import copy
kadonotakashi 0:8fdf9a60065b 22 from os.path import join, dirname, splitext, basename, exists, relpath, isfile
kadonotakashi 0:8fdf9a60065b 23 from os import makedirs, write, curdir, remove
kadonotakashi 0:8fdf9a60065b 24 from tempfile import mkstemp
kadonotakashi 0:8fdf9a60065b 25 from shutil import rmtree
kadonotakashi 0:8fdf9a60065b 26 from distutils.version import LooseVersion
kadonotakashi 0:8fdf9a60065b 27
kadonotakashi 0:8fdf9a60065b 28 from tools.targets import CORE_ARCH
kadonotakashi 0:8fdf9a60065b 29 from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS
kadonotakashi 0:8fdf9a60065b 30 from tools.hooks import hook_tool
kadonotakashi 0:8fdf9a60065b 31 from tools.utils import mkdir, NotSupportedException, run_cmd
kadonotakashi 0:8fdf9a60065b 32
kadonotakashi 0:8fdf9a60065b 33 class ARM(mbedToolchain):
kadonotakashi 0:8fdf9a60065b 34 LINKER_EXT = '.sct'
kadonotakashi 0:8fdf9a60065b 35 LIBRARY_EXT = '.ar'
kadonotakashi 0:8fdf9a60065b 36
kadonotakashi 0:8fdf9a60065b 37 STD_LIB_NAME = "%s.ar"
kadonotakashi 0:8fdf9a60065b 38 DIAGNOSTIC_PATTERN = re.compile('"(?P<file>[^"]+)", line (?P<line>\d+)( \(column (?P<column>\d+)\)|): (?P<severity>Warning|Error|Fatal error): (?P<message>.+)')
kadonotakashi 0:8fdf9a60065b 39 INDEX_PATTERN = re.compile('(?P<col>\s*)\^')
kadonotakashi 0:8fdf9a60065b 40 DEP_PATTERN = re.compile('\S+:\s(?P<file>.+)\n')
kadonotakashi 0:8fdf9a60065b 41 SHEBANG = "#! armcc -E"
kadonotakashi 0:8fdf9a60065b 42 SUPPORTED_CORES = ["Cortex-M0", "Cortex-M0+", "Cortex-M3", "Cortex-M4",
kadonotakashi 0:8fdf9a60065b 43 "Cortex-M4F", "Cortex-M7", "Cortex-M7F", "Cortex-M7FD", "Cortex-A9"]
kadonotakashi 0:8fdf9a60065b 44 ARMCC_RANGE = (LooseVersion("5.06"), LooseVersion("5.07"))
kadonotakashi 0:8fdf9a60065b 45 ARMCC_VERSION_RE = re.compile(b"Component: ARM Compiler (\d+\.\d+)")
kadonotakashi 0:8fdf9a60065b 46
kadonotakashi 0:8fdf9a60065b 47 @staticmethod
kadonotakashi 0:8fdf9a60065b 48 def check_executable():
kadonotakashi 0:8fdf9a60065b 49 """Returns True if the executable (armcc) location specified by the
kadonotakashi 0:8fdf9a60065b 50 user exists OR the executable can be found on the PATH.
kadonotakashi 0:8fdf9a60065b 51 Returns False otherwise."""
kadonotakashi 0:8fdf9a60065b 52 return mbedToolchain.generic_check_executable("ARM", 'armcc', 2, 'bin')
kadonotakashi 0:8fdf9a60065b 53
kadonotakashi 0:8fdf9a60065b 54 def __init__(self, target, notify=None, macros=None,
kadonotakashi 0:8fdf9a60065b 55 build_profile=None, build_dir=None):
kadonotakashi 0:8fdf9a60065b 56 mbedToolchain.__init__(
kadonotakashi 0:8fdf9a60065b 57 self, target, notify, macros, build_dir=build_dir,
kadonotakashi 0:8fdf9a60065b 58 build_profile=build_profile)
kadonotakashi 0:8fdf9a60065b 59 if target.core not in self.SUPPORTED_CORES:
kadonotakashi 0:8fdf9a60065b 60 raise NotSupportedException(
kadonotakashi 0:8fdf9a60065b 61 "this compiler does not support the core %s" % target.core)
kadonotakashi 0:8fdf9a60065b 62
kadonotakashi 0:8fdf9a60065b 63 if getattr(target, "default_lib", "std") == "small":
kadonotakashi 0:8fdf9a60065b 64 if "-DMBED_RTOS_SINGLE_THREAD" not in self.flags['common']:
kadonotakashi 0:8fdf9a60065b 65 self.flags['common'].append("-DMBED_RTOS_SINGLE_THREAD")
kadonotakashi 0:8fdf9a60065b 66 if "-D__MICROLIB" not in self.flags['common']:
kadonotakashi 0:8fdf9a60065b 67 self.flags['common'].append("-D__MICROLIB")
kadonotakashi 0:8fdf9a60065b 68 if "--library_type=microlib" not in self.flags['ld']:
kadonotakashi 0:8fdf9a60065b 69 self.flags['ld'].append("--library_type=microlib")
kadonotakashi 0:8fdf9a60065b 70 if "--library_type=microlib" not in self.flags['common']:
kadonotakashi 0:8fdf9a60065b 71 self.flags['common'].append("--library_type=microlib")
kadonotakashi 0:8fdf9a60065b 72
kadonotakashi 0:8fdf9a60065b 73 if target.core == "Cortex-M0+":
kadonotakashi 0:8fdf9a60065b 74 cpu = "Cortex-M0"
kadonotakashi 0:8fdf9a60065b 75 elif target.core == "Cortex-M4F":
kadonotakashi 0:8fdf9a60065b 76 cpu = "Cortex-M4.fp"
kadonotakashi 0:8fdf9a60065b 77 elif target.core == "Cortex-M7FD":
kadonotakashi 0:8fdf9a60065b 78 cpu = "Cortex-M7.fp.dp"
kadonotakashi 0:8fdf9a60065b 79 elif target.core == "Cortex-M7F":
kadonotakashi 0:8fdf9a60065b 80 cpu = "Cortex-M7.fp.sp"
kadonotakashi 0:8fdf9a60065b 81 else:
kadonotakashi 0:8fdf9a60065b 82 cpu = target.core
kadonotakashi 0:8fdf9a60065b 83
kadonotakashi 0:8fdf9a60065b 84 ARM_BIN = join(TOOLCHAIN_PATHS['ARM'], "bin")
kadonotakashi 0:8fdf9a60065b 85 ARM_INC = join(TOOLCHAIN_PATHS['ARM'], "include")
kadonotakashi 0:8fdf9a60065b 86
kadonotakashi 0:8fdf9a60065b 87 main_cc = join(ARM_BIN, "armcc")
kadonotakashi 0:8fdf9a60065b 88
kadonotakashi 0:8fdf9a60065b 89 self.flags['common'] += ["--cpu=%s" % cpu]
kadonotakashi 0:8fdf9a60065b 90
kadonotakashi 0:8fdf9a60065b 91 self.asm = [main_cc] + self.flags['common'] + self.flags['asm']
kadonotakashi 0:8fdf9a60065b 92 self.cc = [main_cc] + self.flags['common'] + self.flags['c']
kadonotakashi 0:8fdf9a60065b 93 self.cppc = [main_cc] + self.flags['common'] + self.flags['c'] + self.flags['cxx']
kadonotakashi 0:8fdf9a60065b 94
kadonotakashi 0:8fdf9a60065b 95 self.ld = [join(ARM_BIN, "armlink")] + self.flags['ld']
kadonotakashi 0:8fdf9a60065b 96
kadonotakashi 0:8fdf9a60065b 97 self.ar = join(ARM_BIN, "armar")
kadonotakashi 0:8fdf9a60065b 98 self.elf2bin = join(ARM_BIN, "fromelf")
kadonotakashi 0:8fdf9a60065b 99
kadonotakashi 0:8fdf9a60065b 100 self.SHEBANG += " --cpu=%s" % cpu
kadonotakashi 0:8fdf9a60065b 101
kadonotakashi 0:8fdf9a60065b 102 def version_check(self):
kadonotakashi 0:8fdf9a60065b 103 stdout, _, retcode = run_cmd([self.cc[0], "--vsn"], redirect=True)
kadonotakashi 0:8fdf9a60065b 104 msg = None
kadonotakashi 0:8fdf9a60065b 105 min_ver, max_ver = self.ARMCC_RANGE
kadonotakashi 0:8fdf9a60065b 106 match = self.ARMCC_VERSION_RE.search(stdout)
kadonotakashi 0:8fdf9a60065b 107 found_version = LooseVersion(match.group(1).decode("utf-8")) if match else None
kadonotakashi 0:8fdf9a60065b 108 min_ver, max_ver = self.ARMCC_RANGE
kadonotakashi 0:8fdf9a60065b 109 if found_version and (found_version < min_ver or found_version >= max_ver):
kadonotakashi 0:8fdf9a60065b 110 msg = ("Compiler version mismatch: Have {}; "
kadonotakashi 0:8fdf9a60065b 111 "expected version >= {} and < {}"
kadonotakashi 0:8fdf9a60065b 112 .format(found_version, min_ver, max_ver))
kadonotakashi 0:8fdf9a60065b 113 elif not match or len(match.groups()) != 1:
kadonotakashi 0:8fdf9a60065b 114 msg = ("Compiler version mismatch: Could not detect version; "
kadonotakashi 0:8fdf9a60065b 115 "expected version >= {} and < {}"
kadonotakashi 0:8fdf9a60065b 116 .format(min_ver, max_ver))
kadonotakashi 0:8fdf9a60065b 117
kadonotakashi 0:8fdf9a60065b 118 if msg:
kadonotakashi 0:8fdf9a60065b 119 self.notify.cc_info({
kadonotakashi 0:8fdf9a60065b 120 "message": msg,
kadonotakashi 0:8fdf9a60065b 121 "file": "",
kadonotakashi 0:8fdf9a60065b 122 "line": "",
kadonotakashi 0:8fdf9a60065b 123 "col": "",
kadonotakashi 0:8fdf9a60065b 124 "severity": "WARNING",
kadonotakashi 0:8fdf9a60065b 125 })
kadonotakashi 0:8fdf9a60065b 126
kadonotakashi 0:8fdf9a60065b 127 def _get_toolchain_labels(self):
kadonotakashi 0:8fdf9a60065b 128 if getattr(self.target, "default_lib", "std") == "small":
kadonotakashi 0:8fdf9a60065b 129 return ["ARM", "ARM_MICRO"]
kadonotakashi 0:8fdf9a60065b 130 else:
kadonotakashi 0:8fdf9a60065b 131 return ["ARM", "ARM_STD"]
kadonotakashi 0:8fdf9a60065b 132
kadonotakashi 0:8fdf9a60065b 133 def parse_dependencies(self, dep_path):
kadonotakashi 0:8fdf9a60065b 134 dependencies = []
kadonotakashi 0:8fdf9a60065b 135 for line in open(dep_path).readlines():
kadonotakashi 0:8fdf9a60065b 136 match = ARM.DEP_PATTERN.match(line)
kadonotakashi 0:8fdf9a60065b 137 if match is not None:
kadonotakashi 0:8fdf9a60065b 138 #we need to append chroot, because when the .d files are generated the compiler is chrooted
kadonotakashi 0:8fdf9a60065b 139 dependencies.append((self.CHROOT if self.CHROOT else '') + match.group('file'))
kadonotakashi 0:8fdf9a60065b 140 return dependencies
kadonotakashi 0:8fdf9a60065b 141
kadonotakashi 0:8fdf9a60065b 142 def parse_output(self, output):
kadonotakashi 0:8fdf9a60065b 143 msg = None
kadonotakashi 0:8fdf9a60065b 144 for line in output.splitlines():
kadonotakashi 0:8fdf9a60065b 145 match = ARM.DIAGNOSTIC_PATTERN.match(line)
kadonotakashi 0:8fdf9a60065b 146 if match is not None:
kadonotakashi 0:8fdf9a60065b 147 if msg is not None:
kadonotakashi 0:8fdf9a60065b 148 self.notify.cc_info(msg)
kadonotakashi 0:8fdf9a60065b 149 msg = None
kadonotakashi 0:8fdf9a60065b 150 msg = {
kadonotakashi 0:8fdf9a60065b 151 'severity': match.group('severity').lower(),
kadonotakashi 0:8fdf9a60065b 152 'file': match.group('file'),
kadonotakashi 0:8fdf9a60065b 153 'line': match.group('line'),
kadonotakashi 0:8fdf9a60065b 154 'col': match.group('column') if match.group('column') else 0,
kadonotakashi 0:8fdf9a60065b 155 'message': match.group('message'),
kadonotakashi 0:8fdf9a60065b 156 'text': '',
kadonotakashi 0:8fdf9a60065b 157 'target_name': self.target.name,
kadonotakashi 0:8fdf9a60065b 158 'toolchain_name': self.name
kadonotakashi 0:8fdf9a60065b 159 }
kadonotakashi 0:8fdf9a60065b 160 elif msg is not None:
kadonotakashi 0:8fdf9a60065b 161 # Determine the warning/error column by calculating the ^ position
kadonotakashi 0:8fdf9a60065b 162 match = ARM.INDEX_PATTERN.match(line)
kadonotakashi 0:8fdf9a60065b 163 if match is not None:
kadonotakashi 0:8fdf9a60065b 164 msg['col'] = len(match.group('col'))
kadonotakashi 0:8fdf9a60065b 165 self.notify.cc_info(msg)
kadonotakashi 0:8fdf9a60065b 166 msg = None
kadonotakashi 0:8fdf9a60065b 167 else:
kadonotakashi 0:8fdf9a60065b 168 msg['text'] += line+"\n"
kadonotakashi 0:8fdf9a60065b 169
kadonotakashi 0:8fdf9a60065b 170 if msg is not None:
kadonotakashi 0:8fdf9a60065b 171 self.notify.cc_info(msg)
kadonotakashi 0:8fdf9a60065b 172
kadonotakashi 0:8fdf9a60065b 173 def get_dep_option(self, object):
kadonotakashi 0:8fdf9a60065b 174 base, _ = splitext(object)
kadonotakashi 0:8fdf9a60065b 175 dep_path = base + '.d'
kadonotakashi 0:8fdf9a60065b 176 return ["--depend", dep_path]
kadonotakashi 0:8fdf9a60065b 177
kadonotakashi 0:8fdf9a60065b 178 def get_config_option(self, config_header):
kadonotakashi 0:8fdf9a60065b 179 return ['--preinclude=' + config_header]
kadonotakashi 0:8fdf9a60065b 180
kadonotakashi 0:8fdf9a60065b 181 def get_compile_options(self, defines, includes, for_asm=False):
kadonotakashi 0:8fdf9a60065b 182 opts = ['-D%s' % d for d in defines]
kadonotakashi 0:8fdf9a60065b 183 config_header = self.get_config_header()
kadonotakashi 0:8fdf9a60065b 184 if config_header is not None:
kadonotakashi 0:8fdf9a60065b 185 opts = opts + self.get_config_option(config_header)
kadonotakashi 0:8fdf9a60065b 186 if for_asm:
kadonotakashi 0:8fdf9a60065b 187 return opts
kadonotakashi 0:8fdf9a60065b 188 if self.RESPONSE_FILES:
kadonotakashi 0:8fdf9a60065b 189 opts += ['--via', self.get_inc_file(includes)]
kadonotakashi 0:8fdf9a60065b 190 else:
kadonotakashi 0:8fdf9a60065b 191 opts += ["-I%s" % i for i in includes]
kadonotakashi 0:8fdf9a60065b 192
kadonotakashi 0:8fdf9a60065b 193 return opts
kadonotakashi 0:8fdf9a60065b 194
kadonotakashi 0:8fdf9a60065b 195 @hook_tool
kadonotakashi 0:8fdf9a60065b 196 def assemble(self, source, object, includes):
kadonotakashi 0:8fdf9a60065b 197 # Preprocess first, then assemble
kadonotakashi 0:8fdf9a60065b 198 dir = join(dirname(object), '.temp')
kadonotakashi 0:8fdf9a60065b 199 mkdir(dir)
kadonotakashi 0:8fdf9a60065b 200 tempfile = join(dir, basename(object) + '.E.s')
kadonotakashi 0:8fdf9a60065b 201
kadonotakashi 0:8fdf9a60065b 202 # Build preprocess assemble command
kadonotakashi 0:8fdf9a60065b 203 cmd_pre = copy(self.asm)
kadonotakashi 0:8fdf9a60065b 204 cmd_pre.extend(self.get_compile_options(
kadonotakashi 0:8fdf9a60065b 205 self.get_symbols(True), includes, True))
kadonotakashi 0:8fdf9a60065b 206 cmd_pre.extend(["-E", "-o", tempfile, source])
kadonotakashi 0:8fdf9a60065b 207
kadonotakashi 0:8fdf9a60065b 208 # Build main assemble command
kadonotakashi 0:8fdf9a60065b 209 cmd = self.asm + ["-o", object, tempfile]
kadonotakashi 0:8fdf9a60065b 210
kadonotakashi 0:8fdf9a60065b 211 # Call cmdline hook
kadonotakashi 0:8fdf9a60065b 212 cmd_pre = self.hook.get_cmdline_assembler(cmd_pre)
kadonotakashi 0:8fdf9a60065b 213 cmd = self.hook.get_cmdline_assembler(cmd)
kadonotakashi 0:8fdf9a60065b 214
kadonotakashi 0:8fdf9a60065b 215 # Return command array, don't execute
kadonotakashi 0:8fdf9a60065b 216 return [cmd_pre, cmd]
kadonotakashi 0:8fdf9a60065b 217
kadonotakashi 0:8fdf9a60065b 218 @hook_tool
kadonotakashi 0:8fdf9a60065b 219 def compile(self, cc, source, object, includes):
kadonotakashi 0:8fdf9a60065b 220 # Build compile command
kadonotakashi 0:8fdf9a60065b 221 cmd = cc + self.get_compile_options(self.get_symbols(), includes)
kadonotakashi 0:8fdf9a60065b 222
kadonotakashi 0:8fdf9a60065b 223 cmd.extend(self.get_dep_option(object))
kadonotakashi 0:8fdf9a60065b 224
kadonotakashi 0:8fdf9a60065b 225 cmd.extend(["-o", object, source])
kadonotakashi 0:8fdf9a60065b 226
kadonotakashi 0:8fdf9a60065b 227 # Call cmdline hook
kadonotakashi 0:8fdf9a60065b 228 cmd = self.hook.get_cmdline_compiler(cmd)
kadonotakashi 0:8fdf9a60065b 229
kadonotakashi 0:8fdf9a60065b 230 return [cmd]
kadonotakashi 0:8fdf9a60065b 231
kadonotakashi 0:8fdf9a60065b 232 def compile_c(self, source, object, includes):
kadonotakashi 0:8fdf9a60065b 233 return self.compile(self.cc, source, object, includes)
kadonotakashi 0:8fdf9a60065b 234
kadonotakashi 0:8fdf9a60065b 235 def compile_cpp(self, source, object, includes):
kadonotakashi 0:8fdf9a60065b 236 return self.compile(self.cppc, source, object, includes)
kadonotakashi 0:8fdf9a60065b 237
kadonotakashi 0:8fdf9a60065b 238 def correct_scatter_shebang(self, scatter_file, cur_dir_name=None):
kadonotakashi 0:8fdf9a60065b 239 """Correct the shebang at the top of a scatter file.
kadonotakashi 0:8fdf9a60065b 240
kadonotakashi 0:8fdf9a60065b 241 Positional arguments:
kadonotakashi 0:8fdf9a60065b 242 scatter_file -- the scatter file to correct
kadonotakashi 0:8fdf9a60065b 243
kadonotakashi 0:8fdf9a60065b 244 Keyword arguments:
kadonotakashi 0:8fdf9a60065b 245 cur_dir_name -- the name (not path) of the directory containing the
kadonotakashi 0:8fdf9a60065b 246 scatter file
kadonotakashi 0:8fdf9a60065b 247
kadonotakashi 0:8fdf9a60065b 248 Return:
kadonotakashi 0:8fdf9a60065b 249 The location of the correct scatter file
kadonotakashi 0:8fdf9a60065b 250
kadonotakashi 0:8fdf9a60065b 251 Side Effects:
kadonotakashi 0:8fdf9a60065b 252 This method MAY write a new scatter file to disk
kadonotakashi 0:8fdf9a60065b 253 """
kadonotakashi 0:8fdf9a60065b 254 with open(scatter_file, "r") as input:
kadonotakashi 0:8fdf9a60065b 255 lines = input.readlines()
kadonotakashi 0:8fdf9a60065b 256 if (lines[0].startswith(self.SHEBANG) or
kadonotakashi 0:8fdf9a60065b 257 not lines[0].startswith("#!")):
kadonotakashi 0:8fdf9a60065b 258 return scatter_file
kadonotakashi 0:8fdf9a60065b 259 else:
kadonotakashi 0:8fdf9a60065b 260 new_scatter = join(self.build_dir, ".link_script.sct")
kadonotakashi 0:8fdf9a60065b 261 if cur_dir_name is None:
kadonotakashi 0:8fdf9a60065b 262 cur_dir_name = dirname(scatter_file)
kadonotakashi 0:8fdf9a60065b 263 self.SHEBANG += " -I %s" % cur_dir_name
kadonotakashi 0:8fdf9a60065b 264 if self.need_update(new_scatter, [scatter_file]):
kadonotakashi 0:8fdf9a60065b 265 with open(new_scatter, "w") as out:
kadonotakashi 0:8fdf9a60065b 266 out.write(self.SHEBANG)
kadonotakashi 0:8fdf9a60065b 267 out.write("\n")
kadonotakashi 0:8fdf9a60065b 268 out.write("".join(lines[1:]))
kadonotakashi 0:8fdf9a60065b 269
kadonotakashi 0:8fdf9a60065b 270 return new_scatter
kadonotakashi 0:8fdf9a60065b 271
kadonotakashi 0:8fdf9a60065b 272 @hook_tool
kadonotakashi 0:8fdf9a60065b 273 def link(self, output, objects, libraries, lib_dirs, scatter_file):
kadonotakashi 0:8fdf9a60065b 274 base, _ = splitext(output)
kadonotakashi 0:8fdf9a60065b 275 map_file = base + ".map"
kadonotakashi 0:8fdf9a60065b 276 args = ["-o", output, "--info=totals", "--map", "--list=%s" % map_file]
kadonotakashi 0:8fdf9a60065b 277 args.extend(objects)
kadonotakashi 0:8fdf9a60065b 278 args.extend(libraries)
kadonotakashi 0:8fdf9a60065b 279 if lib_dirs:
kadonotakashi 0:8fdf9a60065b 280 args.extend(["--userlibpath", ",".join(lib_dirs)])
kadonotakashi 0:8fdf9a60065b 281 if scatter_file:
kadonotakashi 0:8fdf9a60065b 282 new_scatter = self.correct_scatter_shebang(scatter_file)
kadonotakashi 0:8fdf9a60065b 283 args.extend(["--scatter", new_scatter])
kadonotakashi 0:8fdf9a60065b 284
kadonotakashi 0:8fdf9a60065b 285 cmd_pre = self.ld + args
kadonotakashi 0:8fdf9a60065b 286 cmd = self.hook.get_cmdline_linker(cmd_pre)
kadonotakashi 0:8fdf9a60065b 287
kadonotakashi 0:8fdf9a60065b 288 if self.RESPONSE_FILES:
kadonotakashi 0:8fdf9a60065b 289 cmd_linker = cmd[0]
kadonotakashi 0:8fdf9a60065b 290 link_files = self.get_link_file(cmd[1:])
kadonotakashi 0:8fdf9a60065b 291 cmd = [cmd_linker, '--via', link_files]
kadonotakashi 0:8fdf9a60065b 292
kadonotakashi 0:8fdf9a60065b 293 self.notify.cc_verbose("Link: %s" % ' '.join(cmd))
kadonotakashi 0:8fdf9a60065b 294 self.default_cmd(cmd)
kadonotakashi 0:8fdf9a60065b 295
kadonotakashi 0:8fdf9a60065b 296 @hook_tool
kadonotakashi 0:8fdf9a60065b 297 def archive(self, objects, lib_path):
kadonotakashi 0:8fdf9a60065b 298 if self.RESPONSE_FILES:
kadonotakashi 0:8fdf9a60065b 299 param = ['--via', self.get_arch_file(objects)]
kadonotakashi 0:8fdf9a60065b 300 else:
kadonotakashi 0:8fdf9a60065b 301 param = objects
kadonotakashi 0:8fdf9a60065b 302 self.default_cmd([self.ar, '-r', lib_path] + param)
kadonotakashi 0:8fdf9a60065b 303
kadonotakashi 0:8fdf9a60065b 304 @hook_tool
kadonotakashi 0:8fdf9a60065b 305 def binary(self, resources, elf, bin):
kadonotakashi 0:8fdf9a60065b 306 _, fmt = splitext(bin)
kadonotakashi 0:8fdf9a60065b 307 # On .hex format, combine multiple .hex files (for multiple load regions) into one
kadonotakashi 0:8fdf9a60065b 308 bin_arg = {".bin": "--bin", ".hex": "--i32combined"}[fmt]
kadonotakashi 0:8fdf9a60065b 309 cmd = [self.elf2bin, bin_arg, '-o', bin, elf]
kadonotakashi 0:8fdf9a60065b 310 cmd = self.hook.get_cmdline_binary(cmd)
kadonotakashi 0:8fdf9a60065b 311
kadonotakashi 0:8fdf9a60065b 312 # remove target binary file/path
kadonotakashi 0:8fdf9a60065b 313 if exists(bin):
kadonotakashi 0:8fdf9a60065b 314 if isfile(bin):
kadonotakashi 0:8fdf9a60065b 315 remove(bin)
kadonotakashi 0:8fdf9a60065b 316 else:
kadonotakashi 0:8fdf9a60065b 317 rmtree(bin)
kadonotakashi 0:8fdf9a60065b 318
kadonotakashi 0:8fdf9a60065b 319 self.notify.cc_verbose("FromELF: %s" % ' '.join(cmd))
kadonotakashi 0:8fdf9a60065b 320 self.default_cmd(cmd)
kadonotakashi 0:8fdf9a60065b 321
kadonotakashi 0:8fdf9a60065b 322 @staticmethod
kadonotakashi 0:8fdf9a60065b 323 def name_mangle(name):
kadonotakashi 0:8fdf9a60065b 324 return "_Z%i%sv" % (len(name), name)
kadonotakashi 0:8fdf9a60065b 325
kadonotakashi 0:8fdf9a60065b 326 @staticmethod
kadonotakashi 0:8fdf9a60065b 327 def make_ld_define(name, value):
kadonotakashi 0:8fdf9a60065b 328 return "--predefine=\"-D%s=%s\"" % (name, value)
kadonotakashi 0:8fdf9a60065b 329
kadonotakashi 0:8fdf9a60065b 330 @staticmethod
kadonotakashi 0:8fdf9a60065b 331 def redirect_symbol(source, sync, build_dir):
kadonotakashi 0:8fdf9a60065b 332 if not exists(build_dir):
kadonotakashi 0:8fdf9a60065b 333 makedirs(build_dir)
kadonotakashi 0:8fdf9a60065b 334 handle, filename = mkstemp(prefix=".redirect-symbol.", dir=build_dir)
kadonotakashi 0:8fdf9a60065b 335 write(handle, "RESOLVE %s AS %s\n" % (source, sync))
kadonotakashi 0:8fdf9a60065b 336 return "--edit=%s" % filename
kadonotakashi 0:8fdf9a60065b 337
kadonotakashi 0:8fdf9a60065b 338
kadonotakashi 0:8fdf9a60065b 339 class ARM_STD(ARM):
kadonotakashi 0:8fdf9a60065b 340 def __init__(self, target, notify=None, macros=None,
kadonotakashi 0:8fdf9a60065b 341 build_profile=None, build_dir=None):
kadonotakashi 0:8fdf9a60065b 342 ARM.__init__(self, target, notify, macros, build_dir=build_dir,
kadonotakashi 0:8fdf9a60065b 343 build_profile=build_profile)
kadonotakashi 0:8fdf9a60065b 344 if not set(("ARM", "uARM")).intersection(set(target.supported_toolchains)):
kadonotakashi 0:8fdf9a60065b 345 raise NotSupportedException("ARM/uARM compiler support is required for ARM build")
kadonotakashi 0:8fdf9a60065b 346
kadonotakashi 0:8fdf9a60065b 347
kadonotakashi 0:8fdf9a60065b 348 class ARM_MICRO(ARM):
kadonotakashi 0:8fdf9a60065b 349 PATCHED_LIBRARY = False
kadonotakashi 0:8fdf9a60065b 350 def __init__(self, target, notify=None, macros=None,
kadonotakashi 0:8fdf9a60065b 351 silent=False, extra_verbose=False, build_profile=None,
kadonotakashi 0:8fdf9a60065b 352 build_dir=None):
kadonotakashi 0:8fdf9a60065b 353 target.default_lib = "small"
kadonotakashi 0:8fdf9a60065b 354 ARM.__init__(self, target, notify, macros, build_dir=build_dir,
kadonotakashi 0:8fdf9a60065b 355 build_profile=build_profile)
kadonotakashi 0:8fdf9a60065b 356 if not set(("ARM", "uARM")).intersection(set(target.supported_toolchains)):
kadonotakashi 0:8fdf9a60065b 357 raise NotSupportedException("ARM/uARM compiler support is required for ARM build")
kadonotakashi 0:8fdf9a60065b 358
kadonotakashi 0:8fdf9a60065b 359 class ARMC6(ARM_STD):
kadonotakashi 0:8fdf9a60065b 360 SHEBANG = "#! armclang -E --target=arm-arm-none-eabi -x c"
kadonotakashi 0:8fdf9a60065b 361 SUPPORTED_CORES = ["Cortex-M0", "Cortex-M0+", "Cortex-M3", "Cortex-M4",
kadonotakashi 0:8fdf9a60065b 362 "Cortex-M4F", "Cortex-M7", "Cortex-M7F", "Cortex-M7FD",
kadonotakashi 0:8fdf9a60065b 363 "Cortex-M23", "Cortex-M23-NS", "Cortex-M33",
kadonotakashi 0:8fdf9a60065b 364 "Cortex-M33-NS", "Cortex-A9"]
kadonotakashi 0:8fdf9a60065b 365 ARMCC_RANGE = (LooseVersion("6.10"), LooseVersion("7.0"))
kadonotakashi 0:8fdf9a60065b 366
kadonotakashi 0:8fdf9a60065b 367 @staticmethod
kadonotakashi 0:8fdf9a60065b 368 def check_executable():
kadonotakashi 0:8fdf9a60065b 369 return mbedToolchain.generic_check_executable("ARMC6", "armclang", 1)
kadonotakashi 0:8fdf9a60065b 370
kadonotakashi 0:8fdf9a60065b 371 def __init__(self, target, *args, **kwargs):
kadonotakashi 0:8fdf9a60065b 372 mbedToolchain.__init__(self, target, *args, **kwargs)
kadonotakashi 0:8fdf9a60065b 373 if target.core not in self.SUPPORTED_CORES:
kadonotakashi 0:8fdf9a60065b 374 raise NotSupportedException(
kadonotakashi 0:8fdf9a60065b 375 "this compiler does not support the core %s" % target.core)
kadonotakashi 0:8fdf9a60065b 376 if CORE_ARCH[target.core] < 8:
kadonotakashi 0:8fdf9a60065b 377 self.notify.cc_info({
kadonotakashi 0:8fdf9a60065b 378 'severity': "Error", 'file': "", 'line': "", 'col': "",
kadonotakashi 0:8fdf9a60065b 379 'message': "ARMC6 does not support ARM architecture v{}"
kadonotakashi 0:8fdf9a60065b 380 " targets".format(CORE_ARCH[target.core]),
kadonotakashi 0:8fdf9a60065b 381 'text': '', 'target_name': self.target.name,
kadonotakashi 0:8fdf9a60065b 382 'toolchain_name': self.name
kadonotakashi 0:8fdf9a60065b 383 })
kadonotakashi 0:8fdf9a60065b 384
kadonotakashi 0:8fdf9a60065b 385 if not set(("ARM", "ARMC6")).intersection(set(target.supported_toolchains)):
kadonotakashi 0:8fdf9a60065b 386 raise NotSupportedException("ARM/ARMC6 compiler support is required for ARMC6 build")
kadonotakashi 0:8fdf9a60065b 387
kadonotakashi 0:8fdf9a60065b 388 if target.core.lower().endswith("fd"):
kadonotakashi 0:8fdf9a60065b 389 self.flags['common'].append("-mcpu=%s" % target.core.lower()[:-2])
kadonotakashi 0:8fdf9a60065b 390 self.flags['ld'].append("--cpu=%s" % target.core.lower()[:-2])
kadonotakashi 0:8fdf9a60065b 391 self.SHEBANG += " -mcpu=%s" % target.core.lower()[:-2]
kadonotakashi 0:8fdf9a60065b 392 elif target.core.lower().endswith("f"):
kadonotakashi 0:8fdf9a60065b 393 self.flags['common'].append("-mcpu=%s" % target.core.lower()[:-1])
kadonotakashi 0:8fdf9a60065b 394 self.flags['ld'].append("--cpu=%s" % target.core.lower()[:-1])
kadonotakashi 0:8fdf9a60065b 395 self.SHEBANG += " -mcpu=%s" % target.core.lower()[:-1]
kadonotakashi 0:8fdf9a60065b 396 elif target.core.startswith("Cortex-M33"):
kadonotakashi 0:8fdf9a60065b 397 self.flags['common'].append("-mcpu=cortex-m33+nodsp")
kadonotakashi 0:8fdf9a60065b 398 self.flags['common'].append("-mfpu=none")
kadonotakashi 0:8fdf9a60065b 399 self.flags['ld'].append("--cpu=Cortex-M33.no_dsp.no_fp")
kadonotakashi 0:8fdf9a60065b 400 elif not target.core.startswith("Cortex-M23"):
kadonotakashi 0:8fdf9a60065b 401 self.flags['common'].append("-mcpu=%s" % target.core.lower())
kadonotakashi 0:8fdf9a60065b 402 self.flags['ld'].append("--cpu=%s" % target.core.lower())
kadonotakashi 0:8fdf9a60065b 403 self.SHEBANG += " -mcpu=%s" % target.core.lower()
kadonotakashi 0:8fdf9a60065b 404
kadonotakashi 0:8fdf9a60065b 405 if target.core == "Cortex-M4F":
kadonotakashi 0:8fdf9a60065b 406 self.flags['common'].append("-mfpu=fpv4-sp-d16")
kadonotakashi 0:8fdf9a60065b 407 self.flags['common'].append("-mfloat-abi=hard")
kadonotakashi 0:8fdf9a60065b 408 elif target.core == "Cortex-M7F":
kadonotakashi 0:8fdf9a60065b 409 self.flags['common'].append("-mfpu=fpv5-sp-d16")
kadonotakashi 0:8fdf9a60065b 410 self.flags['common'].append("-mfloat-abi=softfp")
kadonotakashi 0:8fdf9a60065b 411 elif target.core == "Cortex-M7FD":
kadonotakashi 0:8fdf9a60065b 412 self.flags['common'].append("-mfpu=fpv5-d16")
kadonotakashi 0:8fdf9a60065b 413 self.flags['common'].append("-mfloat-abi=softfp")
kadonotakashi 0:8fdf9a60065b 414 elif target.core.startswith("Cortex-M23"):
kadonotakashi 0:8fdf9a60065b 415 self.flags['common'].append("-march=armv8-m.base")
kadonotakashi 0:8fdf9a60065b 416
kadonotakashi 0:8fdf9a60065b 417 if target.core == "Cortex-M23" or target.core == "Cortex-M33":
kadonotakashi 0:8fdf9a60065b 418 self.flags['cxx'].append("-mcmse")
kadonotakashi 0:8fdf9a60065b 419 self.flags['c'].append("-mcmse")
kadonotakashi 0:8fdf9a60065b 420
kadonotakashi 0:8fdf9a60065b 421 # Create Secure library
kadonotakashi 0:8fdf9a60065b 422 if ((target.core == "Cortex-M23" or self.target.core == "Cortex-M33") and
kadonotakashi 0:8fdf9a60065b 423 kwargs.get('build_dir', False)):
kadonotakashi 0:8fdf9a60065b 424 build_dir = kwargs['build_dir']
kadonotakashi 0:8fdf9a60065b 425 secure_file = join(build_dir, "cmse_lib.o")
kadonotakashi 0:8fdf9a60065b 426 self.flags["ld"] += ["--import_cmse_lib_out=%s" % secure_file]
kadonotakashi 0:8fdf9a60065b 427 # Add linking time preprocessor macro DOMAIN_NS
kadonotakashi 0:8fdf9a60065b 428 if target.core == "Cortex-M23-NS" or self.target.core == "Cortex-M33-NS":
kadonotakashi 0:8fdf9a60065b 429 define_string = self.make_ld_define("DOMAIN_NS", "0x1")
kadonotakashi 0:8fdf9a60065b 430 self.flags["ld"].append(define_string)
kadonotakashi 0:8fdf9a60065b 431
kadonotakashi 0:8fdf9a60065b 432 asm_cpu = {
kadonotakashi 0:8fdf9a60065b 433 "Cortex-M0+": "Cortex-M0",
kadonotakashi 0:8fdf9a60065b 434 "Cortex-M4F": "Cortex-M4.fp",
kadonotakashi 0:8fdf9a60065b 435 "Cortex-M7F": "Cortex-M7.fp.sp",
kadonotakashi 0:8fdf9a60065b 436 "Cortex-M7FD": "Cortex-M7.fp.dp",
kadonotakashi 0:8fdf9a60065b 437 "Cortex-M23-NS": "Cortex-M23",
kadonotakashi 0:8fdf9a60065b 438 "Cortex-M33-NS": "Cortex-M33" }.get(target.core, target.core)
kadonotakashi 0:8fdf9a60065b 439
kadonotakashi 0:8fdf9a60065b 440 if target.core.startswith("Cortex-M33"):
kadonotakashi 0:8fdf9a60065b 441 self.flags['asm'].append("--cpu=Cortex-M33.no_dsp.no_fp")
kadonotakashi 0:8fdf9a60065b 442 else :
kadonotakashi 0:8fdf9a60065b 443 self.flags['asm'].append("--cpu=%s" % asm_cpu)
kadonotakashi 0:8fdf9a60065b 444
kadonotakashi 0:8fdf9a60065b 445 self.cc = ([join(TOOLCHAIN_PATHS["ARMC6"], "armclang")] +
kadonotakashi 0:8fdf9a60065b 446 self.flags['common'] + self.flags['c'])
kadonotakashi 0:8fdf9a60065b 447 self.cppc = ([join(TOOLCHAIN_PATHS["ARMC6"], "armclang")] +
kadonotakashi 0:8fdf9a60065b 448 self.flags['common'] + self.flags['cxx'])
kadonotakashi 0:8fdf9a60065b 449 self.asm = [join(TOOLCHAIN_PATHS["ARMC6"], "armasm")] + self.flags['asm']
kadonotakashi 0:8fdf9a60065b 450 self.ld = [join(TOOLCHAIN_PATHS["ARMC6"], "armlink")] + self.flags['ld']
kadonotakashi 0:8fdf9a60065b 451 self.ar = [join(TOOLCHAIN_PATHS["ARMC6"], "armar")]
kadonotakashi 0:8fdf9a60065b 452 self.elf2bin = join(TOOLCHAIN_PATHS["ARMC6"], "fromelf")
kadonotakashi 0:8fdf9a60065b 453
kadonotakashi 0:8fdf9a60065b 454 def _get_toolchain_labels(self):
kadonotakashi 0:8fdf9a60065b 455 return ["ARM", "ARM_STD", "ARMC6"]
kadonotakashi 0:8fdf9a60065b 456
kadonotakashi 0:8fdf9a60065b 457 def parse_dependencies(self, dep_path):
kadonotakashi 0:8fdf9a60065b 458 return mbedToolchain.parse_dependencies(self, dep_path)
kadonotakashi 0:8fdf9a60065b 459
kadonotakashi 0:8fdf9a60065b 460 def is_not_supported_error(self, output):
kadonotakashi 0:8fdf9a60065b 461 return "#error [NOT_SUPPORTED]" in output
kadonotakashi 0:8fdf9a60065b 462
kadonotakashi 0:8fdf9a60065b 463 def parse_output(self, output):
kadonotakashi 0:8fdf9a60065b 464 pass
kadonotakashi 0:8fdf9a60065b 465
kadonotakashi 0:8fdf9a60065b 466 def get_config_option(self, config_header):
kadonotakashi 0:8fdf9a60065b 467 return ["-include", config_header]
kadonotakashi 0:8fdf9a60065b 468
kadonotakashi 0:8fdf9a60065b 469 def get_compile_options(self, defines, includes, for_asm=False):
kadonotakashi 0:8fdf9a60065b 470 opts = ['-D%s' % d for d in defines]
kadonotakashi 0:8fdf9a60065b 471 opts.extend(["-I%s" % i for i in includes])
kadonotakashi 0:8fdf9a60065b 472 if for_asm:
kadonotakashi 0:8fdf9a60065b 473 return ["--cpreproc",
kadonotakashi 0:8fdf9a60065b 474 "--cpreproc_opts=%s" % ",".join(self.flags['common'] + opts)]
kadonotakashi 0:8fdf9a60065b 475 else:
kadonotakashi 0:8fdf9a60065b 476 config_header = self.get_config_header()
kadonotakashi 0:8fdf9a60065b 477 if config_header:
kadonotakashi 0:8fdf9a60065b 478 opts.extend(self.get_config_option(config_header))
kadonotakashi 0:8fdf9a60065b 479 return opts
kadonotakashi 0:8fdf9a60065b 480
kadonotakashi 0:8fdf9a60065b 481 @hook_tool
kadonotakashi 0:8fdf9a60065b 482 def assemble(self, source, object, includes):
kadonotakashi 0:8fdf9a60065b 483 cmd_pre = copy(self.asm)
kadonotakashi 0:8fdf9a60065b 484 cmd_pre.extend(self.get_compile_options(
kadonotakashi 0:8fdf9a60065b 485 self.get_symbols(True), includes, for_asm=True))
kadonotakashi 0:8fdf9a60065b 486 cmd_pre.extend(["-o", object, source])
kadonotakashi 0:8fdf9a60065b 487 return [self.hook.get_cmdline_assembler(cmd_pre)]
kadonotakashi 0:8fdf9a60065b 488
kadonotakashi 0:8fdf9a60065b 489 @hook_tool
kadonotakashi 0:8fdf9a60065b 490 def compile(self, cc, source, object, includes):
kadonotakashi 0:8fdf9a60065b 491 cmd = copy(cc)
kadonotakashi 0:8fdf9a60065b 492 cmd.extend(self.get_compile_options(self.get_symbols(), includes))
kadonotakashi 0:8fdf9a60065b 493 cmd.extend(["-o", object, source])
kadonotakashi 0:8fdf9a60065b 494 cmd = self.hook.get_cmdline_compiler(cmd)
kadonotakashi 0:8fdf9a60065b 495 return [cmd]