diff --git a/kvmd/plugins/hid/otg/device.py b/kvmd/plugins/hid/otg/device.py index 412297fc..8dbe2889 100644 --- a/kvmd/plugins/hid/otg/device.py +++ b/kvmd/plugins/hid/otg/device.py @@ -260,8 +260,8 @@ class BaseDeviceProcess(multiprocessing.Process): # pylint: disable=too-many-in flags |= (os.O_RDWR if self.__read_size else os.O_WRONLY) self.__fd = os.open(self.__device_path, flags) except Exception as err: - logger.error(self.gettext("Can't open HID-%s device %s: %s"), - self.__name, self.__device_path, tools.efmt(err)) + #logger.error(self.gettext("Can't open HID-%s device %s: %s"),self.__name, self.__device_path, tools.efmt(err)) + pass if self.__fd >= 0: try: diff --git a/kvmd/plugins/msd/otg/__init__.py b/kvmd/plugins/msd/otg/__init__.py index b850c79c..f8e58e89 100644 --- a/kvmd/plugins/msd/otg/__init__.py +++ b/kvmd/plugins/msd/otg/__init__.py @@ -25,6 +25,7 @@ import contextlib import dataclasses import functools import time +import os from typing import AsyncGenerator @@ -259,6 +260,7 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes @aiotools.atomic_fg async def set_connected(self, connected: bool) -> None: + print(self.__drive) async with self.__state.busy(): assert self.__state.vd if connected: @@ -274,6 +276,15 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes self.__drive.set_rw_flag(self.__state.vd.rw) self.__drive.set_cdrom_flag(self.__state.vd.cdrom) + #reboot UDC to fix otg cd-rom and flash switch + udc_path = self.__drive.get_udc_path() + with open(udc_path) as file: + enabled = bool(file.read().strip()) + if enabled: + with open(udc_path, "w") as file: + file.write("\n") + with open(udc_path, "w") as file: + file.write(sorted(os.listdir("/sys/class/udc"))[0]) if self.__state.vd.rw: await self.__state.vd.image.remount_rw(True) self.__drive.set_image_path(self.__state.vd.image.path) diff --git a/kvmd/plugins/msd/otg/drive.py b/kvmd/plugins/msd/otg/drive.py index 998355e4..e69560e9 100644 --- a/kvmd/plugins/msd/otg/drive.py +++ b/kvmd/plugins/msd/otg/drive.py @@ -40,6 +40,7 @@ class MsdDriveLockedError(MsdOperationError): class Drive: def __init__(self, gadget: str, instance: int, lun: int) -> None: func = f"mass_storage.usb{instance}" + self.__udc_path = os.path.join(f"/sys/kernel/config/usb_gadget", gadget, usb.G_UDC) self.__profile_func_path = usb.get_gadget_path(gadget, usb.G_PROFILE, func) self.__profile_path = usb.get_gadget_path(gadget, usb.G_PROFILE) self.__lun_path = usb.get_gadget_path(gadget, usb.G_FUNCTIONS, func, f"lun.{lun}") @@ -49,6 +50,9 @@ class Drive: def get_watchable_paths(self) -> list[str]: return [self.__lun_path, self.__profile_path] + + def get_udc_path(self) -> str: + return self.__udc_path # =====