使用飞凌嵌入式IMX6UL-C1板子——qt+opencv环境搭建

使用飞凌嵌入式IMX6UL-C1板子——qt+opencv环境搭建

准备工作:

  • Ubuntu18.04虚拟机环境
  • 飞凌官方提供的qt-tslib库,gcc交叉编译器,opencv源码库,qt源码,具体如下:
    在这里插入图片描述
安装交叉编译器
  • 方便环境编译,将交叉编译器安装到/usr/local/下新建一个文件目录arm-imx6ul。
sudo mkdir /usr/local/arm-imx6ul
cd /usr/local/arm-imx6ul
sudo cp ~/feiling/gcc-4.6.2-glibc-2.13-linao-multilib-2011.12.tar.gz .
sudo tar -xvf gcc-4.6.2-glibc-2.13-linao-multilib-2011.12.tar.gz
#加入环境变量
sudo vi /etc/environment
#	添加环境编译
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/local/arm-imx6ul/gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12/fsl-linaro-toolchain/bin/:/opt/mips64el-buildroot-linux-gnu_sdk-buildroot/bin"

source /etc/environment
  • 解压完即完成了交叉编译器的安装。
安装qt SDK

执行以下命令

cd /files/
mkdir /usr/local/freescale
cp QT4.8.6-SDK.tar.bz2 /usr/local/freescale/
cd /usr/local/freescale/
tar jxvf QT4.8.6-SDK.tar.bz2

注意此步完成后/usr/local 下会有/freescale/QT4.8.6 文件夹,文件名必须与此保持一致,不能改动

安装tslib
cd /files/
cp tslib-sdk.tar.bz2 /usr/local/arm-imx6ul
cd /usr/local/arm-imx6ul
tar jxvf tslib-sdk.tar.bz2
安装qt creator
  • 由于我是之前已经安装过高版本的qt creator,所以不再需要安装飞凌提供的qt creator。不过在这可以给出安装步骤。
  • 下载链接:
  • http://download.qt.io/official_releases/qtcreator/
    执行以下命令:
cd /files/
chmod 777 qt-creator-linux-x86-opensource-2.6.2.bin
./qt-creator-linux-x86-opensource-2.6.2.bin

# 点击“Finish”完成。
#	执行以下命令打开 Qt Creator:
cd /opt/qtcreator-2.6.2/bin/
./qtcreator &

qt开发环境配置

  • 打开qt creator ,选择Tools ->Options->Build & Run->Compilers,添加前一步安装好的qt-sdk路径及编译器路径。如下图:
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

  • 此时,发现报错
    在这里插入图片描述

qt version is not properly installed,错误修复
  • 该错误发现是qmake的版本不匹配目前使用的机器或者Ubuntu18.04的版本太高了。
    在这里插入图片描述
  • 所以决定使用qt源代码编译一版飞凌下使用的qtSDK环境。
使用源码编译qt-SDK
#	解压源码
tar -xvf qt-everywhere-src-4.8.6.tar.gz
cd qt-everywhere-src-4.8.6/mkspecs
cp ~/feiling/linux-imx6ul-g++ . -rf

#	修改linux-imx6ul-g++/qmake.conf
#
# qmake configuration for building with arm-none-linux-gnueabi-g++
#

export CROSS_COMPILE=/usr/local/arm-imx6ul/gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12/fsl-linaro-toolchain/bin/arm-fsl-linux-gnueabi-
#export ROOTFS=/dv/nfs/bt

include(../../common/linux.conf)
include(../../common/gcc-base-unix.conf)
include(../../common/g++-unix.conf)
include(../../common/qws.conf)

# modifications to g++.conf
QMAKE_CC                = arm-fsl-linux-gnueabi-gcc -lts
QMAKE_CXX               = arm-fsl-linux-gnueabi-g++ -lts
QMAKE_LINK              = arm-fsl-linux-gnueabi-g++ -lts
QMAKE_LINK_SHLIB        = arm-fsl-linux-gnueabi-g++ -lts
QMAKE_LFLAGS			+= -W1,rpath=/work/imx6/rootfs/usr/lib

# modifications to linux.conf
QMAKE_AR                = arm-fsl-linux-gnueabi-ar cqs
QMAKE_OBJCOPY           = arm-fsl-linux-gnueabi-objcopy
QMAKE_STRIP             = arm-fsl-linux-gnueabi-strip

