您的位置 首页 观点

Arm-Linux摄像头驱动程序的移植

Arm开发板上摄像头的移植有两种方法:第一,将驱动程序添加到内核,通过编译内核,烧写到板子上;第二种,通过动态加载摄像头驱动…

Arm开发板上摄像头的移植有两种办法:榜首,将驱动程序添加到内核,经过编译内核,烧写到板子上;第二种,经过动态加载摄像头驱动模块的办法进行硬件的驱动。作者首先在PC的linux体系进行摄像驱动程序的移植,确保驱动程序版别正确,然后将驱动程序编译成模块,经过文件体系挂载到板子,然后进行加载,从而创立摄像头设备节点。下面将详细介绍摄像头动态加载的进程。

移植进程所运用的摄像头类型ZC301P,arm板上的内核版别为2.6.9,开发板为pxa270,所选用的驱动程序包为spca5xx-20060501.tar.gz。

榜首步,运用指令解压文件: tar zxvf spca5xx-20060501.tar.gz

进入spca5xx-20060501 : cd spca5xx-20060501

第二步,修正Makefile文件:VERSION = 00.60.00

Makefile的内容如下,注释掉的为蓝色,赤色表明修正过的内容:

CC =arm-linux-gcc

LD =arm-linux-ld
CVSVERSION = “$Experimental work Michel Xhaard && Reza Jelveh 03/02/2004”
DEFINES =

###
# The following flags enable experimental features.
# By default, these are enabled for development versions of the driver, and
# disabled for release versions.

# Optional: Enable driver debugging
DEFINES += –DSPCA50X_ENABLE_DEBUG

# Optional: Enable direct register read/write for PAC207 development
#DEFINES += -DSPCA5XX_ENABLE_REGISTERPLAY

###
# The following flags enable features that arent yet implemented, and
# therefore are disabled by default.

# Optional: Enable compression
DEFINES += -DSPCA50X_ENABLE_COMPRESSION

###
# Rest of Makefile follows here. You probably wont need to touch this.

# Setup defines
DEFINES += -DCONFIG_USB_SPCA5XX_MODULE=1 -DMODULE -D__KERNEL__
DEFINES += -DVID_HARDWARE_SPCA5XX=0xFF -DSPCA5XX_VERSION=\”$(VERSION)\”

ifneq ($(shell uname -r | cut -d. -f1,2), 2.4)

ifneq ($(KERNELRELEASE),) # We were called by kbuild
CFLAGS += $(DEFINES)
obj-m += spca5xx.o
spca5xx-objs := drivers/usb/spca5xx.o drivers/usb/spcadecoder.o

else # We were called from command line

#KERNEL_VERSION = `uname -r`

KERNEL_VERSION = 2.6.9

#KERNELDIR := /lib/modules/$(KERNEL_VERSION)/build
KERNELDIR := /up-techpxa270/kernel/linux-2.6.9

PWD := $(shell pwd)
#MODULE_INSTALLDIR = /lib/modules/$(KERNEL_VERSION)/kernel/drivers/usb/media/

MODULE_INSTALLDIR =/root/modules/

# Targets, dont change!
default:
@echo Building SPCA5XX driver for 2.5/2.6 kernel.
@echo Remember: you must have read/write access to your kernel source tree.
$(MAKE) -C $(KERNELDIR) SUBDIRS=$(PWD) CC=$(CC) modules

install:
mkdir -p $(MODULE_INSTALLDIR)
rm -f $(MODULE_INSTALLDIR)spca50x.ko
rm -f $(MODULE_INSTALLDIR)et61x.ko
install -c -m 0644 spca5xx.ko $(MODULE_INSTALLDIR)
/sbin/depmod -ae

uninstall:
rm -f $(MODULE_INSTALLDIR)/spca5xx.ko
/sbin/depmod -aq

endif

else # kernel version test

#############################################################################
# For Linux 2.4 users.
# Change the following lines according to your system configuration.
# It is important to configure your particular source tree (“make dep”) before
# compiling this module!
#############################################################################
###
# This makefile will build the spca50x driver module external to the kernel
# source tree. It makes it easier to swap kernels.

