LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-18-2010, 09:43 AM   #1
David Li
Member
 
Registered: Mar 2010
Posts: 42

Rep: Reputation: 15
Driver can not be inserted with error "inserting gedv0.ko: -1 Invalid mosule format"


I compiled a driver for linux-2.6.22.6 kernel, but when I inserted it on the target platform, error "invalid module format" appeared. Then I used dmesg to check the details, it said "No module found in object". I tried many different things, but no success. I did a modinfo and found that the kernel version that I compiled against was not in the modinfo section. I am not sure if that is the reason, if it is then how do I get the compiled against kernel version number into the driver modinfo section.

I urgently need help to get this resolved, any help will be greatly appreciated.

David
 
Old 03-18-2010, 12:12 PM   #2
irmin
Member
 
Registered: Jan 2010
Location: the universe
Distribution: Slackware (modified), Slackware64 (modified), openSuSE (modified)
Posts: 342

Rep: Reputation: 62
How did you compile the kernel module? If you want to compile a module for a kernel, say 2.6.32 with a certain configuration, download the source code (e.g. from http://www.kernel.org/) create a proper configuration and use the Makefiles from this directory tree to compile the module:
Code:
make -C /path/to/kernel/source SUBDIRS=`cwd`
or similar. The makefiles from one kernel will only create modules for that kernel (I think you can change this behaviour, but I do not know how, sorry). This mechanism is ok, because if some kernel internals are changed, the modules will not be binary compatible: (e.g. suppose a function abc(int) is in kernel x.y.z but it is changed to abc(int,void*) int u.v.w. So the module for x.y.z will not work with u.v.w for sure (resulting in kernel oops, ...))
 
Old 03-18-2010, 01:33 PM   #3
David Li
Member
 
Registered: Mar 2010
Posts: 42

Original Poster
Rep: Reputation: 15
I compiled the kernel module on the computer that runs linux-2.6.27.7-9-default kernel. But I was compling for kernel linux-2.6.22.6 platform, I have kernel souce code (2.6.22.6) on my computer to compile against. I heard that I can include the target kernel header files to generate the driver for the target kernel. How to I install the header files? Because I simply download the 2.6.22.6 kernel source code and extract it and did not install any header files.

Thanks,
David
 
Old 03-18-2010, 02:44 PM   #4
irmin
Member
 
Registered: Jan 2010
Location: the universe
Distribution: Slackware (modified), Slackware64 (modified), openSuSE (modified)
Posts: 342

Rep: Reputation: 62
You can install the headers by typing (in the kernel source dir):
Code:
INSTALL_HDR_PATH=/where/to/install make headers_install
Did you type 'make prepare' after kernel configuration? This sets up everything to allow building external modules?
 
Old 03-18-2010, 05:47 PM   #5
David Li
Member
 
Registered: Mar 2010
Posts: 42

Original Poster
Rep: Reputation: 15
Thanks for your reply.

I did not compile the kernel I only extract the kernel source code. When I tried to make the kernel, it did not complete. Do I need to compile the kernel? I thought I only need header files to compile the driver against. How do I do kernel configuration?

I just need to complie the kernel version number into the kernel object (KO file).
 
Old 03-18-2010, 06:04 PM   #6
irmin
Member
 
Registered: Jan 2010
Location: the universe
Distribution: Slackware (modified), Slackware64 (modified), openSuSE (modified)
Posts: 342

Rep: Reputation: 62
No you do not need to compile the kernel, just "make prepare" is required. This will setup the build environment properly. But a configuration is needed, because some features depend on the selected options. Take /proc/config.gz from the target system, uncompress it and save it as .config in the toplevel source directory, then type "make prepare". When building a kernel module with the configured kernel build system, the version information should be correct.
 
Old 03-19-2010, 10:22 AM   #7
David Li
Member
 
Registered: Mar 2010
Posts: 42

Original Poster
Rep: Reputation: 15
I am building a module on my computer for an embedded system so the target system you mean my computer not the embedded system, right?

"toplevelsource" means target kernel source, right? Just want to make sure.

Thanks,
 
Old 03-19-2010, 11:43 AM   #8
irmin
Member
 
Registered: Jan 2010
Location: the universe
Distribution: Slackware (modified), Slackware64 (modified), openSuSE (modified)
Posts: 342

Rep: Reputation: 62
Yes, all refer to the target system (the system, the module is supposed to be used = the embedded system in your case). You have to use the configuration of the kernel, that runs on the embedded system. You will also need to cross-compile the module:
Code:
make -C /path/to/kernel/source ARCH=targetarchitecture CROSS_COMPILE=/your/cross/compiler/prefix- prepare
make -C /path/to/kernel/source ARCH=targetarchitecture CROSS_COMPILE=/your/cross/compiler/prefix- SUBDIRS=`cwd`
Here the assignment of the cross compiler prefix is for example "CROSS_COMPILE = /usr/local/bin/arm-linux-". targetarchitecture is the name of the target architecture, have a look at the arch subdirectory in the kernel sources.
 
Old 03-19-2010, 12:16 PM   #9
David Li
Member
 
Registered: Mar 2010
Posts: 42

Original Poster
Rep: Reputation: 15
When I did "make prepare" I had many errors. I guess that is because I did not input the right selections when run the config. It is simply too many input selections. Any comments?

Thanks,
David
 
Old 03-19-2010, 12:39 PM   #10
irmin
Member
 
Registered: Jan 2010
Location: the universe
Distribution: Slackware (modified), Slackware64 (modified), openSuSE (modified)
Posts: 342

Rep: Reputation: 62
Perhaps this is also due to a previous configuration for another system. Try to run "make distclean", then put the appropriate configuration to .config and the try "make prepare". Note: For every call to make you will need to specify ARCH and CROSS_COMPILE (unless you modified them in the top level Makefile).

If the errors remain, please post them here.
 
Old 03-19-2010, 12:41 PM   #11
David Li
Member
 
Registered: Mar 2010
Posts: 42

Original Poster
Rep: Reputation: 15
What I am trying to do is to compile a module on my linux desk-top computer and run that module on a linux embedded system. We have been doing that for previous 2.4 kernel and old embedded platform. Now, we have a 2.6.22 kernel and new generation of embedded system. We running into this preoblem. Do we have any life support?

Thanks,
David
 
Old 03-19-2010, 01:04 PM   #12
irmin
Member
 
Registered: Jan 2010
Location: the universe
Distribution: Slackware (modified), Slackware64 (modified), openSuSE (modified)
Posts: 342

Rep: Reputation: 62
The normal way to compile a kernel module is to configure the kernel source for the target system, call "make prepare" and then compile the module by using the kernel makefiles. These makefiles are designed such that they call the appropriate commands for the creation of kernel modules (calling modpost (that generates the version information), ...).

I wonder how you actually compile the module, because you do not need to install any kernel headers for this process.
 
Old 03-19-2010, 01:29 PM   #13
David Li
Member
 
Registered: Mar 2010
Posts: 42

Original Poster
Rep: Reputation: 15
I got everything working, installed the kernel headers, configured, did make prepare. But I still don't have any version number in the module (KO file).

Last edited by David Li; 03-19-2010 at 01:36 PM.
 
Old 03-19-2010, 01:36 PM   #14
irmin
Member
 
Registered: Jan 2010
Location: the universe
Distribution: Slackware (modified), Slackware64 (modified), openSuSE (modified)
Posts: 342

Rep: Reputation: 62
How do you compile your kernel module? What does "modinfo yourmodule.ko" say?
 
Old 03-19-2010, 02:42 PM   #15
David Li
Member
 
Registered: Mar 2010
Posts: 42

Original Poster
Rep: Reputation: 15
This is the make file:

.SUFFIXES: .o .c

KERNELDIR = ../../kernel/linux-2.6.22.6/include/linux
HOMEKERNEL = /home/kernel/linux-2.6.22.6/include/linux
.c.o:
$(CC) $(CFLAGS) -c $*.c
CC = arm-none-linux-gnueabi-gcc
LINK = arm-none-linux-gnueabi-ld
CFLAGS = -D__KERNEL__ -DMODULE -DLINUX -O2 -O -c isystem/lib/modules/'uname -r'/build/include -Wall -I$(KERNELDIR) -I$(HOMEKERNEL) -I. -D"KBUILD_MODNAME=gedv0" -D"KBUILD_BASENAME=KBUILD_STR(gedv0)"
LFLAGS = -r -S $^ -o $@
GEDRVOBJS = p3defs.o p3api.o gedrv.o
GEDRVINCS = p3defs.h p3api.h p3types.h gedrv.h
GEDRVSRCS = $(GEDRVOBJS:.o=.c)

all: gedv0.o
echo all made
clean:
rm -f *.o *.err
gedv0.o: $(GEDRVOBJS)
$(LINK) -r $(GEDRVOBJS) -o gedv0.ko
$(GEDRVOBJS): $(GEDRVINCS)

modinfo gives following output:

filename: gedv0.ko
license: Private IP
description: I/O driver
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the error "invalid module format" and "insert kernel module"? shayori Linux - Newbie 8 02-25-2010 04:48 AM
[SOLVED] booting a newly compiled kernel error :"invalid or unsupported executable format" shivanth Linux - Kernel 1 09-16-2009 07:57 AM
ns:"error when calling class OldSim"&tclsh:"invalid command+child process exits abn." shojaru Linux - Newbie 0 03-05-2009 05:23 AM
error: Error for wireless request "Set Mode" (8B06) : invalid argument "roaming" penguin chick Linux - Wireless Networking 5 08-22-2008 02:16 PM
Ndiswrapper "Invalid driver" error - but it worked before i switched distros! drewbug01 Linux - Wireless Networking 5 11-01-2006 01:36 PM


All times are GMT -5. The time now is 02:51 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration