2

I want to enumerate my USB-UART bridges with my own script. The script shall be called with some attributes and return a new devfs node name.

  1. I tested the script on console:

    ./rc3e.py -d get-devfs-node tty --vendor 10C4 --product EA60 --driver cp210x --serial "Board=KC705;Serial=5081a76781f40229d39e6c9802400fd2"
    KC705_0/ttyUSB
    
  2. I implemented a static udev rule:

    # Silicon Labs - CP2103 USB to UART Bridge Controller
    SUBSYSTEM=="tty", SUBSYSTEMS=="usb", ATTRS{idProduct}=="ea60", ATTRS{idVendor}=="10c4", ATTRS{serial}=="Board=KC705;Serial=5081a76781f40229d39e6c9802400fd2", SYMLINK+="KC705_0/ttyUSB"
    
  3. I'm testing the udev rule with /usr/bin/logger:

    SUBSYSTEM=="tty", SUBSYSTEMS=="usb", PROGRAM="/usr/bin/logger -p user.error 'product=%attr{idProduct} vendor=$attr{idVendor} drivers=$driver serial=$attr{serial}'"
    

    Here I'm stuck.
    The reported line in /var/log/syslog is this:

    Sep 23 15:12:26 xxxxxx root: product= vendor= drivers=cp210x serial=
    

$driver gets replaced, but $att{key} is always empty.

This is my udevadm info -a -n /dev/ttyUSB2 output:

udevadm info -a -n /dev/ttyUSB2

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:14.0/usb1/1-3/1-3:1.0/ttyUSB2/tty/ttyUSB2':
    KERNEL=="ttyUSB2"
    SUBSYSTEM=="tty"
    DRIVER==""

  looking at parent device '/devices/pci0000:00/0000:00:14.0/usb1/1-3/1-3:1.0/ttyUSB2':
    KERNELS=="ttyUSB2"
    SUBSYSTEMS=="usb-serial"
    DRIVERS=="cp210x"                                      <-- key of interrest
    ATTRS{port_number}=="0"

  looking at parent device '/devices/pci0000:00/0000:00:14.0/usb1/1-3/1-3:1.0':
    KERNELS=="1-3:1.0"
    SUBSYSTEMS=="usb"
    DRIVERS=="cp210x"
    ATTRS{bAlternateSetting}==" 0"
    ATTRS{bInterfaceClass}=="ff"
    ATTRS{bInterfaceNumber}=="00"
    ATTRS{bInterfaceProtocol}=="00"
    ATTRS{bInterfaceSubClass}=="00"
    ATTRS{bNumEndpoints}=="02"
    ATTRS{interface}=="CP2103 USB to UART Bridge Controller"
    ATTRS{supports_autosuspend}=="1"

  looking at parent device '/devices/pci0000:00/0000:00:14.0/usb1/1-3':
    KERNELS=="1-3"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{authorized}=="1"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bDeviceClass}=="00"
    ATTRS{bDeviceProtocol}=="00"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{bMaxPower}=="100mA"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{bcdDevice}=="0100"
    ATTRS{bmAttributes}=="80"
    ATTRS{busnum}=="1"
    ATTRS{configuration}==""
    ATTRS{devnum}=="2"
    ATTRS{devpath}=="3"
    ATTRS{idProduct}=="ea60"                               <-- key of interrest
    ATTRS{idVendor}=="10c4"                                <-- key of interrest
    ATTRS{ltm_capable}=="no"
    ATTRS{manufacturer}=="Silicon Labs"
    ATTRS{maxchild}=="0"
    ATTRS{product}=="CP2103 USB to UART Bridge Controller"
    ATTRS{quirks}=="0x0"
    ATTRS{removable}=="unknown"
    ATTRS{serial}=="Board=KC705;Serial=5081a76781f40229d39e6c9802400fd2"    <-- key of interrest
    ATTRS{speed}=="12"
    ATTRS{urbnum}=="258427"
    ATTRS{version}==" 1.10"

What should I change to pass these parameters to my script?

EDIT 1:

