<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應用 > Arm-Linux攝像頭驅(qū)動程序的移植

          Arm-Linux攝像頭驅(qū)動程序的移植

          作者: 時間:2016-11-11 來源:網(wǎng)絡(luò) 收藏
          Arm開發(fā)板上攝像頭的移植有兩種方法:第一,將驅(qū)動程序添加到內(nèi)核,通過編譯內(nèi)核,燒寫到板子上;第二種,通過動態(tài)加載攝像頭驅(qū)動模塊的方法進行硬件的驅(qū)動。作者首先在PC的linux系統(tǒng)進行攝像驅(qū)動程序的移植,保證驅(qū)動程序版本正確,然后將驅(qū)動程序編譯成模塊,通過文件系統(tǒng)掛載到板子,然后進行加載,進而創(chuàng)建攝像頭設(shè)備節(jié)點。下面將具體介紹攝像頭動態(tài)加載的過程。

          移植過程所使用的攝像頭型號ZC301P,arm板上的內(nèi)核版本為2.6.9,開發(fā)板為pxa270,所采用的驅(qū)動程序包為spca5xx-20060501.tar.gz。

          本文引用地址:http://www.ex-cimer.com/article/201611/316654.htm

          第一步,使用命令解壓文件: tar zxvf spca5xx-20060501.tar.gz

          進入spca5xx-20060501 : cd spca5xx-20060501

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

          Makefile的內(nèi)容如下,注釋掉的為藍色,紅色表示修改過的內(nèi)容:

          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

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

          關(guān)于修改Makefile文件做幾點說明:1Makefile文件針對不同內(nèi)核回編譯成不同的目標文件,該Makefile前部分是針對2.6的內(nèi)核,后部分針對2.4的內(nèi)核,用戶根據(jù)自己的內(nèi)核進行修改,我修改的是2.6.9的內(nèi)核,關(guān)于2.4.x是表示2.4的某個版本,只是一個代號,用戶自己根據(jù)實際修改。2修改的東西,主要有兩個,一是gcc變成arm-linux-gcc;二是內(nèi)核路徑,注意這是交叉編譯環(huán)境的內(nèi)核路徑,即arm-linux的內(nèi)核路徑,非pc上linux系統(tǒng)的內(nèi)核。3 在Makefile文件修改之后,如果你的arm-linux從未編譯,需要先編譯內(nèi)核,然后在make。MODULE_INSTALLDIR 這個是你編譯生成的模塊放在哪個路徑,可以不用改,當然為了方便,最好改成你想要的文件夾下,文件夾權(quán)限要改成可讀寫的。

          第三步: make

          編譯成功后,會在模塊MODULE_INSTALLDIR 路徑生成spca5xx.ko,spca5xx.o等目標文件。

          第四步:將你的目標文件spca5xx.ko(2.6內(nèi)核)或者spca5xx.o(2.4內(nèi)核)掛載到arm開發(fā)板上

          第五步:在開發(fā)板上進入掛載的文件夾下 insmod spca5xx.ko

          第六步: 插上攝像頭,測試攝像頭

          不出意外情況下,在/dev/下會有video0設(shè)備符,或者是/dev/v4l/video0

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

          按 ctrl+C 退出,將a.jpg拷貝到pc linux下通過gqview軟件進行查看,也可以編一個圖像采集小程序,抓取一幀保存成文件,然后到pclinux下進行查看。gqview軟件下得麻煩,我是寫了個小程序,將jpg文件保存下來,到pc linux

          下直接看的,很方便。

          當然,也有意外,攝像頭驅(qū)動加載之后,不能使用攝像頭,下一篇文章將會介紹一個特殊情況。我也是被這個問題卡了一兩天,問了一個技術(shù)達人才解決的。前面過程網(wǎng)上很多,我是將過程再細化一些,供初學者參考,共同進步。



          關(guān)鍵詞: Arm-Linux攝像頭驅(qū)

          評論


          相關(guān)推薦

          技術(shù)專區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();