fabiobaltieri / open-usb-can

Open Source USB to CANBUS interface
GNU General Public License v3.0
106 stars 44 forks source link

kernel-module build troubles #1

Closed iDoka closed 10 years ago

iDoka commented 10 years ago

firmware-sources nice and build perfectly fine, but i have troubles with kernel-module build:

I have RHEL 6.5 64bit with kernel version 2.6.32-358.23.2.el6.x86_64 and I think that my system is not fully integrated SocketCAN.

By path /usr/src/kernels/2.6.32-358.23.2.el6.x86_64/include/linux/can necessary file led.h is absent. And I have problem with others include files when building module (e.g. CAN_CTRLMODE_ONE_SHOT define) :

$ make KERNELDIR=/usr/src/kernels/2.6.32-358.23.2.el6.x86_64
make -C /usr/src/kernels/2.6.32-358.23.2.el6.x86_64 M=/home/idoka/open-usb-can/kernel-module modules
make[1]: Entering directory `/usr/src/kernels/2.6.32-358.23.2.el6.x86_64'
  CC [M]  open-usb-can.o
open-usb-can.c:40:27: error: linux/can/led.h: No such file or directory
open-usb-can.c: In function ‘open_usb_can_read_bulk_callback’:
open-usb-can.c:200: error: implicit declaration of function ‘alloc_can_skb’
open-usb-can.c:200: warning: assignment makes pointer from integer without a cast
open-usb-can.c:216: error: implicit declaration of function ‘can_led_event’
open-usb-can.c:216: error: ‘CAN_LED_EVENT_RX’ undeclared (first use in this function)
open-usb-can.c:216: error: (Each undeclared identifier is reported only once
open-usb-can.c:216: error: for each function it appears in.)
open-usb-can.c: In function ‘open_usb_can_write_bulk_callback’:
open-usb-can.c:254: error: implicit declaration of function ‘usb_free_coherent’
open-usb-can.c:272: error: ‘CAN_LED_EVENT_TX’ undeclared (first use in this function)
open-usb-can.c: In function ‘open_usb_can_setup_rx_urbs’:
open-usb-can.c:321: error: implicit declaration of function ‘usb_alloc_coherent’
open-usb-can.c:322: warning: assignment makes pointer from integer without a cast
open-usb-can.c: In function ‘open_usb_can_open’:
open-usb-can.c:436: error: ‘CAN_LED_EVENT_OPEN’ undeclared (first use in this function)
open-usb-can.c: In function ‘open_usb_can_start_xmit’:
open-usb-can.c:457: error: implicit declaration of function ‘can_dropped_invalid_skb’
open-usb-can.c:468: warning: assignment makes pointer from integer without a cast
open-usb-can.c: In function ‘open_usb_can_close’:
open-usb-can.c:582: error: ‘CAN_LED_EVENT_STOP’ undeclared (first use in this function)
open-usb-can.c: In function ‘open_usb_can_probe’:
open-usb-can.c:680: error: too many arguments to function ‘alloc_candev’
open-usb-can.c:694: warning: assignment discards qualifiers from pointer target type
open-usb-can.c:697: error: ‘struct can_priv’ has no member named ‘do_get_berr_counter’
open-usb-can.c:698: error: ‘struct can_priv’ has no member named ‘ctrlmode_supported’
open-usb-can.c:699: error: ‘CAN_CTRLMODE_ONE_SHOT’ undeclared (first use in this function)
open-usb-can.c:743: error: implicit declaration of function ‘devm_can_led_init’
make[2]: *** [open-usb-can.o] Error 1
make[1]: *** [_module_] Error 2
make[1]: Leaving directory `/usr/src/kernels/2.6.32-358.23.2.el6.x86_64'
make: *** [default] Error 2

I tried to make the assembly on another system - Ububntu 12.04 64bit:

$ make KERNELDIR=/usr/src/linux-headers-3.2.0-54-generic
make -C /usr/src/linux-headers-3.2.0-54-generic M=/home/idoka/open-usb-can/kernel-module modules
make[1]: Entering directory `/usr/src/linux-headers-3.2.0-54-generic'
  CC [M]  open-usb-can.o
open-usb-can.c:35:27: fatal error: linux/can/led.h: No such file or directory compilation terminated.
make[2]: *** [open-usb-can.o] Error 1
make[1]: *** [_module_] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-3.2.0-54-generic'
make: *** [default] Error 2

The same result..

== Two ask: ==

  1. Which version of kernel you compiled the driver? What Linux distribution to use?
  2. Can I place new/missing header-files on existing kernel version or should I use only the version of the kernel for which writing a kernel module open-usb-can?

Fabio Thanks!

fabiobaltieri commented 10 years ago

Hi!

So, the module should be distribution agnostic, but back then I was using Slackware with -git kernels (I now, not the answer you was hoping for :-).

Anyway, the RHEL log is for a very old kernel, but you can still make it build by removing everything that refer to led, ONE_SHOT, and other funny fields (really, just delete that stuff). You will lose some functionality, but you probably don't care anyway.

As for the second log, you just miss CAN-LED support, which was merged in 3.9... Again, you can just remove all the references.

Coincidentally, I'm on the same situation on my current laptop, so I quickly hacked the LED stuff out and pushed a new no-led branch with the modification, feel free to check it out, it should probably work on Ubuntu, and you can easily fix it for RHEL.

https://github.com/fabiobaltieri/open-usb-can/commit/274cb9b811ee43544d42ba47639ab588d700e1f8

Cheers, Fabio

iDoka commented 10 years ago

Ok. I run

grep -n LED open-usb-can.c

and commented this string. Also I exclude ONE_SHOT from 'OR' equation.

But my main system is RHEL. As I know SocketCAN support were added in the 2.6.25 Linux kernel. I guess that I need to take some header-files to make the driver from Ubuntu 12.04? And replace section include, e.g.: before:

#include <linux/can.h>

after

#include "can.h"

Which header-files I need?

Thanks!

fabiobaltieri commented 10 years ago

Uh - linux/can.h should be ok, there was no error for that in your logs!

iDoka commented 10 years ago

I tried using for build on RHEL header files from Ubuntu 12.04: linux/can/dev.h linux/usb.h

$ make KERNELDIR=/usr/src/kernels/2.6.32-358.23.2.el6.x86_64
make -C /usr/src/kernels/2.6.32-358.23.2.el6.x86_64 M=/home/idoka/open-usb-can/kernel-module modules
make[1]: Entering directory `/usr/src/kernels/2.6.32-358.23.2.el6.x86_64'
  CC [M]  open-usb-can.o
