LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   how to compile a module with a newer version of the linux kernel? (https://www.linuxquestions.org/questions/programming-9/how-to-compile-a-module-with-a-newer-version-of-the-linux-kernel-204959/)

fvarela 07-14-2004 12:14 PM

how to compile a module with a newer version of the linux kernel?
 
Hi,

I am trying to write a custom module. The Linux kernel version is 2.6.6-1.435. For some reason, the source code version installed in my notebook was 2.6.5-1.358. Although I could compile my module, I could not loaded using insmod due to an error with VERMAGIC.
I decided to download the version which corresponds to the installed kernel version. After downloading the source code, I did:

root% rpm -Uvh kernel-sourcecode-2.6.6-1.435.2.3.noarch.rpm

The problem now is that the module does not compile. These are some of the errors I get:

------
[root@phy2-dhcp230 new]# make -C /usr/src/linux-2.6.6-1.435.2.3/ SUBDIRS=$PWD modules

make: Entering directory `/usr/src/linux-2.6.6-1.435.2.3'
Makefile:434: .config: No such file or directory
CC [M] /home/fvarela/bu/linux/drivers/v26/new/newkhello.o
In file included from include/linux/module.h:9,
from /home/fvarela/bu/linux/drivers/v26/new/newkhello.c:1:
include/linux/config.h:4:28: linux/autoconf.h: No such file or directory
In file included from include/linux/module.h:10,
from /home/fvarela/bu/linux/drivers/v26/new/newkhello.c:1:
include/linux/sched.h:4:37: asm/param.h: No such file or directory
In file included from include/linux/types.h:13,
from include/linux/capability.h:16,
from include/linux/sched.h:7,
from include/linux/module.h:10,
from /home/fvarela/bu/linux/drivers/v26/new/newkhello.c:1:
include/linux/posix_types.h:47:29: asm/posix_types.h: No such file or directory
In file included from include/linux/capability.h:16,
from include/linux/sched.h:7,
from include/linux/module.h:10,
from /home/fvarela/bu/linux/drivers/v26/new/newkhello.c:1:
include/linux/types.h:14:23: asm/types.h: No such file or directory
In file included from include/linux/capability.h:16,
from include/linux/sched.h:7,

------

I guess this has something to do with the installation of the new source code, and maybe in particular, with the #include sentences that I use that maybe are still pointing to the old source:

#include <linux/module.h>
#include <linux/config.h>
#include <linux/init.h>

1.- What else do I need to do in order to compile my module with the newer version of the kernel source?

2.- Will I gain anything if I compile the new version of the kernel?

Thanx,
F.

shishir 07-15-2004 03:23 AM

the 2.5+ line of kernels changed the module handling ...now a .o file is not used as a module, but a .ko (kernel object ) file is generated ..
read the documentation/kbuild/makefiles.txt to understand the kernel makefile...

do #include <linux/kernel.h>

a simple make would do.

you'd need new modutils to be able to insmod the modules on 2.6.
available at :
http://www.kernel.org/pub/linux/kern...rusty/modules/

read a file called: post-halloween-2.6.txt

install carefully so that you dont break the insmod'ing for older kernels..

hope this helped
use this makefile
Code:


ifneq ($(KERNELRELEASE),)
obj-m := <module-name>.o

else
 KDIR:= /lib/modules/$(shell uname -r)/build
CC := gcc
CFLAGS  := -c -nostdinc \
-D__KERNEL__ -I /$(KDIR) \
 -I /usr/lib/gcc-lib/i386-redhat-linux/3.2.2/include/

PWD := $(shell pwd)

default :
make -C $(KDIR) SUBDIRS=$(PWD) modules
clean :
rm *.o *.ko
endif


cjs_pro 07-29-2004 02:00 AM

Have a look at the linux source directory (rpm'ed). You may find the real soure code still in form of tar.bz2. If so, unzip it and (maybe) make a symbol link to the source directory as well if your module makefile looks at something like /usr/src/linux.

God luck


All times are GMT -5. The time now is 03:27 PM.