First, many thanks to Sliver-X here: https://www.linuxquestions.org/questions/showthread.php?p=6113811#post6113811
and
@3615ulla here : https://forum.batocera.org/d/3393-compile-a-linux-module-for-current-525-batocera
Why this tutorial : In some cases, PS2 controllers with a USB adaptor will not work with the hid-sony module of a 4.10 or higher kernel.
So it will be necessary to compile the 4.9.xxx source of the hid-sony module with the version of the Batocera kernel you are using.
1- Use the (so helpfull) wiki “compile_batocera.linux” here : https://wiki.batocera.org/doku.php?id=compile_batocera.linux
and preferably use Docker.
2- After the
make O=$PWD/output/x86_64 BR2_EXTERNAL=$PWD -C $PWD/buildroot batocera-x86_64_defconfig
cd output/x86_64
Do not do make
, but do : make linux-menuconfig
=> and check that “batocera-x86_64_defconfig” has been taken into account,
then choose “Custom kernel”, and type the current kernel version of your Batocera. For example: 5.4.16.
Save and exit
3- output/x86_64$ make linux-source
(this downloads the sources of the kernel chosen before, e.g. 5.4.16)
4- output/x86_64$ make linux-build
(about 2h of compilation for 4 CPUs)
5- Download the latest tarball of kernel 4.9 (e.g. linux-4.9.223.tar.xz) here : https://www.kernel.org
Unzip linux-4.9.xxx.tar.xz/linux-4.9.xxx/drivers/hid/
6- Copy hid-ids.h and hid-sony.c from kernel 4.9.xxx to these folders :
output/x86_64/build/linux-5.x.xx/drivers/hid/
and
output/x86_64/build/linux-headers-5.x.xx/drivers/hid/
7- output/x86_64$ make linux-rebuild
(it will compile the 4.9.xxx module for the kernel of your Batocera)
8- Get the new module : output/x86_64/target/lib/modules/5.4.16/kernel/drivers/hid/hid-sony.ko
9- In your functional Batocera, type F1 with your keyboard, then click on Applications, and xTerm to open a terminal :
Unload old module : rmmod hid_sony
Replace old module by the new one : cp folderOfNewModule/hid-sony.ko /lib/modules/5.x.xxx/kernel/drivers/hid/hid-sony.ko
Load new module : insmod /lib/modules/5.x.xx/kernel/drivers/hid/hid-sony.ko
Run this /usr/bin/batocera-save-overlay
to use the new module on each reboot.
10- Check and test these modifications
11- So, have fun with your old PS2 controllers !
Lionel
(Translated from french by DeepL)