串行 USB 未显示(Udev 故障排除)

串行 USB 未显示(Udev 故障排除)

我正在尝试为基于 USBtiny 的 AVR 程序员编写 udev 规则。在其他非 Gentoo 系统上,USB 设备将显示在/dev/ttyUSB0。我希望它在我的系统上显示为类似的东西,可能/dev/ttyACM0或者其他东西。

我相信我的内核配置正确,因为我可以插入 USB 转串口转换器,并且它显示为/dev/ttyUSB0.

这是一个安装了 eudev 的最新 Gentoo openrc 系统。

运行“udevadm Monitor”时,插入设备后我可以看到以下情况发生:

KERNEL[1859.422447] add      /devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.1 (usb)
KERNEL[1859.422777] add      /devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.1/1-1.1:1.0 (usb)
KERNEL[1859.423050] bind     /devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.1 (usb)
UDEV  [1859.990399] add      /devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.1 (usb)
UDEV  [1859.991792] add      /devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.1/1-1.1:1.0 (usb)
UDEV  [1859.996016] bind     /devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.1 (usb)

我抓住了“/devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.1”并检查了信息:

% udevadm info -a -p /devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.1                                   

Udevadm info starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.

  looking at device '/devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.1':
    KERNEL=="1-1.1"
    SUBSYSTEM=="usb"
    DRIVER=="usb"
    ATTR{configuration}==""
    ATTR{bMaxPacketSize0}=="8"
    ATTR{bDeviceClass}=="ff"
    ATTR{bcdDevice}=="0105"
    ATTR{bNumInterfaces}==" 1"
    ATTR{bConfigurationValue}=="1"
    ATTR{manufacturer}=="Adafruit"
    ATTR{bNumConfigurations}=="1"
    ATTR{authorized}=="1"
    ATTR{speed}=="1.5"
    ATTR{idProduct}=="0c9f"
    ATTR{urbnum}=="9"
    ATTR{devnum}=="6"
    ATTR{product}=="USBtiny"
    ATTR{maxchild}=="0"
    ATTR{bmAttributes}=="80"
    ATTR{bDeviceSubClass}=="00"
    ATTR{bMaxPower}=="100mA"
    ATTR{rx_lanes}=="1"
    ATTR{removable}=="removable"
    ATTR{idVendor}=="1781"
    ATTR{version}==" 1.10"
    ATTR{avoid_reset_quirk}=="0"
    ATTR{bDeviceProtocol}=="00"
    ATTR{tx_lanes}=="1"
    ATTR{ltm_capable}=="no"
    ATTR{devpath}=="1.1"
    ATTR{busnum}=="1"
    ATTR{quirks}=="0x0"

  looking at parent device '/devices/pci0000:00/0000:00:1a.0/usb1/1-1':
    KERNELS=="1-1"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{configuration}==""
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{bDeviceClass}=="09"
    ATTRS{bcdDevice}=="0000"
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{authorized}=="1"
    ATTRS{speed}=="480"
    ATTRS{idProduct}=="0020"
    ATTRS{urbnum}=="193"
    ATTRS{devnum}=="2"
    ATTRS{maxchild}=="6"
    ATTRS{bmAttributes}=="e0"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bMaxPower}=="0mA"
    ATTRS{rx_lanes}=="1"
    ATTRS{removable}=="fixed"
    ATTRS{idVendor}=="8087"
    ATTRS{version}==" 2.00"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{bDeviceProtocol}=="01"
    ATTRS{tx_lanes}=="1"
    ATTRS{ltm_capable}=="no"
    ATTRS{devpath}=="1"
    ATTRS{busnum}=="1"
    ATTRS{quirks}=="0x0"

  looking at parent device '/devices/pci0000:00/0000:00:1a.0/usb1':
    KERNELS=="usb1"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{configuration}==""
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{bDeviceClass}=="09"
    ATTRS{bcdDevice}=="0505"
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{manufacturer}=="Linux 5.5.1-gentoo ehci_hcd"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{authorized}=="1"
    ATTRS{speed}=="480"
    ATTRS{idProduct}=="0002"
    ATTRS{urbnum}=="134"
    ATTRS{devnum}=="1"
    ATTRS{product}=="EHCI Host Controller"
    ATTRS{maxchild}=="3"
    ATTRS{bmAttributes}=="e0"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bMaxPower}=="0mA"
    ATTRS{rx_lanes}=="1"
    ATTRS{removable}=="unknown"
    ATTRS{idVendor}=="1d6b"
    ATTRS{interface_authorized_default}=="1"
    ATTRS{authorized_default}=="1"
    ATTRS{version}==" 2.00"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{serial}=="0000:00:1a.0"
    ATTRS{bDeviceProtocol}=="00"
    ATTRS{tx_lanes}=="1"
    ATTRS{ltm_capable}=="no"
    ATTRS{devpath}=="0"
    ATTRS{busnum}=="1"
    ATTRS{quirks}=="0x0"

  looking at parent device '/devices/pci0000:00/0000:00:1a.0':
    KERNELS=="0000:00:1a.0"
    SUBSYSTEMS=="pci"
    DRIVERS=="ehci-pci"
    ATTRS{broken_parity_status}=="0"
    ATTRS{subsystem_device}=="0x2163"
    ATTRS{dma_mask_bits}=="32"
    ATTRS{vendor}=="0x8086"
    ATTRS{local_cpus}=="f"
    ATTRS{companion}==""
    ATTRS{class}=="0x0c0320"
    ATTRS{numa_node}=="-1"
    ATTRS{msi_bus}=="1"
    ATTRS{device}=="0x3b3c"
    ATTRS{local_cpulist}=="0-3"
    ATTRS{driver_override}=="(null)"
    ATTRS{d3cold_allowed}=="1"
    ATTRS{irq}=="23"
    ATTRS{revision}=="0x06"
    ATTRS{consistent_dma_mask_bits}=="32"
    ATTRS{ari_enabled}=="0"
    ATTRS{uframe_periodic_max}=="100"
    ATTRS{enable}=="1"
    ATTRS{subsystem_vendor}=="0x17aa"

  looking at parent device '/devices/pci0000:00':
    KERNELS=="pci0000:00"
    SUBSYSTEMS==""
    DRIVERS==""

