def main():
    """Entry Point"""
    try:
        # Parse Options
        parser = ArgumentParser()

        parser.add_argument("-S", "--supported-toolchains",
                            action="store_true",
                            dest="supported_toolchains",
                            default=False,
                            help="Displays supported matrix of"
                            " targets and toolchains")

        parser.add_argument('-f', '--filter',
                            dest='general_filter_regex',
                            default=None,
                            help='Filter targets')

        parser.add_argument("-v", "--verbose",
                            action="store_true",
                            dest="verbose",
                            default=False,
                            help="Verbose diagnostic output")

        options = parser.parse_args()

        # Only prints matrix of supported toolchains
        if options.supported_toolchains:
            print(mcu_toolchain_matrix(
                platform_filter=options.general_filter_regex))
            exit(0)

        # If auto_detect attribute is present, we assume other auto-detection
        # parameters like 'toolchains_filter' are also set.
        muts = get_autodetected_MUTS_list()

        mcu_filter = options.general_filter_regex or ".*"

        count = 0
        for mut in muts.values():
            if re.match(mcu_filter, mut['mcu'] or "Unknown"):
                interface_version = get_interface_version(mut['disk'])
                print("")
                print("[mbed] Detected %s, port %s, mounted %s, interface "
                      "version %s:" %
                      (mut['mcu'], mut['port'], mut['disk'], interface_version))
                print("[mbed] Supported toolchains for %s" % mut['mcu'])
                print(mcu_toolchain_matrix(platform_filter=mut['mcu']))
                count += 1

        if count == 0:
            print("[mbed] No mbed targets were detected on your system.")

    except KeyboardInterrupt:
        print("\n[CTRL+c] exit")
    except Exception as exc:
        import traceback
        traceback.print_exc(file=sys.stdout)
        print("[ERROR] %s" % str(exc))
        sys.exit(1)
Beispiel #2
0
def main():
    """Entry Point"""
    try:
        # Parse Options
        parser = ArgumentParser()

        parser.add_argument("-S", "--supported-toolchains",
                            action="store_true",
                            dest="supported_toolchains",
                            default=False,
                            help="Displays supported matrix of"
                            " targets and toolchains")

        parser.add_argument('-f', '--filter',
                            dest='general_filter_regex',
                            default=None,
                            help='Filter targets')

        parser.add_argument("-v", "--verbose",
                            action="store_true",
                            dest="verbose",
                            default=False,
                            help="Verbose diagnostic output")

        options = parser.parse_args()

        # Only prints matrix of supported toolchains
        if options.supported_toolchains:
            print(mcu_toolchain_matrix(
                platform_filter=options.general_filter_regex))
            exit(0)

        # If auto_detect attribute is present, we assume other auto-detection
        # parameters like 'toolchains_filter' are also set.
        muts = get_autodetected_MUTS_list()

        mcu_filter = options.general_filter_regex or ".*"

        count = 0
        for mut in muts.values():
            if re.match(mcu_filter, mut['mcu'] or "Unknown"):
                interface_version = get_interface_version(mut['disk'])
                print("")
                print("[mbed] Detected %s, port %s, mounted %s, interface "
                      "version %s:" %
                      (mut['mcu'], mut['port'], mut['disk'], interface_version))
                print("[mbed] Supported toolchains for %s" % mut['mcu'])
                print(mcu_toolchain_matrix(platform_filter=mut['mcu']))
                count += 1

        if count == 0:
            print("[mbed] No mbed targets were detected on your system.")

    except KeyboardInterrupt:
        print("\n[CTRL+c] exit")
    except Exception as exc:
        import traceback
        traceback.print_exc(file=sys.stdout)
        print("[ERROR] %s" % str(exc))
        sys.exit(1)
