Linux内核中如何增加自己的驱动代码
2016-05-31 23:41
405 查看
Linux内核中如何增加自己的驱动代码?本文给出了详细的步骤。其实本质上就是修改kconfig和makefile两个文件。
先熟悉下kconfig的语法
第一行,菜单名
第二行,配置项名称,代表整个配置项
第三行,配置类型,包括bool,tristate,string,hex和int.
第四行,领带项,如果anotherconfigurename存在,则显示。
第五行,默认
第六,七行,帮助信息。
Linux内核中增加自己的驱动代码实例介绍:
要求drivers目录下,增加一个文件夹yonganadded,此文件下入自己的驱动,如globalvar,等。
Drivers目录的makefile追加:obj-y+=yonganadded/
Drivers目录的Kconfig中endmenu前追加:source"drivers/yonganadded/Kconfig"
Yonganadded目录中
Makefile内容:obj-y+=globalvar/
Kconfig内容:
menuconfigYONGAN
tristate"driversaddedbyyongan"
---help---
itdependsonwhatyouwrite
ifYONGAN
source"drivers/yonganadded/globalvar/Kconfig"
endif
在globalvar目录中
Makefile:obj-$(GLOBALVAR)+=/globalvar.o
Kconfig:configGLOBALVAR
bool"globalvar"
---help---
Provideatestofreadandwrite
最终结果:
总结:
先熟悉下kconfig的语法
1.menumenuname 2.configuremyconfigurename 3.boolconfigurenametoshow 4.dependsonanotherconfigurename 5.defaulty 6.help 7.somewordsyouarefreedomtoexplain 8.endmenu
第一行,菜单名
第二行,配置项名称,代表整个配置项
第三行,配置类型,包括bool,tristate,string,hex和int.
第四行,领带项,如果anotherconfigurename存在,则显示。
第五行,默认
第六,七行,帮助信息。
Linux内核中增加自己的驱动代码实例介绍:
要求drivers目录下,增加一个文件夹yonganadded,此文件下入自己的驱动,如globalvar,等。
Drivers目录的makefile追加:obj-y+=yonganadded/
Drivers目录的Kconfig中endmenu前追加:source"drivers/yonganadded/Kconfig"
Yonganadded目录中
Makefile内容:obj-y+=globalvar/
Kconfig内容:
menuconfigYONGAN
tristate"driversaddedbyyongan"
---help---
itdependsonwhatyouwrite
ifYONGAN
source"drivers/yonganadded/globalvar/Kconfig"
endif
在globalvar目录中
Makefile:obj-$(GLOBALVAR)+=/globalvar.o
Kconfig:configGLOBALVAR
bool"globalvar"
---help---
Provideatestofreadandwrite
最终结果:
总结:
相关文章推荐
- 还是要习惯在linux环境下作Java开发
- linux下安装python库
- linux下安装pip
- linux grep命令详解
- Segmentation fault到底是何方妖孽
- 如何知道一台Linux服务器使用的是千兆网卡还是万兆网卡
- 如何备份及恢复Linux文件权限
- Linux CentOS6.5下编译安装MySQL 5.6.16
- Linux下的进度条小程序
- 快速配置Linux下的Vim编辑器
- Linux下coredump调试3:补录
- Linux下出现error while loading shared libraries,...cannot open shared object file: No such file..
- maven安装(linux)
- Linux下U盘变成只读
- Centos下Zookeeper设置自启动
- Linux 中实现进度条
- Linux下coredump调试2:实例
- Linux系统下makefile教程讲解
- linux下history日志记录脚本
- Linux 默认目录结构