Udev
udev 規則讓我抓狂
我有這個
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"
所以基本上,我使用子句 SUBSYSTEM S ==" usb " 而不是 SUBSYSTEM=“usb-serial”。
問題是它為什麼起作用?為什麼不
usb-serial
觸發udev
守護程序。尤其是當它恰好在那裡時,人們可以用udevadm info
???謝謝
在 udev 規則中,您只能匹配一台設備。您可以選擇要匹配的設備,但不能混合來自多個設備的條件。正如它在輸出中所說
udevadm info
:要匹配的規則可以由設備的屬性和單個父設備的屬性組成。
ATTRS{serial}=="A400CZBK"
擁有KERNELS=="2-1.1"
和的父母一方SUBSYSTEMS=="usb"
。目標設備本身俱有KERNEL=="ttyUSB0"
和SUBSYSTEM=="tty"
。所以你可以使用其中任何一個。但是您不能使用SUBSYSTEM=="usb-serial"
,它不存在於任何設備上,也不能使用 ,它SUBSYSTEMS=="usb-serial"
僅存在於不同的父設備上。