看来,以下 udev 规则将起作用:

# /etc/udev/rules.d/99-usbtiny.rules
SUBSYSTEM=="usb", ATTR{manufacturer}=="Adafruit", ATTR{product}=="USBtiny", ATTR{idProduct}=="0c9f", ATTR{idVendor}=="1781", MODE="0660", GROUP="plugdev", SYMLINK+="usbtiny%n"

这和我在互联网上其他地方看到的其他人是一样的。一个区别是 idVendor 似乎是一个 ATTRS,但它不是“udevadm info”输出中的父节点属性。

我重新加载规则的过程是运行“udevadm control -R”。我还尝试重新启动 udev“/etc/init.d/udev restart”并重新启动。设备永远不会在 /dev/ 下创建条目。我已经尝试了上述所有方法,但没有使用 udev 规则的“SYMLINK”部分。

我可以使用 lsusb 查看该设备:

 % lsusb                                                                                                             
Bus 002 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 006: ID 1781:0c9f Multiple Vendors USBtiny

我知道内核也可以通过 dmesg 的尾部看到它:

[ 1859.351137] usb 1-1.1: new low-speed USB device number 6 using ehci-pci
[ 1859.440168] usb 1-1.1: New USB device found, idVendor=1781, idProduct=0c9f, bcdDevice= 1.05
[ 1859.440172] usb 1-1.1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 1859.440175] usb 1-1.1: Product: USBtiny
[ 1859.440177] usb 1-1.1: Manufacturer: Adafruit

有人还有其他故障排除技巧吗?就像我说的,我将 USB 串行转换器注册为 /dev/ 下的设备,并且我可以在“udevadm 监视器”输出中很好地看到它。我觉得我错过了一些小东西,这几天我一直在为此烦恼。任何指示将不胜感激。

我的内核中还内置了所有串行 USB 驱动程序:

  --- USB Serial Converter support