#KERNEL_VERSION = `uname -r`

KERNEL_VERSION = 2.4.x

###
# Location of the header files (most importantly the config files)
# for the kernel you want to build the module against.
# This should be correct for the currently installed kernel on your machine.
#KINCLUDE = /lib/modules/$(KERNEL_VERSION)/build/include

KINCLUDE =/up-techpxa270/kernel/linux2.4.x

KERNEL_ACFILE = $(KINCLUDE)/linux/autoconf.h
KERNEL_MODVERSIONSFILE = $(KINCLUDE)/linux/modversions.h
#MODULE_INSTALLDIR = /lib/modules/$(KERNEL_VERSION)/kernel/drivers/usb/

MODULE_INSTALLDIR =/root/modules/

# Detect module versioning support
ifneq ($(strip $(shell grep define CONFIG_MODVERSIONS 1 $(KERNEL_ACFILE))),)
DEFINES += -DMODVERSIONS -include $(KERNEL_MODVERSIONSFILE)
endif

# Detect SMP support
ifneq ($(strip $(shell grep define CONFIG_SMP 1 $(KERNEL_ACFILE))),)
DEFINES += -D__SMP__ -DSMP
endif

# Setup the tools
#CC = gcc
#LD = ld

CC=arm-linux-gcc

LD =arm-linux-gcc

# Setup compiler warnings
WARNINGS = -Wall -Wpointer-arith
WARNINGS += -Wcast-align -Wwrite-strings -Wstrict-prototypes
WARNINGS += -Wuninitialized -Wreturn-type -Wunused -Wparentheses

# Setup compiler flags
CFLAGS = -O2 -fomit-frame-pointer -fno-strict-aliasing -pipe
CFLAGS += -mpreferred-stack-boundary=2
CFLAGS += -I$(KINCLUDE) -Idrivers/usb

# Setup link flags
LDFLAGS = –strip-debug -r

# Setup the list of files to be included in a distribution
DIST_FILES = CHANGELOG \
README \
Makefile \
drivers/usb/Config.in \
drivers/usb/spcadecoder.c \
drivers/usb/spcadecoder.h \
drivers/usb/spcagamma.h \
drivers/usb/spcaCompat.h \
drivers/usb/spcausb.h \
drivers/usb/spca500_init.h \
drivers/usb/spca501_init.h \
drivers/usb/sp5xxfw2.dat \
drivers/usb/sp5xxfw2.h \
drivers/usb/spca505_init.h \
drivers/usb/spca506.h \
drivers/usb/spca508_init.h \
drivers/usb/spca561.h \
drivers/usb/sonix.h \
drivers/usb/cs2102.h \
drivers/usb/hv7131b.h \
drivers/usb/icm105a.h \
drivers/usb/hv7131c.h \
drivers/usb/hdcs2020.h \
drivers/usb/pb0330.h \
drivers/usb/tas5130c.h \
drivers/usb/zc3xx.h\
drivers/usb/tv8532.h\
drivers/usb/cxlib.h\
drivers/usb/sn9cxxx.h\
drivers/usb/cx11646.h\
drivers/usb/pac207.h\
drivers/usb/spca5xx.c \
drivers/usb/spca5xx.h

OBJS = drivers/usb/spcadecoder.o \
drivers/usb/spca5xx.o

BINARY = spca5xx.o

###
# Targets follow here

binary:$(OBJS)
@echo Linking $(BINARY)
@$(LD) $(LDFLAGS) -o $(BINARY) $(OBJS)

install: binary
@echo Installing.. Your root password may be required.
su -c “make install-root”

install-root:
@echo Installing..
@mkdir -p /lib/modules/`uname -r`/kernel/drivers/usb
@rm -f /lib/modules/`uname -r`/kernel/drivers/usb/spca50x.o
@rm -f /lib/modules/`uname -r`/kernel/drivers/usb/et61x.o
@cp spca5xx.o /lib/modules/`uname -r`/kernel/drivers/usb/spca5xx.o
@/sbin/depmod

