nicman23 / dkms-hid-nintendo

dkms-hid-nintendo
GNU General Public License v2.0
240 stars 43 forks source link

Compilation Error (on Jetson Nano / Ubuntu 18.04) #7

Closed specialcircumstances closed 4 years ago

specialcircumstances commented 4 years ago

Does not appear to want to compile for me... :(

Linux jetson-nano01 4.9.140-tegra #1 SMP PREEMPT Wed Apr 8 18:10:49 PDT 2020 aarch64 aarch64 aarch64 GNU/Linux

dkms: 2.2.1.0

nano@jetson-nano01:~/src$ cd dkms-hid-nintendo/
nano@jetson-nano01:~/src/dkms-hid-nintendo$ sudo dkms add .

Creating symlink /var/lib/dkms/nintendo/1.0/source ->
                 /usr/src/nintendo-1.0

DKMS: add completed.
nano@jetson-nano01:~/src/dkms-hid-nintendo$ sudo dkms build nintendo -v 1.0

Kernel preparation unnecessary for this kernel.  Skipping...

Building module:
cleaning build area...
make -j4 KERNELRELEASE=4.9.140-tegra -C /lib/modules/4.9.140-tegra/build M=/var/lib/dkms/nintendo/1.0/build/src modules...(bad exit status: 2)
ERROR (dkms apport): binary package for nintendo: 1.0 not found
Error! Bad return status for module build on kernel: 4.9.140-tegra (aarch64)
Consult /var/lib/dkms/nintendo/1.0/build/make.log for more information.

nano@jetson-nano01:~/src/dkms-hid-nintendo$ cat /var/lib/dkms/nintendo/1.0/build/make.log
DKMS make.log for nintendo-1.0 for kernel 4.9.140-tegra (aarch64)
Thu  4 Jun 17:51:21 BST 2020
make: Entering directory '/usr/src/linux-headers-4.9.140-tegra-ubuntu18.04_aarch64/kernel-4.9'
  CC [M]  /var/lib/dkms/nintendo/1.0/build/src/hid-nintendo.o
/var/lib/dkms/nintendo/1.0/build/src/hid-nintendo.c: In function ‘joycon_leds_create’:
/var/lib/dkms/nintendo/1.0/build/src/hid-nintendo.c:1551:46: error: ‘LED_ON’ undeclared (first use in this function); did you mean ‘LED_OFF’?
   led->brightness = ((i + 1) <= input_num) ? LED_ON : LED_OFF;
                                              ^~~~~~
                                              LED_OFF
/var/lib/dkms/nintendo/1.0/build/src/hid-nintendo.c:1551:46: note: each undeclared identifier is reported only once for each function it appears in
scripts/Makefile.build:341: recipe for target '/var/lib/dkms/nintendo/1.0/build/src/hid-nintendo.o' failed
make[1]: *** [/var/lib/dkms/nintendo/1.0/build/src/hid-nintendo.o] Error 1
Makefile:1629: recipe for target '_module_/var/lib/dkms/nintendo/1.0/build/src' failed
make: *** [_module_/var/lib/dkms/nintendo/1.0/build/src] Error 2
make: Leaving directory '/usr/src/linux-headers-4.9.140-tegra-ubuntu18.04_aarch64/kernel-4.9'
nano@jetson-nano01:~/src/dkms-hid-nintendo$
DanielOgorchock commented 4 years ago

This is due to differences in the 4.9 kernel. Refer to this patch: https://gitlab.com/djogorchock/l4t-kernel-4.9/-/commit/f34052aa3ef60d1b9822a0afe5ee1ed5f46ed277

specialcircumstances commented 4 years ago

Thanks - I manually patched my copy of hid-nintendo.c and it has compiled and installed OK.

Will it work without the patch to the kernel though?

Tetsujinfr commented 4 years ago

hi, what changes did you apply exactly and where on the system? I have manually patched the hid-nintendo.c from this repo folder (added the #define LED_ON 1 on L37) but where can I find the file drivers/hid/hid-core.c on the jetson?

thanks a lot

DanielOgorchock commented 4 years ago

The hid-core changes need to be made to the kernel itself rather than the dkms module. It requires a full kernel recompilation unfortunately. This requirement was removed in newer kernels. See https://lore.kernel.org/patchwork/patch/836705/

Tetsujinfr commented 4 years ago

Oh boy, this sounds like I am never going to make it. I am running jetpack 4.4, is there a simple way I can do that or would you know a helpful tutorial? I am not an expert in linux kernel, I feel I am going to screw up my jetpack unless I can follow a clear path on how to do this. I was so happy to find this great repo and using a joycon to control the jetson xavier but it looks this is going to be more challenging than what I thought...

nicman23 commented 4 years ago

you can also look at how switchroot (linux for the switch) do things but 4.4 is pretty old. i am going to close this for now. if someone else has issues with 4.4 i ll reopen and try to backport it.

jwhited commented 4 years ago

@nicman23 really appreciate your work on this module. @Tetsujinfr was referring to the "Jetpack" version, this is not the kernel version. Jetpack is essentially the image that Nvidia provides to install on their Jetson platform.

Jetpack 4.4 is the latest image at time of writing and has a modified 4.9 kernel:

jwhited@jwhited-dc:~/dkms-hid-nintendo$ uname -a
Linux jwhited-dc 4.9.140-tegra #1 SMP PREEMPT Thu Jun 25 21:25:44 PDT 2020 aarch64 aarch64 aarch64 GNU/Linux

Would be neat if this module could be backported to support this as the Jetson platform is commonly used in robotics and as part of the Donkeycar project.

Speaking from a Donkeycar perspective - the spectrum of users ranges from non-technical to AI researchers. Would be nice to add a supported controller to this list that doesn't require changes to the kernel.

Happy to help on the backport testing for the Jetson Nano.

nicman23 commented 4 years ago

yeah i know, i am working on focal for the n. switch, which is tegra210. go to the switchroot discord and ask around. they got 4.9 too.

jwhited commented 4 years ago

for future issue finders and @specialcircumstances @Tetsujinfr - I think I have this working without needing to touch the kernel:

udev rule to workaround hid_have_special_driver: https://stackoverflow.com/a/54299197

1) defined LED_ON to fix build error - https://github.com/jwhited/dkms-hid-nintendo/commit/56960d591c3ac0b4832de0245918885c35e8d0f5

2) installed module as instructed in README