Beispiel #3
0
    def init_serial(self, serial_baud=None, serial_timeout=None):
        """ Initialize serial port.
            Function will return error is port can't be opened or initialized
        """
        # Overload serial port configuration from default to parameters' values if they are specified
        serial_baud = serial_baud if serial_baud is not None else self.serial_baud
        serial_timeout = serial_timeout if serial_timeout is not None else self.serial_timeout

        if get_module_avail('mbed_lstools') and self.options.auto_detect:
            # Ensure serial port is up-to-date (try to find it 60 times)
            found = False

            for i in range(0, 60):
                print('Looking for %s with MBEDLS' % self.options.micro)
                muts_list = get_autodetected_MUTS_list(
                    platform_name_filter=[self.options.micro])

                if 1 in muts_list:
                    mut = muts_list[1]
                    self.port = mut['port']
                    found = True
                    break
                else:
                    sleep(3)

            if not found:
                return False

        # Clear serial port
        if self.serial:
            self.serial.close()
            self.serial = None

        # We will pool for serial to be re-mounted if it was unmounted after device reset
        result = self.pool_for_serial_init(serial_baud,
                                           serial_timeout)  # Blocking

        # Port can be opened
        if result:
            self.flush()
        return result
    def init_serial(self, serial_baud=None, serial_timeout=None):
        """ Initialize serial port.
            Function will return error is port can't be opened or initialized
        """
        # Overload serial port configuration from default to parameters' values if they are specified
        serial_baud = serial_baud if serial_baud is not None else self.serial_baud
        serial_timeout = serial_timeout if serial_timeout is not None else self.serial_timeout

        if get_module_avail('mbed_lstools') and self.options.auto_detect:
            # Ensure serial port is up-to-date (try to find it 60 times)
            found = False

            for i in range(0, 60):
                print('Looking for %s with MBEDLS' % self.options.micro)
                muts_list = get_autodetected_MUTS_list(platform_name_filter=[self.options.micro])

                if 1 in muts_list:
                    mut = muts_list[1]
                    self.port = mut['port']
                    found = True
                    break
                else:
                    sleep(3)

            if not found:
                return False

        # Clear serial port
        if self.serial:
            self.serial.close()
            self.serial = None

        # We will pool for serial to be re-mounted if it was unmounted after device reset
        result = self.pool_for_serial_init(serial_baud, serial_timeout) # Blocking

        # Port can be opened
        if result:
            self.flush()
        return result
