PDA

View Full Version : Modules and Drivers for FC5



john-poma
29th May 2006, 05:48 AM
Hello,
Where may I find documentations how to write kernel modules and drivers for FC5.
Thanks a lot on advance.
John

markkuk
29th May 2006, 09:11 AM
Read The Linux Kernel Module Programming Guide (http://tldp.org/LDP/lkmpg/2.6/html/index.html).

giulix
29th May 2006, 09:18 AM
A few references here (http://www-oss.fnal.gov/projects/fermilinux/common/class/advanced-admin/Module-HOWTO.html#AEN49) and here (http://janitor.kernelnewbies.org/docs/driver-howto.html)

john-poma
1st June 2006, 05:53 PM
1. I install 3 weeks ago the Fedora Core 5 without problems and all is going very well.
2. I have to develop some modules and drivers for FC5.
3. I use some examples and Makefile that I use with FC4 and all is going wrong.
4. Now, following your information I consult and try to follow the tldp.org documentation
4.1. My hello-1.c file is the same with in more :
#define __NO_VERSION__
#include <linux/version.h>

Instead of "KERN_INFO" I use <1>

4.2. The Makefile is completely different:
Here my previous Makefile.

TARGET := hello-1
WARN := -W -Wall -Wstrict-prototypes -Wmissing-prototypes
INCLUDE := -isystem /lib/modules/`uname -r`/build/kernel
CFLAGS := -O2 -DMODULE -D__KERNEL__ ${WARN} ${INCLUDE}
cc := gcc

${TARGET}.o: ${TARGET}.c

.PHONY: clean

clean:
rm -rf ${TARGET}.o

4.3. Here the Makefile in the tldf.org documentation :

obj-m += hello-1.o

all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
make -C /lib/modules/$($shell uname-r)/build M=$(PWD) clean

Now in the tldp.org documentation 2.2 Compiling Kernel Modules - Example 2-2.
it is specified:

"From a technical point of view just the fist line is really necessary,
the "all" and "cleanup" were added for pure convenience".
But if I try the make command without all: and clean: lines
I receive the message -> No target.

5. Using the Makefile as proposed in tldf.org :

5.1. The make command fail because : /usr/src/kernels/2.6.16-1.2122_FC5-smp-i686 - no such file or directory.
In fact, I found in /usr/src/kernels an 2.6.16-1.2122_FC5-i686.
Ok, I create and copy all in a new 2.6.16-1.2122_FC5-smp-i686.
5.2. Now, in /lib/modules/2.6.16-1.2122_FC5smp I found a broken sym link "build" that point to
../../../usr/src/kernels/2.6.16-1.2122_FC5-i686 .
So I make the sym link to points to the new ../../../usr/src/kernels/2.6.16-1.2122_FC5-smp-i686.
I found also a sym kink source -> build???!!!.

5.2. I run the make command and all seems going well.

The modinfo command on hello-1.ko is as follow:

filename: hello-1.ko
vermagic: 2.6.16-1.2122_FC5 686 REGPARM 4KSTACKS gcc-4.1
depends:
srcversion: 939B71B6F38359E6D09B8D3


6. Problem with the - insmod.

6.1. At the command insmod hello-1.ko insmod returns:

hello-1: disagrees about version of symbol struct_module
insmod: error inserting 'hello-1.ko': -1 Invalid module format

6.2. I turn to http://tldp.org/LDP/lkmpg/2.6/html/index.html - 2.8. Building modules for a precompiled kernel
Unfortunately the structure of the directories are different on my system than the description gived in
the documentation. e.g. there is no /usr/src/linux but I have /usr/src/kernels/ with 3 subdirectories:
2.6.16-1.2111_FC5-i686
2.6.16-1.2122_FC5-i686
2.6.16-1.2122_FC5-smp-i686
the last one is just the copy of 2.6.16-1.2122_FC5-i686 with the -smp- to be accepted by the Makefile
unamer -r return 2.6.16-1.2122_FC5smp.

6.3. Following the documentation I change the EXTRAVERSION in the Makefile in /usr/src/kernels/2.6.16-1.2122_FC5-smp-i686
from 2.6.16-1.2122_FC5 in 2.6.16-1.2122_FC5smp (so the same that in /boot/config-2.6.16-1.2111_FC5smp)

6.4. In the documentation 2.8. section I find also:
"A simple cp /lib/modules/`uname -r`/build/Makefile /usr/src/linux-`uname -r` should suffice"
Unfortunately, as I say previously my /lib/modules/`uname -r` build is a simple sym link to
/usr/src/kernels/2.6.16-1.2122_FC5-smp-i686 where I found the Makefile.

7. I retry the modified make for hello-1.c there is well a new hello-1.ko but insmod till gives the same error.

I have the impression that all the structures of the directories on my installation is very different than the documentation or the documentation I find at http://tldp.org/LDP/lkmpg/2.6/html/index.html
is not the one for Fedora Core 5.

Rem: I do all that on console (Ctrl-Alt-F1) and not in X environment.

Thanks for any help.

John Poma

markkuk
2nd June 2006, 08:33 AM
4.3. Here the Makefile in the tldf.org documentation :


obj-m += hello-1.o

all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
make -C /lib/modules/$($shell uname-r)/build M=$(PWD) clean

Make sure that the command lines are indented with tab characters, not spaces. Lines beginning with spaces are ignored: http://www.gnu.org/software/make/manual/make.html#Command-Syntax


5.1. The make command fail because : /usr/src/kernels/2.6.16-1.2122_FC5-smp-i686 - no such file or directory.
You haven't installed the kernel-smp-devel package.


In fact, I found in /usr/src/kernels an 2.6.16-1.2122_FC5-i686.
Ok, I create and copy all in a new 2.6.16-1.2122_FC5-smp-i686.
5.2. Now, in /lib/modules/2.6.16-1.2122_FC5smp I found a broken sym link "build" that point to
../../../usr/src/kernels/2.6.16-1.2122_FC5-i686 .
So I make the sym link to points to the new ../../../usr/src/kernels/2.6.16-1.2122_FC5-smp-i686.
Undo all those changes before installing kernel-smp-devel.

john-poma
2nd June 2006, 05:55 PM
OK I restore all as before.
I install the kernel-smp-devel package 2.6.16-1.2080_FC5-smp-i686
(why not a 2.6.16-1.2122_FC5-i686 ?).
In /lib/modules I have always my 2.6.16-1.2122_FC5smp directory with a build broken sym link to /usr/src/kernels/2.6.16-1.2122_FC5-smp-i686.
Since the Makefile refers to uname -r -> 2.6.16-1.2122_FC5smp : result = no such file or directory.

Is it normal that baout kbuild I find only
/usr/lib/kde3/kbuildsycoca.so
and
/usr/lib/kde3/kbuildsycoca.la

Thanks a lot.

markkuk
2nd June 2006, 06:44 PM
You must install the kernel-smp-devel package version that matches your currently running kernel. If your kernel is 2.6.16-1.2122_FC5-i686, you must install kernel-smp-devel-2.6.16-1.2122_FC5-i686. "yum install kernel-smp-devel" should automatically install the right version.

john-poma
2nd June 2006, 07:12 PM
OK, it's exactly what I do. There was a lot of mirror errors.
Now I make a yum update kernel-smp-devel and I have the good version.
I retry all the stuffs and let you know.
Thans a lot.
John

john-poma
3rd June 2006, 03:23 AM
Ioffi, all is going well.
Thanks a lot markuk. And sorry to disturb you.
We can close the thread.
John