我的自定义 udev hwdb 规则不起作用

我的自定义 udev hwdb 规则不起作用

我使用的是安装在 EFI 模式下的 ubuntu 14.04,我尝试编写简单的 udev 规则,该规则将为所有外部 USB 键盘映射capslock以进行转义。我vim经常使用和插入和拔出键盘,因此这将大大简化事情。因此,按照不同的教程,我制作了这样的文件

cat /etc/udev/hwdb.d/61-keyboard-local.hwdb


keyboard:usb:v*p*
keyboard:usb:v046dpc30e*
    KEYBOARD_KEY_58=esc

然后我执行

udevadm hwdb --update

但它不起作用。我首先使用了双重映射,这是任何 USB 键盘的一般规则

keyboard:usb:v*p*

我已经插上电源了

keyboard:usb:v046dpc30e*

我以为也许特定的工作会起作用但不幸的是没有。

所以我尝试调试错误之处并按照其他教程运行此操作:

udevadm --debug test /devices/pci0000:00/0000:00:14.0/usb3/3-2/3-2:1.0/0003:046D:C30E.0007/input/input20
calling: test
version 204 
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:          204 
file size:         5740456 bytes
header size             80 bytes
strings            1262416 bytes
nodes              4477960 bytes
load module index
read rules file: /lib/udev/rules.d/40-crda.rules
read rules file: /lib/udev/rules.d/40-gnupg.rules
read rules file: /lib/udev/rules.d/40-gnupg2.rules
read rules file: /lib/udev/rules.d/40-hyperv-hotadd.rules
read rules file: /lib/udev/rules.d/40-inputattach.rules
read rules file: /lib/udev/rules.d/40-libgphoto2-6.rules
GOTO 'libgphoto2_usb_end' has no matching label in: '/lib/udev/rules.d/40-libgphoto2-6.rules'
read rules file: /lib/udev/rules.d/40-libsane.rules
read rules file: /lib/udev/rules.d/40-usb-media-players.rules
read rules file: /lib/udev/rules.d/40-usb_modeswitch.rules
read rules file: /lib/udev/rules.d/42-usb-hid-pm.rules
read rules file: /lib/udev/rules.d/50-firmware.rules
read rules file: /lib/udev/rules.d/50-udev-default.rules
read rules file: /lib/udev/rules.d/55-dm.rules
read rules file: /lib/udev/rules.d/56-hpmud.rules
read rules file: /lib/udev/rules.d/60-cdrom_id.rules
read rules file: /lib/udev/rules.d/60-keyboard.rules
read rules file: /lib/udev/rules.d/60-pcmcia.rules
read rules file: /lib/udev/rules.d/60-persistent-alsa.rules
read rules file: /lib/udev/rules.d/60-persistent-input.rules
read rules file: /lib/udev/rules.d/60-persistent-serial.rules
read rules file: /lib/udev/rules.d/60-persistent-storage-dm.rules
read rules file: /lib/udev/rules.d/60-persistent-storage-tape.rules
read rules file: /lib/udev/rules.d/60-persistent-storage.rules
read rules file: /lib/udev/rules.d/60-persistent-v4l.rules
read rules file: /lib/udev/rules.d/61-accelerometer.rules
read rules file: /lib/udev/rules.d/64-btrfs.rules
read rules file: /lib/udev/rules.d/64-xorg-xkb.rules
read rules file: /lib/udev/rules.d/66-xorg-synaptics-quirks.rules
read rules file: /lib/udev/rules.d/69-cd-sensors.rules
IMPORT found builtin 'usb_id --export %p', replacing /lib/udev/rules.d/69-cd-sensors.rules:89
read rules file: /lib/udev/rules.d/69-libmtp.rules
read rules file: /lib/udev/rules.d/69-xorg-vmmouse.rules
read rules file: /lib/udev/rules.d/69-xserver-xorg-input-wacom.rules
read rules file: /etc/udev/rules.d/70-persistent-net.rules
read rules file: /lib/udev/rules.d/70-power-switch.rules
read rules file: /lib/udev/rules.d/70-printers.rules
read rules file: /lib/udev/rules.d/70-uaccess.rules
read rules file: /lib/udev/rules.d/71-seat.rules
read rules file: /lib/udev/rules.d/73-idrac.rules
read rules file: /lib/udev/rules.d/73-seat-late.rules
read rules file: /lib/udev/rules.d/75-net-description.rules
read rules file: /lib/udev/rules.d/75-persistent-net-generator.rules
read rules file: /lib/udev/rules.d/75-probe_mtd.rules
read rules file: /lib/udev/rules.d/75-tty-description.rules
read rules file: /lib/udev/rules.d/77-mm-ericsson-mbm.rules
read rules file: /lib/udev/rules.d/77-mm-huawei-net-port-types.rules
read rules file: /lib/udev/rules.d/77-mm-longcheer-port-types.rules
read rules file: /lib/udev/rules.d/77-mm-nokia-port-types.rules
read rules file: /lib/udev/rules.d/77-mm-pcmcia-device-blacklist.rules
read rules file: /lib/udev/rules.d/77-mm-platform-serial-whitelist.rules
read rules file: /lib/udev/rules.d/77-mm-qdl-device-blacklist.rules
read rules file: /lib/udev/rules.d/77-mm-simtech-port-types.rules
read rules file: /lib/udev/rules.d/77-mm-usb-device-blacklist.rules
read rules file: /lib/udev/rules.d/77-mm-usb-serial-adapters-greylist.rules
read rules file: /lib/udev/rules.d/77-mm-x22x-port-types.rules
read rules file: /lib/udev/rules.d/77-mm-zte-port-types.rules
read rules file: /lib/udev/rules.d/77-nm-olpc-mesh.rules
read rules file: /lib/udev/rules.d/78-graphics-card.rules
read rules file: /lib/udev/rules.d/78-sound-card.rules
read rules file: /lib/udev/rules.d/80-drivers.rules
read rules file: /lib/udev/rules.d/80-mm-candidate.rules
read rules file: /lib/udev/rules.d/80-udisks2.rules
read rules file: /lib/udev/rules.d/85-brltty.rules
read rules file: /lib/udev/rules.d/85-hdparm.rules
read rules file: /lib/udev/rules.d/85-hplj10xx.rules
read rules file: /lib/udev/rules.d/85-keyboard-configuration.rules
read rules file: /lib/udev/rules.d/85-regulatory.rules
read rules file: /lib/udev/rules.d/85-usbmuxd.rules
read rules file: /lib/udev/rules.d/90-alsa-restore.rules
read rules file: /lib/udev/rules.d/90-alsa-ucm.rules
read rules file: /lib/udev/rules.d/90-libgpod.rules
read rules file: /lib/udev/rules.d/90-pulseaudio.rules
read rules file: /lib/udev/rules.d/95-cd-devices.rules
read rules file: /lib/udev/rules.d/95-udev-late.rules
read rules file: /lib/udev/rules.d/95-upower-battery-recall-dell.rules
read rules file: /lib/udev/rules.d/95-upower-battery-recall-fujitsu.rules
read rules file: /lib/udev/rules.d/95-upower-battery-recall-gateway.rules
read rules file: /lib/udev/rules.d/95-upower-battery-recall-ibm.rules
read rules file: /lib/udev/rules.d/95-upower-battery-recall-lenovo.rules
read rules file: /lib/udev/rules.d/95-upower-battery-recall-toshiba.rules
read rules file: /lib/udev/rules.d/95-upower-csr.rules
read rules file: /lib/udev/rules.d/95-upower-hid.rules
read rules file: /lib/udev/rules.d/95-upower-wup.rules
read rules file: /lib/udev/rules.d/97-bluetooth-hid2hci.rules
rules contain 196608 bytes tokens (16384 * 12 bytes), 33727 bytes strings
18818 strings (164973 bytes), 15727 de-duplicated (134338 bytes), 3092 trie nodes used
device 0x15f81b0 has devpath '/devices/pci0000:00/0000:00:14.0/usb3/3-2/3-2:1.0/0003:046D:C30E.0007/input/input20'
device 0x1600050 filled with db file data
device 0x15ff420 has devpath '/devices/virtual/dmi/id'
value '[dmi/id]sys_vendor' is 'Hewlett-Packard'
IMPORT builtin 'usb_id' /lib/udev/rules.d/40-libgphoto2-6.rules:3
device 0x15ff420 has devpath '/devices/pci0000:00/0000:00:14.0/usb3/3-2/3-2:1.0/0003:046D:C30E.0007'
device 0x1605e30 has devpath '/devices/pci0000:00/0000:00:14.0/usb3/3-2/3-2:1.0'
/sys/devices/pci0000:00/0000:00:14.0/usb3/3-2/3-2:1.0: if_class 3 protocol 0
device 0x1607b80 has devpath '/devices/pci0000:00/0000:00:14.0/usb3/3-2'
device 0x1608170 has devpath '/devices/pci0000:00/0000:00:14.0/usb3'
device 0x1608550 has devpath '/devices/pci0000:00/0000:00:14.0'
device 0x1608930 has devpath '/devices/pci0000:00'
IMPORT builtin 'input_id' /lib/udev/rules.d/50-udev-default.rules:10
capabilities/ev raw kernel attribute: 120013
capabilities/abs raw kernel attribute: 0
capabilities/rel raw kernel attribute: 0
capabilities/key raw kernel attribute: 1000000000007 ff800000000007ff febeffdff3cfffff fffffffffffffffe
test_key: checking bit block 0 for any keys; found=1
test_key: checking bit block 64 for any keys; found=1
test_key: checking bit block 128 for any keys; found=1
test_key: checking bit block 192 for any keys; found=1
IMPORT builtin 'hwdb' /lib/udev/rules.d/50-udev-default.rules:11
IMPORT builtin 'hwdb' returned non-zero
IMPORT builtin 'path_id' /lib/udev/rules.d/60-persistent-input.rules:31
device 0x15ff420 filled with db file data
RUN 'kmod load $env{MODALIAS}' /lib/udev/rules.d/80-drivers.rules:5
unable to create temporary db file '/run/udev/data/+input:input20.tmp': Permission denied
.INPUT_CLASS=kbd
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb3/3-2/3-2:1.0/0003:046D:C30E.0007/input/input20
EV=120013
ID_BUS=usb
ID_FOR_SEAT=input-pci-0000_00_14_0-usb-0_2_1_0
ID_INPUT=1
ID_INPUT_KEY=1
ID_INPUT_KEYBOARD=1
ID_MODEL=HID_compliant_keyboard
ID_MODEL_ENC=HID\x20compliant\x20keyboard
ID_MODEL_ID=c30e
ID_PATH=pci-0000:00:14.0-usb-0:2:1.0
ID_PATH_TAG=pci-0000_00_14_0-usb-0_2_1_0
ID_REVISION=0180
ID_SERIAL=Logitech_HID_compliant_keyboard
ID_TYPE=hid
ID_USB_DRIVER=usbhid
ID_USB_INTERFACES=:030101:030000:
ID_USB_INTERFACE_NUM=00
ID_VENDOR=Logitech
ID_VENDOR_ENC=Logitech
ID_VENDOR_ID=046d
KEY=1000000000007 ff800000000007ff febeffdff3cfffff fffffffffffffffe
LED=7
MODALIAS=input:b0003v046DpC30Ee0110-e0,1,4,11,14,k71,72,73,74,75,77,79,7A,7B,7C,7D,7E,7F,80,81,82,83,84,85,86,87,88,89,8A,B7,B8,B9,BA,BB,BC,BD,BE,BF,C0,C1,C2,F0,ram4,l0,1,2,sfw
MSC=10
NAME="Logitech HID compliant keyboard"
PHYS="usb-0000:00:14.0-2/input0"
PRODUCT=3/46d/c30e/110
PROP=0
SUBSYSTEM=input
TAGS=:seat:
UDEV_LOG=7
UNIQ=""
USEC_INITIALIZED=3550400
run: 'kmod load input:b0003v046DpC30Ee0110-e0,1,4,11,14,k71,72,73,74,75,77,79,7A,7B,7C,7D,7E,7F,80,81,82,83,84,85,86,87,88,89,8A,B7,B8,B9,BA,BB,BC,BD,BE,BF,C0,C1,C2,F0,ram4,l0,1,2,sfw'
unload module index

