How to uniquely identify two identical USB-serial adapters in Linux

Kristina picture Kristina · Mar 24, 2011 · Viewed 7.3k times · Source

I have an embedded board running Linux which has two identical 4-port FTDI USB-serial chips. The USB-serial chips are hard wired to individual USB ports on the motherboard. There is no way for these devices to ever be "removed", "disconnected", or moved to a different physical USB location.

I'm worried on each bootup there will be a race condition with udev populating /dev/ttyUSBs. There is no guarantee one chip will always get enumerated before the other one, resulting in chip #1 sometimes getting /dev/ttyUSB0-3 and sometimes getting /dev/ttyUSB4-7.

Since this board is going to be used in an automated environment, it is not possible for a user to connect to the board on every boot up to manually decide which chip is assigned to which bank of /dev/ttyUSB's.

I need some way of making sure the processes running on my board are using the correct serial channel every time the device starts up. I'm guessing this can be done by either telling udev which /dev/ttyUSBs to assign to each chip, or running a script on start up after udev populated /dev to determine which chip got which /dev/ttyUSB#'s.

The problem is both chips are completely identical, but they will always be connected to the same physical USB location.

How can I tell these chips apart in Linux? And, how can I either set or determine which chip has which /dev/ttyUSB# on start up?

Answer

caf picture caf · Mar 25, 2011

You can tell udevd to assign specific names to the ports based on their physical connection, by creating rules that match against specific DEVPATH.

The DEVPATH is the path to the device under sysfs, starting at /devices/. It will look something like /devices/pci0000:00/0000:00:1d.3/usb5/5-2.