1 在kernel/driver目录下面建立hello_wuxy的文件夹
在hello_wuxy里面添加 Makefile Kconfig 以及hello_wuxy.c
Makefile 内容如下:
#
# Makefile for test hello_wuxy driver
#
obj-$(CONFIG_HELLO_WUXY) += hello_wuxy.o
Kconfig 内容如下:
config HELLO_WUXY
tristate "add hello_wuxy to kernel"
help
This enables support add hello_wuxy to kernel
其中红色内容的配置宏一定要对应,tristate 表示三态:即M 模块编译,*编译进内核,以及不选。还有一个为bool,bool就只有yes or no
add hello_wuxy to kernel 为我们能在make menuconfig 里面看到的内容
hello_wuxy.c 内容如下:
#include <linux/init.h>
#include <linux/modules.h>
static hello_init()
{
printk(0"printf hello wuxy!!!!!!!!!!!");
return 0;
}
static hello_exit()
{
printk(0"printf bye wuxy!!!!!!!!!!!!!");
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("wuxy");
2 另外需要在driver目录下面的Kconfig文件里面添加
source "drivers/hello_wuxy/Kconfig"
才能在make menuconfig 里面看到我们添加的配置项。
然后将Device Drivers里面的add hello_wuxy to kernel 选上保存即可编译hello_wuxy.ko