我有这个usb-serial
设备:
root@imx6_armboard:/etc/udev/rules.d# udevadm info -a -p $(udevadm info -q path -n /dev/ttyUSB0)
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/platform/fsl-ehci.1/usb2/2-1/2-1.1/2-1.1:1.0/ttyUSB0/tty/ttyUSB0':
KERNEL=="ttyUSB0"
SUBSYSTEM=="tty"
DRIVER==""
looking at parent device '/devices/platform/fsl-ehci.1/usb2/2-1/2-1.1/2-1.1:1.0/ttyUSB0':
KERNELS=="ttyUSB0"
SUBSYSTEMS=="usb-serial"
DRIVERS=="ftdi_sio"
ATTRS{latency_timer}=="1"
ATTRS{port_number}=="0"
looking at parent device '/devices/platform/fsl-ehci.1/usb2/2-1/2-1.1/2-1.1:1.0':
KERNELS=="2-1.1:1.0"
SUBSYSTEMS=="usb"
DRIVERS=="ftdi_sio"
ATTRS{bInterfaceNumber}=="00"
ATTRS{bAlternateSetting}==" 0"
ATTRS{bNumEndpoints}=="02"
ATTRS{bInterfaceClass}=="ff"
ATTRS{bInterfaceSubClass}=="ff"
ATTRS{bInterfaceProtocol}=="ff"
ATTRS{supports_autosuspend}=="1"
ATTRS{interface}=="FT232R USB UART"
looking at parent device '/devices/platform/fsl-ehci.1/usb2/2-1/2-1.1':
KERNELS=="2-1.1"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
ATTRS{configuration}==""
ATTRS{bNumInterfaces}==" 1"
ATTRS{bConfigurationValue}=="1"
ATTRS{bmAttributes}=="a0"
ATTRS{bMaxPower}==" 90mA"
ATTRS{urbnum}=="30409"
ATTRS{idVendor}=="0403"
ATTRS{idProduct}=="6001"
ATTRS{bcdDevice}=="0600"
ATTRS{bDeviceClass}=="00"
ATTRS{bDeviceSubClass}=="00"
ATTRS{bDeviceProtocol}=="00"
ATTRS{bNumConfigurations}=="1"
ATTRS{bMaxPacketSize0}=="8"
ATTRS{speed}=="12"
ATTRS{busnum}=="2"
ATTRS{devnum}=="9"
ATTRS{devpath}=="1.1"
ATTRS{version}==" 2.00"
ATTRS{maxchild}=="0"
ATTRS{quirks}=="0x0"
ATTRS{avoid_reset_quirk}=="0"
ATTRS{authorized}=="1"
ATTRS{manufacturer}=="FTDI"
ATTRS{product}=="FT232R USB UART"
ATTRS{serial}=="A400CZBK"
looking at parent device '/devices/platform/fsl-ehci.1/usb2/2-1':
KERNELS=="2-1"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
ATTRS{configuration}==""
ATTRS{bNumInterfaces}==" 1"
ATTRS{bConfigurationValue}=="1"
ATTRS{bmAttributes}=="e0"
ATTRS{bMaxPower}==" 2mA"
ATTRS{urbnum}=="15513"
ATTRS{idVendor}=="0424"
ATTRS{idProduct}=="2513"
ATTRS{bcdDevice}=="0bb3"
ATTRS{bDeviceClass}=="09"
ATTRS{bDeviceSubClass}=="00"
ATTRS{bDeviceProtocol}=="02"
ATTRS{bNumConfigurations}=="1"
ATTRS{bMaxPacketSize0}=="64"
ATTRS{speed}=="480"
ATTRS{busnum}=="2"
ATTRS{devnum}=="2"
ATTRS{devpath}=="1"
ATTRS{version}==" 2.00"
ATTRS{maxchild}=="3"
ATTRS{quirks}=="0x0"
ATTRS{avoid_reset_quirk}=="0"
ATTRS{authorized}=="1"
looking at parent device '/devices/platform/fsl-ehci.1/usb2':
KERNELS=="usb2"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
ATTRS{configuration}==""
ATTRS{bNumInterfaces}==" 1"
ATTRS{bConfigurationValue}=="1"
ATTRS{bmAttributes}=="e0"
ATTRS{bMaxPower}==" 0mA"
ATTRS{urbnum}=="48"
ATTRS{idVendor}=="1d6b"
ATTRS{idProduct}=="0002"
ATTRS{bcdDevice}=="0300"
ATTRS{bDeviceClass}=="09"
ATTRS{bDeviceSubClass}=="00"
ATTRS{bDeviceProtocol}=="01"
ATTRS{bNumConfigurations}=="1"
ATTRS{bMaxPacketSize0}=="64"
ATTRS{speed}=="480"
ATTRS{busnum}=="2"
ATTRS{devnum}=="1"
ATTRS{devpath}=="0"
ATTRS{version}==" 2.00"
ATTRS{maxchild}=="1"
ATTRS{quirks}=="0x0"
ATTRS{avoid_reset_quirk}=="0"
ATTRS{authorized}=="1"
ATTRS{manufacturer}=="Linux 3.0.35-02671-gb0836db ehci_hcd"
ATTRS{product}=="Freescale On-Chip EHCI Host Controller"
ATTRS{serial}=="fsl-ehci.1"
ATTRS{authorized_default}=="1"
looking at parent device '/devices/platform/fsl-ehci.1':
KERNELS=="fsl-ehci.1"
SUBSYSTEMS=="platform"
DRIVERS=="fsl-ehci"
looking at parent device '/devices/platform':
KERNELS=="platform"
SUBSYSTEMS==""
DRIVERS=="
我尝试为此创建一条规则/etc/udev/rules.d/99-usbserial-sensors.rules
。这个
SUBSYSTEM=="usb-serial", KERNEL=="ttyUSB?", ATTRS{serial}=="A400CZBK", SYMLINK+="sensO2"
我花了一个所有的一天,查看文档并在调试模式下运行,udevd
试图udevadm
找出为什么该规则没有按预期工作。
最终(当天),这条规则发挥了作用:
SUBSYSTEMS=="usb", KERNEL=="ttyUSB?", ATTRS{serial}=="A400CZBK", SYMLINK+="sensO2"
所以基本上,我使用了子句 SUBSYSTEMS= = = =USB" 而不是 SUBSYSTEM="usb-serial"。
问题是为什么它有效?为什么不usb-serial
触发udev
守护进程。尤其是当它就在那里,以便人们可以用udevadm info
???抓住它时。
谢谢
答案1
在 udev 规则中,您只能匹配一台设备。您可以选择要匹配的设备,但不能混合多个设备的条件。正如它的输出中所说udevadm info
:
匹配的规则可以由设备的属性和来自设备的属性组成一台单亲设备。
ATTRS{serial}=="A400CZBK"
具有 的父级具有KERNELS=="2-1.1"
和SUBSYSTEMS=="usb"
。目标设备本身具有KERNEL=="ttyUSB0"
和SUBSYSTEM=="tty"
。因此,您可以使用其中任何一个。但您不能使用SUBSYSTEM=="usb-serial"
,它不存在于任何设备上,也不能使用SUBSYSTEMS=="usb-serial"
,它仅存在于不同的父级上。