linux下驱动程序简述

编写hello驱动步骤:
  编写hello驱动代码
  编写makefile
  编译和加载hello驱动
  编写应用程序测试hello驱动

hello驱动代码:
  hello_open()
  hello_write()
  hello_read()
  hello_init()
  hello_exit()

编译hello需要makefile文件:
  应用层程序在编译的时候,需要链接C运行时库和glibc库
  驱动需要引用内核的头文件和函数,不能链接和使用应用层的任何lib库

执行make,编译出helloDev.ko;把驱动insmod helloDev.ko加载到内核
(dmesg命令 显示信息)
  在执行insmod的时候,驱动文件里的hello_init(),被调用了
  在执行rmmod的时候,hello_exit()被调用了

执行应用程序的时候,发现错误,找不到设备文件;
  为hello驱动手动创建设备文件mknod /dev/hello c 232 0 (这里的232 0跟驱动文件里定义的主次设备号对应起来 )
  执行dmesg查看驱动输出,发现驱动力的hell_open、hello_write、hello_read依次被调用了

驱动流程: 

  编写驱动代码

  编译驱动

  加载驱动

  创建设备文件

  测试驱动

posted @ 2021-05-26 09:50  我爱茜茜公主  阅读(93)  评论(0)    收藏  举报