#QMAKE_INCDIR                = /work/imx6/rootfs/usr/include
#QMAKE_INCDIR               +=/work/imx6/rootfs/usr/include/arm-linux-gnueabi/
QMAKE_INCDIR                +=/usr/local/arm-imx6ul/tslib/include
QMAKE_LIBDIR                +=/usr/local/arm-imx6ul/tslib/lib
#QMAKE_INCDIR_OPENGL         = /work/imx6/rootfs/usr/include/GL
#QMAKE_LIBDIR_OPENGL         = /work/imx6/rootfs/usr/lib
#QMAKE_INCDIR_OPENGL_ES1     = /usr/include/GLES
#QMAKE_LIBDIR_OPENGL_ES1     = /tftpboot/rootfs/usr/lib
#QMAKE_INCDIR_OPENGL_ES1CL   = /tftpboot/rootfs/usr/include/GLES
#QMAKE_LIBDIR_OPENGL_ES1CL   = /tftpboot/rootfs/usr/lib
#QMAKE_INCDIR_OPENGL_ES2     = /work/imx6/rootfs/usr/include/GLES2
#QMAKE_LIBDIR_OPENGL_ES2     = /work/imx6/rootfs/usr/lib
#QMAKE_INCDIR_EGL            = /work/imx6/rootfs/usr/include/EGL
#QMAKE_LIBDIR_EGL            = /work/imx6/rootfs/usr/lib
#QMAKE_LIBDIR_GAL            = /work/imx6/rootfs/usr/lib
#QMAKE_INCDIR_GAL            = /work/imx6/rootfs/usr/include/

QMAKE_LIBS_OPENGL_ES1       += -lGLESv1_CM -lEGL -lGAL
QMAKE_LIBS_OPENGL_ES1CL     += -lGLES_CL -lEGL -lGAL
#QMAKE_LIBS_EGL              += -lEGL
QMAKE_LIBS_EGL              += -lEGL -lGAL
QMAKE_LIBS_OPENGL_ES2       += -lGLESv2 -lEGL -lGAL
QMAKE_LIBS_OPENVG           += -lOpenVG -lEGL -lGAL

IMX6_CFLAGS             = -march=armv7-a -mfpu=neon -DLINUX=1 -DEGL_API_FB=1
IMX6_CFLAGS_RELEASE     = -O2 $$IMX6_CFLAGS
QMAKE_CFLAGS_RELEASE   += $$IMX6_CFLAGS_RELEASE
QMAKE_CXXFLAGS_RELEASE += $$IMX6_CFLAGS_RELEASE
QMAKE_CFLAGS_DEBUG     += $$IMX6_CFLAGS
QMAKE_CXXFLAGS_DEBUG   += $$IMX6_CFLAGS

load(qt_config)

  • 后发现不能使用这个linux-imx6ul-g++的配置,需要使用qws/linux-arm-g++的配置进行configure配置,而使用的configure的配置如下:
#!/bin/sh

./configure \
 -prefix /opt/QT4.8.6 \
 -opensource \
 -confirm-license \
 -release -shared \
 -embedded arm \
 -xplatform qws/linux-arm-g++ \
 -depths 16,18,24,32 \
 -fast \
 -optimized-qmake \
 -little-endian -host-little-endian \
 -pch \
 -qt-sql-sqlite \
 -qt-libjpeg \
 -qt-zlib \
 -qt-libpng \
 -qt-libmng \
 -qt-libtiff \
 -qt-freetype \
 -webkit \
 -multimedia \
 -audio-backend \
 -phonon-backend \
 -no-openssl \
 -no-glib \
 -no-qt3support \
 -no-libtiff -no-libmng \
 -no-opengl \
 -no-mmx -no-sse -no-sse2 \
 -no-3dnow \
 -no-qvfb \
 -phonon-backend \
 -no-nis \
 -no-opengl \
 -no-cups \
 -no-separate-debug-info \
 -nomake docs \
 -qt-mouse-tslib \
 -qt-mouse-linuxinput \
 -qt-kbd-linuxinput \
 -qt-gfx-transformed \
 -qt-gfx-linuxfb \
 -I/usr/local/arm-imx6ul/tslib/include \
 -L/usr/local/arm-imx6ul/tslib/lib

  • 执行后提示:
    在这里插入图片描述
  • 以上报错
