compiling modules ok, but error when installing: Invalid module format
Hello, I am working through the first example in Linux Device Drivers, Third Edition, with updated source code from a repository on github. Below are the steps I followed, which lead to a version mismatch.
Clone book examples repository https://github.com/duxing2007/ldd3-examples-3.x $ git tag v3.0 v3.0.1 v3.10 v3.12 v3.14 v3.2 v3.4 $ git checkout v3.4 My kernel module tree is linux-sunxi: 3.4.103-00033-g9a1cd03 I used this module tree when building an SD card image, however the system is not running on that image at the moment. The running system's Linux version (Debian wheezy) is: $ uname -r 3.4.79 The module (hello.c) is compiling fine, however when I go to install it I get this error: $ sudo insmod hello.ko Error: could not insert module hello.ko: Invalid module format Now that I have laid everything out, maybe I see the problem. Is it because the running kernel is 3.4.79, and the module was built using kernel sources from 3.4.103? Here is a list of the tags in my local linux-sunxi git repository: 3.4.103-00033-g9a1cd03$ git tag latest lichee3-i-onik.de-a10_source_1.5 lichee3-i-onik.de-a13_source_1.5 lichee3-qware linaro-packaging ... ... v3.4.7 v3.5 Since the running system is Linux 3.4.79, anything I try to install in it should be version <= 3.4.79, or should it be 3.4.0 < my stuff < 3.4.79? Thanks! |
I have a high suspicion the problem is your module's version magic string, a static version string, is not correct. Please run and give the output of the following.
Code:
modinfo hello.ko Code:
$ uname -r |
Hi flip, thanks for the input. Indeed it does not match:
Code:
~/src/modules/ldd3-examples-3.x/misc-modules$ sudo modinfo hello.ko Now the hello.ko is not loading in the real, running system, v3.4.79 . I'm in the process of re-cloning the linux-sunxi repository (I messed mine up). The plan is -not- to use the 3.4.103 from it, but checkout the 3.4.7 tag. Build it, then retry building the 'hello.c' module again. Does that sound correct? |
Your running kernel version 3.4.79 and your kernel modules version 3.4.103 are definately a mismatch, so we have verified the problem.
Have a read here: http://www.tldp.org/LDP/lkmpg/2.6/html/x380.html You do not need that git repository you are using for a hello world kernel module. You do need the kernel sources. If you are running the default generic debian kernel from its repositories, be sure to have the exact same source tree for that kernel. It's better to obtain the latest vanilla kernel sources from kernel.org, and use it. Quote:
Here is the url to the homepage of that with the full table of contents. I believe it to be a much better guide to compiling your first hello world kernel module. http://www.tldp.org/LDP/lkmpg/2.6/html/index.html As a side note, dkms can possibly allow you to load a mismatched kernel module though this may not be the best approach. From my understanding, it is typically used for proprietary kernel modules such as nvidia's and vmware's. Aside from that, a module compiled for one kernel won't load if you boot a different kernel unless you enable CONFIG_MODVERSIONS in the kernel. |
Quote:
Quote:
Quote:
https://github.com/duxing2007/ldd3-examples-3.x or the kernel repository, https://github.com/linux-sunxi/linux-sunxi.git? I'm confused when you say 'You do need the kernel sources'. Aren't the sources in the repository? Quote:
https://github.com/linux-sunxi/linux-sunxi.git This is because sunxi says they had to tweak the Linux kernel so that it can run their Cubieboard2 specific drivers. Can't quote exactly where I read that at the moment. Quote:
Quote:
Quote:
Now must get some sleep. Although there is one more thing I need to clear up, for sure a misunderstanding of git. I have a fresh copy of the linux-sunxi kernel repository. The first thing that you are supposed to do, before running 'make' on the image and modules, is run this command: Code:
make ARCH=arm sun7i_defconfig Next: Code:
make -j2 ARCH=arm uImage modules When I try to checkout v3.4.7, and repeat the same steps, I get an error on the very first step: Code:
~/sysdev/linux-sunxi$ make ARCH=arm sun7i_defconfig |
Quote:
https://github.com/linux-sunxi/linux...ch/arm/configs You could try contacting the developers. |
Thanks flip, I'm just getting used to navigating around a GitHub repository, thanks to your assistance. I only knew how to clone, didn't realize I could dig in there to find information. Not quite confident enough to ask someone there to please add my file.
However, I did try adding it myself, in my local repository, and got past the first steps successfully: ~/sysdev/linux-sunxi$ make ARCH=arm sun7i_defconfig Won't go into the gory details of what happened next. Enough to say that, as stated in a reference from previous posts: There is no way in hell that the module will load, unless it's 'vermagic' number matches exactly your system's kernel version. So to the 'some progress' part. My kernel is 3.4.79. Since my git kernel tree produces v3.4.103, and there is a tag in there for 3.4.7, somewhere in my repository must be a v3.4.79. Some googling and a few trials later: Code:
~/sysdev/linux-sunxi$ git log --all --grep='v3.4.79' Next I checked it out, and tagged it: Code:
~/sysdev/linux-sunxi$ git checkout 7369062e14dc82006e544c04928ebb3bf97fd98f I now had my git kernel tree exactly matching the working system, and the sun7i_defconfig file in the right place. The kernel build went ok, except for a missing .h file: Code:
CC [M] drivers/input/touchscreen/synaptics_i2c_rmi.o Code:
~/src/modules/ldd3-examples-3.x/misc-modules$ sudo modinfo hello.ko I looked into how/where the compiler adds this extra information. At the very top it has: Code:
VERSION = 3 Code:
~/sysdev/linux-sunxi$ cat Makefile | grep EXTRAVERSION Quote:
Thanks! |
Just an update. I was able to get my 'out of tree' module to install by recompiling the kernel, replacing the original uImage in nanda with the newly created uImage, then using the same compiler to compile the module.
Everything seems to be working as before, even if I have not yet moved the modules from the new build tree into the system. Here's the kernel I used: Kernel and new module info: Code:
$ uname -r After running 'make ARCH=arm sun7i_defconfig' make sure, if installing the uImage on nand, that the nand options are selected: Code:
CONFIG_SUNXI_NAND=y Code:
make ARCH=arm menuconfig Also, learned about 'make mrproper'. I think this is the command to run, if you need to recompile the kernel a second (or n'th) time. I was using just 'make clean' and, as far as I can remember, that never worked. Links: The Linux Kernel Module Programming Guide http://www.tldp.org/LDP/lkmpg/2.6/html/index.html Building External Modules https://www.kernel.org/doc/Documenta...ld/modules.txt How to: Compile Linux kernel modules http://www.cyberciti.biz/tips/compil...el-module.html Kernel Symbols and CONFIG_MODVERSIONS http://linux.die.net/lkmpg/x380.html Difference between make mrproper and make clean? http://www.linuxquestions.org/questi...-clean-473144/ Dont add “+” to linux kernel version http://stackoverflow.com/questions/1...kernel-version |
All times are GMT -5. The time now is 10:33 AM. |