It seems like you are using an older (2.4) method on newer (2.6) kernels. Moreover, you are including your header files from
/usr/src/linux instead of those matching to your particular kernel (this may point to your actual kernel sources, but this is not the recommended way).
First off, please dont do this:
Quote:
Originally Posted by ciotog
It would seem to me you need to #include /usr/src/linux/.config so that CONFIG_X86_L1_CACHE_SHIFT is defined properly.
|
Basically, on newer kernels, everyone is advised to use the kernel make system. This means you will change directory to your kernel build tree, run
make from there with some magical options which make the make system compile and link your module. If you just want to use this without all the explanation, skip down to the Makefile at the end.
<EXPLANATION>
First, we need the kernel build tree: If you compiled your kernel from source and installed modules with
make modules_install (on your 2.6 kernel), it should have created a directory
/lib/modules/`uname -r` which has a two symlinks:
source points to the kernel source tree, and
build points to the kernel build tree (note, that in most cases, they are the same).
The build tree is needed intact for this to work. Next, we need to know some of the magical variables we pass to the make system. The first such option tells the make system you want to compile external module(s) which reside in the directory you specify. This is
M variable (alternatively, you could use the older
SUBDIRS variable).
The other variable will tell the make system what to compile (in this case, your one file:
hello1.c) and how to link it (in this case, as a module). To specify linkage as a module, you use the variable
obj-m (the value of this variable is the same name as the source file except the suffix is
.o rather than
.c).
Now, we should be set for making your module. Basically, this is what you do (replace
/path/to/your/source with the location of
hello1.c):
Code:
$ make -C /lib/modules/`uname -r`/build M=/path/to/your/source obj-m=hello1.o
You should end up with (among other new files) a file named
hello1.ko in the directory you specified. This is your module which you can insert with
insmod hello1.ko (as root). Alternatively, you can install the module like this:
Code:
# make -C /lib/modules/`uname -r`/build M=/path/to/your/source obj-m=hello1.o modules_install
and insert it with
modprobe hello1 (as root).
</EXPLANATION>
If you dont want to do this by hand each time, you can create a Makefile that looks something like this:
Code:
ifndef KERNELDIR
KERNELDIR := /lib/modules/$(shell uname -r)/build
endif
obj-m := hello1.o
all:
$(MAKE) -C $(KERNELDIR) M=$(PWD)
clean:
$(MAKE) -C $(KERNELDIR) M=$(PWD) clean
install:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install
/sbin/depmod -ae
Place this file in the same directory that contains
hello1.c, and just run
make to build your module.