[<<][pool][>>][..]
Fri Dec 31 15:00:26 EST 2010

Naming USB devices

Problem: I have several USB devices that have an identity: hard
drives, usb serial cables, USB sticks, ...  How to map them to the
right device name?

For drives it's easy:  in /etc/fstab just add the by-id name, like:

/dev/disk/by-id/scsi-1Seagate_Portable_2GH3XQRH-part1


Now for tty usb devices.  I just plugged in a FTDI TTL cable:

[2049983.757824] usb 2-1.3: new full speed USB device using ehci_hcd and address 9
[2049983.857000] usb 2-1.3: New USB device found, idVendor=0403, idProduct=6001
[2049983.857003] usb 2-1.3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[2049983.857006] usb 2-1.3: Product: TTL232R
[2049983.857007] usb 2-1.3: Manufacturer: FTDI
[2049983.857009] usb 2-1.3: SerialNumber: FTDCIX5Z
[2049983.879508] usbcore: registered new interface driver usbserial
[2049983.879520] USB Serial support registered for generic
[2049983.879578] usbcore: registered new interface driver usbserial_generic
[2049983.879580] usbserial: USB Serial Driver core
[2049983.888013] USB Serial support registered for FTDI USB Serial Device
[2049983.888095] ftdi_sio 2-1.3:1.0: FTDI USB Serial Device converter detected
[2049983.888168] usb 2-1.3: Detected FT232RL
[2049983.888170] usb 2-1.3: Number of endpoints 2
[2049983.888172] usb 2-1.3: Endpoint 1 MaxPacketSize 64
[2049983.888173] usb 2-1.3: Endpoint 2 MaxPacketSize 64
[2049983.888175] usb 2-1.3: Setting MaxPacketSize 64
[2049983.888935] usb 2-1.3: FTDI USB Serial Device converter now attached to ttyUSB0
[2049983.888947] usbcore: registered new interface driver ftdi_sio
[2049983.888948] ftdi_sio: v1.5.0:USB FTDI Serial Converters Driver

It connects to /dev/ttyUSB0.
However, I want this to be something like /dev/ttyPIC0.  How to?

See [1] but replace "udevinfo" with "udevadm info" on Debian.

# udevadm info -q path -n ttyUSB0
/class/tty/ttyUSB0

# udevadm info -a -p /class/tty/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 '/class/tty/ttyUSB0':
    KERNEL=="ttyUSB0"
    SUBSYSTEM=="tty"
    DRIVER==""

  looking at parent device '/class/tty':
    KERNELS=="tty"
    SUBSYSTEMS=="subsystem"
    DRIVERS==""

Starting from that, this should be what I need:

BUS=="usb", SYSFS{idProduct}=="6001", SYSFS{idVendor}=="0403", SYSFS{serial}=="FTDCIX5Z", NAME="ftdi"

But the "serial" doesn't match the "SerialNumber" tag.  So let's try
that.  Nothing..

Going with this[2].

It takes a wholly different approach, using ATTRS instaed of SYSFS.
Let's try again:

SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ATTRS{serial}=="FTDCIX5Z", SYMLINK+="ftdi"

Nothing.

I'm shooting in the dark.
  - Do you need to restart udev when config files change?
  - Where are the udev defaults?  (A: /lib/udev)
  - How to get debug information?
  - Who assigns the device to "dialout" ?
  - how does the override work? 00_* vs 99_*
  - different udev versions, ATTRS or SYSFS ?

RTFM?

The -a / --attribute-walk option prints all attribs.  What I get (see
above) doesn't really say much.

Removing that I don't get a match either.

It simply doesn't work as advertised.

Debugger? [3]

# udevadm monitor --env
UDEV - the event which udev sends out after rule processing
KERNEL - the kernel uevent

KERNEL[1293833567.771646] add      /devices/pci0000:00/0000:00:13.2/usb2/2-1/2-1.2 (usb)
UDEV_LOG=3
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:13.2/usb2/2-1/2-1.2
SUBSYSTEM=usb
DEVNAME=bus/usb/002/030
DEVTYPE=usb_device
PHYSDEVBUS=usb
DEVICE=/proc/bus/usb/002/030
PRODUCT=403/6001/600
TYPE=0/0/0
BUSNUM=002
DEVNUM=030
SEQNUM=1926
MAJOR=189
MINOR=157

KERNEL[1293833567.773003] add      /devices/pci0000:00/0000:00:13.2/usb2/2-1/2-1.2/2-1.2:1.0 (usb)
UDEV_LOG=3
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:13.2/usb2/2-1/2-1.2/2-1.2:1.0
SUBSYSTEM=usb
DEVTYPE=usb_interface
PHYSDEVBUS=usb
DEVICE=/proc/bus/usb/002/030
PRODUCT=403/6001/600
TYPE=0/0/0
INTERFACE=255/255/255
MODALIAS=usb:v0403p6001d0600dc00dsc00dp00icFFiscFFipFF
SEQNUM=1927

KERNEL[1293833567.773181] add      /devices/pci0000:00/0000:00:13.2/usb2/2-1/2-1.2/2-1.2:1.0/ttyUSB0 (usb-serial)
UDEV_LOG=3
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:13.2/usb2/2-1/2-1.2/2-1.2:1.0/ttyUSB0
SUBSYSTEM=usb-serial
PHYSDEVBUS=usb-serial
SEQNUM=1928