3) add hid_nintendo to /etc/modules and reboot

(env) jwhited@jwhited-dc:~$ cat /etc/modules
# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.

# bluedroid_pm, supporting module for bluetooth
bluedroid_pm
# modules for camera HAL
nvhost_vi
# nvgpu module
nvgpu
# nintendo switch controller module
hid_nintendo

4) verify module is loaded

(env) jwhited@jwhited-dc:~$ lsmod | grep hid_nintendo
hid_nintendo           28942  0

5) plug in controller and watch dmesg to get vendor and device identifiers:

[  128.472719] tegra-xusb-padctl 7009f000.xusb_padctl: power on UTMI pads 1
[  128.684440] usb 1-2.1: new full-speed USB device number 4 using tegra-xusb
[  128.711657] usb 1-2.1: New USB device found, idVendor=057e, idProduct=2009
[  128.711725] usb 1-2.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[  128.711772] usb 1-2.1: Product: Pro Controller
[  128.711817] usb 1-2.1: Manufacturer: Nintendo Co., Ltd.
[  128.712352] usb 1-2.1: SerialNumber: 000000000001
[  128.724760] input: Nintendo Co., Ltd. Pro Controller as /devices/70090000.xusb/usb1/1-2/1-2.1/1-2.1:1.0/0003:057E:2009.0001/input/input2
[  128.725202] hid-generic 0003:057E:2009.0001: input,hidraw0: USB HID v1.11 Joystick [Nintendo Co., Ltd. Pro Controller] on usb-70090000.xusb-2.1/input0

6) add udev rule to unbind from hid-generic and bind to nintendo

(env) jwhited@jwhited-dc:~$ cat /etc/udev/rules.d/99-hid-nintendo.rules
ACTION=="add", KERNEL=="0003:057E:2009.*", SUBSYSTEM=="hid", DRIVER=="hid-generic", \
RUN+="/bin/bash -c 'echo $kernel > /sys/bus/hid/drivers/hid-generic/unbind'", \
RUN+="/bin/bash -c 'echo $kernel > /sys/bus/hid/drivers/nintendo/bind'"

7) replug controller and verify nintendo driver is bound

[  673.563200] tegra-xusb-padctl 7009f000.xusb_padctl: power on UTMI pads 1
[  673.775070] usb 1-2.1: new full-speed USB device number 8 using tegra-xusb
[  673.801857] usb 1-2.1: New USB device found, idVendor=057e, idProduct=2009
[  673.801925] usb 1-2.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[  673.801973] usb 1-2.1: Product: Pro Controller
[  673.802016] usb 1-2.1: Manufacturer: Nintendo Co., Ltd.
[  673.802057] usb 1-2.1: SerialNumber: 000000000001
[  673.810840] input: Nintendo Co., Ltd. Pro Controller as /devices/70090000.xusb/usb1/1-2/1-2.1/1-2.1:1.0/0003:057E:2009.0005/input/input6
[  673.811243] hid-generic 0003:057E:2009.0005: input,hidraw0: USB HID v1.11 Joystick [Nintendo Co., Ltd. Pro Controller] on usb-70090000.xusb-2.1/input0
[  673.884800] nintendo 0003:057E:2009.0005: hidraw0: USB HID v81.11 Joystick [Nintendo Co., Ltd. Pro Controller] on usb-70090000.xusb-2.1/input0
[  674.778326] nintendo 0003:057E:2009.0005: using factory cal for left stick
[  674.818746] nintendo 0003:057E:2009.0005: using factory cal for right stick
[  674.898334] nintendo 0003:057E:2009.0005: using factory cal for IMU
[  675.098359] nintendo 0003:057E:2009.0005: controller MAC = DC:68:EB:3A:2E:D8
[  675.183527] input: Nintendo Switch Pro Controller as /devices/70090000.xusb/usb1/1-2/1-2.1/1-2.1:1.0/0003:057E:2009.0005/input/input7
[  675.185799] input: Nintendo Switch Pro Controller IMU as /devices/70090000.xusb/usb1/1-2/1-2.1/1-2.1:1.0/0003:057E:2009.0005/input/input8

8) install joystick to test controller

(env) jwhited@jwhited-dc:/etc/udev/rules.d$ sudo apt-get install joystick
[...install output omitted...]

9) run jstest and press things

(env) jwhited@jwhited-dc:/etc/udev/rules.d$ jstest /dev/input/js0
Driver version is 2.1.0.
Joystick (Nintendo Switch Pro Controller) has 6 axes (X, Y, Rx, Ry, Hat0X, Hat0Y)
and 14 buttons (BtnA, BtnB, BtnX, BtnY, BtnZ, BtnTL, BtnTR, BtnTL2, BtnTR2, BtnSelect, BtnStart, BtnMode, BtnThumbL, BtnThumbR).
Testing ... (interrupt to exit)
Axes:  0:   213  1:     0  2:     0  3:   886  4:     0  5:     0 Buttons:  0:on  1:on  2:on  3:on  4:off  5:off  6:off  7:off  8:off  9:off 10:off 11:off 12:off 13:off