README 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. # HID-BPF programs
  2. This directory contains various fixes for devices. They add new features or
  3. fix some behaviors without being entirely mandatory. It is better to load them
  4. when you have such a device, but they should not be a requirement for a device
  5. to be working during the boot stage.
  6. The .bpf.c files provided here are not automatically compiled in the kernel.
  7. They should be loaded in the kernel by `udev-hid-bpf`:
  8. https://gitlab.freedesktop.org/libevdev/udev-hid-bpf
  9. The main reasons for these fixes to be here is to have a central place to
  10. "upstream" them, but also this way we can test them thanks to the HID
  11. selftests.
  12. Once a .bpf.c file is accepted here, it is duplicated in `udev-hid-bpf`
  13. in the `src/bpf/stable` directory, and distributions are encouraged to
  14. only ship those bpf objects. So adding a file here should eventually
  15. land in distributions when they update `udev-hid-bpf`
  16. ## Compilation
  17. Just run `make`
  18. ## Installation
  19. ### Automated way
  20. Just run `sudo udev-hid-bpf install ./my-awesome-fix.bpf.o`
  21. ### Manual way
  22. - copy the `.bpf.o` you want in `/etc/udev-hid-bpf/`
  23. - create a new udev rule to automatically load it
  24. The following should do the trick (assuming udev-hid-bpf is available in
  25. /usr/bin):
  26. ```
  27. $> cp xppen-ArtistPro16Gen2.bpf.o /etc/udev-hid-bpf/
  28. $> udev-hid-bpf inspect xppen-ArtistPro16Gen2.bpf.o
  29. [
  30. {
  31. "name": "xppen-ArtistPro16Gen2.bpf.o",
  32. "devices": [
  33. {
  34. "bus": "0x0003",
  35. "group": "0x0001",
  36. "vid": "0x28BD",
  37. "pid": "0x095A"
  38. },
  39. {
  40. "bus": "0x0003",
  41. "group": "0x0001",
  42. "vid": "0x28BD",
  43. "pid": "0x095B"
  44. }
  45. ],
  46. ...
  47. $> cat <EOF > /etc/udev/rules.d/99-load-hid-bpf-xppen-ArtistPro16Gen2.rules
  48. ACTION!="add|remove", GOTO="hid_bpf_end"
  49. SUBSYSTEM!="hid", GOTO="hid_bpf_end"
  50. # xppen-ArtistPro16Gen2.bpf.o
  51. ACTION=="add",ENV{MODALIAS}=="hid:b0003g0001v000028BDp0000095A", RUN{program}+="/usr/local/bin/udev-hid-bpf add $sys$devpath /etc/udev-hid-bpf/xppen-ArtistPro16Gen2.bpf.o"
  52. ACTION=="remove",ENV{MODALIAS}=="hid:b0003g0001v000028BDp0000095A", RUN{program}+="/usr/local/bin/udev-hid-bpf remove $sys$devpath "
  53. # xppen-ArtistPro16Gen2.bpf.o
  54. ACTION=="add",ENV{MODALIAS}=="hid:b0003g0001v000028BDp0000095B", RUN{program}+="/usr/local/bin/udev-hid-bpf add $sys$devpath /etc/udev-hid-bpf/xppen-ArtistPro16Gen2.bpf.o"
  55. ACTION=="remove",ENV{MODALIAS}=="hid:b0003g0001v000028BDp0000095B", RUN{program}+="/usr/local/bin/udev-hid-bpf remove $sys$devpath "
  56. LABEL="hid_bpf_end"
  57. EOF
  58. $> udevadm control --reload
  59. ```
  60. Then unplug and replug the device.
  61. ## Checks
  62. ### udev rule
  63. You can check that the udev rule is correctly working by issuing
  64. ```
  65. $> udevadm test /sys/bus/hid/devices/0003:28BD:095B*
  66. ...
  67. run: '/usr/local/bin/udev-hid-bpf add /sys/devices/virtual/misc/uhid/0003:28BD:095B.0E57 /etc/udev-hid-bpf/xppen-ArtistPro16Gen2.bpf.o'
  68. ```
  69. ### program loaded
  70. You can check that the program has been properly loaded with `bpftool`
  71. ```
  72. $> bpftool prog
  73. ...
  74. 247: tracing name xppen_16_fix_eraser tag 18d389353ed2ef07 gpl
  75. loaded_at 2024-03-28T16:02:28+0100 uid 0
  76. xlated 120B jited 77B memlock 4096B
  77. btf_id 487
  78. ```