知道如何调试它并使其工作吗?

答案1

格式为KEYBOARD_KEY_<hex scan code>。使用“evtest”查找正确的扫描代码。运行它,选择适当的设备并按下您想要扫描代码的键。查找类似以下内容的内容:

Event: time 1410505361.975680, type 4 (EV_MSC), code 4 (MSC_SCAN), value 70039
Event: time 1410505361.975680, type 1 (EV_KEY), code 58 (KEY_CAPSLOCK), value 1

您希望代码位于之后MSC_SCAN,因此在我的键盘上它是 70039,我相信这对所有 USB 键盘都适用。

此外,之后:

udevadm hwdb --update

你需要:

udevadm trigger

激活新的映射。

答案2

我遇到了类似的问题。对我来说,问题实际上在这里:

kmod load $env{MODALIAS}' /lib/udev/rules.d/80-drivers.rules:5

我怀疑你想要的是其他规则,但你得到的是:

kmod load input:b0003v046DpC30Ee0110-e0,1,4,11,14,k71,72,73,74,75,77,79,7A,7B,7C,7D,7E,7F,80,81,82,83,84,85,86,87,88,89,8A,B7,B8,B9,BA,BB,BC,BD,BE,BF,C0,C1,C2,F0,ram4,l0,1,2,sfw

