meta data for this page

udevadm

reloading rules

udevadm control --reload-rules
udevadm control --reload-rules && udevadm trigger

Testing rules

udevadm test /sys/class/tty/ttyACM0

NOTE: This program is for debugging only, it does not run any program specified by a RUN key. It may show incorrect results, because some values may be different, or not available at a simulation run.

Getting info

udevadm info --attribute-walk --path=/sys/class/tty/ttyACM0
udevadm info --attribute-walk --name=/dev/ttyUSB0

Get Telit modem serial number

udevadm info -q property -n /dev/ttyACM1 | grep ID_SERIAL_SHORT
ID_SERIAL_SHORT=356136070718830

Debug

/etc/udev/udev.conf
udev_log="debug"
udevadm control --log-priority=debug

Rules

Order

Files should be named xx-descriptive-name.rules, the xx should be chosen first according to the following sequence points:

< 60 most user rules; if you want to prevent an assignment being overriden by default rules, use the := operator.

these cannot access persistent information such as that from vol_id

< 70 rules that run helpers such as vol_id to populate the udev db

< 90 rules that run other programs (often using information in the udev db)

>=90 rules that should run last

Executing commands

Triggering commands should be done using RUN, because it is executed after all systemd actions.

SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="0", RUN+="/usr/bin/true"
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="1", RUN+="/usr/bin/true"

RUN vs PROGRAM

PROGRAM is used to return device name, e.g. to return name for symlink. It is called during device setup, so it is not good place to execute external tools.

ACTION=="add", DRIVERS=="usb", ATTRS{manufacturer}=="Telit", ATTRS{idVendor}=="1bc7", ATTRS{idProduct}=="0021", PROGRAM="/bin/sh -c '/bin/echo -e {\\042imei\\042:\\042%s{serial}\\042} > /etc
/imei.json'"

Shell ENV

ID_BUS=usb
DEVNAME=/dev/ttyACM0
ID_VENDOR_FROM_DATABASE=Telit Wireless Solutions
ACTION=add
ID_SERIAL_SHORT=356611070046259
ID_USB_DRIVER=cdc_acm
ID_TYPE=generic
MAJOR=166
DEVPATH=/devices/platform/ocp/47400000.usb/47401c00.usb/musb-hdrc.0.auto/usb1/1-1/1-1:1.0/tty/ttyACM0
ID_MODEL_ENC=FIH7160
ID_USB_INTERFACES=:020201:0a0000:020d00:0a0001:
ID_MODEL=FIH7160
DEVLINKS=/dev/serial/by-path/platform-musb-hdrc.0.auto-usb-0:1:1.0 /dev/serial/by-id/usb-Telit_FIH7160_356611070046259-if00
ID_SERIAL=Telit_FIH7160_356611070046259
SUBSYSTEM=tty
ID_MODEL_ID=0036
MINOR=0
ID_PATH=platform-musb-hdrc.0.auto-usb-0:1:1.0
ID_MODEL_FROM_DATABASE=LE910 V2
ID_VENDOR_ENC=Telit
ID_PATH_TAG=platform-musb-hdrc_0_auto-usb-0_1_1_0
ID_VENDOR=Telit
ID_USB_INTERFACE_NUM=00
ID_VENDOR_ID=1bc7
ID_REVISION=1730
SUBSYSTEM=="input", KERNEL=="event[0-9]*", ENV{ID_INPUT_TOUCHSCREEN}=="1", ATTRS{name}=="edt-ft53*", SYMLINK+="input/touchscreen", OPTIONS+="link_priority=100"
SUBSYSTEM=="input", KERNEL=="event[0-9]*", ENV{ID_INPUT_TOUCHSCREEN}=="1", ATTRS{name}=="ti-tsc",    SYMLINK+="input/touchscreen", OPTIONS+="link_priority=0"

link_priority: higher has higher priority

Define symlink name in device tree (add property symlink) i.e:

&pwm4 {
	pinctrl-names = "default";
	pinctrl-0 = <&pinctrl_pwm4>;
	status = "okay";
	symlink = "buzzer";
};
ATTR{device/of_node/symlink}!="", ENV{DEVNAME}!="", SYMLINK+="%s{device/of_node/symlink}"

See:

Triggering systemd

SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="0", TAG+="systemd", ENV{SYSTEMD_WANTS}="powersaving.service"
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="1", TAG+="systemd", ENV{SYSTEMD_WANTS}="powersaving.service"
SUBSYSTEM=="printer", TAG+="systemd", ENV{SYSTEMD_WANTS}="printer.target"

More info about systemd interactions: systemd.device — Device unit configuration

Prevent ModemManager

/etc/udev/rules.d/99-nomm.rules
ATTRS{idVendor}=="0451" ATTR{idProduct}=="bef3", ENV{ID_MM_DEVICE_IGNORE}="1"