[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Static device naming with udev, help please

[ As discussed previously, I am coming back to the list with the
  (hopefully) relevant part of what you sent me privately. ]

On Sun, Nov 16, 2008 at 08:06:10 -0600, Nate Bargmann wrote:
> * Florian Kulzer [2008 Nov 16 06:59 -0600]:
> > On Sat, Nov 15, 2008 at 18:14:45 -0600, Nate Bargmann wrote:
> > > * Florian Kulzer [2008 Nov 15 08:04 -0600]:
> > > > On Sat, Nov 15, 2008 at 07:21:59 -0600, Nate Bargmann wrote:
> > 
> > [...]
> > 
> > > > I would try it like this:
> > > > 
> > > > KERNEL=="ttyUSB*", SUBSYSTEMS=="usb", ATTRS{busnum}=="6", ATTRS{devnum}=="3", SYMLINK+="tty_dgl0"
> > > > KERNEL=="ttyUSB*", SUBSYSTEMS=="usb", ATTRS{busnum}=="7", ATTRS{devnum}=="5", SYMLINK+="tty_dgl1"


> My system doesn't like that either:
> # udevadm test $(udevadm info --query=path --name /dev/usb/ttyUSB0) | grep -E 'get_name|symlink'
> node name not found
> devpath parameter missing

Ah, my mistake: Google had suggested to me that ttyUSB* device nodes are
created under /dev/usb/, so I used the wrong path in the command above.
You have to replace that by /dev/ttyUSB0.

> Besides, how does a mere mortal figure *that* command out?

You can read the entrails of the sacrificial chicken that you mentioned
earlier. ;)

In case you are out of chickens: If you know the sysfs path of the
device (from the output of udevinfo quoted below) then the command is
much shorter:

udevadm test /class/tty/ttyUSB0

Since I did not know the sysfs path I used command substitution $(...)
to let "udevadm info ..." fill in that information on the fly. The
documentation in /usr/share/doc/udev/writing_udev_rules/index.html has a
few similar examples.

The grep expression is the result of a bit of trial-and-error with my
USB stick to find a way of isolating the relevant lines in the "udevadm
test ..." output.


> The dongles aren't modems, they just provide an RS-232 port to a
> machine that lacks them for amateur radio software device interface. 
> These dongles are left plugged into the machine and the order in which
> they're assigned ttyUSB0/1 matters to the software that uses them. 
> When they come up in random order I have to hunt down various
> configurations, based on the program, and reset things.  When they flip
> from boot to boot, it's particularly maddening.
> Anyway, here are a couple of files invoked with:
> udevinfo -a --name=/dev/ttyUSB0 > ttyUSB0.txt
> udevinfo -a --name=/dev/ttyUSB1 > ttyUSB1.txt
> for your viewing pleasure.

What follows is an edited diff of the two files with suggestions for how
to write the rules. Lines starting with "-" and "+" are unique to
ttyUSB0 and ttyUSB1, respectively; lines beginning with " " are common
to both of them; "|" marks my comments; "[...]" indicates deletions of
common lines.

-  looking at device '/class/tty/ttyUSB0':
+  looking at device '/class/tty/ttyUSB1':
-    KERNEL=="ttyUSB0"
+    KERNEL=="ttyUSB1"

| The devices themselves offer no distinction except the kernel names
| (which can switch places), but they give us the starting point for our
| rules:
|   KERNEL=="ttyUSB*"

-  looking at parent device '/devices/pci0000:00/0000:00:1e.0/0000:03:0c.0/usb6/6-2/6-2:1.0/ttyUSB0':
+  looking at parent device '/devices/pci0000:00/0000:00:1e.0/0000:03:0c.1/usb7/7-2/7-2:1.0/ttyUSB1':
-    KERNELS=="ttyUSB0"
+    KERNELS=="ttyUSB1"

| The first parent device does not provide any helpful identifiers,
| but we see that the parents have the same KERNEL parameters as the
| children, therefore we have to make the start of our rules more
| specific:
|   KERNEL=="ttyUSB*", SUBSYSTEM=="tty"

-  looking at parent device '/devices/pci0000:00/0000:00:1e.0/0000:03:0c.0/usb6/6-2/6-2:1.0':
+  looking at parent device '/devices/pci0000:00/0000:00:1e.0/0000:03:0c.1/usb7/7-2/7-2:1.0':
-    KERNELS=="6-2:1.0"
+    KERNELS=="7-2:1.0"


-    ATTRS{modalias}=="usb:v067Bp2303d0400dc00dsc00dp00icFFisc00ip00"
+    ATTRS{modalias}=="usb:v067Bp2303d0300dc00dsc00dp00icFFisc00ip00"

| This parent offers two properties to distinguish the devices, for
| example like this:
|   KERNEL=="ttyUSB*", SUBSYSTEM=="tty", KERNELS=="6-2:1.0", SYMLINK+="tty_dgl0" 
|   KERNEL=="ttyUSB*", SUBSYSTEM=="tty", KERNELS=="7-2:1.0", SYMLINK+="tty_dgl1" 
| Using ATTRS{modalias} instead of KERNELS should also work.

-  looking at parent device '/devices/pci0000:00/0000:00:1e.0/0000:03:0c.0/usb6/6-2':
+  looking at parent device '/devices/pci0000:00/0000:00:1e.0/0000:03:0c.1/usb7/7-2':
-    KERNELS=="6-2"
+    KERNELS=="7-2"


-    ATTRS{bcdDevice}=="0400"
+    ATTRS{bcdDevice}=="0300"


-    ATTRS{busnum}=="6"
+    ATTRS{busnum}=="7"
-    ATTRS{devnum}=="3"
+    ATTRS{devnum}=="5"


-    ATTRS{manufacturer}=="Prolific Technology Inc. "
+    ATTRS{manufacturer}=="Prolific Technology Inc."
-    ATTRS{product}=="USB-Serial Controller D"
+    ATTRS{product}=="USB-Serial Controller"

| There are more possibilities here, for example the difference in the
| product strings:
|   KERNEL=="ttyUSB*", SUBSYSTEM=="tty", ATTRS{product}=="USB-Serial Controller D", SYMLINK+="tty_dgl0"
|   KERNEL=="ttyUSB*", SUBSYSTEM=="tty", ATTRS{product}=="USB-Serial Controller", SYMLINK+="tty_dgl1"
| It seems to me that our earlier rule with ATTRS{busnum} and
| ATTRS{devnum} should work, too; maybe the missing SUBSYSTEM=="tty" was
| the problem.


The remaining parent devices higher up the chain also offer some unique
identifiers, but I generally try not to walk up the sysfs tree any
further than necessary. (The higher up a parent node sits, the greater
is the risk that it has other children which by accident match my rules
and thus confuse things.)

Regards,            | http://users.icfo.es/Florian.Kulzer
          Florian   |

Reply to: