obj-m := test.o
KERNELBUILD := /lib/modules/`uname -r`/build
default:
@echo " BUILD kmod"
@make -C $(KERNELBUILD) M=$(shell pwd) modules
clean:
@echo " CLEAN kmod"
@rm -rf *.o Module.markers modules.order
@rm -rf .depend .*.cmd *.ko *.mod.c .tmp_versions *.symvers .*.d
one example:
#include
#include
MODULE_LICENSE("Dual BSD/GPL");
static int __init mod_entry_func(void)
{
printk("hello world! is init ");
return 0;
}
static void __exit mod_exit_func(void)
{
printk("Hello world is exit\n");
return ;
}
module_init (mod_entry_func);
module_exit (mod_exit_func);
编译:make
加载:insmode test.ko
卸载:rmmode test
用printk输出的信息不显示在终端,若要查看,输入:
dmesg
即可查看
阅读(755) | 评论(0) | 转发(0) |