udev regras me deixando louca

2

Eu tenho esse usb-serial device:

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=="

Eu tentei criar uma regra para isso em /etc/udev/rules.d/99-usbserial-sensors.rules . esse aqui

SUBSYSTEM=="usb-serial", KERNEL=="ttyUSB?", ATTRS{serial}=="A400CZBK", SYMLINK+="sensO2"

Eu passei um dia INTEIRO , examinando a documentação e executando udevd e udevadm no modo de depuração, tentando descobrir por que essa regra não funcionou como esperado.

No final (do dia), esta regra funcionou:

SUBSYSTEMS=="usb", KERNEL=="ttyUSB?", ATTRS{serial}=="A400CZBK", SYMLINK+="sensO2"

Então, basicamente, eu usei a cláusula SUBSISTEMA S == " usb " em vez de SUBSYSTEM="usb-serial".

e a pergunta é por que isso funcionou? Por que o usb-serial não aciona o daemon udev ? Especialmente quando está lá exatamente para que alguém possa pegá-lo com udevadm info

Obrigado

    
por nass 06.10.2015 / 18:04

1 resposta

2

Em uma regra do udev, você só pode corresponder a um dispositivo. Você pode escolher com qual dispositivo corresponder, mas não pode misturar condições de vários dispositivos. Como se diz na saída de udevadm info :

A rule to match, can be composed by the attributes of the device and the attributes from one single parent device.

O pai único que tem ATTRS{serial}=="A400CZBK" tem KERNELS=="2-1.1" e SUBSYSTEMS=="usb" . O dispositivo de destino em si tem KERNEL=="ttyUSB0" e SUBSYSTEM=="tty" . Então você pode usar qualquer um desses. Mas você não pode usar SUBSYSTEM=="usb-serial" , que não está presente em nenhum dispositivo, nem SUBSYSTEMS=="usb-serial" , que está presente apenas em um pai diferente.

    
por 07.10.2015 / 04:59