You have not explicitly asked to use pkg-config and are cross-compiling.
pkg-config will not be used to automatically query cflag/lib parameters for
dependencies
  • 添加配置选项 -force-pkg-config
  • 测试之后还是报错,判断应该是tslib库不匹配的原因,考虑到后期不需要触摸功能,所以去掉-qt-mouse-tslib配置选项,重新配置编译:
    在这里插入图片描述
    此时成功:
  • 参考autoconfig.sh的内容如下:
#!/bin/sh

./configure \
 -force-pkg-config \
 -prefix /opt/QT4.8.6 \
 -opensource \
 -confirm-license \
 -release -shared \
 -embedded arm \
 -xplatform qws/linux-arm-g++ \
 -depths 16,18,24,32 \
 -fast \
 -optimized-qmake \
 -little-endian -host-little-endian \
 -pch \
 -qt-sql-sqlite \
 -qt-libjpeg \
 -qt-zlib \
 -qt-libpng \
 -qt-libmng \
 -qt-libtiff \
 -qt-freetype \
 -webkit \
 -multimedia \
 -audio-backend \
 -phonon-backend \
 -no-openssl \
 -no-glib \
 -no-qt3support \
 -no-libtiff -no-libmng \
 -no-opengl \
 -no-mmx -no-sse -no-sse2 \
 -no-3dnow \
 -no-qvfb \
 -phonon-backend \
 -no-nis \
 -no-opengl \
 -no-cups \
 -no-separate-debug-info \
 -nomake docs \
 -qt-mouse-linuxinput \
 -qt-kbd-linuxinput \
 -qt-gfx-transformed \
 -qt-gfx-linuxfb \
# -I/usr/local/arm-imx6ul/tslib/include \
# -L/usr/local/arm-imx6ul/tslib/lib

 #-nomake examples -nomake tools -nomake docs \
 #-no-xcursor -no-xfixes -no-xrandr -no-xrender \
#
# -qt-mouse-tslib \
#make -j8
#
#make install -j8
#exit
  • 执行make 编译:
  • 报错
    在这里插入图片描述
  • 该报错为qmake路径不对,进入Makefile修改qmake路径:
cd src/tools/bootstrap/Makefile
QMAKE         = /home/ww/feiling/qt-source/qt-everywhere-opensource-src-4.8.6/bin/qmake
sudo make
  • 进行make编译。
  • 继续报错:
    在这里插入图片描述
  • 依然还是老毛病,发现所有的Makefile都是这个问题,所以现在清除所有Makefile进行重新配置编译。
find ./ -name Makefile -delete
sudo ./autoconfigure.sh

在这里插入图片描述

  • 进行make编译,等待。

【报错】提示缺少libz.so.1的动态库:
在这里插入图片描述
【重新添加libz.so.1的系统依赖动态库后再次报错】
在这里插入图片描述

  • 修改:vim src/corelib/Makefile 加上-lrt
LIBS          = $(SUBLIBS)  -L/opt/qt-everywhere-opensource-src-4.8.4/lib -lpthread -lm -ldl -lrt
  • 继续编译

【报错】error: ‘QSharedMemory’ does not name a type

  • 尝试清理重新编译:
make confclean
./autoconfigure.sh
make

【编译成功】

  • make install
  • 在安装目录下生成编译成功后的qmake
    在这里插入图片描述
  • 继续前一步,在qt creator上添加新编译产生的qmake:
    在这里插入图片描述

opencv交叉编译:

  • 下载opencv源码
  • 安装编译依赖库 cmake 、cmake-qt-gui
sudo apt-get install cmake
sudo apt-get install cmake-qt-gui
cd /home/ww/feiling/opencv/opencv-2.4.13.6
sudo cmake-gui

在这里插入图片描述

  • 设定好其中的源码路径,生成的编译库路径,选择交叉编译器的环境等等,然后进入刚刚选择好的编译路径下;
  • 进入编译路径下:make
  • 等待出错:
【出错】

错误1: 没有链接到 pthread 库

