《linux设备驱动程序》笔记一——加载helloworld驱动

加载驱动命令:insmod hello.ko
卸载驱动命令:rmmod hello.ko

写hello驱动文件/driver/hello/hello.c

 1 #include<linux/init.h>
  2 #include<linux/module.h>
  3 static int hello_init(void)
  4 {
  5     printk(KERN_ALERT "hello world enter!\n");
  6     return 0;
  7 }
  8 static void hello_exit(void)
  9 {
 10     printk(KERN_ALERT "HELLO WORLD EXIT !\n");
 11 
 12 }
 13 module_init(hello_init);
 14     module_exit(hello_exit);
 15 
 16 

之后需要在hello文件夹下面创建Makefile 很简单加一句话obj-m := hello.o
再在driver目录下的Makefile文件中添加一句话 obj-y +=hello/
之后在kernel目录下编译模块make modules 就可以看到hello文件夹下面生成了hello.ko文件 可以加载
这里写图片描述

猜你喜欢

转载自blog.csdn.net/demondhxq/article/details/79129085