尝试添加回来:

DRIVER!="?*", ENV{MODALIAS}=="?*", RUN{builtin}="kmod load $env{MODALIAS}"

转到第 5 行80-drivers.rules,看看您会得到什么。

答案3

您需要有一个实际上与系统中的 udev 规则实际执行的 hwdb 查找相匹配的模式,请记住发行版的 udev 规则在较新版本中可能会有所不同。

udevadm test您需要知道如何根据指导您的信息来确定模式应该是什么样子。

对我来说相关的/dev/input/by-id/*-kbd设备是/dev/input/by-id/usb-GASIA_PS2toUSB_Adapter-event-kbd

正在执行udevadm test

$ sudo udevadm --debug test `udevadm info -q path -n /dev/input/by-id/usb-GASIA_PS2toUSB_Adapter-event-kbd`

您需要查找有证据表明 udev 规则正在执行相关 hwdb 查找的行:

...
event14: IMPORT builtin 'hwdb' /usr/lib/udev/rules.d/60-evdev.rules:8
...
event14: IMPORT builtin 'hwdb' /usr/lib/udev/rules.d/60-evdev.rules:17
...

如果您查看引用的规则文件,您可以看到哪些规则被满足,然后找出那些具有足够选择性以匹配您想要重新映射的设备。例如,在我的/usr/lib/udev/rules.d/60-evdev.rules第 17 行:

# device matching the input device name + properties + the machine's DMI data
KERNELS=="input*", IMPORT{builtin}="hwdb 'evdev:name:$attr{name}:phys:$attr{phys}:ev:$attr{capabilities/ev}:$attr{[dmi/id]modalias}'", \
  RUN{builtin}+="keyboard", GOTO="evdev_end"

因此,在 hwdb 中查找的字符串以 开头,evdev:name:后跟设备的名称属性,但那是什么?

在设备上使用udevadm info -a以查看其属性(除了使用您可能已经在日志中拥有的有关更多动态替换的信息udevadm test):

$ udevadm info -a -n /dev/input/by-id/usb-GASIA_PS2toUSB_Adapter-event-kbd
...
  looking at parent device '/devices/pci0000:00/0000:00:10.0/usb2/2-3/2-3:1.0/0003:0E8F:0020.0002/input/input19':
    ...
    ATTRS{name}=="GASIA PS2toUSB Adapter"
    ...

所以名字是GASIA PS2toUSB Adapter,我的模式可以是

evdev:name:GASIA PS2toUSB Adapter:*

对于我的目的来说,这似乎足够具有选择性,刚好匹配我想要重新映射按键的设备。

现在只需evtest在设备上使用来映射 USB 扫描码,并查找找出/usr/src/linux/input-event-codes.h要映射到的键盘符号,然后将其全部放入自定义 hwdb 文件中。

/etc/udev/hwdb.d/90-custom-keyboard.hwdb

evdev:name:GASIA PS2toUSB Adapter:*
 KEYBOARD_KEY_70056=backspace
 KEYBOARD_KEY_7003c=kpminus
 # ...

然后

sudo systemd-hwdb update
sudo udevadm trigger

相关内容