TracNav
- Home
- Research Overview
- MPhil Information
Research Projects
- Wireless Comms
- Bat System
- Broadband Phone
Visual tags
- Sentient Vehicles
- Task Assignment
- NLMaP
- Computing for the Future of the Planet
- SESAME
- Active Floor
- Open-Source CSK Energy
Development Info
DTG Local Pages
- Cambridge Weather
- Contact Details
udev
Author: Jonathan Davies
udev is a Linux utility which provides persistent device names even when the kernel provides variable names. For a detailed description of udev, see the udev homepage or the FAQ. This page gives a brief tutorial about configuring udev to work with some of the devices that we use in the Sentient Van.
In the Sentient Van, we have a large number of devices which present an RS232-style interface over USB, making use of the usbserial kernel module. Depending on the order in which these devices are detected, they will each be assigned device files such as /dev/ttyUSB0, /dev/ttyUSB1, /dev/ttyUSB2, and so on. Since there is no guarantee that a particular physical device will always be assigned the same device file, this makes it hard to write applications to interface with these devices. udev provides a means by which these applications can permanently refer to a device file which is guaranteed to always be assigned to the same physical device. This device file may either appear as a symbolic link to the appropriate underlying kernel-supplied device file or as a normal device file which acts in the same way as the kernel-supplied device file.
udev uses a rules file, usually located in /etc/udev/rules.d/50-udev.rules. Whenever a new device is inserted, udev will check this file for a rule matching the description of the device and will generate the appropriate virtual device file or symbolic link.
In order to create rules, we make heavy use of udevinfo. If we have a device at /dev/ttyUSB0, then we execute the following command to establish the location of the device in the sysfs tree:
# udevinfo -q path -n ttyUSB0
This will return a string such as /class/tty/ttyUSB0, which is the path within the sysfs tree at which the device is located. Now execute the following command to yield a wealth of information about that device:
# udevinfo -a -p /class/tty/ttyUSB0
TODO: give some sample output
The output will show all the available information regarding each device in the hierarchy above the device at /class/tty/ttyUSB0. Find the section that refers to the physical device you have inserted. In this section, establish which lines describe items that uniquely describe your device. Typical lines for USB devices to look at include idProduct, idVendor, manufacturer and serial.
For a USB device, we can now create a rule such as the following:
BUS=="usb", SYSFS{idProduct}=="ff00", SYSFS{idVendor}=="0403", SYSFS{serial}=="FT2YYD3U", NAME="ftdi"
This rule will cause all USB devices matching that product ID, vendor ID and serial number to appear at the device file /dev/ftdi (as well as /dev/ttyUSB0 or whatever it would usually appear as).
If we had wanted /dev/ftdi to be a symbolic link pointing to /dev/ttyUSB0, we would change the NAME="ftdi" part of the rule to SYMLINK="ftdi". The use of symbolic links makes it clearer to the user what device file the virtual file refers to. However, one advantage of the NAME approach is that we are also able to specify the file permissions for the new device file: this is not possible using the SYMLINK approach. This can be achieved by appending MODE="666" (or similar) to the rule line.
Note that for non-USB (or similar) devices, we don't necessarily have access to such a rich quantity of information. We can unfortunately no longer rely on vendor and product IDs. We therefore lose the advantages of udev since our rule must describe the physical port into which the device is plugged rather than the identity of the device itself. Nevertheless, it does allow us to give a pleasant and meaningful name to the device rather (rather than something like /dev/ttyS0) provided that it is never moved between ports.