In file included from open-usb-can.c:36:
usb.h: In function ‘usb_mark_last_busy’:
usb.h:549: error: implicit declaration of function ‘pm_runtime_mark_last_busy’
usb.h: In function ‘usb_maxpacket’:
usb.h:1618: error: implicit declaration of function ‘usb_endpoint_maxp’
In file included from open-usb-can.c:41:
dev.h: At top level:
dev.h:51: warning: ‘struct can_berr_counter’ declared inside parameter list
dev.h:51: warning: its scope is only this definition or declaration, which is probably not what you want
open-usb-can.c: In function ‘open_usb_can_probe’:
open-usb-can.c:700: warning: assignment discards qualifiers from pointer target type
open-usb-can.c: At top level:
open-usb-can.c:788: warning: data definition has no type or storage class
open-usb-can.c:788: warning: type defaults to ‘int’ in declaration of ‘module_usb_driver’
open-usb-can.c:788: warning: parameter names (without types) in function declaration
make[2]: *** [open-usb-can.o] Error 1
make[1]: *** [_module_/home/idoka/proj/open-usb-can/kernel-module] Error 2
make[1]: Leaving directory `/usr/src/kernels/2.6.32-358.23.2.el6.x86_64'
make: *** [default] Error 2

I guess that different kernel version using different kernel/driver API. Suppose is right?

Can I just move the compiled *.ko driver from Ubuntu to RHEL? Will it work?

PS: Sorry for my questions. I'm really a newbee.

fabiobaltieri commented 10 years ago

Uh - I can't understand what's going on but it looks like your headers are messed up... this should not happen if you just installed the kernel header package for your distro unless something it screwed up with the kernel configuration. Does it work on the Ubuntu? The errors you posted in the first report were looking better than this...

In any case, you can't copy the module binary from a different kernel.

iDoka commented 10 years ago
  1. On Ubuntu I commented out LED-related string in open-usb-can.c and succesfully build the driver.
  2. But on RHEL many struct and functions prototype is absent (or incompatible) in header files (can/dev.h, usb.h located in /usr/src/kernels/2.6.32-358.23.2.el6.x86_64/include/linux ). How to build driver on RHEL? ( I mean how can I work with the open-usb-can device on RHEL) What is my next step?
$ make KERNELDIR=/usr/src/kernels/2.6.32-358.23.2.el6.x86_64
make -C /usr/src/kernels/2.6.32-358.23.2.el6.x86_64 M=/home/idoka/open-usb-can/kernel-module modules
make[1]: Entering directory `/usr/src/kernels/2.6.32-358.23.2.el6.x86_64'
  CC [M]  open-usb-can.o
open-usb-can.c: In function ‘open_usb_can_read_bulk_callback’:
open-usb-can.c:206: error: implicit declaration of function ‘alloc_can_skb’
open-usb-can.c:206: warning: assignment makes pointer from integer without a cast
open-usb-can.c: In function ‘open_usb_can_write_bulk_callback’:
open-usb-can.c:260: error: implicit declaration of function ‘usb_free_coherent’
open-usb-can.c: In function ‘open_usb_can_setup_rx_urbs’:
open-usb-can.c:327: error: implicit declaration of function ‘usb_alloc_coherent’
open-usb-can.c:328: warning: assignment makes pointer from integer without a cast
open-usb-can.c: In function ‘open_usb_can_start_xmit’:
open-usb-can.c:463: error: implicit declaration of function ‘can_dropped_invalid_skb’
open-usb-can.c:474: warning: assignment makes pointer from integer without a cast
open-usb-can.c: In function ‘open_usb_can_probe’:
open-usb-can.c:686: error: too many arguments to function ‘alloc_candev’
open-usb-can.c:700: warning: assignment discards qualifiers from pointer target type
open-usb-can.c:703: error: ‘struct can_priv’ has no member named ‘do_get_berr_counter’
open-usb-can.c:704: error: ‘struct can_priv’ has no member named ‘ctrlmode_supported’
make[2]: *** [open-usb-can.o] Error 1
make[1]: *** [_module_/home/doka/proj/can/open-usb-can/kernel-module] Error 2
make[1]: Leaving directory `/usr/src/kernels/2.6.32-358.23.2.el6.x86_64'
make: *** [default] Error 2
fabiobaltieri commented 10 years ago

Hi, so I've dig a bit deeper into the revision history and unfortunately it turns out that in v2.6.32 the can-dev APIs were still under heavy development and differs a lot from the current ones, hence the errors with alloc_can_skb and alloc_candev. Add possible similar issues with usb and other stuff.

At this point I would really suggest you to consider updating the kernel to something more modern... 2.6.32 was released in Dec 2012 after all...

Sorry about that!