Debian 6 驱动开发环境搭建

本文详细介绍了如何在 Debian 6 系统中搭建驱动开发环境,包括安装相关工具、查看系统版本、安装内核头文件等步骤,并提供了测试示例,演示如何编写和运行驱动模块。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Debian 6 驱动开发环境搭建
1.安装相关工具
apt
-get install -y gcc g++ gdb make build-essential

2.查看系统版本,并安装内核头文件
root@
192.168.20.128:~/ # uname -r
2.6.32-5-686
apt
-cache search linux-headers-2.6.32-5-686
apt
-get install -y linux-headers-2.6.32-5-686

3.查看内核头文件位置
看下会安装到哪
:
apt
-cache show linux-headers-2.6.32-5-686

有这么句
:
These files are going to be installed into
/usr/src/linux-headers-2.6.32-5-686, and can be used for building modules

就是这里啦
.
/usr/src/linux-headers-2.6.32-5-686

4.好了,接下来写测试例子:hello,抄了http://bbs.chinaunix.net/thread-3570849-1-1.html
上的代码
:
文件1
:hello.c
#include <linux/init.h>
#include <linux/module.h>

MODULE_LICENSE("GPL");

static 
int hello_init(void)
{
    printk(KERN_ALERT 
"Hello, world\n");
    
return 0;
}

static void hello_exit(void)
{
    printk(KERN_ALERT 
"Goodbye, cruel world\n");
}

module_init(hello_init);
module_exit(hello_exit);

文件2
:Makefile:
obj
-m   +=hello.o
KERNELDIR   
:= /usr/src/linux-headers-2.6.32-5-686
PWD 
:=$(shell pwd)
.PHONY: test clean all
all
:
    $(MAKE) 
-C $(KERNELDIR) M=$(PWD) modules
clean
:
    rm 
-rf *.*~ core .depend .*.cmd *.ko *.mod..tmp_versionsm *.order *.symvers

test
:
    insmod 
./hello.ko
    rmmod hello
    dmesg 
-c
    
5.好了,现在测试开始,成功的话,就可以看到下面的文字了.
如果有问题的话
,向google大神请教吧.另外要看
root@
192.168.20.128:~/cpp # make 
make -/usr/src/linux-headers-2.6.32-5-686 M=/root/cpp modules
make[
1]: Entering directory `/usr/src/linux-headers-2.6.32-5-686'
  CC [M]  /root/cpp/hello.o
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /root/cpp/hello.mod.o
  LD [M]  /root/cpp/hello.ko
make[1]: Leaving directory `/usr/src/linux-headers-2.6.32-5-686
'
root@
192.168.20.128:~/cpp # make test
insmod ./hello.ko
rmmod hello
dmesg 
-c
[  
673.500413] Hello, world
[  
673.504907] Goodbye, cruel world
root@
192.168.20.128:~/cpp #


6.最后.安装开发帮助文档
apt
-get install -y manpages-kernel-dev linux-manual
man 
9 printk
man 
9 module_init

参考资料
: 
http
://bbs.chinaunix.net/thread-3570849-1-1.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值