博客
关于我
在linux内核里面新添加一个驱动模块
阅读量:640 次
发布时间:2019-03-14

本文共 1593 字,大约阅读时间需要 5 分钟。

这篇文章完全参考:原文:https://blog.csdn.net/u012247418/article/details/83684126  

原文讲解的特别详细,希望大家都去看原文

发这篇博客的原因完全只是为了方便自己以后查阅。

 

1. 构建测试模块:hello

1.1 在linux-3.4/drivers/下新建目录hello

cd linux-3.4/drivers/

mkdir hello

1.2 在hello/下新建hello.c Makefile Kconfig三个文件

hello.c:

#include 
//所有模块都需要的头文件#include
// init&exit相关宏#include
MODULE_LICENSE("GPL");MODULE_AUTHOR("baoli");MODULE_DESCRIPTION("hello world module"); static int __init hello_init(void){ printk(KERN_WARNING "hello world.\n"); return 0;}static void __exit hello_exit(void){ printk(KERN_WARNING "hello exit!\n");} module_init(hello_init);module_exit(hello_exit);

Makefile:

obj-$(CONFIG_HELLO) += hello.o

Kconfig:

menu "HELLO TEST Driver "comment "HELLO TEST Driver Config" config HELLO	tristate "hello module test"	default m	help	This is the hello test driver  endmenu

1.3 修改上一级目录的Kconfig和Makefile

进入linux-3.4/drivers/

1)编辑Makefile,在后面添加一行:

obj-$(CONFIG_HELLO) += hello/

2)编辑Kconfig,在后面添加一行:

source "drivers/hello/Kconfig"

注:某些内核版本需要同时在arch/arm/Kconfig中添加:source "drivers/hello/Kconfig"

 

2. make menuconfig配置

1)执行:make menuconfig ARCH=arm

2)选择并进入:Device Drivers选项

可以看到新增 HELLO TEST Driver选项

3)进入 HELLO TEST Driver选项

可以选择<m> <y> <n>,分别为编译成内核模块、编译进内核、不编译。

 

3. 编译

退出保存后

开始编译内核

1)如果选择编译成模块<m>

编译内核过程中,会有如下输出:

LD drivers/hello/built-in.o

CC [M] drivers/hello/hello.o

CC drivers/hello/hello.mod.o

LD [M] drivers/hello/hello.ko

2)如果选择编译进内核<y>

编译内核过程中,会有如下输出:

CC drivers/hello/hello.o

LD drivers/hello/built-in.o

 

编译完成后,drivers/hello/下新增hello.o和hello.ko,并且/linux-3.4/output/lib/modules/3.4.39/下也会有hello.ko。

 

你可能感兴趣的文章
Mysqldump参数大全(参数来源于mysql5.5.19源码)
查看>>
mysqldump备份时忽略某些表
查看>>
mysqldump实现数据备份及灾难恢复
查看>>
mysqldump数据库备份无法进行操作只能查询 --single-transaction
查看>>
mysqldump的一些用法
查看>>
mysqli
查看>>
MySQLIntegrityConstraintViolationException异常处理
查看>>
mysqlreport分析工具详解
查看>>
MySQLSyntaxErrorException: Unknown error 1146和SQLSyntaxErrorException: Unknown error 1146
查看>>
Mysql_Postgresql中_geometry数据操作_st_astext_GeomFromEWKT函数_在java中转换geometry的16进制数据---PostgreSQL工作笔记007
查看>>
mysql_real_connect 参数注意
查看>>
mysql_secure_installation初始化数据库报Access denied
查看>>
MySQL_西安11月销售昨日未上架的产品_20161212
查看>>
Mysql——深入浅出InnoDB底层原理
查看>>
MySQL“被动”性能优化汇总
查看>>
MySQL、HBase 和 Elasticsearch:特点与区别详解
查看>>
MySQL、Redis高频面试题汇总
查看>>
MYSQL、SQL Server、Oracle数据库排序空值null问题及其解决办法
查看>>
mysql一个字段为空时使用另一个字段排序
查看>>
MySQL一个表A中多个字段关联了表B的ID,如何关联查询?
查看>>