From 72dce4de8935eb32fbdeb11d415a6b003d7bd46c Mon Sep 17 00:00:00 2001 From: mofeng-git Date: Tue, 5 Nov 2024 17:54:38 +0000 Subject: [PATCH] =?UTF-8?q?#46=20=E4=BF=AE=E5=A4=8D=20CD-ROM=20=E4=B8=8E?= =?UTF-8?q?=20FLASH=20=E6=A8=A1=E5=BC=8F=E7=BD=91=E9=A1=B5=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E5=88=87=E6=8D=A2=20=E6=8C=82=E8=BD=BD=20MSD=20?= =?UTF-8?q?=E6=97=B6=E9=87=8D=E5=90=AF=20UDC=20=E7=A1=AE=E4=BF=9D=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E7=94=9F=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kvmd/plugins/hid/otg/device.py | 4 ++-- kvmd/plugins/msd/otg/__init__.py | 11 +++++++++++ kvmd/plugins/msd/otg/drive.py | 4 ++++ 3 files changed, 17 insertions(+), 2 deletions(-) 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 @@ def __ensure_device(self) -> bool: 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 dataclasses import functools import time +import os from typing import AsyncGenerator @@ -259,6 +260,7 @@ async def set_params( @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 @@ async def set_connected(self, connected: bool) -> None: 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 @@ def __init__(self) -> None: 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 @@ def is_enabled(self) -> bool: def get_watchable_paths(self) -> list[str]: return [self.__lun_path, self.__profile_path] + + def get_udc_path(self) -> str: + return self.__udc_path # =====