meta data for this page
  •  

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
linux:udev [2016/04/06 12:07]
niziak created
linux:udev [2023/12/13 16:31] (current)
niziak
Line 1: Line 1:
-=== Debug ===+==== udevadm ==== 
 +=== reloading rules === 
 +<code bash>​udevadm control --reload-rules</​code>​ 
 +<code bash>​udevadm control --reload-rules && udevadm trigger</​code>​ 
 + 
 +=== Testing rules === 
 +<code bash>​udevadm test /​sys/​class/​tty/​ttyACM0</​code>​ 
 + 
 +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 ==== 
 +<code bash> 
 +udevadm info --attribute-walk --path=/​sys/​class/​tty/​ttyACM0 
 +udevadm info --attribute-walk --name=/​dev/​ttyUSB0 
 +</​code>​ 
 + 
 +=== Get Telit modem serial number === 
 +<code bash> 
 +udevadm info -q property -n /​dev/​ttyACM1 | grep ID_SERIAL_SHORT 
 +ID_SERIAL_SHORT=356136070718830 
 +</​code>​ 
 + 
 +==== Debug ====
 <file | /​etc/​udev/​udev.conf>​ <file | /​etc/​udev/​udev.conf>​
 udev_log="​debug"​ udev_log="​debug"​
 </​file>​ </​file>​
 +
 +<code bash>
 +udevadm control --log-priority=debug
 +
 +</​code>​
 +
 +==== 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.
 +<​code>​
 +SUBSYSTEM=="​power_supply",​ ENV{POWER_SUPPLY_ONLINE}=="​0",​ RUN+="/​usr/​bin/​true"​
 +SUBSYSTEM=="​power_supply",​ ENV{POWER_SUPPLY_ONLINE}=="​1",​ RUN+="/​usr/​bin/​true"​
 +</​code>​
 +
 +**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.
 +
 +
 +<​code>​
 +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'"​
 +</​code>​
 +
 +=== Shell ENV ===
 +<code bash>
 +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
 +</​code>​
 +
 +
 +=== Creating device symlinks ===
 +<​code>​
 +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"​
 +</​code>​
 +''​link_priority'':​ higher has higher priority
 +
 +Define symlink name in device tree (add property ''​symlink''​) i.e:
 +<​code>​
 +&pwm4 {
 + pinctrl-names = "​default";​
 + pinctrl-0 = <&​pinctrl_pwm4>;​
 + status = "​okay";​
 + symlink = "​buzzer";​
 +};
 +</​code>​
 +
 +<​code>​
 +ATTR{device/​of_node/​symlink}!="",​ ENV{DEVNAME}!="",​ SYMLINK+="​%s{device/​of_node/​symlink}"​
 +</​code>​
 +
 +See:
 +  - [[https://​github.com/​mvduin/​py-uio/​blob/​master/​dts/​pwmss2.dtsi#​L122|pwmss2.dtsi]]
 +  - [[https://​github.com/​mvduin/​py-uio/​blob/​master/​etc/​udev/​rules.d/​10-of-symlink.rules|10-of-symlink.rules]]
 +  - [[https://​github.com/​mvduin/​py-uio/​blob/​master/​dts/​pwmss2.dtsi|pwmss2.dtsi]]
 +
 +=== Triggering systemd ===
 +<​code>​
 +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"​
 +</​code>​
 +
 +More info about systemd interactions:​ [[https://​www.freedesktop.org/​software/​systemd/​man/​latest/​systemd.device.html|systemd.device — Device unit configuration]]
 +
 +=== Prevent ModemManager ===
 +<file | /​etc/​udev/​rules.d/​99-nomm.rules>​
 +ATTRS{idVendor}=="​0451"​ ATTR{idProduct}=="​bef3",​ ENV{ID_MM_DEVICE_IGNORE}="​1"​
 +</​file>​
 +