博客
关于我
在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。

 

你可能感兴趣的文章
MySQL 索引深入解析及优化策略
查看>>
MySQL 索引的面试题总结
查看>>
mysql 索引类型以及创建
查看>>
MySQL 索引连环问题,你能答对几个?
查看>>
Mysql 索引问题集锦
查看>>
Mysql 纵表转换为横表
查看>>
mysql 编译安装 window篇
查看>>
mysql 网络目录_联机目录数据库
查看>>
MySQL 聚簇索引&&二级索引&&辅助索引
查看>>
Mysql 脏页 脏读 脏数据
查看>>
mysql 自增id和UUID做主键性能分析,及最优方案
查看>>
Mysql 自定义函数
查看>>
mysql 行转列 列转行
查看>>
Mysql 表分区
查看>>
mysql 表的操作
查看>>
mysql 视图,视图更新删除
查看>>
MySQL 触发器
查看>>
mysql 让所有IP访问数据库
查看>>
mysql 记录的增删改查
查看>>
MySQL 设置数据库的隔离级别
查看>>