roboticslab-uc3m / installation-guides

Centralized administration of dependency installation guides.
https://robots.uc3m.es/installation-guides/
70 stars 35 forks source link

JR3-PCI driver issues on Linux 5.x kernel (Ubuntu Bionic) #78

Closed rsantos88 closed 4 years ago

rsantos88 commented 4 years ago

The following errors were found during JR3 drivers compilation in Ubuntu 18.04 The kernel version used is 5.3.0-26-generic

$ cat /proc/version
Linux version 5.3.0-26-generic (buildd@lgw01-amd64-039) (gcc version 7.4.0 (Ubuntu 7.4.0-1ubuntu1~18.04.1)) #28~18.04.1-Ubuntu SMP Wed Dec 18 16:40:14 UTC 2019

the errors shown are:

$ make
make -C /lib/modules/5.3.0-26-generic/build M=/home/teo/repos/jr3pci-linux SUBDIRS=/home/teo/repos/jr3pci-linux modules
make[1]: Entering directory '/usr/src/linux-headers-5.3.0-26-generic'
Makefile:227: ================= WARNING ================
Makefile:228: 'SUBDIRS' will be removed after Linux 5.3
Makefile:229: 
Makefile:230: If you are building an individual subdirectory
Makefile:231: in the kernel tree, you can do like this:
Makefile:232: $ make path/to/dir/you/want/to/build/
Makefile:233: (Do not forget the trailing slash)
Makefile:234: 
Makefile:235: If you are building an external module,
Makefile:236: Please use 'M=' or 'KBUILD_EXTMOD' instead
Makefile:237: ==========================================
  CC [M]  /home/teo/repos/jr3pci-linux/jr3pci-driver.o
In file included from /home/teo/repos/jr3pci-linux/jr3pci-driver.c:43:0:
/home/teo/repos/jr3pci-linux/jr3pci-ioctl.c: In function ‘jr3_ioctl’:
/home/teo/repos/jr3pci-linux/jr3pci-ioctl.c:111:57: error: macro "access_ok" passed 3 arguments, but takes just 2
         err = !access_ok(VERIFY_WRITE, (void *)arg, size);
                                                         ^
/home/teo/repos/jr3pci-linux/jr3pci-ioctl.c:111:16: error: ‘access_ok’ undeclared (first use in this function)
         err = !access_ok(VERIFY_WRITE, (void *)arg, size);
                ^~~~~~~~~
/home/teo/repos/jr3pci-linux/jr3pci-ioctl.c:111:16: note: each undeclared identifier is reported only once for each function it appears in
/home/teo/repos/jr3pci-linux/jr3pci-ioctl.c:114:64: error: macro "access_ok" passed 3 arguments, but takes just 2
                err =  !access_ok(VERIFY_READ, (void *)arg, size);
                                                                ^
/home/teo/repos/jr3pci-linux/jr3pci-ioctl.c:102:6: warning: unused variable ‘size’ [-Wunused-variable]
  int size = _IOC_SIZE(cmd); /* the size bitfield in cmd */
      ^~~~
/home/teo/repos/jr3pci-linux/jr3pci-driver.c: In function ‘jr3pci_init_module’:
/home/teo/repos/jr3pci-linux/jr3pci-driver.c:171:63: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
  printk( KERN_INFO "jr3pci: JR3 PCI card detected at 0x%x\n", (int)jr3_base_address);
                                                               ^
scripts/Makefile.build:288: recipe for target '/home/teo/repos/jr3pci-linux/jr3pci-driver.o' failed
make[2]: *** [/home/teo/repos/jr3pci-linux/jr3pci-driver.o] Error 1
Makefile:1655: recipe for target '_module_/home/teo/repos/jr3pci-linux' failed
make[1]: *** [_module_/home/teo/repos/jr3pci-linux] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-5.3.0-26-generic'
Makefile:10: recipe for target 'all' failed
make: *** [all] Error 2
rsantos88 commented 4 years ago

The temporary solution is to edit the file jr3pci-ioctl.c and returning directly zero in the err variable, avoiding calling the check function:

#ifndef LINUX_20
      if (_IOC_DIR(cmd) & _IOC_READ)
              //err = !access_ok(VERIFY_WRITE, (void *)arg, size);
            err = 0;

      if (_IOC_DIR(cmd) & _IOC_WRITE)
                  //err =  !access_ok(VERIFY_READ, (void *)arg, size);
            err = 0;

By doing this, the driver compiles and works correctly. The PCI card LEDs turn on and the jr3 yarp device runs correctly. I leave the issue open to fix the problem that the function access_ok gives with this kernel.

jgvictores commented 4 years ago

Could you verify if simply removing the first parameter is enough, as in https://github.com/martinezjavier/ldd3/commit/887600dab825111721c3bb9ce2331f28adbb648d ?

rsantos88 commented 4 years ago

Yes, it's enough

rsantos88 commented 4 years ago

I've fixed the error, detecting previously the kernel version (see https://github.com/roboticslab-uc3m/jr3pci-linux/commit/87536e37574b69cf6eb96dd04295bb27699f34fd) Now it's working with the two Kernel versions. Note: I've removed verify_area(VERIFY_READ, (void *)arg, size) because it's deprecated and not used in our current versions.

rsantos88 commented 4 years ago

Note2: Added some installation notes if you want to install the drivers on Ubuntu 18.04 (https://github.com/roboticslab-uc3m/installation-guides/commit/68c47866e9f9bd63cd9bdc8daf2367488dd6babb) I'll close the issue :)

PeterBowman commented 4 years ago

Not sure if we should care, but I presume that commit breaks compatibility with the Linux 2.0 kernel?