找回密码
 注册
搜索
热搜: 回贴
微赢网络技术论坛 门户 服务器 Linux/BSD 查看内容

linux 2.6内核简单驱动编写

2009-12-20 13:27| 发布者: admin| 查看: 38| 评论: 0|原作者: 云天河

以前没有接触过驱动,找了几本书来看,看得晕晕的,觉得很多都理解不懂,上网搜,发现不少前辈总结的不错,这里仿着书和网上的资料写了一个简单的练习了一把,觉得好多了,不那么空洞了,过程如下:
1.首先在linux/drivers下建议文件夹beny,进入linux/drivers/beny
写一hello.c,内容如下:
#include
#include
#include
#include
MODULE_LICENSE("Dual BSD/GPL"); //gpl声明
static char *who = "world";
static int times=1;
module_param(times,int,S_IRUGO);
module_param(who,charp,S_IRUGO);
static int hello_init(void)
{
int i;
for(i=0;i
config helloBeny
tristate "hello support" #点击hello devices ---> 进去后会看到 hello support
help
a exercise of driver by Beny! #在 hello support页,点击help时会显示CONFIG_helloBeny... 等提示
endmenu
3.在drivers/beny添加makefile文件,内容如下
obj-$(CONFIG_helloBeny) =hello.o #编译器找到此Makefile时会自动寻找hello.o的同名c文件编译生成hello.o
4.修改上一级Makefile和Kconfig
在Makefile最后添加:obj-$(CONFIG_OLOIR) = beny/
在Kconfig中添加 :source "drivers/beny/Kconfig"
5. 在arch/arm的Kconfig中添加
source "drivers/beny/Kconfig"
ok,修改完了,内核编译后可以看到生成了hello.o、hello.ko等文件。







最新评论

QQ|小黑屋|最新主题|手机版|微赢网络技术论坛 ( 苏ICP备08020429号 )

GMT+8, 2024-9-30 07:29 , Processed in 0.073444 second(s), 12 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

返回顶部