1、驱动程序hello.c:
#include<linux/init.h>
#incude<linux/modules.h>
#include<linux/kernel.h>
/*初始化函数,这里没有加什么有实际意义的部分,只是为了演示创建模块而已*/
static int hello_init(void)
{
printk("hello world,this is my first driver!!!\n");
return 0;
}
/*卸载函数*/
static void hello_exit(void)
{
printk("GoodBye my first drvier!");
}
/*添加到模块函数*/
modules_init(hello_init);
modules_exit(hello_exit);
/*添加开源协议*/
MODULE_LICENSE("GPL");
MODULES_AUTHOR(Mr Dong);
2、编译驱动的makefile文件
LINUXROOT = /opt/linux2.6.24 #这里是你的linux内核所在的路径
obj-m :=hello.o
default:
@make -C $(LINUXROOT) M=$(PWD) modules #注意前面是以tab键开头的
clean:
@make -C $(LINUXROOT) M=$(PWD) clean
3、加载驱动,make后执行insmod hello.ko