Nicolas Borla
/
BBR_1Ebene
BBR 1 Ebene
mbed-os/tools/make.py@0:fbdae7e6d805, 2018-05-14 (annotated)
- Committer:
- borlanic
- Date:
- Mon May 14 11:29:06 2018 +0000
- Revision:
- 0:fbdae7e6d805
BBR
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
borlanic | 0:fbdae7e6d805 | 1 | #! /usr/bin/env python2 |
borlanic | 0:fbdae7e6d805 | 2 | """ |
borlanic | 0:fbdae7e6d805 | 3 | mbed SDK |
borlanic | 0:fbdae7e6d805 | 4 | Copyright (c) 2011-2013 ARM Limited |
borlanic | 0:fbdae7e6d805 | 5 | |
borlanic | 0:fbdae7e6d805 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); |
borlanic | 0:fbdae7e6d805 | 7 | you may not use this file except in compliance with the License. |
borlanic | 0:fbdae7e6d805 | 8 | You may obtain a copy of the License at |
borlanic | 0:fbdae7e6d805 | 9 | |
borlanic | 0:fbdae7e6d805 | 10 | http://www.apache.org/licenses/LICENSE-2.0 |
borlanic | 0:fbdae7e6d805 | 11 | |
borlanic | 0:fbdae7e6d805 | 12 | Unless required by applicable law or agreed to in writing, software |
borlanic | 0:fbdae7e6d805 | 13 | distributed under the License is distributed on an "AS IS" BASIS, |
borlanic | 0:fbdae7e6d805 | 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
borlanic | 0:fbdae7e6d805 | 15 | See the License for the specific language governing permissions and |
borlanic | 0:fbdae7e6d805 | 16 | limitations under the License. |
borlanic | 0:fbdae7e6d805 | 17 | |
borlanic | 0:fbdae7e6d805 | 18 | |
borlanic | 0:fbdae7e6d805 | 19 | TEST BUILD & RUN |
borlanic | 0:fbdae7e6d805 | 20 | """ |
borlanic | 0:fbdae7e6d805 | 21 | from __future__ import print_function |
borlanic | 0:fbdae7e6d805 | 22 | from builtins import str |
borlanic | 0:fbdae7e6d805 | 23 | import sys |
borlanic | 0:fbdae7e6d805 | 24 | import json |
borlanic | 0:fbdae7e6d805 | 25 | from time import sleep |
borlanic | 0:fbdae7e6d805 | 26 | from shutil import copy |
borlanic | 0:fbdae7e6d805 | 27 | from os.path import join, abspath, dirname |
borlanic | 0:fbdae7e6d805 | 28 | from json import load, dump |
borlanic | 0:fbdae7e6d805 | 29 | |
borlanic | 0:fbdae7e6d805 | 30 | # Be sure that the tools directory is in the search path |
borlanic | 0:fbdae7e6d805 | 31 | ROOT = abspath(join(dirname(__file__), "..")) |
borlanic | 0:fbdae7e6d805 | 32 | sys.path.insert(0, ROOT) |
borlanic | 0:fbdae7e6d805 | 33 | |
borlanic | 0:fbdae7e6d805 | 34 | from tools.utils import args_error |
borlanic | 0:fbdae7e6d805 | 35 | from tools.utils import NotSupportedException |
borlanic | 0:fbdae7e6d805 | 36 | from tools.paths import BUILD_DIR |
borlanic | 0:fbdae7e6d805 | 37 | from tools.paths import MBED_LIBRARIES |
borlanic | 0:fbdae7e6d805 | 38 | from tools.paths import RPC_LIBRARY |
borlanic | 0:fbdae7e6d805 | 39 | from tools.paths import USB_LIBRARIES |
borlanic | 0:fbdae7e6d805 | 40 | from tools.paths import DSP_LIBRARIES |
borlanic | 0:fbdae7e6d805 | 41 | from tools.tests import TESTS, Test, TEST_MAP |
borlanic | 0:fbdae7e6d805 | 42 | from tools.tests import TEST_MBED_LIB |
borlanic | 0:fbdae7e6d805 | 43 | from tools.tests import test_known, test_name_known |
borlanic | 0:fbdae7e6d805 | 44 | from tools.targets import TARGET_MAP |
borlanic | 0:fbdae7e6d805 | 45 | from tools.options import get_default_options_parser |
borlanic | 0:fbdae7e6d805 | 46 | from tools.options import extract_profile |
borlanic | 0:fbdae7e6d805 | 47 | from tools.options import extract_mcus |
borlanic | 0:fbdae7e6d805 | 48 | from tools.notifier.term import TerminalNotifier |
borlanic | 0:fbdae7e6d805 | 49 | from tools.build_api import build_project |
borlanic | 0:fbdae7e6d805 | 50 | from tools.build_api import mcu_toolchain_matrix |
borlanic | 0:fbdae7e6d805 | 51 | from tools.build_api import mcu_toolchain_list |
borlanic | 0:fbdae7e6d805 | 52 | from tools.build_api import mcu_target_list |
borlanic | 0:fbdae7e6d805 | 53 | from tools.build_api import merge_build_data |
borlanic | 0:fbdae7e6d805 | 54 | from utils import argparse_filestring_type |
borlanic | 0:fbdae7e6d805 | 55 | from utils import argparse_many |
borlanic | 0:fbdae7e6d805 | 56 | from utils import argparse_dir_not_parent |
borlanic | 0:fbdae7e6d805 | 57 | from tools.toolchains import mbedToolchain, TOOLCHAIN_CLASSES, TOOLCHAIN_PATHS |
borlanic | 0:fbdae7e6d805 | 58 | |
borlanic | 0:fbdae7e6d805 | 59 | if __name__ == '__main__': |
borlanic | 0:fbdae7e6d805 | 60 | # Parse Options |
borlanic | 0:fbdae7e6d805 | 61 | parser = get_default_options_parser(add_app_config=True) |
borlanic | 0:fbdae7e6d805 | 62 | group = parser.add_mutually_exclusive_group(required=False) |
borlanic | 0:fbdae7e6d805 | 63 | group.add_argument( |
borlanic | 0:fbdae7e6d805 | 64 | "-p", |
borlanic | 0:fbdae7e6d805 | 65 | type=argparse_many(test_known), |
borlanic | 0:fbdae7e6d805 | 66 | dest="program", |
borlanic | 0:fbdae7e6d805 | 67 | help="The index of the desired test program: [0-%d]" % (len(TESTS)-1)) |
borlanic | 0:fbdae7e6d805 | 68 | |
borlanic | 0:fbdae7e6d805 | 69 | group.add_argument( |
borlanic | 0:fbdae7e6d805 | 70 | "-n", |
borlanic | 0:fbdae7e6d805 | 71 | type=argparse_many(test_name_known), |
borlanic | 0:fbdae7e6d805 | 72 | dest="program", |
borlanic | 0:fbdae7e6d805 | 73 | help="The name of the desired test program") |
borlanic | 0:fbdae7e6d805 | 74 | |
borlanic | 0:fbdae7e6d805 | 75 | parser.add_argument( |
borlanic | 0:fbdae7e6d805 | 76 | "-j", "--jobs", |
borlanic | 0:fbdae7e6d805 | 77 | type=int, |
borlanic | 0:fbdae7e6d805 | 78 | dest="jobs", |
borlanic | 0:fbdae7e6d805 | 79 | default=0, |
borlanic | 0:fbdae7e6d805 | 80 | help="Number of concurrent jobs. Default: 0/auto (based on host machine's number of CPUs)") |
borlanic | 0:fbdae7e6d805 | 81 | |
borlanic | 0:fbdae7e6d805 | 82 | parser.add_argument( |
borlanic | 0:fbdae7e6d805 | 83 | "-v", "--verbose", |
borlanic | 0:fbdae7e6d805 | 84 | action="store_true", |
borlanic | 0:fbdae7e6d805 | 85 | dest="verbose", |
borlanic | 0:fbdae7e6d805 | 86 | default=False, |
borlanic | 0:fbdae7e6d805 | 87 | help="Verbose diagnostic output") |
borlanic | 0:fbdae7e6d805 | 88 | |
borlanic | 0:fbdae7e6d805 | 89 | parser.add_argument( |
borlanic | 0:fbdae7e6d805 | 90 | "--silent", |
borlanic | 0:fbdae7e6d805 | 91 | action="store_true", |
borlanic | 0:fbdae7e6d805 | 92 | dest="silent", |
borlanic | 0:fbdae7e6d805 | 93 | default=False, |
borlanic | 0:fbdae7e6d805 | 94 | help="Silent diagnostic output (no copy, compile notification)") |
borlanic | 0:fbdae7e6d805 | 95 | |
borlanic | 0:fbdae7e6d805 | 96 | parser.add_argument( |
borlanic | 0:fbdae7e6d805 | 97 | "-D", |
borlanic | 0:fbdae7e6d805 | 98 | action="append", |
borlanic | 0:fbdae7e6d805 | 99 | dest="macros", |
borlanic | 0:fbdae7e6d805 | 100 | help="Add a macro definition") |
borlanic | 0:fbdae7e6d805 | 101 | |
borlanic | 0:fbdae7e6d805 | 102 | group.add_argument( |
borlanic | 0:fbdae7e6d805 | 103 | "-S", "--supported-toolchains", |
borlanic | 0:fbdae7e6d805 | 104 | dest="supported_toolchains", |
borlanic | 0:fbdae7e6d805 | 105 | default=False, |
borlanic | 0:fbdae7e6d805 | 106 | const="matrix", |
borlanic | 0:fbdae7e6d805 | 107 | choices=["matrix", "toolchains", "targets"], |
borlanic | 0:fbdae7e6d805 | 108 | nargs="?", |
borlanic | 0:fbdae7e6d805 | 109 | help="Displays supported matrix of MCUs and toolchains") |
borlanic | 0:fbdae7e6d805 | 110 | |
borlanic | 0:fbdae7e6d805 | 111 | parser.add_argument( |
borlanic | 0:fbdae7e6d805 | 112 | '-f', '--filter', |
borlanic | 0:fbdae7e6d805 | 113 | dest='general_filter_regex', |
borlanic | 0:fbdae7e6d805 | 114 | default=None, |
borlanic | 0:fbdae7e6d805 | 115 | help='For some commands you can use filter to filter out results') |
borlanic | 0:fbdae7e6d805 | 116 | |
borlanic | 0:fbdae7e6d805 | 117 | parser.add_argument( |
borlanic | 0:fbdae7e6d805 | 118 | "--stats-depth", |
borlanic | 0:fbdae7e6d805 | 119 | type=int, |
borlanic | 0:fbdae7e6d805 | 120 | dest="stats_depth", |
borlanic | 0:fbdae7e6d805 | 121 | default=2, |
borlanic | 0:fbdae7e6d805 | 122 | help="Depth level for static memory report") |
borlanic | 0:fbdae7e6d805 | 123 | |
borlanic | 0:fbdae7e6d805 | 124 | # Local run |
borlanic | 0:fbdae7e6d805 | 125 | parser.add_argument("--automated", action="store_true", dest="automated", |
borlanic | 0:fbdae7e6d805 | 126 | default=False, help="Automated test") |
borlanic | 0:fbdae7e6d805 | 127 | parser.add_argument("--host", dest="host_test", |
borlanic | 0:fbdae7e6d805 | 128 | default=None, help="Host test") |
borlanic | 0:fbdae7e6d805 | 129 | parser.add_argument("--extra", dest="extra", |
borlanic | 0:fbdae7e6d805 | 130 | default=None, help="Extra files") |
borlanic | 0:fbdae7e6d805 | 131 | parser.add_argument("--peripherals", dest="peripherals", |
borlanic | 0:fbdae7e6d805 | 132 | default=None, help="Required peripherals") |
borlanic | 0:fbdae7e6d805 | 133 | parser.add_argument("--dep", dest="dependencies", |
borlanic | 0:fbdae7e6d805 | 134 | default=None, help="Dependencies") |
borlanic | 0:fbdae7e6d805 | 135 | parser.add_argument("--source", dest="source_dir", type=argparse_filestring_type, |
borlanic | 0:fbdae7e6d805 | 136 | default=None, help="The source (input) directory", action="append") |
borlanic | 0:fbdae7e6d805 | 137 | parser.add_argument("--duration", type=int, dest="duration", |
borlanic | 0:fbdae7e6d805 | 138 | default=None, help="Duration of the test") |
borlanic | 0:fbdae7e6d805 | 139 | parser.add_argument("--build", dest="build_dir", type=argparse_dir_not_parent(ROOT), |
borlanic | 0:fbdae7e6d805 | 140 | default=None, help="The build (output) directory") |
borlanic | 0:fbdae7e6d805 | 141 | parser.add_argument("-N", "--artifact-name", dest="artifact_name", |
borlanic | 0:fbdae7e6d805 | 142 | default=None, help="The built project's name") |
borlanic | 0:fbdae7e6d805 | 143 | parser.add_argument("-d", "--disk", dest="disk", |
borlanic | 0:fbdae7e6d805 | 144 | default=None, help="The mbed disk") |
borlanic | 0:fbdae7e6d805 | 145 | parser.add_argument("-s", "--serial", dest="serial", |
borlanic | 0:fbdae7e6d805 | 146 | default=None, help="The mbed serial port") |
borlanic | 0:fbdae7e6d805 | 147 | parser.add_argument("-b", "--baud", type=int, dest="baud", |
borlanic | 0:fbdae7e6d805 | 148 | default=None, help="The mbed serial baud rate") |
borlanic | 0:fbdae7e6d805 | 149 | group.add_argument("-L", "--list-tests", action="store_true", dest="list_tests", |
borlanic | 0:fbdae7e6d805 | 150 | default=False, help="List available tests in order and exit") |
borlanic | 0:fbdae7e6d805 | 151 | |
borlanic | 0:fbdae7e6d805 | 152 | # Ideally, all the tests with a single "main" thread can be run with, or |
borlanic | 0:fbdae7e6d805 | 153 | # without the usb, dsp |
borlanic | 0:fbdae7e6d805 | 154 | parser.add_argument("--rpc", |
borlanic | 0:fbdae7e6d805 | 155 | action="store_true", dest="rpc", |
borlanic | 0:fbdae7e6d805 | 156 | default=False, help="Link with RPC library") |
borlanic | 0:fbdae7e6d805 | 157 | |
borlanic | 0:fbdae7e6d805 | 158 | parser.add_argument("--usb", |
borlanic | 0:fbdae7e6d805 | 159 | action="store_true", |
borlanic | 0:fbdae7e6d805 | 160 | dest="usb", |
borlanic | 0:fbdae7e6d805 | 161 | default=False, |
borlanic | 0:fbdae7e6d805 | 162 | help="Link with USB Device library") |
borlanic | 0:fbdae7e6d805 | 163 | |
borlanic | 0:fbdae7e6d805 | 164 | parser.add_argument("--dsp", |
borlanic | 0:fbdae7e6d805 | 165 | action="store_true", |
borlanic | 0:fbdae7e6d805 | 166 | dest="dsp", |
borlanic | 0:fbdae7e6d805 | 167 | default=False, |
borlanic | 0:fbdae7e6d805 | 168 | help="Link with DSP library") |
borlanic | 0:fbdae7e6d805 | 169 | |
borlanic | 0:fbdae7e6d805 | 170 | parser.add_argument("--testlib", |
borlanic | 0:fbdae7e6d805 | 171 | action="store_true", |
borlanic | 0:fbdae7e6d805 | 172 | dest="testlib", |
borlanic | 0:fbdae7e6d805 | 173 | default=False, |
borlanic | 0:fbdae7e6d805 | 174 | help="Link with mbed test library") |
borlanic | 0:fbdae7e6d805 | 175 | |
borlanic | 0:fbdae7e6d805 | 176 | parser.add_argument("--build-data", |
borlanic | 0:fbdae7e6d805 | 177 | dest="build_data", |
borlanic | 0:fbdae7e6d805 | 178 | default=None, |
borlanic | 0:fbdae7e6d805 | 179 | help="Dump build_data to this file") |
borlanic | 0:fbdae7e6d805 | 180 | |
borlanic | 0:fbdae7e6d805 | 181 | # Specify a different linker script |
borlanic | 0:fbdae7e6d805 | 182 | parser.add_argument("-l", "--linker", dest="linker_script", |
borlanic | 0:fbdae7e6d805 | 183 | type=argparse_filestring_type, |
borlanic | 0:fbdae7e6d805 | 184 | default=None, help="use the specified linker script") |
borlanic | 0:fbdae7e6d805 | 185 | |
borlanic | 0:fbdae7e6d805 | 186 | options = parser.parse_args() |
borlanic | 0:fbdae7e6d805 | 187 | |
borlanic | 0:fbdae7e6d805 | 188 | # Only prints matrix of supported toolchains |
borlanic | 0:fbdae7e6d805 | 189 | if options.supported_toolchains: |
borlanic | 0:fbdae7e6d805 | 190 | if options.supported_toolchains == "matrix": |
borlanic | 0:fbdae7e6d805 | 191 | print(mcu_toolchain_matrix(platform_filter=options.general_filter_regex)) |
borlanic | 0:fbdae7e6d805 | 192 | elif options.supported_toolchains == "toolchains": |
borlanic | 0:fbdae7e6d805 | 193 | toolchain_list = mcu_toolchain_list() |
borlanic | 0:fbdae7e6d805 | 194 | # Only print the lines that matter |
borlanic | 0:fbdae7e6d805 | 195 | for line in toolchain_list.split("\n"): |
borlanic | 0:fbdae7e6d805 | 196 | if not "mbed" in line: |
borlanic | 0:fbdae7e6d805 | 197 | print(line) |
borlanic | 0:fbdae7e6d805 | 198 | elif options.supported_toolchains == "targets": |
borlanic | 0:fbdae7e6d805 | 199 | print(mcu_target_list()) |
borlanic | 0:fbdae7e6d805 | 200 | exit(0) |
borlanic | 0:fbdae7e6d805 | 201 | |
borlanic | 0:fbdae7e6d805 | 202 | # Print available tests in order and exit |
borlanic | 0:fbdae7e6d805 | 203 | if options.list_tests is True: |
borlanic | 0:fbdae7e6d805 | 204 | print('\n'.join(map(str, sorted(TEST_MAP.values())))) |
borlanic | 0:fbdae7e6d805 | 205 | sys.exit() |
borlanic | 0:fbdae7e6d805 | 206 | |
borlanic | 0:fbdae7e6d805 | 207 | # force program to "0" if a source dir is specified |
borlanic | 0:fbdae7e6d805 | 208 | if options.source_dir is not None: |
borlanic | 0:fbdae7e6d805 | 209 | p = 0 |
borlanic | 0:fbdae7e6d805 | 210 | else: |
borlanic | 0:fbdae7e6d805 | 211 | # Program Number or name |
borlanic | 0:fbdae7e6d805 | 212 | p = options.program |
borlanic | 0:fbdae7e6d805 | 213 | |
borlanic | 0:fbdae7e6d805 | 214 | # If 'p' was set via -n to list of numbers make this a single element integer list |
borlanic | 0:fbdae7e6d805 | 215 | if type(p) != type([]): |
borlanic | 0:fbdae7e6d805 | 216 | p = [p] |
borlanic | 0:fbdae7e6d805 | 217 | |
borlanic | 0:fbdae7e6d805 | 218 | # Target |
borlanic | 0:fbdae7e6d805 | 219 | if options.mcu is None : |
borlanic | 0:fbdae7e6d805 | 220 | args_error(parser, "argument -m/--mcu is required") |
borlanic | 0:fbdae7e6d805 | 221 | mcu = extract_mcus(parser, options)[0] |
borlanic | 0:fbdae7e6d805 | 222 | |
borlanic | 0:fbdae7e6d805 | 223 | # Toolchain |
borlanic | 0:fbdae7e6d805 | 224 | if options.tool is None: |
borlanic | 0:fbdae7e6d805 | 225 | args_error(parser, "argument -t/--tool is required") |
borlanic | 0:fbdae7e6d805 | 226 | toolchain = options.tool[0] |
borlanic | 0:fbdae7e6d805 | 227 | |
borlanic | 0:fbdae7e6d805 | 228 | if (options.program is None) and (not options.source_dir): |
borlanic | 0:fbdae7e6d805 | 229 | args_error(parser, "one of -p, -n, or --source is required") |
borlanic | 0:fbdae7e6d805 | 230 | |
borlanic | 0:fbdae7e6d805 | 231 | if options.source_dir and not options.build_dir: |
borlanic | 0:fbdae7e6d805 | 232 | args_error(parser, "argument --build is required when argument --source is provided") |
borlanic | 0:fbdae7e6d805 | 233 | |
borlanic | 0:fbdae7e6d805 | 234 | |
borlanic | 0:fbdae7e6d805 | 235 | notify = TerminalNotifier(options.verbose, options.silent, options.color) |
borlanic | 0:fbdae7e6d805 | 236 | |
borlanic | 0:fbdae7e6d805 | 237 | if not TOOLCHAIN_CLASSES[toolchain].check_executable(): |
borlanic | 0:fbdae7e6d805 | 238 | search_path = TOOLCHAIN_PATHS[toolchain] or "No path set" |
borlanic | 0:fbdae7e6d805 | 239 | args_error(parser, "Could not find executable for %s.\n" |
borlanic | 0:fbdae7e6d805 | 240 | "Currently set search path: %s" |
borlanic | 0:fbdae7e6d805 | 241 | %(toolchain, search_path)) |
borlanic | 0:fbdae7e6d805 | 242 | |
borlanic | 0:fbdae7e6d805 | 243 | # Test |
borlanic | 0:fbdae7e6d805 | 244 | build_data_blob = {} if options.build_data else None |
borlanic | 0:fbdae7e6d805 | 245 | for test_no in p: |
borlanic | 0:fbdae7e6d805 | 246 | test = Test(test_no) |
borlanic | 0:fbdae7e6d805 | 247 | if options.automated is not None: test.automated = options.automated |
borlanic | 0:fbdae7e6d805 | 248 | if options.dependencies is not None: test.dependencies = options.dependencies |
borlanic | 0:fbdae7e6d805 | 249 | if options.host_test is not None: test.host_test = options.host_test; |
borlanic | 0:fbdae7e6d805 | 250 | if options.peripherals is not None: test.peripherals = options.peripherals; |
borlanic | 0:fbdae7e6d805 | 251 | if options.duration is not None: test.duration = options.duration; |
borlanic | 0:fbdae7e6d805 | 252 | if options.extra is not None: test.extra_files = options.extra |
borlanic | 0:fbdae7e6d805 | 253 | |
borlanic | 0:fbdae7e6d805 | 254 | if not test.is_supported(mcu, toolchain): |
borlanic | 0:fbdae7e6d805 | 255 | print('The selected test is not supported on target %s with toolchain %s' % (mcu, toolchain)) |
borlanic | 0:fbdae7e6d805 | 256 | sys.exit() |
borlanic | 0:fbdae7e6d805 | 257 | |
borlanic | 0:fbdae7e6d805 | 258 | # Linking with extra libraries |
borlanic | 0:fbdae7e6d805 | 259 | if options.rpc: test.dependencies.append(RPC_LIBRARY) |
borlanic | 0:fbdae7e6d805 | 260 | if options.usb: test.dependencies.append(USB_LIBRARIES) |
borlanic | 0:fbdae7e6d805 | 261 | if options.dsp: test.dependencies.append(DSP_LIBRARIES) |
borlanic | 0:fbdae7e6d805 | 262 | if options.testlib: test.dependencies.append(TEST_MBED_LIB) |
borlanic | 0:fbdae7e6d805 | 263 | |
borlanic | 0:fbdae7e6d805 | 264 | build_dir = join(BUILD_DIR, "test", mcu, toolchain, test.id) |
borlanic | 0:fbdae7e6d805 | 265 | if options.source_dir is not None: |
borlanic | 0:fbdae7e6d805 | 266 | test.source_dir = options.source_dir |
borlanic | 0:fbdae7e6d805 | 267 | build_dir = options.source_dir |
borlanic | 0:fbdae7e6d805 | 268 | |
borlanic | 0:fbdae7e6d805 | 269 | if options.build_dir is not None: |
borlanic | 0:fbdae7e6d805 | 270 | build_dir = options.build_dir |
borlanic | 0:fbdae7e6d805 | 271 | |
borlanic | 0:fbdae7e6d805 | 272 | try: |
borlanic | 0:fbdae7e6d805 | 273 | bin_file = build_project(test.source_dir, build_dir, mcu, toolchain, |
borlanic | 0:fbdae7e6d805 | 274 | set(test.dependencies), |
borlanic | 0:fbdae7e6d805 | 275 | linker_script=options.linker_script, |
borlanic | 0:fbdae7e6d805 | 276 | clean=options.clean, |
borlanic | 0:fbdae7e6d805 | 277 | notify=notify, |
borlanic | 0:fbdae7e6d805 | 278 | report=build_data_blob, |
borlanic | 0:fbdae7e6d805 | 279 | macros=options.macros, |
borlanic | 0:fbdae7e6d805 | 280 | jobs=options.jobs, |
borlanic | 0:fbdae7e6d805 | 281 | name=options.artifact_name, |
borlanic | 0:fbdae7e6d805 | 282 | app_config=options.app_config, |
borlanic | 0:fbdae7e6d805 | 283 | inc_dirs=[dirname(MBED_LIBRARIES)], |
borlanic | 0:fbdae7e6d805 | 284 | build_profile=extract_profile(parser, |
borlanic | 0:fbdae7e6d805 | 285 | options, |
borlanic | 0:fbdae7e6d805 | 286 | toolchain), |
borlanic | 0:fbdae7e6d805 | 287 | stats_depth=options.stats_depth) |
borlanic | 0:fbdae7e6d805 | 288 | print('Image: %s'% bin_file) |
borlanic | 0:fbdae7e6d805 | 289 | |
borlanic | 0:fbdae7e6d805 | 290 | if options.disk: |
borlanic | 0:fbdae7e6d805 | 291 | # Simple copy to the mbed disk |
borlanic | 0:fbdae7e6d805 | 292 | copy(bin_file, options.disk) |
borlanic | 0:fbdae7e6d805 | 293 | |
borlanic | 0:fbdae7e6d805 | 294 | if options.serial: |
borlanic | 0:fbdae7e6d805 | 295 | # Import pyserial: https://pypi.python.org/pypi/pyserial |
borlanic | 0:fbdae7e6d805 | 296 | from serial import Serial |
borlanic | 0:fbdae7e6d805 | 297 | |
borlanic | 0:fbdae7e6d805 | 298 | sleep(TARGET_MAP[mcu].program_cycle_s) |
borlanic | 0:fbdae7e6d805 | 299 | |
borlanic | 0:fbdae7e6d805 | 300 | serial = Serial(options.serial, timeout = 1) |
borlanic | 0:fbdae7e6d805 | 301 | if options.baud: |
borlanic | 0:fbdae7e6d805 | 302 | serial.setBaudrate(options.baud) |
borlanic | 0:fbdae7e6d805 | 303 | |
borlanic | 0:fbdae7e6d805 | 304 | serial.flushInput() |
borlanic | 0:fbdae7e6d805 | 305 | serial.flushOutput() |
borlanic | 0:fbdae7e6d805 | 306 | |
borlanic | 0:fbdae7e6d805 | 307 | try: |
borlanic | 0:fbdae7e6d805 | 308 | serial.sendBreak() |
borlanic | 0:fbdae7e6d805 | 309 | except: |
borlanic | 0:fbdae7e6d805 | 310 | # In linux a termios.error is raised in sendBreak and in setBreak. |
borlanic | 0:fbdae7e6d805 | 311 | # The following setBreak() is needed to release the reset signal on the target mcu. |
borlanic | 0:fbdae7e6d805 | 312 | try: |
borlanic | 0:fbdae7e6d805 | 313 | serial.setBreak(False) |
borlanic | 0:fbdae7e6d805 | 314 | except: |
borlanic | 0:fbdae7e6d805 | 315 | pass |
borlanic | 0:fbdae7e6d805 | 316 | |
borlanic | 0:fbdae7e6d805 | 317 | while True: |
borlanic | 0:fbdae7e6d805 | 318 | c = serial.read(512) |
borlanic | 0:fbdae7e6d805 | 319 | sys.stdout.write(c) |
borlanic | 0:fbdae7e6d805 | 320 | sys.stdout.flush() |
borlanic | 0:fbdae7e6d805 | 321 | |
borlanic | 0:fbdae7e6d805 | 322 | except KeyboardInterrupt as e: |
borlanic | 0:fbdae7e6d805 | 323 | print("\n[CTRL+c] exit") |
borlanic | 0:fbdae7e6d805 | 324 | except NotSupportedException as e: |
borlanic | 0:fbdae7e6d805 | 325 | print("\nCould not compile for %s: %s" % (mcu, str(e))) |
borlanic | 0:fbdae7e6d805 | 326 | except Exception as e: |
borlanic | 0:fbdae7e6d805 | 327 | if options.verbose: |
borlanic | 0:fbdae7e6d805 | 328 | import traceback |
borlanic | 0:fbdae7e6d805 | 329 | traceback.print_exc(file=sys.stdout) |
borlanic | 0:fbdae7e6d805 | 330 | else: |
borlanic | 0:fbdae7e6d805 | 331 | print("[ERROR] %s" % str(e)) |
borlanic | 0:fbdae7e6d805 | 332 | |
borlanic | 0:fbdae7e6d805 | 333 | sys.exit(1) |
borlanic | 0:fbdae7e6d805 | 334 | if options.build_data: |
borlanic | 0:fbdae7e6d805 | 335 | merge_build_data(options.build_data, build_data_blob, "application") |