Embedded Linux UDEV Rules for Mapping Devices

Embedded Linux UDEV Rules for Mapping Devices


When you load a driver in an embedded Linux environment, it may show up as a device file under /dev/input/eventX ( where X could be 0,1,2... etc. - and which could change each time you reboot). You can setup udev to have a 'rule' that causes the device to alway be mapped to a known name each reboot. For example consider a touchscreen which on some reboot happens to be mapped to /dev/input/event0.

# ls -rlt /dev/input/

crw-rw---- 1 root fluke 13, 64 Jun 5 13:19 event0

To create a constant mapped name for this device go to /sys/class/<device> and find the 'name' of the device:

# pwd

/sys/class/input/event0/device

# ls

capabilities event0 modalias phys properties uevent

device id name power subsystem uniq

# cat name

Atmel Touchscreen

Now setup your rules file ( /etc/udev/rules.d/00-custom.rules ) to include the following rule:

ACTION=="add", SUBSYSTEMS=="input", ATTRS{name}=="Atmel Touchscreen", MODE:="0660", GROUP:="myGroup", SYMLINK:="input/touchscreen", END

Now reboot and you will see:

# ls -rlt /dev/input/

lrwxrwxrwx 1 root root 6 Jun 5 13:19 touchscreen -> event0

crw-rw---- 1 root fluke 13, 64 Jun 5 13:19 event0

Cheers!




ClassyBits 2016