在加载驱动程序时使用 udev 规则执行命令

Execute command with udev rule on loading driver

我有一个名为 "my_touch" 的触摸屏驱动程序,它在启动时加载,因为它列在 /etc/modules 中。我想写一个 Udev 规则来在执行 /usr/sbin/ldattach 25 /dev/ttymxc1 加载后更改行门徒。我尝试了多个 udev 规则,但它们似乎不起作用。我几乎可以肯定规则必须类似于:

KERNEL=="my_touch", SUBSYSTEM=="module", ACTION=="add", RUN+="/usr/sbin/ldattach 25 /dev/ttymxc1"

驱动程序和设备都在 sysfs 中可用。

$ udevadm info -ap /module/my_touch/
  looking at device '/module/my_touch':
    KERNEL=="my_touch"
    SUBSYSTEM=="module"
    DRIVER==""
    ATTR{coresize}=="16384"
    ATTR{initsize}=="0"
    ATTR{initstate}=="live"
    ATTR{refcnt}=="0"
    ATTR{srcversion}=="45DFE5D135E9A5AFB61EB69"
    ATTR{taint}=="O"

  looking at parent device[..]

$ udevadm info -ap /devices/soc0/soc/2100000.aips-bus/21e8000.serial/tty/ttymxc1
  looking at device '/devices/soc0/soc/2100000.aips-bus/21e8000.serial/tty/ttymxc1':
    KERNEL=="ttymxc1"
    SUBSYSTEM=="tty"
    DRIVER==""
    ATTR{close_delay}=="50"
    ATTR{closing_wait}=="3000"
    ATTR{custom_divisor}=="0"
    ATTR{flags}=="0x10000000"
    ATTR{io_type}=="2"
    ATTR{iomem_base}=="0x21E8000"
    ATTR{iomem_reg_shift}=="0"
    ATTR{irq}=="68"
    ATTR{line}=="1"
    ATTR{port}=="0x0"
    ATTR{type}=="62"
    ATTR{uartclk}=="80000000"
    ATTR{xmit_fifo_size}=="32"

  looking at parent device[..]

如果测试规则,我的规则确实存在并且没有显示错误。

$ udevadm test /module/my_touch/
calling: test
version 232
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.

=== trie on-disk ===
tool version:          232
file size:         8447619 bytes
header size             80 bytes
strings            1849043 bytes
nodes              6598496 bytes
Load module index
Found container virtualization none
timestamp of '/etc/systemd/network' changed
Parsed configuration file /lib/systemd/network/99-default.link
Created link configuration context.
timestamp of '/etc/udev/rules.d' changed
Reading rules file: [..]
rules contain 49152 bytes tokens (4096 * 12 bytes), 12709 bytes strings
4208 strings (39523 bytes), 3485 de-duplicated (27538 bytes), 724 trie nodes used
RUN '/usr/sbin/ldattach 25 /dev/ttymxc1' /etc/udev/rules.d/10-Prodrive.rules:2
ACTION=add
DEVPATH=/module/my_touch
SUBSYSTEM=module
USEC_INITIALIZED=1366176459
run: '/usr/sbin/ldattach 25 /dev/ttymxc1'
Unload module index
Unloaded link configuration context.

适当的 udev 规则的线索和一些 explanation/reading 表示赞赏。

为了本帖的完整性;我没有使用 udev 规则,而是创建了一个简单的 systemd 单元文件,它在每次启动时执行。遗憾的是,我无法使 udev 规则起作用。