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