0

I have created one small usbtest driver to test my usb device. I have linux kernel version of 3.2.0 and ubuntu 12.04.

I can load that driver successfully on my PC very well without any issue and i can use that loaded driver without any failure condition.

My Linux PC information :: output of uname -a Linux ci5lub021305 3.2.0-29-generic-pae #46-Ubuntu SMP Fri Jul 27 17:25:43 UTC 2012 i686 i686 i386 GNU/Linux

Linux PC information of another PC on which driver loading failed :: uname -a Linux ci5lub021302 3.2.0-51-generic-pae #77-Ubuntu SMP Wed Jul 24 20:40:32 UTC 2013 i686 i686 i386 GNU/Linux

But, When i tried to load that driver into some another Linux Platform which has different kernel version then at that time it giver following while loading that driver.

insmod: error inserting 'usbtest.ko': -1 Invalid module format

I have seen in the dmesg which shows error regarding module version

usbtest: disagrees about version of symbol module_layout

I have also seen on another forums regarding this issues and they have suggested to compile the driver again in that another PC. But it is not a proper solution which i think.

Is there any one have idea about how to solve this version dependency issue because my client wants the driver from any kernel between 2.6.30 to 3.9 kernel.?

So, I need some specific solution so that compiled driver can be loaded on any Linux kernel version which depending on the specific kernel version.

please help me solve the above issue as soon as possible because this is one critical issue for me.

Thanks in advance for your support.

Ritesh Prajapati
  • 953
  • 2
  • 13
  • 22
  • please have a look at the link for your problem http://stackoverflow.com/questions/18106731/linux-kernel-module-ko-compatibility-between-kernels/18117442#18117442 – Gautham Kantharaju Sep 11 '13 at 11:06
  • Thanks @GauthamKantharaju, I will look into this and let you know later if any query. – Ritesh Prajapati Sep 11 '13 at 11:09
  • You have mentioned in that forum that every one have to rebuild the module again if any one want to load the same module on different kernel version. – Ritesh Prajapati Sep 11 '13 at 11:59
  • Is there any other way by checking any version checking process to solve this issue because it is too hard for me to compile same module on more than 20 kernel which i have to support for this module? – Ritesh Prajapati Sep 11 '13 at 12:01
  • Is there any generic way to solve this type of issue? – Ritesh Prajapati Sep 11 '13 at 12:02
  • How to disable version matching mechanism using any CFLAGS at the time of compiling the kernel module? do you know about this? – Ritesh Prajapati Sep 11 '13 at 12:31
  • 1
    thing is your module should be compatible with kernel version 2.6.30 to 3.9, it means that your kernel module code should take care of the api's signature/prototype change as in the link provided, usage of newer api based on kernel version checking i.e. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,36). This is about compatibility with different kernel versions. – Gautham Kantharaju Sep 11 '13 at 16:40
  • 1
    Coming to kernel module building or compilation, at any point of time you will be using any one linux kernel version i.e either 2.6.30 or 3.9 for example. Then you have to compile your kernel module against the kernel version being used, irrespective of anything. Regarding disabling of version matching mechanism, I have no idea. – Gautham Kantharaju Sep 11 '13 at 16:56
  • Thanks @GauthamKantharaju for your valuable feedback. I am also thinking like that we have to build module if kernel version is going to be changes.Once again thanks. – Ritesh Prajapati Sep 12 '13 at 04:15

1 Answers1

2

You are writing a module that is intended to work with multiple versions of the kernel, you likely have to make use of macros and #ifdef constructs to make your code build properly.

you need to make use of the definitions found in linux/version.h.

Dayal rai
  • 6,548
  • 22
  • 29
  • I have already use that macro to make generic driver using the same way as you are suggesting. But whenever i tried to load the driver on different PC which has different kernel version compare to mine then at that time i got the error which i have mentioned in above question like "insmod: error inserting 'usbtest.ko': -1 Invalid module format". – Ritesh Prajapati Sep 11 '13 at 11:05
  • That is because you have not added kernel version other than your PC in your code.You need to add a range or all specific major release `KERNEL_VERSION` on which you are planning to execute. – Dayal rai Sep 11 '13 at 11:10
  • I didn't get you point yet. in which file, i have to add kernel version to load the driver other than my PC? – Ritesh Prajapati Sep 11 '13 at 11:14
  • I don't want to compile the same driver on other Linux kernel version. Is there any way to change in any version matching file or any thing else to solve this issue without compiling the same module on another Linux kernel PC? – Ritesh Prajapati Sep 11 '13 at 11:19
  • please have a look on [Writing Modules for Multiple Kernel Versions](http://www.tldp.org/LDP/lkmpg/2.4/html/c577.htm) section. – Dayal rai Sep 11 '13 at 11:20
  • I have already tried the way from the above link which you have post but still got the same issue while loading the module using insmod command. – Ritesh Prajapati Sep 11 '13 at 11:58
  • Is there any way to disable version matching process using any CFLAGS while compiling the kernel modules? – Ritesh Prajapati Sep 11 '13 at 12:32