字符设备驱动程序学习笔记一

linux 驱动程序


字符设备驱动程序
网络接口驱动程序
块设备驱动




字符设备 按字节来访问的设备
字符设备驱动用来驱动字符设备 通常实现open close read write




块设备
unix系统一次传输一个或多个512字节
linux允许块设备传送任意数目的字节
字符设备驱动和块设备驱动哪个可以随机访问


网络接口
通常是一个硬件设备(etho),也可以是一个;软件设备如回环接口(lo)




驱动程序的安装


1 模块方式
2 直接编译进内核

1 将程序复制到内核当中drivers/char
[root@localhost char]# cp /opt/linux/examples/hello/hello.c ./


2 修改kconfig,即配置makemenuconfig选项
查看配置菜单:
[root@localhost linux-2.6.38]# make menuconfig ARCH=arm
[root@localhost char]# vi Kconfig
添加如下代码:
config HELLO
bool "hello"
重新查看配置菜单:
[root@localhost linux-2.6.38]# make menuconfig ARCH=arm
进入device drivers-->Character devices
部分内容如下:
#此处可以查看到刚才配置的选项
[ ] hello (NEW) │ │



│ │ -*- Virtual terminal


│ │
│ │ [ ] Support for binding and unbinding console drivers


│ │
│ │ [ ] /dev/kmem virtual device support


│ │
│ │ <*> LED Support for Mini6410 GPIO LEDs


│ │
│ │ <M> Mini6410 module sample


│ │
│ │ <*> Buttons driver for FriendlyARM Mini6410 development


boards │ │
│ │ <*> Buzzer driver for FriendlyARM Mini6410 development


boards │ │
│ │ [*] ADC driver for FriendlyARM Mini6410 development boards


vg3


查看配置结果:
[root@localhost linux-2.6.38]# vi .config
部分代码如下:
#
# Character devices
#
CONFIG_HELLO=y
CONFIG_VT=y


3 修改makefile
[root@localhost linux-2.6.38]# vi drivers/char/Makefile
添加如下内容:
obj-$(CONFIG_HELLO) += hello.o
4 重新编译内核
5 将zImage烧写到开发板测试
部分启动信息如下:
size=0003fc00
fb3: s3cfb frame buffer device
backlight initialized
s3c6400-uart.0: ttySAC0 at MMIO 0x7f005000 (irq = 16) is a S3C6400/10
s3c6400-uart.1: ttySAC1 at MMIO 0x7f005400 (irq = 20) is a S3C6400/10
s3c6400-uart.2: ttySAC2 at MMIO 0x7f005800 (irq = 24) is a S3C6400/10
s3c6400-uart.3: ttySAC3 at MMIO 0x7f005c00 (irq = 28) is a S3C6400/10
leds initialized
buttons initialized
pwm initialized
adc initialized
Hello World!




应用程序使用驱动程序


应用程序
----------------------------------------------
字符设备 文件系统 套接字
块设备文件
----------------------------------------------
字符设备驱动 块设备驱动 协议栈
网络设备驱动
----------------------------------------------
字符设备 块设备 网络接口设备






linux 用户程序通过设备文件(设备节点)来使用驱动程序操作字符设备和块设备
设备位于/dev目录下

猜你喜欢

转载自retacn-yue.iteye.com/blog/1859870