meta data for this page
Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
linux:udev [2016/10/06 11:21] niziak [Rules] |
linux:udev [2023/12/13 16:31] (current) niziak |
||
---|---|---|---|
Line 1: | Line 1: | ||
==== udevadm ==== | ==== udevadm ==== | ||
=== reloading rules === | === reloading rules === | ||
- | udevadm control --reload-rules | + | <code bash>udevadm control --reload-rules</code> |
+ | <code bash>udevadm control --reload-rules && udevadm trigger</code> | ||
=== Testing rules === | === Testing rules === | ||
- | udevadm test /sys/class/tty/ttyACM0 | + | <code bash>udevadm test /sys/class/tty/ttyACM0</code> |
- | ==== Getting info ==== | + | 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 --path=/sys/class/tty/ttyACM0 | ||
+ | udevadm info --attribute-walk --name=/dev/ttyUSB0 | ||
+ | </code> | ||
=== Get Telit modem serial number === | === Get Telit modem serial number === | ||
Line 21: | Line 26: | ||
</file> | </file> | ||
+ | <code bash> | ||
+ | udevadm control --log-priority=debug | ||
+ | |||
+ | </code> | ||
==== Rules ==== | ==== Rules ==== | ||
Line 38: | Line 47: | ||
- | === Executing commands === | + | ==== Executing commands ==== |
+ | Triggering commands should be done using RUN, because it is executed after all systemd actions. | ||
<code> | <code> | ||
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="0", RUN+="/usr/bin/true" | SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="0", RUN+="/usr/bin/true" | ||
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="1", RUN+="/usr/bin/true" | SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="1", RUN+="/usr/bin/true" | ||
</code> | </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 === | === Creating device symlinks === | ||
Line 51: | Line 101: | ||
''link_priority'': higher has higher priority | ''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 === | === Triggering systemd === | ||
Line 58: | Line 126: | ||
SUBSYSTEM=="printer", TAG+="systemd", ENV{SYSTEMD_WANTS}="printer.target" | SUBSYSTEM=="printer", TAG+="systemd", ENV{SYSTEMD_WANTS}="printer.target" | ||
</code> | </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> | ||
+ |