Recently, I tried Linux kernel device module programming, using the "Linux kernel compilation" book, but in the new version of the 2.6 core, the example program cannot be compiled, and I have been searching for a long time. I didn't find a complete solution. I finally finally at the website. Http://lwn.net/ get help, now summarize
INIT and CLEAR naming modes change, makefile changes
Description with a Hello World program
The original version is as follows:
#include
#include
#if config_modversions == 1 # Define modversions # include
} void cleanup_module () {Printk ("Short is the life of a kernel module / n");}
Mvakefile is as follows
CC = gccmodcflags: = -wall -dmodule -d__kernel__ -dlinuxhello.o: hello.c /usr/include/linux/Version.h$ (MODCFLAGS) -C Hello.c
Now need to be changed
#include
Static int hello_init (void) {printk ("<1> Hello, World / N"); Return 0;}
Static void hello_exit (void) {printk ("<1> goodbye, cruel world / n");}
Module_init (Hello_init); Module_exit (Hello_exit);
Makefile as follows
IFNEQ ($ (kernelrelease),) OBJ-M: = Hello.o
Elsekdir: = / lib / modules / $ (shell uname -r) / buildpwd: = $ (Shell PWD)
DEFAULT: $ (MAKE) -C $ (KDir) Subdirs = $ (PWD) ModuLesendif
One thing to focus on
$ (MAKE) -C $ (kdir) Subdirs = $ (PWD) Modules, before this sentence, you must add a Tab, remember to remember
This will have a * .ko file, this file can be inward by INSMOD.
However, I have encountered a problem, that is, my GCC upgrade to 3.4.1 files compiled after INSMOD, prompt to use GCC 3.3, so depressed, and finally used GCC 3.3 to get it.
In addition, this thing INSMOD will not be in the future, but can only see the addition of adding success in LSMOD, and there is no information when rmmod, where is the Printk output in the statement? Used is a multi-user command line mode, no X
The above program is compiled by the kernel 2.6.5
At http://lwn.net/articles/driver-porting/ You will get more information about 2.6 kernel changes