KERNEL[1293833567.773353] add      /class/tty/ttyUSB0 (tty)
UDEV_LOG=3
ACTION=add
DEVPATH=/class/tty/ttyUSB0
SUBSYSTEM=tty
DEVNAME=ttyUSB0
PHYSDEVPATH=/devices/pci0000:00/0000:00:13.2/usb2/2-1/2-1.2/2-1.2:1.0/ttyUSB0
PHYSDEVBUS=usb-serial
PHYSDEVDRIVER=ftdi_sio
SEQNUM=1929
MAJOR=188
MINOR=0

KERNEL[1293833567.773397] add      /class/usb_device/usbdev2.30 (usb_device)
UDEV_LOG=3
ACTION=add
DEVPATH=/class/usb_device/usbdev2.30
SUBSYSTEM=usb_device
DEVNAME=usbdev2.30
PHYSDEVPATH=/devices/pci0000:00/0000:00:13.2/usb2/2-1/2-1.2
PHYSDEVBUS=usb
PHYSDEVDRIVER=usb
SEQNUM=1930
MAJOR=189
MINOR=157

UDEV  [1293833567.775358] add      /class/tty/ttyUSB0 (tty)
UDEV_LOG=3
ACTION=add
DEVPATH=/class/tty/ttyUSB0
SUBSYSTEM=tty
DEVNAME=/dev/ttyUSB0
PHYSDEVPATH=/devices/pci0000:00/0000:00:13.2/usb2/2-1/2-1.2/2-1.2:1.0/ttyUSB0
PHYSDEVBUS=usb-serial
PHYSDEVDRIVER=ftdi_sio
SEQNUM=1929
MAJOR=188
MINOR=0
DEVLINKS=/dev/char/188:0

UDEV  [1293833567.778071] add      /devices/pci0000:00/0000:00:13.2/usb2/2-1/2-1.2 (usb)
UDEV_LOG=3
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:13.2/usb2/2-1/2-1.2
SUBSYSTEM=usb
DEVNAME=/dev/bus/usb/002/030
DEVTYPE=usb_device
PHYSDEVBUS=usb
DEVICE=/proc/bus/usb/002/030
PRODUCT=403/6001/600
TYPE=0/0/0
BUSNUM=002
DEVNUM=030
SEQNUM=1926
ID_VENDOR=FTDI
ID_VENDOR_ENC=FTDI
ID_VENDOR_ID=0403
ID_MODEL=TTL232R
ID_MODEL_ENC=TTL232R
ID_MODEL_ID=6001
ID_REVISION=0600
ID_SERIAL=FTDI_TTL232R_FTDCIX5Z
ID_SERIAL_SHORT=FTDCIX5Z
ID_BUS=usb
ID_USB_INTERFACES=:ffffff:
MAJOR=189
MINOR=157
DEVLINKS=/dev/char/189:157

UDEV  [1293833567.780128] add      /devices/pci0000:00/0000:00:13.2/usb2/2-1/2-1.2/2-1.2:1.0 (usb)
UDEV_LOG=3
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:13.2/usb2/2-1/2-1.2/2-1.2:1.0
SUBSYSTEM=usb
DEVTYPE=usb_interface
PHYSDEVBUS=usb
DEVICE=/proc/bus/usb/002/030
PRODUCT=403/6001/600
TYPE=0/0/0
INTERFACE=255/255/255
MODALIAS=usb:v0403p6001d0600dc00dsc00dp00icFFiscFFipFF
SEQNUM=1927

UDEV  [1293833567.781816] add      /devices/pci0000:00/0000:00:13.2/usb2/2-1/2-1.2/2-1.2:1.0/ttyUSB0 (usb-serial)
UDEV_LOG=3
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:13.2/usb2/2-1/2-1.2/2-1.2:1.0/ttyUSB0
SUBSYSTEM=usb-serial
PHYSDEVBUS=usb-serial
SEQNUM=1928

UDEV  [1293833567.782010] add      /class/usb_device/usbdev2.30 (usb_device)
UDEV_LOG=3
ACTION=add
DEVPATH=/class/usb_device/usbdev2.30
SUBSYSTEM=usb_device
DEVNAME=/dev/usbdev2.30
PHYSDEVPATH=/devices/pci0000:00/0000:00:13.2/usb2/2-1/2-1.2
PHYSDEVBUS=usb
PHYSDEVDRIVER=usb
SEQNUM=1930
MAJOR=189
MINOR=157
DEVLINKS=/dev/char/189:157



The add call has the ENV variable:
ID_SERIAL_SHORT=FTDCIX5Z

So it's definitely available.  Why don't my rules match?


Next: kill udevd and run
# udevd --debug

What do we learn from this?

  - it seems to parse the files on startup, so it looks like restart
    (or HUP?) is necessary to reload the config.

  - SYSFS{}= will be removed in a future udev version, please use
    ATTR{}= to match the event device, or ATTRS{}= to match a parent
    device

  - it doesn't seem to read the rules file in the first place.
    Problem was extension is not ".rules"

  - Got it to match with:
     SUBSYSTEM=="tty", SYMLINK+="foofoo"
    But not with:
     ENV{ID_SERIAL}=="FTDI_TTL232R_FTDCIX5Z"

  - The program /lib/udev/usb_id is used to set the environment
    variables, but apparently it doesn't do so for the rules I'm
    adding.  Trying to add something like this gives errors:
      IMPORT{program}="usb_id --export %p",



[1] http://www.cl.cam.ac.uk/research/dtg/research/wiki/Udev
[2] http://hintshop.ludvig.co.nz/show/persistent-names-usb-serial-devices/
[3] http://www.disa.nu/pub/doc/sles10/usr/share/doc/manual/sles-admin_en/sec.udev.debug.html



[Reply][About]
[<<][pool][>>][..]