您的位置:首页 > 运维架构 > Linux

嵌入式Linux平台USB驱动程序的移植

2012-10-12 20:42 537 查看
本驱动移植基本上参照 http://loveuzz.blogchina.com/loveuzz/4918763.html这个博客上的。写的比较好。感谢网上这么多朋友的分享。开发环境:内核2.6.15.1,busybox1.0,用3.4.5版本编译busybox,驱动程序模块编译用的是3.4.3
release版本。

1. 下载USB补丁文件。我用的是USB-2.6.12.patch.rar.在www.pudn.com网站上能找到。也可在此下载:


文件:usb-2.6.12.patch.rar
大小:51KB
下载:下载
解压此文件 .

2. 打补丁。在drivers/usb/media目录下建立spca5xx目录,mkdir
spca5xx,返回/driver/usb目录下,把补丁文件也放在此目录下,执行 patch –p1 < usb-2.6.12.patch,就会在 usb/media/spca5xx目录下产生如下文件:

cs2102.h

hdcs2020.h

hv7131b.h

hv7131c.h

icm105a.h

Makefile

Makefile.2.4

Makefile.org

pas106b.h

pb0330.h

sn9cxxx.h

sp5xxfw2.dat

sp5xxfw2.h

spca5xx.h

spcaCompat.h

spca_core.c

spcadecoder.c

spcadecoder.h

spcausb.h

tas5130c.h

zc3xx.h

3. 修改drivers/usb/Makefile文件,在

Obj-$(CONFIG_USB_W9968CF) += media/

之后添加一行:

obj-$(CONFIG_USB_SPCA5XX) += media/

4. 修改drivers/usb/media/Kconfig文件,在最后添加

config USB_SPCA5XX

tristate "USB SPCA5XX Sunplus/Vimicro/Sonix jpeg Cameras"

depends on USB && VIDEO_DEV

---help---

Say Y or M here if you want to use one of these webcams:

The built-in microphone is enabled by selecting USB Audio support.

This driver uses the Video For Linux API. You must say Y or M to

"Video For Linux" (under Character Devices) to use this driver.

Information on this API and pointers to "v4l" programs may be found

at <file:Documentation/video4linux/API.html>.

To compile this driver as a module, choose M here: the

module will be called spca5xx.

5. 配置内核 make menuconfig

(1)Multimedia drivers à

<M> Video For Linux

(2) USB support à

<M> Support for Host-side USB

-- USB Host Controller Drivers

<M> OHCI HCD support

(3) --USB Mulltimedia devices

<M> USB SPCA5XX Sunplus/Vimicro/sonix jpeg Cameras

6. 编译内核及模块 ,在源码根目录下执行 make ;make
modules就行。当然你得指定交叉编译环境,可以在顶层的Makefile 里面修改。

7. 拷贝模块文件至开发板目录下

cp drivers/media/video/v4l1-compat.ko /home/yuaf/root_nfs/

cp drivers/media/video/v4l2-common.ko /home/yuaf/root_nfs/

cp drivers/media/video/videodev.ko/ /home/yuaf/root_nfs/

cp drivers/usb/core/usbcore.ko /home/yuaf/root_nfs/

cp drivers/usb/media/spca5xx/spca5xx.ko /home/yuaf/root_nfs/

8. 9、将USB摄像头插入开发板(注:必须先插入摄像头才能插入模块文件,否则系统会出现kernel
oops

9. 重新启动开发板

10. 插入模块文件(注:这里必须注意模块的插入顺序,这是因为模块的依赖关系)

Insmod usbcore.ko

Insmod ohci-hcd.ko

Insmod v4l1-compat.ko

Insmod v4l2-common.ko

Insmod videodev.ko

Insmod spca5xx.ko

插入以上模块之后,建议设备文件

Cd /dev

Mknod video0 c 81 0

也可以将以上语句写到 /etc/init.d/rcS文件中,当开发板启动时自动加载模块。加载过程中出现如下信息。

usbcore: registered new driver usbfs

usbcore: registered new driver hub

Using ohci-hcd.ko

Set S3C2410 UPLLCON!

s3c2410-ohci s3c2410-ohci: S3C24XX OHCI

s3c2410-ohci s3c2410-ohci: new USB bus registered, assigned bus number 1

s3c2410-ohci s3c2410-ohci: irq 42, io mem 0x49000000

usb usb1: Product: S3C24XX OHCI

usb usb1: Manufacturer: Linux 2.6.15.1 ohci_hcd

usb usb1: SerialNumber: s3c24xx

hub 1-0:1.0: USB hub found

hub 1-0:1.0: 2 ports detected

Using v4l1-compat.ko

Using v4l2-common.ko

usb 1-1: new full speed USB device using s3c2410-ohci and address 2

Using videodev.ko

usb 1-1: Product: PC Camera

usb 1-1: Manufacturer: Vimicro Corp.

Linux video capture interface: v1.00

Using spca5xx.ko

drivers/usb/media/spca5xx/spca_core.c: USB SPCA5XX camera found. Type Vimicro Zc301P 0x301b

usbcore: registered new driver spca5xx

drivers/usb/media/spca5xx/spca_core.c: spca5xx driver 00.57.06LE registered

这样这个驱动就移植完成了。

11. 用命令测试

Cat /dev/video0 > /tmp/a.jpg.

进入tmp目录可以看见有此文件。

也可以用servfox 和 spcaview 进行数据的采集和查看,在嵌入式Linux版块中对此有相关的介绍。

总结:在整个过程中要还是要注意编译器的问题,若生成模块,你也可以用modinfo 查看一下模块的信息。内核版本要一致等。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: