Exemplo n.º 1
0
    def parse_id_to_devices(self, tid):
        """
        :param tid: target id
        """
        flasher = Flash()
        available = Common(self.logger).get_available_device_mapping(
            flasher.get_all_flashers(), tid)
        target_ids = []
        available_target_ids = []
        if not available:
            msg = "Could not find any connected device"
            print(msg)
            raise GeneralFatalError(message=msg,
                                    return_code=EXIT_CODE_DEVICES_MISSING)

        if 'all' in tid:
            for device in available:
                target_ids.append(device['target_id'])
        else:
            for item in tid:
                for device in available:
                    available_target_ids.append(device['target_id'])
                    if device['target_id'] == item or \
                            device['target_id'].startswith(item):
                        if device['target_id'] not in target_ids:
                            target_ids.append(device['target_id'])
        if not target_ids:
            print("Could not find given target_id from attached devices")
            print("Available target_ids:")
            print(available_target_ids)
            raise GeneralFatalError(message="Could not map device",
                                    return_code=EXIT_CODE_COULD_NOT_MAP_DEVICE)

        if len(target_ids) == 1:
            return target_ids[0]

        return target_ids
Exemplo n.º 2
0
    def subcmd_flash_handler(self, args):
        """
        flash command handler
        """
        if not args.tid:
            msg = "Target_id is missing"
            raise FlashError(message=msg,
                             return_code=EXIT_CODE_TARGET_ID_MISSING)

        check_file(self.logger, args.target_filename or args.input)
        check_file(self.logger, args.input)
        check_file_exists(self.logger, args.input)
        check_file_extension(self.logger, args.target_filename or args.input)

        flasher = Flash()
        available = Common(self.logger).get_available_device_mapping(
            flasher.get_all_flashers(), args.tid)
        available_target_ids = []
        retcode = EXIT_CODE_SUCCESS
        if args.platform_name:
            if args.platform_name not in flasher.get_supported_targets():
                self.logger.error("Not supported platform: %s",
                                  args.platform_name)
                self.logger.error("Supported platforms: %s",
                                  flasher.get_supported_targets())
                raise FlashError(message="Platform {} not supported".format(
                    args.platform_name),
                                 return_code=EXIT_CODE_NOT_SUPPORTED_PLATFORM)

        if 'all' in args.tid:
            retcode = flasher.flash(build=args.input,
                                    target_id='all',
                                    platform_name=args.platform_name,
                                    target_filename=args.target_filename,
                                    method=args.method,
                                    no_reset=args.no_reset)

        if len(available) <= 0:
            msg = "Could not find any connected device"
            raise FlashError(message=msg,
                             return_code=EXIT_CODE_DEVICES_MISSING)

        available_platforms, target_ids_to_flash = \
            self.prepare_platforms_and_targets(available, args.tid, available_target_ids)

        if not target_ids_to_flash:
            self.logger.error(
                "Could not find given target_id from attached devices")
            self.logger.error("Available target_ids: %s", available_target_ids)
            raise FlashError(message="Could not map device",
                             return_code=EXIT_CODE_COULD_NOT_MAP_DEVICE)
        elif len(available_platforms) > 1:
            if not args.platform_name:
                self.logger.error(
                    "More than one platform detected for given target_id")
                self.logger.error(
                    "Please specify the platform with -t <PLATFORM_NAME>")
                self.logger.error("Found platforms: %s", available_platforms)
                raise FlashError(
                    message=
                    "More than one platform detected for given target id",
                    return_code=EXIT_CODE_PLATFORM_REQUIRED)
        else:
            retcode = flasher.flash(build=args.input,
                                    target_id=target_ids_to_flash,
                                    target_filename=args.target_filename,
                                    platform_name=available_platforms[0],
                                    method=args.method,
                                    no_reset=args.no_reset)

        return retcode