#include
#include
#include
static int hello_init(void){
}
static void hello_exit(void)
{
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("LJL");
Makle 的编写
obj-m := hello.o
KERNELBUILD :=/usr/src/linux-headers-3.2.0-24-generic-pae
default:
clean:
记住不是顶行写的一定要空一格TAB键值 也就是四个字符间隔
编译后生成hello.ko
可以试一下
方法二:直接编译进内核
还是以上边那个模板举例子
然后在Makefile中添加变量以及编译路径
例如我再kernel/driver/char/下面的Makefile中的首行添加如下:
OBJ-$(CONFIG-HELLO) += hello.o
然后在/kernel/driver/char/下边的Kconfig 中添加如下语句:(Kconfig的作用大家肯定知道 不在此缀述。)
config HELLO
bool "HELLO DRV"
现在就可以的回到kernel根目录下make menuconfig -》driver》char》就可以选择了选中后直接编译内核就可以了