使用linux分布编译,Linux UVC driver 交叉编译

官网介绍如下:

Typical usage is:

git clone git://linuxtv.org/media_build.git

cd media_build

./build

make install

这个是针对你当前运行的linux环境的编译。下面介绍下如何针对指定的内核版本进行交叉编译。

1 下载项目源码:

git clone git://linuxtv.org/media_build.git

cd media_build

anzyelay@ubuntu:media_build$ ls devel_scripts/

analyze_build.pl gen_rename_patch.pl README rename_patch.sh

anzyelay@ubuntu:media_build$ ls linux/

Makefile patches_for_kernel.pl use_dir.pl version_patch.pl

anzyelay@ubuntu:media_build$ ls v4l/

compat.h Kconfig.misc Kconfig.sound Makefile Makefile.mm obsolete.txt versions.txt

firmware Kconfig.mm Kconfig.staging Makefile.kernel Makefile.sound scripts

2 指定内核版本或内核源码目录:

在此之前需要在你指定的内核源码中设置好交叉环境编译执行一次,然后再执行make modules_prepare生成Module.symvers文件,为外部模块编译做好准备工作,然后后面才能正常编译

方法1 :

make release DIR=内核源码目录

执行结果如下 anzyelay@ubuntu:media_build$ make release DIR=/home/anzyelay/Desktop/arm/linux-3.6.6-gcc.4.9.4 make -C /home/anzyelay/Desktop/media_build/v4l release

make[1]: Entering directory `/home/anzyelay/Desktop/media_build/v4l'

Searching in /home/anzyelay/Desktop/arm/linux-3.6.6-gcc.4.9.4/Makefile for kernel version.

Forcing compiling to version 3.6.6

make[1]: Leaving directory `/home/anzyelay/Desktop/media_build/v4l'

方法2 :

make release VER=版本号(如:3.5.0-54-generic)

但这方法要先做好/lib/modules/3.5.0-54-generic/build的指向。

具体做法:内核源码同样编译执行好,也要make modules_prepare,然后将源码连接到此目录:

ln -s /path/to/kerne-src /lib/modules/3.5.0-54-generic/build

如果你直接在编译内核源码后make modules_install了,那就不需要了手动ln了,它会自动完成上述操作。

3 下载驱动并编译

3.1 使用默认自动执行

./build

这个脚本执行了包括:检查下载最新UVC驱动,检测指定内核所需要的backport补丁(我直接理解成逆向补丁),编译

3.2 手动分布执行

下载uvc驱动:

下载地址

打补丁编译 make -jN

4 配置

如需要也可适当配置需要功能,在配置之前还需要先执行一次编译,不然linux/Kconfig文件不全,将最新的linux-media.tar.bz2源码下载解压出来并打上补丁,直接执行一次./build,让它自行完成吧,不然就手动make download /make apply_patches

make menuconfig

这里项目代码打补丁后在v4l/Kconfig里有个小错误要解决,见下面的error1

注:似乎在media_build目录下做menuconfig配置,有时不起作用,要在你指定的内核源码处修改配置才能起到作用,我重新来了一遍,把内核里的Multimedia support选项关了,在media_build的配置中选上了一样不编译,真奇怪。

只能说内核里的配置选项会影响到譔项目本身的配置。

4 安装

make install

安装时的INSTALL_MOD_PATH我试过没用。它就是默认安装在/lib/modules/kernel-version/下的。不知道如何去改变安装位置.

anzyelay@ubuntu:media_build$ ls /lib/modules/3.6.6/

kernel modules.dep modules.inputmap modules.seriomap modules.usbmap

modules.alias modules.dep.bin modules.isapnpmap modules.softdep

modules.alias.bin modules.devname modules.ofmap modules.symbols

modules.ccwmap modules.ieee1394map modules.pcimap modules.symbols.bin

详情可以make help查看

5 项目文件media_build几点说明

anzyelay@ubuntu:media_build$ ls

backports COPYING dvb-firmwares.tar.bz2 linux modules.order README v4l

build devel_scripts INSTALL Makefile Module.symvers README.patches

v4l:编译出来的文件都在此目录下,

linux:下载和解压出的驱动源代码目录,原文件仅有makefile,和三个脚本文件

