DragonBoard 410C移植支持OpenGL的Qt环境教程

首先介绍一下我的开发环境:

物理机:windows 10 64位;
虚拟器:Virtualbox 5.20;
虚拟机:Ubuntu 16.04 64位;
开发板:DragonBoard 410C 【内核 4.9.34-linaro-lt-qcom】

[Host PC] = 表示在自己主机的Ubuntu系统中操作
[DragonBoard] = 表示在DragonBoard 410c开发板上操作

配置DragonBoard 410c开发板

第1步:更新到最新的软件包。

需要灵活地将 “4.9.34” 替换为你自己410c的内核版本。
sudo apt-mark hold linux-image-4.9.34-linaro-lt-qcom
sudo apt-get update -y
sudo apt-get upgrade -y
sudo apt-get dist-upgrade -y

第2步:安装QT相关的依赖
sudo apt-get build-dep -y qt4-x11
sudo apt-get build-dep -y libqt5gui5
sudo apt-get install -y libudev-dev libinput-dev libts-dev libxcb-xinerama0-dev libxcb-xinerama0
sudo mkdir /usr/local/qt5dragon
sudo chown linaro:linaro /usr/local/qt5dragon

说明:libts-dev没找到;第一次build-dep -y libqt5gui5 没成功,原因是要安装的Gstreamer相关库版本跟当前系统已安装的版本有冲突。我apt-get remove --purge gstreamer*后解决,然后再sudo apt-get build-dep -y libqt5gui5 即OK。

配置Host PC

第1步:[Host PC]创建工作路径
在自己Ubuntu的home路径下创建 "linaro"路径
mkdir linaro
cd linaro

第2步:[Host PC]建立 sysroot,存放410c板子上的一系列文件
[Host PC]在linaro路径下建立sysroot目录,然后从DragonBoard 410c里提取 /lib 、/usr路径下的文件到Host PC . 需灵活替换DragonBoard’s IP address.

mkdir sysroot sysroot/usr
rsync -avz [email protected]:/lib sysroot
rsync -avz [email protected]:/usr/include sysroot/usr
rsync -avz [email protected]:/usr/lib sysroot/usr

补充:debian下查询ip地址方式如下:
nmcli con show
nmcli dev show “DEVICE-Name”

第3步:[Host PC]建立 Sysroot的symlinks,使 sysroot 中的符号链接是相对的。通过下面链接中的脚本配置:

chmod +x sysroot-relativelinks.py
sudo ./sysroot-relativelinks.py sysroot

第4步:[Host PC]下载交叉编译工具链

wget https://releases.linaro.org/components/toolchain/binaries/latest/aarch64-linux-gnu/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz
tar -xf gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz

第5步:[Host PC]下载你想用的QT源码,并配置模块【我下载的是qt-everywhere-opensource-src-5.7.0.tar.xz】
git clone https://code.qt.io/qt/qt5.git
cd qt5
./init-repository -f --module-subset=default,-qtwebkit,-qtwebkit-examples,-qtwebengine

第6步:[Host PC]自定义 mkspec
Qt 使用设备 "mkspecs " 配置 qmake 到自己的硬件。DragonBoard 没有内置的 mkspec, 所以我们必须自己做。mkspec 定义了要使用的编译器, 在哪里可以找到 OpenGL 和 EGL 图形库等。
下面我提供了一个 mkspec实例,做了与 DragonBoard相关 的工作。首先,在qt-everywhere-opensource-src-5.7.0/qtbase/mkspecs/路径下创建linux-dragonboard:
mkdir linux-dragonboard/
cd linux-dragonboard

在"linux-dragonboard" 路径下创建 “qmake.conf” :
nano qmake.conf

在qmake.conf中填充如下内容:
# qmake configuration for the Dragonboard 410C
MAKEFILE_GENERATOR = UNIX
CONFIG += incremental
QMAKE_INCREMENTAL_STYLE = sublib
include(…/common/linux_device_pre.conf)
SYSROOT = /home/eric/SelfCompile/linaro/sysroot #需替换为自己前面创建的sysroot路径
LIB_PATH = SYSROOT/usr/lib/aarch64linuxgnuQMAKELFLAGS+=fuseld=goldQMAKELFLAGS+=Wl,rpathlink,{SYSROOT}/usr/lib/aarch64-linux-gnu QMAKE_LFLAGS+=-fuse-ld=gold QMAKE_LFLAGS += -Wl,-rpath-link,{SYSROOT}/usr/lib/aarch64-linux-gnu
QMAKE_LFLAGS += -Wl,-rpath-link,SYSROOT/usr/libQMAKELFLAGS+=Wl,rpathlink,{SYSROOT}/usr/lib QMAKE_LFLAGS += -Wl,-rpath-link,{SYSROOT}/lib/aarch64-linux-gnu
QMAKE_LIBDIR_EGL = LIBPATHQMAKELIBDIROPENVG={LIB_PATH} QMAKE_LIBDIR_OPENVG = {LIB_PATH}
QMAKE_INCDIR_OPENGL = SYSROOT/usr/include/GLES2QMAKELIBDIROPENGL={SYSROOT}/usr/include/GLES2 QMAKE_LIBDIR_OPENGL = {LIB_PATH}
QMAKE_INCDIR_EGL = $${SYSROOT}/usr/include/EGL
QMAKE_LIBS_EGL = -lEGL -lGLESv2
include(…/common/linux_device_post.conf)
load(qt_config)

DragonBoard 410C移植支持OpenGL的Qt环境教程

在 "linux-dragonboard"路径下创建"qplatformdefs.h"并填充如下内容:
nano qplatformdefs.h

/****************************************************************************
**
** Copyright © 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the qmake spec of the Qt Toolkit.
**
** QTBEGINLICENSE:LGPLQT_BEGIN_LICENSE:LGPL
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** QTENDLICENSEQT_END_LICENSE
**
****************************************************************************/

#include “…/…/linux-g++/qplatformdefs.h”

第7步:拷贝创建的linux-dragonboard目录到"/qt-everywhere-opensource-src-5.7.0/qtbase/mkspecs/devices"路径下
cp -r linux-dragonboard/ qt-everywhere-opensource-src-5.7.0/qtbase/mkspecs/devices/

Build Qt
第1步:[Host PC]在"linaro" 路径下创建build目录。此目录方便编译失败时重新编译。
mkdir qt5-build
cd qt5-build

第2步:配置编译选项,然后运行配置脚本。
运行的脚本内容如下:
/home/eric/SelfCompile/QtSrcCode/qt-everywhere-opensource-src-5.7.0/configure -release -opengl es2 -device linux-dragonboard
-device-option CROSS_COMPILE=/home/eric/Tools/CrossCompileTool/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-
-sysroot /home/eric/SelfCompile/linaro/sysroot -opensource
-confirm-license -make libs -prefix /usr/local/qt570dragon
-extprefix /home/eric/SelfCompile/linaro/qt570dragon
-hostprefix /home/eric/SelfCompile/linaro/qt5-qmake -v -nomake examples -nomake tests

第3步:编译&安装
make -j4
make install

如果遇到编译中出错误, 则可以删除 “qt5-build” 目录中的所有内容并重试。确保路径正确无误, 这将是最常见的一个错误。