#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
MODULE_LICENSE("Dual BSD/GPL");
static int hello_init (void)
{
printk("hello linux kernel\n");
return 0;
}
static void hello_exit (void)
{
printk("bye..lwave from the kernel\n");
}
module_init(hello_init);
module_exit(hello_exit);
obj-m := hello.o
beyes@linux-beyes:~/C/kernel> make -C /usr/src/linux-2.6.30 M=`pwd` modules
make: Entering directory `/usr/src/linux-2.6.30'
CC [M] /home/beyes/C/kernel/hello.o
Building modules, stage 2.
MODPOST 1 modules
CC /home/beyes/C/kernel/hello.mod.o
LD [M] /home/beyes/C/kernel/hello.ko
make: Leaving directory `/usr/src/linux-2.6.30'
beyes@linux-beyes:~/C/kernel> ls
hello.c hello.ko hello.mod.c hello.mod.o hello.o Makefile Module.markers modules.order Module.symvers
make: Entering directory `/usr/src/linux-2.6.30'
Building modules, stage 2.
MODPOST 0 modules
make: Leaving directory `/usr/src/linux-2.6.30'
beyes@linux-beyes:~/C/kernel> ls
hello.c Makefile Module.markers modules.order Module.symvers
obj-m := module.o
module-objs := file1.o file2.o
linux-beyes:/home/beyes/C/kernel # insmod ./hello.ko
linux-beyes:/home/beyes/C/kernel # cat /var/log/messages | grep hello
Aug 7 01:55:35 linux-beyes kernel: hello linux kernel
rmmod hello
linux-beyes:/home/beyes/C/kernel # cat /var/log/messages | grep bye
Aug 7 02:02:56 linux-beyes kernel: bye..lwave from the kernel
obj-m := hello.o
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
clean:
rm -rf *.ko
rm -rf *.mod.*
rm -rf .*.cmd
rm -rf *.o
ERROR: Kernel configuration is invalid.
include/linux/autoconf.h or include/config/auto.conf are missing.
Run 'make oldconfig && make prepare' on kernel src to fix it.
make oldconfig
make prepare
/bin/sh: scripts/mod/modpost: 没有那个文件或目录
make[1]: *** [__modpost] 错误 127
make: *** [modules] 错误 2
make scripts
insmod:error inserting 'hello.ko': -1 Invalid module format
make -C /lib/modules/`uname -r`/build M=`pwd` modules
| 欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) | Powered by Discuz! X3.2 |