[*]   USB Serial Console device support
[*]   USB Generic Serial Driver
<*>   USB Serial Simple Driver
<*>   USB AIRcable Bluetooth Dongle Driver
<*>   USB ARK Micro 3116 USB Serial Driver
<*>   USB Belkin and Peracom Single Port Serial Driver
<*>   USB Winchiphead CH341 Single Port Serial Driver
<*>   USB ConnectTech WhiteHEAT Serial Driver
<*>   USB Digi International AccelePort USB Serial Driver
<*>   USB CP210x family of UART Bridge Controllers
<*>   USB Cypress M8 USB Serial Driver
<*>   USB Empeg empeg-car Mark I/II Driver
<*>   USB FTDI Single Port Serial Driver
<*>   USB Handspring Visor / Palm m50x / Sony Clie Driver
<*>   USB PocketPC PDA Driver
<*>   USB IR Dongle Serial Driver
<*>   USB Inside Out Edgeport Serial Driver
<*>   USB Inside Out Edgeport Serial Driver (TI device
<*>   USB Fintek F81232 Single Port Serial Driver
<*>   USB Fintek F81532/534 Multi-Ports Serial Driver
<*>   USB Garmin GPS driver
<*>   USB IPWireless (3G UMTS TDD) Driver
<*>   USB Infinity USB Unlimited Phoenix Driver
<*>   USB Keyspan PDA Single Port Serial Driver
<*>   USB Keyspan USA-xxx Serial Driver
<*>   USB KL5KUSB105 (Palmconnect) Driver
<*>   USB KOBIL chipcard reader
<*>   USB MCT Single Port Serial Driver
<*>   USB Metrologic Instruments USB-POS Barcode Scanner Driver
<*>   USB Moschip 7720 Serial Driver
<*>   USB Moschip 7840/7820 USB Serial Driver
<*>   USB Moxa UPORT Serial Driver
<*>   USB Navman GPS device
<*>   USB Prolific 2303 Single Port Serial Driver
<*>   USB Ours Technology Inc. OTi-6858 USB To RS232 Bridge Controller
<*>   USB Qualcomm Auxiliary Serial Port Driver
<*>   USB Qualcomm Serial modem
<*>   USB SPCP8x5 USB To Serial Driver
<*>   USB Safe Serial (Encapsulated) Driver
  [ ]     USB Secure Encapsulated Driver - Padded
<*>   USB Sierra Wireless Driver
<*>   USB Symbol Barcode driver (serial mode
<*>   USB TI 3410/5052 Serial Driver
<*>   USB REINER SCT cyberJack pinpad/e-com chipcard reader
<*>   USB Xircom / Entrega Single Port Serial Driver
<*>   USB driver for GSM and CDMA modems
<*>   USB ZyXEL omni.net LCD Plus Driver
<*>   USB Opticon Barcode driver (serial mode)
<*>   Xsens motion tracker serial interface driver
<*>   USB-Wishbone adapter interface driver
<*>   USB Quatech SSU-100 Single Port Serial Driver
<*>   USB Quatech Serial Driver for USB 2 devices
<*>   USB Renesas uPD78F0730 Single Port Serial Driver
<*>   USB Debugging Device

我在这里查看了其他一些问题,我真的很挠头,因为我什至无法让符号链接出现在/dev/.

我为此经历的主要资源是:

答案1

并非所有 USB 设备都呈现为类似串行端口的设备。特别是,USBtinyISP 根本不模拟串行端口,而是通过libusb使用本机 USB 通信进行访问。

我还有来自 Adafruit 的 USBtinyISP,其 USB 供应商和产品 ID 与您的完全相同,分别为 0x1781 和 0x0c9f。它既不会产生/dev/ttyUSB*也不会产生/dev/ttyACM*任何设备,但avrdude可以很好地与其通信。

Bus 001 Device 006: ID 1781:0c9f Multiple Vendors USBtiny

在您的情况下,已在总线 1、设备 6 处检测到 USBtinyISP,因此用于libusb与设备通信的设备节点将为/dev/bus/usb/001/006。您的 udev 规则可能已经应用到该设备。

另外,至少在 Debian 上,该avrdude软件包已经包含一个 udev 规则文件。它将/lib/udev/rules.d/60-avrdude.rules像任何系统默认 udev 规则文件一样安装到其中,/etc/udev/rules.d仅用于本地自定义/覆盖。该文件已经涵盖了 USBtinyISP。

要告知avrdude默认使用 USBtinyISP,您可能需要~/.avrduderc为自己创建一个文件,其中包含以下行:

default_programmer = "usbtiny";

这将消除在每个avrdude命令行指定程序员类型的要求。

答案2

你提到的ATTR{idVendor}和类似的。应该是这样吗ATTRS{...}?我还发现最少的规则更好。

例如,我的 Debian 系统上有以下内容:

% cat /etc/udev/rules.d/ols.rules               
#Rules for Openbench Logix Snifferslogic. Creates a nice link to the ols
ATTRS{idVendor}=="04d8", ATTRS{idProduct}=="fc92", MODE="0666", SYMLINK+="OpenLogicSniffer"

所以我会尝试:

ATTRS{idVendor}=="1781", ATTRS{idProduct}=="0c9f", MODE="0660", GROUP="plugdev", SYMLINK+="usbtiny%n"

答案3

我认为你应该使用 MODE="0666" 而不是 MODE="0660"。

相关内容