新闻中心

EEPW首页>嵌入式系统>设计应用> Arm-Linux摄像头驱动程序的移植

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

作者: 时间:2016-11-11 来源:网络 收藏
Arm开发板上摄像头的移植有两种方法:第一,将驱动程序添加到内核,通过编译内核,烧写到板子上;第二种,通过动态加载摄像头驱动模块的方法进行硬件的驱动。作者首先在PC的linux系统进行摄像驱动程序的移植,保证驱动程序版本正确,然后将驱动程序编译成模块,通过文件系统挂载到板子,然后进行加载,进而创建摄像头设备节点。下面将具体介绍摄像头动态加载的过程。

移植过程所使用的摄像头型号ZC301P,arm板上的内核版本为2.6.9,开发板为pxa270,所采用的驱动程序包为spca5xx-20060501.tar.gz。

本文引用地址://m.amcfsurvey.com/article/201611/316654.htm

第一步,使用命令解压文件: 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 enabledfor 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

下直接看的,很方便。

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



关键词:Arm-Linux摄像头驱

评论


相关推荐

技术专区

关闭