Linux:如何为设备分配 USB 驱动程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8391644/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Linux: How to assign USB driver to device
提问by linsek
This question is two-fold:
这个问题有两个方面:
1- How do you manually detach a driver from a USB device and attach a different one? For example, I have a device that when connected automatically uses the usb-storage driver.
1- 如何从 USB 设备手动分离驱动程序并连接另一个?例如,我有一个在连接时自动使用 USB 存储驱动程序的设备。
// usbview output
// USB视图输出
Vendor Id: xxxx
Product Id: xxxx
...
Number of Interfaces: 2
Interface Number: 0
Name: usb-storage
Number of Endpoints: 2
...
Interface Number: 1
Name: (none)
Number of Endpoints: 2
...
I do not want to use the usb-storage driver, so I have an application running on the host in which I use the libusb library to detach the usb-storage driver and then I claim the interface. I then can send data to and from the applications running on my USB device and on my host Linux system.
我不想使用 USB 存储驱动程序,所以我在主机上运行了一个应用程序,我在其中使用 libusb 库分离 USB 存储驱动程序,然后我声明了接口。然后,我可以在我的 USB 设备和我的主机 Linux 系统上运行的应用程序之间发送数据。
How do you detach a driver manually outside of an application?
如何在应用程序之外手动分离驱动程序?
2- How do I automatically assign the driver to attach on device plugin. I currently have a udev rule setup to set the device permissions automatically.
2- 如何自动分配驱动程序以附加到设备插件上。我目前有一个 udev 规则设置来自动设置设备权限。
SUBSYSTEM=="usb", ATTR{idVendor}=="xxxx", MODE="0666"
Can I use udev rules to assign drivers to specific interfaces on the USB device? For example, if I wanted the usbnet module to be used on automatically on interface 0 instead of usb-storage, is that possible in udev?
我可以使用 udev 规则为 USB 设备上的特定接口分配驱动程序吗?例如,如果我希望在接口 0 上自动使用 usbnet 模块而不是 usb-storage,这在 udev 中可行吗?
Thanks,
谢谢,
(I'm a little confused about how StackExchange works with it's different sites or if they are all the same. This is a Linux question so it was also posted on Unix & Linux. Forgive me if it shouldn't be posted here too, but StackOverflow also handles Linux, so...)
(我对 StackExchange 如何与它的不同站点一起工作或者它们是否都相同感到有些困惑。这是一个 Linux 问题,所以它也发布在 Unix 和 Linux 上。如果不应该在这里发布,请原谅我,但 StackOverflow 也处理 Linux,所以...)
采纳答案by bofh.at
This question sounds a lot like a USB device containing a small flash disk which contains the Windows driver, but actually it's a sort of network access device (UMTS modem comes to my mind). If this is the case, try to use USB_ModeSwitch, which contains a database of USB devices and the commands and data which must be used to move the device from "storage mode" to "network access mode". If the device is not configured in the database, Usb Sniffer for Windowscan be used on Windows to trace the USB traffic and extract the necessary command/data combo.
这个问题听起来很像一个 USB 设备,其中包含一个包含 Windows 驱动程序的小闪存盘,但实际上它是一种网络访问设备(我想到了 UMTS 调制解调器)。如果是这种情况,请尝试使用USB_ModeSwitch,其中包含 USB 设备的数据库以及将设备从“存储模式”移动到“网络访问模式”时必须使用的命令和数据。如果该设备未在数据库中配置,则可以在 Windows 上使用Usb Sniffer forWindows 来跟踪 USB 流量并提取必要的命令/数据组合。
Automation of usb_modeswitch, so that it performs it's magic when you plug in your device can be done using udev rules. If you're using a Fedora or Ubuntu based distribution, this is handled for you when you install the packages providing usb_modeswitch (sorry I've no info about SUSE but i think it's similar).In Fedora it's the package use_modeswitch_data, which provides a wrapper for the usb_modeswitch cmd and the necessary rule files.
usb_modeswitch 的自动化,以便它在您插入设备时执行它的魔术可以使用 udev 规则来完成。如果您使用的是基于 Fedora 或 Ubuntu 的发行版,则在您安装提供 usb_modeswitch 的软件包时会为您处理此问题(抱歉,我没有关于 SUSE 的信息,但我认为它很相似)。在 Fedora 中,它是软件包 use_modeswitch_data,它提供了一个usb_modeswitch cmd 的包装器和必要的规则文件。
If you really want bind/unbind USB devices to drivers, see this LWN article. As root, echo $usbid > /sys/bus/usb/drivers/usb-storage/unbind
will unbind the USB device with $usbid
from the "usb-storage" driver. Using the same command, but using bind
instead of unbind
, will try to bind the device to the driver. But be aware that it makes no sense (and will not work) to bind a device which acts like a storage device to a usbnet driver.
如果您真的希望将 USB 设备绑定/取消绑定到驱动程序,请参阅此 LWN 文章。以 rootecho $usbid > /sys/bus/usb/drivers/usb-storage/unbind
身份,将解除 USB 设备与$usbid
“usb-storage”驱动程序的绑定。使用相同的命令,但使用bind
代替unbind
,将尝试将设备绑定到驱动程序。但是请注意,将充当存储设备的设备绑定到 USB 网络驱动程序是没有意义的(并且不会起作用)。