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.

make.py 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. #! /usr/bin/env python2
  2. """
  3. mbed SDK
  4. Copyright (c) 2011-2013 ARM Limited
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. TEST BUILD & RUN
  15. """
  16. import sys
  17. from time import sleep
  18. from shutil import copy
  19. from os.path import join, abspath, dirname
  20. # Be sure that the tools directory is in the search path
  21. ROOT = abspath(join(dirname(__file__), ".."))
  22. sys.path.insert(0, ROOT)
  23. from workspace_tools.utils import args_error
  24. from workspace_tools.paths import BUILD_DIR
  25. from workspace_tools.paths import RTOS_LIBRARIES
  26. from workspace_tools.paths import ETH_LIBRARY
  27. from workspace_tools.paths import USB_HOST_LIBRARIES, USB_LIBRARIES
  28. from workspace_tools.paths import DSP_LIBRARIES
  29. from workspace_tools.paths import FS_LIBRARY
  30. from workspace_tools.paths import UBLOX_LIBRARY
  31. from workspace_tools.tests import TESTS, Test, TEST_MAP
  32. from workspace_tools.tests import TEST_MBED_LIB
  33. from workspace_tools.targets import TARGET_MAP
  34. from workspace_tools.options import get_default_options_parser
  35. from workspace_tools.build_api import build_project
  36. try:
  37. import workspace_tools.private_settings as ps
  38. except:
  39. ps = object()
  40. if __name__ == '__main__':
  41. # Parse Options
  42. parser = get_default_options_parser()
  43. parser.add_option("-p",
  44. type="int",
  45. dest="program",
  46. help="The index of the desired test program: [0-%d]" % (len(TESTS)-1))
  47. parser.add_option("-n",
  48. dest="program_name",
  49. help="The name of the desired test program")
  50. parser.add_option("-j", "--jobs",
  51. type="int",
  52. dest="jobs",
  53. default=1,
  54. help="Number of concurrent jobs (default 1). Use 0 for auto based on host machine's number of CPUs")
  55. parser.add_option("-v", "--verbose",
  56. action="store_true",
  57. dest="verbose",
  58. default=False,
  59. help="Verbose diagnostic output")
  60. parser.add_option("--silent",
  61. action="store_true",
  62. dest="silent",
  63. default=False,
  64. help="Silent diagnostic output (no copy, compile notification)")
  65. parser.add_option("-D", "",
  66. action="append",
  67. dest="macros",
  68. help="Add a macro definition")
  69. # Local run
  70. parser.add_option("--automated", action="store_true", dest="automated",
  71. default=False, help="Automated test")
  72. parser.add_option("--host", dest="host_test",
  73. default=None, help="Host test")
  74. parser.add_option("--extra", dest="extra",
  75. default=None, help="Extra files")
  76. parser.add_option("--peripherals", dest="peripherals",
  77. default=None, help="Required peripherals")
  78. parser.add_option("--dep", dest="dependencies",
  79. default=None, help="Dependencies")
  80. parser.add_option("--source", dest="source_dir",
  81. default=None, help="The source (input) directory")
  82. parser.add_option("--duration", type="int", dest="duration",
  83. default=None, help="Duration of the test")
  84. parser.add_option("--build", dest="build_dir",
  85. default=None, help="The build (output) directory")
  86. parser.add_option("-d", "--disk", dest="disk",
  87. default=None, help="The mbed disk")
  88. parser.add_option("-s", "--serial", dest="serial",
  89. default=None, help="The mbed serial port")
  90. parser.add_option("-b", "--baud", type="int", dest="baud",
  91. default=None, help="The mbed serial baud rate")
  92. parser.add_option("-L", "--list-tests", action="store_true", dest="list_tests",
  93. default=False, help="List available tests in order and exit")
  94. # Ideally, all the tests with a single "main" thread can be run with, or
  95. # without the rtos, eth, usb_host, usb, dsp, fat, ublox
  96. parser.add_option("--rtos",
  97. action="store_true", dest="rtos",
  98. default=False, help="Link with RTOS library")
  99. parser.add_option("--eth",
  100. action="store_true", dest="eth",
  101. default=False,
  102. help="Link with Ethernet library")
  103. parser.add_option("--usb_host",
  104. action="store_true",
  105. dest="usb_host",
  106. default=False,
  107. help="Link with USB Host library")
  108. parser.add_option("--usb",
  109. action="store_true",
  110. dest="usb",
  111. default=False,
  112. help="Link with USB Device library")
  113. parser.add_option("--dsp",
  114. action="store_true",
  115. dest="dsp",
  116. default=False,
  117. help="Link with DSP library")
  118. parser.add_option("--fat",
  119. action="store_true",
  120. dest="fat",
  121. default=False,
  122. help="Link with FS ad SD card file system library")
  123. parser.add_option("--ublox",
  124. action="store_true",
  125. dest="ublox",
  126. default=False,
  127. help="Link with U-Blox library")
  128. parser.add_option("--testlib",
  129. action="store_true",
  130. dest="testlib",
  131. default=False,
  132. help="Link with mbed test library")
  133. # Specify a different linker script
  134. parser.add_option("-l", "--linker", dest="linker_script",
  135. default=None, help="use the specified linker script")
  136. (options, args) = parser.parse_args()
  137. # Print available tests in order and exit
  138. if options.list_tests is True:
  139. print '\n'.join(map(str, sorted(TEST_MAP.values())))
  140. sys.exit()
  141. # force program to "0" if a source dir is specified
  142. if options.source_dir is not None:
  143. p = 0
  144. n = None
  145. else:
  146. # Program Number or name
  147. p, n = options.program, options.program_name
  148. if n is not None and p is not None:
  149. args_error(parser, "[ERROR] specify either '-n' or '-p', not both")
  150. if n:
  151. # We will transform 'n' to list of 'p' (integers which are test numbers)
  152. nlist = n.split(',')
  153. for test_id in nlist:
  154. if test_id not in TEST_MAP.keys():
  155. args_error(parser, "[ERROR] Program with name '%s' not found"% test_id)
  156. p = [TEST_MAP[n].n for n in nlist]
  157. elif p is None or (p < 0) or (p > (len(TESTS)-1)):
  158. message = "[ERROR] You have to specify one of the following tests:\n"
  159. message += '\n'.join(map(str, sorted(TEST_MAP.values())))
  160. args_error(parser, message)
  161. # If 'p' was set via -n to list of numbers make this a single element integer list
  162. if type(p) != type([]):
  163. p = [p]
  164. # Target
  165. if options.mcu is None :
  166. args_error(parser, "[ERROR] You should specify an MCU")
  167. mcu = options.mcu
  168. # Toolchain
  169. if options.tool is None:
  170. args_error(parser, "[ERROR] You should specify a TOOLCHAIN")
  171. toolchain = options.tool
  172. # Test
  173. for test_no in p:
  174. test = Test(test_no)
  175. if options.automated is not None: test.automated = options.automated
  176. if options.dependencies is not None: test.dependencies = options.dependencies
  177. if options.host_test is not None: test.host_test = options.host_test;
  178. if options.peripherals is not None: test.peripherals = options.peripherals;
  179. if options.duration is not None: test.duration = options.duration;
  180. if options.extra is not None: test.extra_files = options.extra
  181. if not test.is_supported(mcu, toolchain):
  182. print 'The selected test is not supported on target %s with toolchain %s' % (mcu, toolchain)
  183. sys.exit()
  184. # Linking with extra libraries
  185. if options.rtos: test.dependencies.append(RTOS_LIBRARIES)
  186. if options.eth: test.dependencies.append(ETH_LIBRARY)
  187. if options.usb_host: test.dependencies.append(USB_HOST_LIBRARIES)
  188. if options.usb: test.dependencies.append(USB_LIBRARIES)
  189. if options.dsp: test.dependencies.append(DSP_LIBRARIES)
  190. if options.fat: test.dependencies.append(FS_LIBRARY)
  191. if options.ublox: test.dependencies.append(UBLOX_LIBRARY)
  192. if options.testlib: test.dependencies.append(TEST_MBED_LIB)
  193. build_dir = join(BUILD_DIR, "test", mcu, toolchain, test.id)
  194. if options.source_dir is not None:
  195. test.source_dir = options.source_dir
  196. build_dir = options.source_dir
  197. if options.build_dir is not None:
  198. build_dir = options.build_dir
  199. target = TARGET_MAP[mcu]
  200. try:
  201. bin_file = build_project(test.source_dir, build_dir, target, toolchain, test.dependencies, options.options,
  202. linker_script=options.linker_script,
  203. clean=options.clean,
  204. verbose=options.verbose,
  205. silent=options.silent,
  206. macros=options.macros,
  207. jobs=options.jobs)
  208. print 'Image: %s'% bin_file
  209. if options.disk:
  210. # Simple copy to the mbed disk
  211. copy(bin_file, options.disk)
  212. if options.serial:
  213. # Import pyserial: https://pypi.python.org/pypi/pyserial
  214. from serial import Serial
  215. sleep(target.program_cycle_s())
  216. serial = Serial(options.serial, timeout = 1)
  217. if options.baud:
  218. serial.setBaudrate(options.baud)
  219. serial.flushInput()
  220. serial.flushOutput()
  221. try:
  222. serial.sendBreak()
  223. except:
  224. # In linux a termios.error is raised in sendBreak and in setBreak.
  225. # The following setBreak() is needed to release the reset signal on the target mcu.
  226. try:
  227. serial.setBreak(False)
  228. except:
  229. pass
  230. while True:
  231. c = serial.read(512)
  232. sys.stdout.write(c)
  233. sys.stdout.flush()
  234. except KeyboardInterrupt, e:
  235. print "\n[CTRL+c] exit"
  236. except Exception,e:
  237. if options.verbose:
  238. import traceback
  239. traceback.print_exc(file=sys.stdout)
  240. else:
  241. print "[ERROR] %s" % str(e)