init

Dependencies:   mbed

Committer:
Nathan Yonkee
Date:
Fri Mar 02 07:16:49 2018 -0700
Revision:
10:46a4cf51ee38
Parent:
9:d58e77ebd769
remove mbed-os

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Nathan Yonkee 9:d58e77ebd769 1 #! /usr/bin/env python2
Nathan Yonkee 9:d58e77ebd769 2 """
Nathan Yonkee 9:d58e77ebd769 3 mbed SDK
Nathan Yonkee 9:d58e77ebd769 4 Copyright (c) 2011-2013 ARM Limited
Nathan Yonkee 9:d58e77ebd769 5
Nathan Yonkee 9:d58e77ebd769 6 Licensed under the Apache License, Version 2.0 (the "License");
Nathan Yonkee 9:d58e77ebd769 7 you may not use this file except in compliance with the License.
Nathan Yonkee 9:d58e77ebd769 8 You may obtain a copy of the License at
Nathan Yonkee 9:d58e77ebd769 9
Nathan Yonkee 9:d58e77ebd769 10 http://www.apache.org/licenses/LICENSE-2.0
Nathan Yonkee 9:d58e77ebd769 11
Nathan Yonkee 9:d58e77ebd769 12 Unless required by applicable law or agreed to in writing, software
Nathan Yonkee 9:d58e77ebd769 13 distributed under the License is distributed on an "AS IS" BASIS,
Nathan Yonkee 9:d58e77ebd769 14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Nathan Yonkee 9:d58e77ebd769 15 See the License for the specific language governing permissions and
Nathan Yonkee 9:d58e77ebd769 16 limitations under the License.
Nathan Yonkee 9:d58e77ebd769 17 """
Nathan Yonkee 9:d58e77ebd769 18 from __future__ import print_function
Nathan Yonkee 9:d58e77ebd769 19 import sys
Nathan Yonkee 9:d58e77ebd769 20 import os
Nathan Yonkee 9:d58e77ebd769 21 import re
Nathan Yonkee 9:d58e77ebd769 22
Nathan Yonkee 9:d58e77ebd769 23 ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
Nathan Yonkee 9:d58e77ebd769 24 sys.path.insert(0, ROOT)
Nathan Yonkee 9:d58e77ebd769 25
Nathan Yonkee 9:d58e77ebd769 26 from tools.options import get_default_options_parser
Nathan Yonkee 9:d58e77ebd769 27
Nathan Yonkee 9:d58e77ebd769 28 # Check: Extra modules which are required by core test suite
Nathan Yonkee 9:d58e77ebd769 29 from tools.utils import check_required_modules
Nathan Yonkee 9:d58e77ebd769 30 check_required_modules(['prettytable'])
Nathan Yonkee 9:d58e77ebd769 31
Nathan Yonkee 9:d58e77ebd769 32 # Imports related to mbed build api
Nathan Yonkee 9:d58e77ebd769 33 from tools.build_api import mcu_toolchain_matrix
Nathan Yonkee 9:d58e77ebd769 34 from tools.test_api import get_autodetected_MUTS_list
Nathan Yonkee 9:d58e77ebd769 35 from tools.test_api import get_module_avail
Nathan Yonkee 9:d58e77ebd769 36 from argparse import ArgumentParser
Nathan Yonkee 9:d58e77ebd769 37
Nathan Yonkee 9:d58e77ebd769 38 try:
Nathan Yonkee 9:d58e77ebd769 39 import mbed_lstools
Nathan Yonkee 9:d58e77ebd769 40 except:
Nathan Yonkee 9:d58e77ebd769 41 pass
Nathan Yonkee 9:d58e77ebd769 42
Nathan Yonkee 9:d58e77ebd769 43 def main():
Nathan Yonkee 9:d58e77ebd769 44 """Entry Point"""
Nathan Yonkee 9:d58e77ebd769 45 try:
Nathan Yonkee 9:d58e77ebd769 46 # Parse Options
Nathan Yonkee 9:d58e77ebd769 47 parser = ArgumentParser()
Nathan Yonkee 9:d58e77ebd769 48
Nathan Yonkee 9:d58e77ebd769 49 parser.add_argument("-S", "--supported-toolchains",
Nathan Yonkee 9:d58e77ebd769 50 action="store_true",
Nathan Yonkee 9:d58e77ebd769 51 dest="supported_toolchains",
Nathan Yonkee 9:d58e77ebd769 52 default=False,
Nathan Yonkee 9:d58e77ebd769 53 help="Displays supported matrix of"
Nathan Yonkee 9:d58e77ebd769 54 " targets and toolchains")
Nathan Yonkee 9:d58e77ebd769 55
Nathan Yonkee 9:d58e77ebd769 56 parser.add_argument('-f', '--filter',
Nathan Yonkee 9:d58e77ebd769 57 dest='general_filter_regex',
Nathan Yonkee 9:d58e77ebd769 58 default=None,
Nathan Yonkee 9:d58e77ebd769 59 help='Filter targets')
Nathan Yonkee 9:d58e77ebd769 60
Nathan Yonkee 9:d58e77ebd769 61 parser.add_argument("-v", "--verbose",
Nathan Yonkee 9:d58e77ebd769 62 action="store_true",
Nathan Yonkee 9:d58e77ebd769 63 dest="verbose",
Nathan Yonkee 9:d58e77ebd769 64 default=False,
Nathan Yonkee 9:d58e77ebd769 65 help="Verbose diagnostic output")
Nathan Yonkee 9:d58e77ebd769 66
Nathan Yonkee 9:d58e77ebd769 67 options = parser.parse_args()
Nathan Yonkee 9:d58e77ebd769 68
Nathan Yonkee 9:d58e77ebd769 69 # Only prints matrix of supported toolchains
Nathan Yonkee 9:d58e77ebd769 70 if options.supported_toolchains:
Nathan Yonkee 9:d58e77ebd769 71 print(mcu_toolchain_matrix(
Nathan Yonkee 9:d58e77ebd769 72 platform_filter=options.general_filter_regex))
Nathan Yonkee 9:d58e77ebd769 73 exit(0)
Nathan Yonkee 9:d58e77ebd769 74
Nathan Yonkee 9:d58e77ebd769 75 # If auto_detect attribute is present, we assume other auto-detection
Nathan Yonkee 9:d58e77ebd769 76 # parameters like 'toolchains_filter' are also set.
Nathan Yonkee 9:d58e77ebd769 77 muts = get_autodetected_MUTS_list()
Nathan Yonkee 9:d58e77ebd769 78
Nathan Yonkee 9:d58e77ebd769 79 mcu_filter = options.general_filter_regex or ".*"
Nathan Yonkee 9:d58e77ebd769 80
Nathan Yonkee 9:d58e77ebd769 81 count = 0
Nathan Yonkee 9:d58e77ebd769 82 for mut in muts.values():
Nathan Yonkee 9:d58e77ebd769 83 if re.match(mcu_filter, mut['mcu'] or "Unknown"):
Nathan Yonkee 9:d58e77ebd769 84 interface_version = get_interface_version(mut['disk'])
Nathan Yonkee 9:d58e77ebd769 85 print("")
Nathan Yonkee 9:d58e77ebd769 86 print("[mbed] Detected %s, port %s, mounted %s, interface "
Nathan Yonkee 9:d58e77ebd769 87 "version %s:" %
Nathan Yonkee 9:d58e77ebd769 88 (mut['mcu'], mut['port'], mut['disk'], interface_version))
Nathan Yonkee 9:d58e77ebd769 89 print("[mbed] Supported toolchains for %s" % mut['mcu'])
Nathan Yonkee 9:d58e77ebd769 90 print(mcu_toolchain_matrix(platform_filter=mut['mcu']))
Nathan Yonkee 9:d58e77ebd769 91 count += 1
Nathan Yonkee 9:d58e77ebd769 92
Nathan Yonkee 9:d58e77ebd769 93 if count == 0:
Nathan Yonkee 9:d58e77ebd769 94 print("[mbed] No mbed targets were detected on your system.")
Nathan Yonkee 9:d58e77ebd769 95
Nathan Yonkee 9:d58e77ebd769 96 except KeyboardInterrupt:
Nathan Yonkee 9:d58e77ebd769 97 print("\n[CTRL+c] exit")
Nathan Yonkee 9:d58e77ebd769 98 except Exception as exc:
Nathan Yonkee 9:d58e77ebd769 99 import traceback
Nathan Yonkee 9:d58e77ebd769 100 traceback.print_exc(file=sys.stdout)
Nathan Yonkee 9:d58e77ebd769 101 print("[ERROR] %s" % str(exc))
Nathan Yonkee 9:d58e77ebd769 102 sys.exit(1)
Nathan Yonkee 9:d58e77ebd769 103
Nathan Yonkee 9:d58e77ebd769 104 def get_interface_version(mount_point):
Nathan Yonkee 9:d58e77ebd769 105 """ Function returns interface version from the target mounted on the specified mount point
Nathan Yonkee 9:d58e77ebd769 106
Nathan Yonkee 9:d58e77ebd769 107 mount_point can be acquired via the following:
Nathan Yonkee 9:d58e77ebd769 108 muts = get_autodetected_MUTS_list()
Nathan Yonkee 9:d58e77ebd769 109 for mut in muts.values():
Nathan Yonkee 9:d58e77ebd769 110 mount_point = mut['disk']
Nathan Yonkee 9:d58e77ebd769 111
Nathan Yonkee 9:d58e77ebd769 112 @param mount_point Name of disk where platform is connected to host machine.
Nathan Yonkee 9:d58e77ebd769 113 """
Nathan Yonkee 9:d58e77ebd769 114 if get_module_avail('mbed_lstools'):
Nathan Yonkee 9:d58e77ebd769 115 try :
Nathan Yonkee 9:d58e77ebd769 116 mbedls = mbed_lstools.create()
Nathan Yonkee 9:d58e77ebd769 117 mbeds = mbedls.list_mbeds(unique_names=True, read_details_txt=True)
Nathan Yonkee 9:d58e77ebd769 118
Nathan Yonkee 9:d58e77ebd769 119 for mbed in mbeds:
Nathan Yonkee 9:d58e77ebd769 120 if mbed['mount_point'] == mount_point:
Nathan Yonkee 9:d58e77ebd769 121
Nathan Yonkee 9:d58e77ebd769 122 if 'daplink_version' in mbed:
Nathan Yonkee 9:d58e77ebd769 123 return mbed['daplink_version']
Nathan Yonkee 9:d58e77ebd769 124 except :
Nathan Yonkee 9:d58e77ebd769 125 return 'unknown'
Nathan Yonkee 9:d58e77ebd769 126
Nathan Yonkee 9:d58e77ebd769 127 return 'unknown'
Nathan Yonkee 9:d58e77ebd769 128
Nathan Yonkee 9:d58e77ebd769 129 if __name__ == '__main__':
Nathan Yonkee 9:d58e77ebd769 130 main()