linux驱动模板

#include<linux/module.h>
#include<linux/init.h>
#include<linux/kernel.h>
static int __init  hello_init(void)  //不写void 会报一个错误
{

  printk("Hello,Kernel\n");

  return 0;
}

static void hello_exit(void)
{

  printk("Exit hello exit\n");

}

module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE("GPL"); // 没有这个GPL也会报一个错误

编译命令:

 make  -C  /lib/modules/`uname -r`/build   SUBDIRS=`pwd`    modules

obj-m = hello.o
KVERS = $(shell uname -r)    #变量KVERS为当前linux版本值






default:
        #make -C /lib/modules/$(KERNEL)/build M=$(PWD) modules    // 这个有错误
        make  -C  /lib/modules/`uname -r`/build   SUBDIRS=`pwd`    modules

 

加载模块:

卸载模块:

猜你喜欢

转载自www.cnblogs.com/nowroot/p/12499799.html