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

时间:2019-03-15 18:57:49

标签: linux udev debian-stretch

我有一个名为“ 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规则,并希望对其中的内容进行一些解释/阅读。

1 个答案:

答案 0 :(得分:0)

为了确保该线程的完整性;我没有使用udev规则,而是创建了一个执行每次引导的简单systemd单元文件。可悲的是,我无法使udev规则起作用。