#include <linux/kernel.h>
#include <linux/module.h>
static int __init hello_init(void) //內核加載函數
{
printk("Hello driver!\n"); //內核模塊中用於輸出的函數
return 0;
}
static void __exit hello_exit(void) //內核卸載函數
{
printk("ByeBye");
}
module_init(hello_init); //驅動入口函數
module_exit(hello_exit); //出口函數
MODULE_LICENSE("GPL"); //模塊許可證聲明澹ㄥ必須)
MODULE_AUTHOR("StephenYee([email protected])");
makefile文件:
ifeq ($(KERNELRELEASE),)
KERNELDIR ?= $(HOME)/linux-2.6.14
PWD := $(shell pwd)
modules:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
modules_install:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install
clean:
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions *.order *.symvers
.PHONY: modules modules_install clean
else
obj-m := hello.o
endi