patches_for_kernel.pl检测当前内核所需要的补丁文件,(其实就是读取Backport.txt,只要kernel version

backports:回溯补丁文件夹,简言之就是下载的uvc驱动源码是最新的内核函数,要倒回适应旧版本的源码就需要打反补丁了,

#

6 error

1 make menuconfig时出现 :./Kconfig:n: unknown option “xxx”

具体如下: ./Kconfig:519: syntax error

./Kconfig:518: unknown option "Say"

./Kconfig:519: unknown option "To"

./Kconfig:520: unknown option "called"

./Kconfig:523: syntax error

./Kconfig:522:warning: multi-line strings not supported

./Kconfig:522: unknown option "If"

make[1]: *** [menuconfig] Error 1

make[1]: Leaving directory `/home/anzyelay/Desktop/media_build/v4l'

make: *** [menuconfig] Error 2

这个是./v4l/kconfig这个文件的第518行有点格式问题 508 # IR_HIX5HD2 disabled for insufficient kernel version

509 config IR_HIX5HD2

510 tristate "Hisilicon hix5hd2 IR remote control"

511 depends on RC_CORE

512 default n

513 depends on VIDEO_KERNEL_VERSION

514 ---help---

515 WARNING! This driver needs at least kernel 3.10.0! It may not

516 compile or work correctly on your kernel, which is too old.

517

518 Say Y here if you want to use hisilicon hix5hd2 remote control.

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

520 called ir-hix5hd2.

521

522 If you're not sure, select N here

523

修改下就好了

2 make install 时出现strip: Unable to recognise the format of the input file xxx

具体如下: strip: Unable to recognise the format of the input file `/lib/modules/3.6.6/kernel/drivers/media//cec-edid.ko'

strip: Unable to recognise the format of the input file `/lib/modules/3.6.6/kernel/drivers/media//media.ko'

这个是strip要用arm-linux-strip才行。它这里默认是用的Pc版的,所以无法安装,我找了N久也没找到此控制命令的环境变量,不知道如何处理了,我用了最笨的法子,直接暂时把strip的连接指向arm-linux-strip版,安装完好再恢复回来。

3 frame_vector: module license ‘unspecified’ taints kernel.

frame_vector 缺少 MODULE_LICENSE(“GPL”)申明

在frame_vector.c文件中加入即可MODULE_LICENSE(“GPL”);

4 Unknown symbol xxx

在插入摄像头自动加载驱动时出现如下错误: videobuf2_vmalloc: Unknown symbol dma_buf_vmap (err 0)

videobuf2_vmalloc: Unknown symbol dma_buf_export_named (err 0)

videobuf2_vmalloc: Unknown symbol dma_buf_vunmap (err 0)

上网查知如下说明:

如果模块在编译过程中出现没有定义的变量(编译过程中显示*.*undefined!)警告时, 这样编译出来的ko在最后插入时候将报以下错误(unknown symbol,can’t insert)

回到项目中再次make时确实出现这些警告。 WARNING:"dma_buf_vunmap" [/home/anzyelay/Desktop/media_build/v4l/videobuf2-vmalloc.ko] undefined! WARNING: "dma_buf_export_named" [/home/anzyelay/Desktop/media_build/v4l/videobuf2-vmalloc.ko] undefined! WARNING: "dma_buf_vmap" [/home/anzyelay/Desktop/media_build/v4l/videobuf2-vmalloc.ko] undefined!

WARNING:"dma_buf_fd" [/home/anzyelay/Desktop/media_build/v4l/videobuf2-core.ko] undefined! WARNING: "dma_buf_put" [/home/anzyelay/Desktop/media_build/v4l/videobuf2-core.ko] undefined!

WARNING:"dma_buf_get" [/home/anzyelay/Desktop/media_build/v4l/videobuf2-core.ko] undefined!

搜索 dma_buf_vunmap发现如下 ./backports/v3.1_no_dma_buf_h.patch: void *dma_buf_vmap(struct dma_buf *);

./backports/v3.1_no_dma_buf_h.patch:+static inline void *dma_buf_vmap(struct dma_buf *dmabuf)

前面说过backports是补丁存放文件夹,既然有补丁,那会不会是没打上补丁呢?到看看补丁文件发现是a/include/linux/dma-buf.h文件,直接打开./linux/include/linux/dma-buf.h看了下果然是没有打上补丁,那就手动打吧 cd linux

patch -p1 < ../backports/v3.1_no_dma_buf_h.patch

再次make,警告消失

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值