root@fpga-cloud:/dev# udevadm info /dev/ttyUSB2
P: /devices/pci0000:00/0000:00:14.0/usb1/1-3/1-3:1.0/ttyUSB2/tty/ttyUSB2
N: ttyUSB2
S: KC705_0/ttyUSB
S: serial/by-id/usb-Silicon_Labs_CP2103_USB_to_UART_Bridge_Controller_Board=KC705_Serial=5081a76781f40229d39e6c9802400fd2-if00-port0
S: serial/by-path/pci-0000:00:14.0-usb-0:3:1.0-port0
S: ttyUSB.KC705
E: DEVLINKS=/dev/KC705_2/ttyUSB /dev/serial/by-id/usb-Silicon_Labs_CP2103_USB_to_UART_Bridge_Controller_Board=KC705_Serial=5081a76781f40229d39e6c9802400fd2-if00-port0 /dev/KC705_1/ttyUSB /dev/ttyUSB.KC705 /dev/serial/by-path/pci-0000:00:14.0-usb-0:3:1.0-port0
E: DEVNAME=/dev/ttyUSB2
E: DEVPATH=/devices/pci0000:00/0000:00:14.0/usb1/1-3/1-3:1.0/ttyUSB2/tty/ttyUSB2
E: ID_BUS=usb
E: ID_MM_CANDIDATE=1
E: ID_MODEL=CP2103_USB_to_UART_Bridge_Controller
E: ID_MODEL_ENC=CP2103\x20USB\x20to\x20UART\x20Bridge\x20Controller
E: ID_MODEL_FROM_DATABASE=CP210x UART Bridge / myAVR mySmartUSB light
E: ID_MODEL_ID=ea60
E: ID_PATH=pci-0000:00:14.0-usb-0:3:1.0
E: ID_PATH_TAG=pci-0000_00_14_0-usb-0_3_1_0
E: ID_PCI_CLASS_FROM_DATABASE=Serial bus controller
E: ID_PCI_INTERFACE_FROM_DATABASE=XHCI
E: ID_PCI_SUBCLASS_FROM_DATABASE=USB controller
E: ID_REVISION=0100
E: ID_SERIAL=Silicon_Labs_CP2103_USB_to_UART_Bridge_Controller_Board=KC705_Serial=5081a76781f40229d39e6c9802400fd2
E: ID_SERIAL_SHORT=Board=KC705_Serial=5081a76781f40229d39e6c9802400fd2
E: ID_TYPE=generic
E: ID_USB_DRIVER=cp210x
E: ID_USB_INTERFACES=:ff0000:
E: ID_USB_INTERFACE_NUM=00
E: ID_VENDOR=Silicon_Labs
E: ID_VENDOR_ENC=Silicon\x20Labs
E: ID_VENDOR_FROM_DATABASE=Cygnal Integrated Products, Inc.
E: ID_VENDOR_ID=10c4
E: MAJOR=188
E: MINOR=2
E: SUBSYSTEM=tty
E: TAGS=:systemd:
E: USEC_INITIALIZED=7849322
  • @don_crissti I added your requested report. – Paebbels Sep 23 '15 at 14:24
  • 1
    The result of your test rule with /usr/bin/logger is normal... As I said here, the attributes used are those of the first parent selected with SUBSYSTEMS (in your case) so that parent that has only the {driver} attribute. The attributes you are interested in belong to the parent of this parent device so you'll have to match via environment variables, e.g. for your test rule: SUBSYSTEM=="tty", SUBSYSTEMS=="usb", PROGRAM="/usr/bin/logger.....'product=%E{ID_MODEL_ID} vendor=%E{ID_VENDOR_ID} drivers=%E{ID_USB_DRIVER} serial=%E{ID_SERIAL}'" – don_crissti Sep 23 '15 at 14:30
  • @don_crissti Let me guess .... E stands for environment value, so I need to use $env{...} and then I need to use the keys from udevadm info /dev/ttyUSB2 (without -a -n)? For example $env{ID_VENDOR_ID}. Am I correct? – Paebbels Sep 23 '15 at 14:32
  • @don_crissti My original serial string, which I programmed into the CP2103, contains a ; char. This is translated into _ (see ID_SERIAL_SHORT). What other delimiter could I use in the serial string? Current format: Key1=Value1;Key2=Value2. – Paebbels Sep 23 '15 at 15:14
  • @don_crissti Now I get Sep 23 17:33:08 fpga-cloud kernel: Error: Driver 'processor_aggregator' is already registered, aborting... messages in /var/log/kern.log. If I rename the called script, I can see a correct assembled command line: Sep 23 17:33:03 fpga-cloud systemd-udevd[31030]: failed to execute '/opt/rc3e/rc3e-devfs.py' '/opt/rc3e/rc3e-devfs.p -d get-devfs-node tty --vendor 10c4 --product ea60 --driver cp210x --serial Board=KC705_Serial=5081a76781f40229d39e6c9802400fd2': No such file or directory. – Paebbels Sep 23 '15 at 15:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.