../../lib/libopencv_core.so: undefined reference to `pthread_mutexattr_destroy'
../../lib/libopencv_core.so: undefined reference to `pthread_create'
../../lib/libopencv_core.so: undefined reference to `dlopen'
../../lib/libopencv_core.so: undefined reference to `pthread_mutex_trylock'
../../lib/libopencv_core.so: undefined reference to `clock_gettime'
../../lib/libopencv_core.so: undefined reference to `dlsym'
../../lib/libopencv_core.so: undefined reference to `pthread_mutexattr_settype'
../../lib/libopencv_core.so: undefined reference to `pthread_join'
../../lib/libopencv_core.so: undefined reference to `pthread_mutexattr_init'
collect2: ld returned 1 exit status
make[2]: *** [bin/opencv_perf_core] 错误 1
make[1]: *** [modules/core/CMakeFiles/opencv_perf_core.dir/all] 错误 2
make: *** [all] 错误 2
  • 解决1:

修改编译目录下的 CMakeCache.txt 文件:

找到 CMAKE_EE_LINKER_FLAGS:STRING 项:

 190 //Flags used by the linker.
 191 CMAKE_EXE_LINKER_FLAGS:STRING=' '

修改成以下:

 190 //Flags used by the linker.
 191 CMAKE_EXE_LINKER_FLAGS:STRING= -pthread -lrt

修改完成,继续 make

等待出错…

  • 错误2: 没有链接到 dl 库
[ 49%] Built target opencv_ts
Linking CXX executable ../../bin/opencv_perf_core
../../lib/libopencv_core.so: undefined reference to `dlopen'
../../lib/libopencv_core.so: undefined reference to `dlsym'
collect2: ld returned 1 exit status
make[2]: *** [bin/opencv_perf_core] 错误 1
make[1]: *** [modules/core/CMakeFiles/opencv_perf_core.dir/all] 错误 2
make: *** [all] 错误 2
  • 解决2:
    同样是 CMAKE_EE_LINKER_FLAGS:STRING ,继续添加 -ldl
 190 //Flags used by the linker.
 191 CMAKE_EXE_LINKER_FLAGS:STRING= -pthread -lrt -ldl

再make…

  • 错误3:
    用arm-2009q3(4.4.1)编译工具链编译时,还会出现以下错误(4.6.3无此报错)
/root/library/opencv/opencv-3.2.0/modules/imgproc/src/drawing.cpp:1026: error: call of overloaded 'abs(long long int&)' is ambiguous
/usr/local/arm/arm-2009q3/bin/../arm-none-linux-gnueabi/libc/usr/include/stdlib.h:720: note: candidates are: int abs(int)
  • 解决3:
    百度解决方案,将错误处的drawing.cpp文件中的 abs()函数改为 fabs()

再再make …

  • 错误4:

用arm-2009q3(4.4.1)编译工具链编译时,还会出现以下错误(4.5.1无此报错)

Linking CXX executable ../../bin/opencv_perf_core
/usr/local/arm/arm-2009q3/bin/../lib/gcc/arm-none-linux-gnueabi/4.4.1/../../../../arm-none-linux-gnueabi/bin/ld: ../../bin/opencv_perf_core: hidden symbol `__sync_fetch_and_add_4' in /usr/local/arm/arm-2009q3/bin/../lib/gcc/arm-none-linux-gnueabi/4.4.1/libgcc.a(linux-atomic.o) is referenced by DSO
/usr/local/arm/arm-2009q3/bin/../lib/gcc/arm-none-linux-gnueabi/4.4.1/../../../../arm-none-linux-gnueabi/bin/ld: final link failed: Nonrepresentable section on output
collect2: ld returned 1 exit status
make[2]: *** [bin/opencv_perf_core] 错误 1
make[1]: *** [modules/core/CMakeFiles/opencv_perf_core.dir/all] 错误 2
make: *** [all] 错误 
  • 解决4:
    无解。。。。。。暂未找到对应办法
    建议换个高版本的编译工具链吧。
    相同配置,arm-2009q3(4.4.1)比4.6.1多了几个怪怪的问题。

  • ** 编译完成,编译安装**

sudo make install

在这里插入图片描述

最后一步,重新编译飞凌板子的内核

  • 进入linux内核linux-3.14
  • 修改build.sh内容.
#!/bin/bash
export CPUS=`grep -c processor /proc/cpuinfo`
export ARCH=arm
#export CROSS_COMPILE=/opt/freescale/usr/local/gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12/fsl-linaro-toolchain/bin/arm-none-linux-gnueabi-
export CROSS_COMPILE=/usr/local/arm-imx6ul/gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12/fsl-linaro-toolchain/bin/arm-none-linux-gnueabi-
#export PATH=/opt/freescale/usr/local/gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12/fsl-linaro-toolchain/bin:$PATH
export PATH=/usr/local/arm-imx6ul/gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12/fsl-linaro-toolchain/bin/:$PATH
DEVTYPE=$1
make distclean
if [ -n "$DEVTYPE" ]; then
	if [ ${DEVTYPE} == "emmc" ]; then
		make linux_imx6ul_emmc_defconfig 
	elif [ ${DEVTYPE} == "nand" ]; then
		make linux_imx6ul_nand_defconfig
	else
		echo "not support now"
	fi;