dist:clean binary
@echo Making distributable archives
@rm -f spca5xx-src-$(VERSION).tar.gz
@tar zcf spca5xx-src-$(VERSION).tar.gz $(DIST_FILES)
@rm -f spca5xx-module-$(VERSION).tar.gz
@cp $(BINARY) spca5xx-$(VERSION).o
@tar zcf spca5xx-module-$(VERSION).tar.gz spca5xx-$(VERSION).o README
@rm spca5xx-$(VERSION).o

.c.o:Makefile $*.c
@echo Compiling $*.c
@$(CC) $(CFLAGS) $(WARNINGS) $(DEFINES) -c $*.c -o $*.o

###
# Dependencies follow here

drivers/usb/spca5xx.o: drivers/usb/spca5xx.h \
drivers/usb/spcaCompat.h \
drivers/usb/spcausb.h \
drivers/usb/sonix.h \
drivers/usb/spca500_init.h \
drivers/usb/spca501_init.h \
drivers/usb/sp5xxfw2.h \
drivers/usb/spca505_init.h \
drivers/usb/spca506.h \
drivers/usb/spca508_init.h \
drivers/usb/spca561.h \
drivers/usb/zc3xx.h\
drivers/usb/tv8532.h\
drivers/usb/cx11646.h\
drivers/usb/mr97311.h\
drivers/usb/sn9cxxx.h\
drivers/usb/pac207.h\

drivers/usb/spcadecoder.o: drivers/usb/spcadecoder.h \
drivers/usb/spcagamma.h \

endif # End kernel version test

##############################################################################
# OTHER TARGETS
##############################################################################
clean:
rm -r -f drivers/usb/*.o drivers/usb/.spcadecoder.o.cmd \
drivers/usb/.spca5xx.o.cmd *.o *.ko *.mod.* .[a-z]* core *.i

##############################################################################

关于修正Makefile文件做几点阐明:1Makefile文件针对不同内核回编译成不同的方针文件,该Makefile前部分是针对2.6的内核,后部分针对2.4的内核,用户依据自己的内核进行修正,我修正的是2.6.9的内核,关于2.4.x是表明2.4的某个版别,仅仅一个代号,用户自己依据实践修正。2修正的东西,主要有两个,一是gcc变成arm-linux-gcc;二是内核途径,留意这是穿插编译环境的内核途径,即arm-linux的内核途径,非pc上linux体系的内核。3 在Makefile文件修正之后,假如你的arm-linux从未编译,需求先编译内核,然后在make。MODULE_INSTALLDIR 这个是你编译生成的模块放在哪个途径,能够不必改,当然为了便利,最好改成你想要的文件夹下,文件夹权限要改成可读写的。

第三步: make

编译成功后,会在模块MODULE_INSTALLDIR 途径生成spca5xx.ko,spca5xx.o等方针文件。

第四步:将你的方针文件spca5xx.ko(2.6内核)或许spca5xx.o(2.4内核)挂载到arm开发板上

第五步:在开发板上进入挂载的文件夹下 insmod spca5xx.ko

第六步: 插上摄像头,测验摄像头

不出意外情况下,在/dev/下会有video0设备符,或许是/dev/v4l/video0

第七步: cat /dev/video0 > a.jpg 看看是否有文件a.jpg

按 ctrl+C 退出,将a.jpg拷贝到pc linux下经过gqview软件进行检查,也能够编一个图画收集小程序,抓取一帧保存成文件,然后到pclinux下进行检查。gqview软件下得费事,我是写了个小程序,将jpg文件保存下来,到pc linux

下直接看的,很便利。

当然,也有意外,摄像头驱动加载之后,不能运用摄像头,下一篇文章将会介绍一个特殊情况。我也是被这个问题卡了一两天,问了一个技能达人才处理的。前面进程网上许多,我是将进程再细化一些,供初学者参阅,共同进步。

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/news/guandian/274490.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部