Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

arm.py 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. """
  2. mbed SDK
  3. Copyright (c) 2011-2013 ARM Limited
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. """
  14. import re
  15. from os.path import join
  16. from workspace_tools.toolchains import mbedToolchain
  17. from workspace_tools.settings import ARM_BIN, ARM_INC, ARM_LIB, MY_ARM_CLIB, ARM_CPPLIB
  18. from workspace_tools.hooks import hook_tool
  19. from workspace_tools.settings import GOANNA_PATH
  20. class ARM(mbedToolchain):
  21. LINKER_EXT = '.sct'
  22. LIBRARY_EXT = '.ar'
  23. STD_LIB_NAME = "%s.ar"
  24. DIAGNOSTIC_PATTERN = re.compile('"(?P<file>[^"]+)", line (?P<line>\d+): (?P<severity>Warning|Error): (?P<message>.+)')
  25. DEP_PATTERN = re.compile('\S+:\s(?P<file>.+)\n')
  26. def __init__(self, target, options=None, notify=None, macros=None, silent=False):
  27. mbedToolchain.__init__(self, target, options, notify, macros, silent)
  28. if target.core == "Cortex-M0+":
  29. cpu = "Cortex-M0"
  30. elif target.core == "Cortex-M4F":
  31. cpu = "Cortex-M4.fp"
  32. elif target.core == "Cortex-M7F":
  33. cpu = "Cortex-M7.fp.sp"
  34. else:
  35. cpu = target.core
  36. main_cc = join(ARM_BIN, "armcc")
  37. common = ["-c",
  38. "--cpu=%s" % cpu, "--gnu",
  39. "-Otime", "--split_sections", "--apcs=interwork",
  40. "--brief_diagnostics", "--restrict", "--multibyte_chars"
  41. ]
  42. if "save-asm" in self.options:
  43. common.extend(["--asm", "--interleave"])
  44. if "debug-info" in self.options:
  45. common.append("-g")
  46. common.append("-O0")
  47. else:
  48. common.append("-O3")
  49. common_c = [
  50. "--md", "--no_depend_system_headers",
  51. '-I%s' % ARM_INC
  52. ]
  53. self.asm = [main_cc] + common + ['-I%s' % ARM_INC]
  54. if not "analyze" in self.options:
  55. self.cc = [main_cc] + common + common_c + ["--c99"]
  56. self.cppc = [main_cc] + common + common_c + ["--cpp", "--no_rtti"]
  57. else:
  58. self.cc = [join(GOANNA_PATH, "goannacc"), "--with-cc=" + main_cc.replace('\\', '/'), "--dialect=armcc", '--output-format="%s"' % self.GOANNA_FORMAT] + common + common_c + ["--c99"]
  59. self.cppc= [join(GOANNA_PATH, "goannac++"), "--with-cxx=" + main_cc.replace('\\', '/'), "--dialect=armcc", '--output-format="%s"' % self.GOANNA_FORMAT] + common + common_c + ["--cpp", "--no_rtti"]
  60. self.ld = [join(ARM_BIN, "armlink")]
  61. self.sys_libs = []
  62. self.ar = join(ARM_BIN, "armar")
  63. self.elf2bin = join(ARM_BIN, "fromelf")
  64. def remove_option(self, option):
  65. for tool in [self.asm, self.cc, self.cppc]:
  66. if option in tool:
  67. tool.remove(option)
  68. def assemble(self, source, object, includes):
  69. # Preprocess first, then assemble
  70. tempfile = object + '.E.s'
  71. return [
  72. self.asm + ['-D%s' % s for s in self.get_symbols() + self.macros] + ["-I%s" % i for i in includes] + ["-E", "-o", tempfile, source],
  73. self.hook.get_cmdline_assembler(self.asm + ["-o", object, tempfile])
  74. ]
  75. def parse_dependencies(self, dep_path):
  76. dependencies = []
  77. for line in open(dep_path).readlines():
  78. match = ARM.DEP_PATTERN.match(line)
  79. if match is not None:
  80. dependencies.append(match.group('file'))
  81. return dependencies
  82. def parse_output(self, output):
  83. for line in output.splitlines():
  84. match = ARM.DIAGNOSTIC_PATTERN.match(line)
  85. if match is not None:
  86. self.cc_info(
  87. match.group('severity').lower(),
  88. match.group('file'),
  89. match.group('line'),
  90. match.group('message'),
  91. target_name=self.target.name,
  92. toolchain_name=self.name
  93. )
  94. match = self.goanna_parse_line(line)
  95. if match is not None:
  96. self.cc_info(
  97. match.group('severity').lower(),
  98. match.group('file'),
  99. match.group('line'),
  100. match.group('message')
  101. )
  102. def get_dep_opt(self, dep_path):
  103. return ["--depend", dep_path]
  104. def archive(self, objects, lib_path):
  105. self.default_cmd([self.ar, '-r', lib_path] + objects)
  106. def link(self, output, objects, libraries, lib_dirs, mem_map):
  107. if len(lib_dirs):
  108. args = ["-o", output, "--userlibpath", ",".join(lib_dirs), "--info=totals", "--list=.link_totals.txt"]
  109. else:
  110. args = ["-o", output, "--info=totals", "--list=.link_totals.txt"]
  111. if mem_map:
  112. args.extend(["--scatter", mem_map])
  113. if hasattr(self.target, "link_cmdline_hook"):
  114. args = self.target.link_cmdline_hook(self.__class__.__name__, args)
  115. self.default_cmd(self.ld + args + objects + libraries + self.sys_libs)
  116. @hook_tool
  117. def binary(self, resources, elf, bin):
  118. args = [self.elf2bin, '--bin', '-o', bin, elf]
  119. if hasattr(self.target, "binary_cmdline_hook"):
  120. args = self.target.binary_cmdline_hook(self.__class__.__name__, args)
  121. self.default_cmd(args)
  122. class ARM_STD(ARM):
  123. def __init__(self, target, options=None, notify=None, macros=None, silent=False):
  124. ARM.__init__(self, target, options, notify, macros, silent)
  125. self.cc += ["-D__ASSERT_MSG"]
  126. self.cppc += ["-D__ASSERT_MSG"]
  127. self.ld.append("--libpath=%s" % ARM_LIB)
  128. class ARM_MICRO(ARM):
  129. PATCHED_LIBRARY = False
  130. def __init__(self, target, options=None, notify=None, macros=None, silent=False):
  131. ARM.__init__(self, target, options, notify, macros, silent)
  132. # Compiler
  133. self.asm += ["-D__MICROLIB"]
  134. self.cc += ["--library_type=microlib", "-D__MICROLIB", "-D__ASSERT_MSG"]
  135. self.cppc += ["--library_type=microlib", "-D__MICROLIB", "-D__ASSERT_MSG"]
  136. # Linker
  137. self.ld.append("--library_type=microlib")
  138. # We had to patch microlib to add C++ support
  139. # In later releases this patch should have entered mainline
  140. if ARM_MICRO.PATCHED_LIBRARY:
  141. self.ld.append("--noscanlib")
  142. # System Libraries
  143. self.sys_libs.extend([join(MY_ARM_CLIB, lib+".l") for lib in ["mc_p", "mf_p", "m_ps"]])
  144. if target.core == "Cortex-M3":
  145. self.sys_libs.extend([join(ARM_CPPLIB, lib+".l") for lib in ["cpp_ws", "cpprt_w"]])
  146. elif target.core in ["Cortex-M0", "Cortex-M0+"]:
  147. self.sys_libs.extend([join(ARM_CPPLIB, lib+".l") for lib in ["cpp_ps", "cpprt_p"]])
  148. else:
  149. self.ld.append("--libpath=%s" % ARM_LIB)