fi;
make zImage -j${CPUS}
make dtbs -j${CPUS}
make modules -j${CPUS
  • 执行source build.sh emmc
  • 【报错】
scripts/kconfig/conf --silentoldconfig Kconfig
  CHK     include/config/kernel.release
  CHK     include/generated/uapi/linux/version.h
  CHK     include/generated/utsrelease.h
make[1]: 'include/generated/mach-types.h' is up to date.
  CALL    scripts/checksyscalls.sh
  CHK     include/generated/compile.h
  GZIP    kernel/config_data.gz
  CHK     kernel/config_data.h
  Kernel: arch/arm/boot/Image is ready
  LZO     arch/arm/boot/compressed/piggy.lzo
/bin/sh: 1: lzop: not found
/home/ww/feiling/kernel/linux-3.14.38/arch/arm/boot/compressed/Makefile:193: recipe for target 'arch/arm/boot/compressed/piggy.lzo' failed
make[2]: *** [arch/arm/boot/compressed/piggy.lzo] Error 1
/home/ww/feiling/kernel/linux-3.14.38/arch/arm/boot/Makefile:52: recipe for target 'arch/arm/boot/compressed/vmlinux' failed
make[1]: *** [arch/arm/boot/compressed/vmlinux] Error 2
/home/ww/feiling/kernel/linux-3.14.38/arch/arm/Makefile:305: recipe for target 'zImage' failed
make: *** [zImage] Error 2

  • 缺少依赖库
sudo apt-get install lzop
  • 再次make
    在这里插入图片描述
  • 至此,内核编译完成。

rootfs文件系统的搭建

  • 这里因为考虑到更好LCD屏幕的问题,为了验证LCD屏幕,先使用官方提供的rootfs文件系统进行烧写。
  • 然后通过制作SD卡进行板子烧写。

制作SD烧写卡

  • 使用官方提供的SD卡制作包
cp /update.tar.bz2 ./
cp /createSdcard.sh ./
#	插入SD卡
sudo ./createSdcard.sh

在这里插入图片描述

Copying boot partition
untar update.tar.bz2 to boot partition
sdrun/
sdrun/u-boot.imx
sdrun/zImage
sdrun/imx6ul-14x14-evk.dtb
sdrun/ramdisk.img.u
target/
target/modules.tar.bz2
target/imx6ul-14x14-evk-emmc-c-bak.dtb
target/u-boot.imx
target/imx6ul-14x14-evk-emmc-c-10.4-800x600.dtb
target/rootfs.tar.bz2
target/logo.bmp
target/zImage
target/imx6ul-14x14-evk-emmc-c-7-1024x600.dtb
target/imx6ul-14x14-evk-emmc-c-8-800x600.dtb
target/imx6ul-14x14-evk-emmc-c-10.1-1280x800.dtb
target/imx6ul-14x14-evk-emmc-c-5.6-640x480.dtb
target/imx6ul-14x14-evk-emmc-c-7-800x480.dtb
target/imx6ul-14x14-evk-emmc-c-3.5-320x240.dtb
target/imx6ul-14x14-evk-emmc-c-4.3-480x272.dtb
Buring th u-boot.imx to sdcard
129+0 records in
129+0 records out
132096 bytes (132 kB, 129 KiB) copied, 0.044627 s, 3.0 MB/s
371+0 records in
371+0 records out
379904 bytes (380 kB, 371 KiB) copied, 0.128936 s, 2.9 MB/s

Syncing....

 
Un-mount the partitions 
umount: boot: not mounted.
 
Remove created temp directories 
 
Operation Finished

  • 制作完成,将刚刚编译后的linux内核zImage及设备树.dtb更换到SD卡中。
  • 将上一节中制作好的 SD 卡插入,同时将拨码开关置于下图所示。 1 4 ON, 2 3 5 6 7 8 OFF,如下图:
    在这里插入图片描述
    则可以从 sd 卡启动系统
  • 启动CRT,进入串口查看串口debug信息:
    在这里插入图片描述
  • 烧写完成,显示:
    在这里插入图片描述
  • 将拨片调回emmc启动,1 4 5 on 其他off。
  • 重启启动,显示失败,文件系统正常。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值