Beispiel #5
0
        exit(0)

    # Only prints matrix of supported toolchains
    if opts.supported_toolchains:
        print mcu_toolchain_matrix(platform_filter=opts.general_filter_regex)
        exit(0)

    test_spec = None
    MUTs = None

    if hasattr(opts, 'auto_detect') and opts.auto_detect:
        # If auto_detect attribute is present, we assume other auto-detection
        # parameters like 'toolchains_filter' are also set.
        print "MBEDLS: Detecting connected mbed-enabled devices... "

        MUTs = get_autodetected_MUTS_list()

        for mut in MUTs.values():
            print "MBEDLS: Detected %s, port: %s, mounted: %s" % (
                mut['mcu_unique'] if 'mcu_unique' in mut else mut['mcu'],
                mut['port'], mut['disk'])

        # Set up parameters for test specification filter function (we need to set toolchains per target here)
        use_default_toolchain = 'default' in opts.toolchains_filter if opts.toolchains_filter is not None else True
        use_supported_toolchains = 'all' in opts.toolchains_filter if opts.toolchains_filter is not None else False
        toolchain_filter = opts.toolchains_filter
        platform_name_filter = opts.general_filter_regex if opts.general_filter_regex is not None else opts.general_filter_regex
        # Test specification with information about each target and associated toolchain
        test_spec = get_autodetected_TEST_SPEC(
            MUTs.values(),
            use_default_toolchain=use_default_toolchain,
Beispiel #6
0
        exit(0)

    # Only prints matrix of supported toolchains
    if opts.supported_toolchains:
        print mcu_toolchain_matrix(platform_filter=opts.general_filter_regex)
        exit(0)

    test_spec = None
    MUTs = None

    if hasattr(opts, 'auto_detect') and opts.auto_detect:
        # If auto_detect attribute is present, we assume other auto-detection
        # parameters like 'toolchains_filter' are also set.
        print "MBEDLS: Detecting connected mbed-enabled devices... "

        MUTs = get_autodetected_MUTS_list()

        for mut in MUTs.values():
            print "MBEDLS: Detected %s, port: %s, mounted: %s"% (mut['mcu_unique'] if 'mcu_unique' in mut else mut['mcu'],
                                    mut['port'],
                                    mut['disk'])

        # Set up parameters for test specification filter function (we need to set toolchains per target here)
        use_default_toolchain = 'default' in opts.toolchains_filter if opts.toolchains_filter is not None else True
        use_supported_toolchains = 'all' in opts.toolchains_filter if opts.toolchains_filter is not None else False
        toolchain_filter = opts.toolchains_filter
        platform_name_filter = opts.general_filter_regex if opts.general_filter_regex is not None else opts.general_filter_regex
        # Test specification with information about each target and associated toolchain
        test_spec = get_autodetected_TEST_SPEC(MUTs.values(),
                                               use_default_toolchain=use_default_toolchain,
                                               use_supported_toolchains=use_supported_toolchains,
Beispiel #7
0
    def execute(self, capability, *args, **kwargs):
        """ Executes capability by name.
            Each capability may directly just call some command line
            program or execute building pythonic function
        """
        result = False
        if self.check_parameters(capability, *args, **kwargs) is True:
            image_path = kwargs['image_path']
            destination_disk = kwargs['destination_disk']
            target_mcu = kwargs['target_mcu']
            # Wait for mount point to be ready
            self.check_mount_point_ready(destination_disk)  # Blocking
            # Prepare correct command line parameter values
            image_base_name = basename(image_path)
            destination_path = join(destination_disk, image_base_name)
            if capability == 'smart':
                if os.name == 'posix':
                    cmd = ['cp', image_path, destination_path]
                    result = self.run_command(cmd, shell=False)

                    cmd = ['sync']
                    result = self.run_command(cmd, shell=False)
                elif os.name == 'nt':
                    cmd = ['copy', image_path, destination_path]
                    result = self.run_command(cmd, shell=True)

                # Give the OS and filesystem time to settle down
                sleep(3)

                platform_name_filter = [target_mcu]
                muts_list = {}

                remount_complete = False

                for i in range(0, 60):
                    print('Looking for %s with MBEDLS' % target_mcu)
                    muts_list = get_autodetected_MUTS_list(platform_name_filter=platform_name_filter)

                    if 1 in muts_list:
                        mut = muts_list[1]
                        destination_disk = mut['disk']
                        destination_path = join(destination_disk, image_base_name)

                        if mut['mcu'] == 'LPC1768' or mut['mcu'] == 'LPC11U24':
                            if exists(destination_disk) and exists(destination_path):
                                remount_complete = True
                                break;
                        else:
                            if exists(destination_disk) and not exists(destination_path):
                                remount_complete = True
                                break;

                    sleep(1)

                if remount_complete:
                    print('Remount complete')
                else:
                    print('Remount FAILED')

                    if exists(destination_disk):
                        print('Disk exists')
                    else:
                        print('Disk does not exist')

                    if exists(destination_path):
                        print('Image exists')
                    else:
                        print('Image does not exist')

                    result = None


        return result
Beispiel #8
0
    def execute(self, capability, *args, **kwargs):
        """ Executes capability by name.
            Each capability may directly just call some command line
            program or execute building pythonic function
        """
        result = False
        if self.check_parameters(capability, *args, **kwargs) is True:
            image_path = kwargs['image_path']
            destination_disk = kwargs['destination_disk']
            target_mcu = kwargs['target_mcu']
            # Wait for mount point to be ready
            self.check_mount_point_ready(destination_disk)  # Blocking
            # Prepare correct command line parameter values
            image_base_name = basename(image_path)
            destination_path = join(destination_disk, image_base_name)
            if capability == 'smart':
                if os.name == 'posix':
                    cmd = ['cp', image_path, destination_path]
                    result = self.run_command(cmd, shell=False)

                    cmd = ['sync']
                    result = self.run_command(cmd, shell=False)
                elif os.name == 'nt':
                    cmd = ['copy', image_path, destination_path]
                    result = self.run_command(cmd, shell=True)

                # Give the OS and filesystem time to settle down
                sleep(3)

                platform_name_filter = [target_mcu]
                muts_list = {}

                remount_complete = False

                for i in range(0, 60):
                    print('Looking for %s with MBEDLS' % target_mcu)
                    muts_list = get_autodetected_MUTS_list(
                        platform_name_filter=platform_name_filter)

                    if 1 in muts_list:
                        mut = muts_list[1]
                        destination_disk = mut['disk']
                        destination_path = join(destination_disk,
                                                image_base_name)

                        if mut['mcu'] == 'LPC1768' or mut['mcu'] == 'LPC11U24':
                            if exists(destination_disk) and exists(
                                    destination_path):
                                remount_complete = True
                                break
                        else:
                            if exists(destination_disk
                                      ) and not exists(destination_path):
                                remount_complete = True
                                break

                    sleep(1)

                if remount_complete:
                    print('Remount complete')
                else:
                    print('Remount FAILED')

                    if exists(destination_disk):
                        print('Disk exists')
                    else:
                        print('Disk does not exist')

                    if exists(destination_path):
                        print('Image exists')
                    else:
                        print('Image does not exist')

                    result = None

        return result