Howto build Qt 5.2.1 for Xilinx Zynq.

    Update for Qt 5.3.2: http://blog.idv-tech.com/2014/10/15/building-and-configuring-qt5-tslib-and-evtest-for-arm-xilinx-zynq/.

    This is a small how-to build latest Qt 5.2.1 for Zynq and use it with PetaLinux 2013.10 projects. I'm using 64 bit Ubuntu 13.10 as a host, with Xilinx Vivado 2013.4 and ZedBoard
    'Rev. D' as a target. If this howto works for you, especially if you using it on other boards please let me know, so I can push to Qt Zynq support changes.

  1. Download and extract Qt everywhere sources to your home/Download directory:

    wget http://download.qt-project.org/official_releases/qt/5.2/5.2.1/single/qt-everywhere-opensource-src-5.2.1.tar.gz
    tar -zxvf qt-everywhere-opensource-src-5.2.1.tar.gz

  2. Qt5 don't yet support Zynq device, so we need to add it. You can download and extract prepared files(linux-arm-xilinx-zynq-g++.tar.gz) to 'qt-everywhere-opensource-src-5.2.1/qtbase/mkspecs/devices/linux-arm-xilinx-zynq-g++' folder. Or you create files yourself:
    • In a 'qt-everywhere-opensource-src-5.2.1/qtbase/mkspecs/devices' create new folder named 'linux-arm-xilinx-zynq-g++'.
    • In a 'linux-arm-xilinx-zynq-g++' create 'qmake.conf' file:
    • #
      # qmake configuration for linux-g++ using arm-xilinx-g++ compiler
      #
      
      MAKEFILE_GENERATOR      = UNIX
      CONFIG                 += incremental gdb_dwarf_index
      QMAKE_INCREMENTAL_STYLE = sublib
      
      include(../../common/linux.conf)
      include(../../common/gcc-base-unix.conf)
      include(../../common/g++-unix.conf)
      
      load(device_config)
      
      QT_QPA_DEFAULT_PLATFORM = linuxfb
      
      # modifications to g++.conf
      QMAKE_CC                = $${CROSS_COMPILE}gcc
      QMAKE_CXX               = $${CROSS_COMPILE}g++
      QMAKE_LINK              = $${QMAKE_CXX}
      QMAKE_LINK_SHLIB        = $${QMAKE_CXX}
      
      # modifications to linux.conf
      QMAKE_AR                = $${CROSS_COMPILE}ar cqs
      QMAKE_OBJCOPY           = $${CROSS_COMPILE}objcopy
      QMAKE_NM                = $${CROSS_COMPILE}nm -P
      QMAKE_STRIP             = $${CROSS_COMPILE}strip
      
      QMAKE_CFLAGS           += -I$$[QT_SYSROOT]/include -DZYNQ
      QMAKE_CXXFLAGS         += -Wno-psabi -I$$[QT_SYSROOT]/include -DZYNQ
      QMAKE_LFLAGS           += -L$$[QT_SYSROOT]/lib
      
      QMAKE_CFLAGS           += -march=armv7-a -mcpu=cortex-a9 -mtune=cortex-a9 -mfpu=neon -pipe -fomit-frame-pointer
      QMAKE_CXXFLAGS         += $$QMAKE_CFLAGS
      
      deviceSanityCheckCompiler()
      
      load(qt_config)
      
    • And also 'qplatformdefs.h' file:
    • /****************************************************************************
      **
      ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
      ** Contact: http://www.qt-project.org/legal
      **
      ** This file is part of the qmake spec of the Qt Toolkit.
      **
      ** $QT_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 Digia.  For licensing terms and
      ** conditions see http://qt.digia.com/licensing.  For further information
      ** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
      ** Foundation and appearing in the file LICENSE.LGPL included in the
      ** packaging of this file.  Please review the following information to
      ** ensure the GNU Lesser General Public License version 2.1 requirements
      ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
      **
      ** In addition, as a special exception, Digia gives you certain additional
      ** rights.  These rights are described in the Digia Qt LGPL Exception
      ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
      **
      ** GNU General Public License Usage
      ** Alternatively, this file may be used under the terms of the GNU
      ** General Public License version 3.0 as published by the Free Software
      ** Foundation and appearing in the file LICENSE.GPL included in the
      ** packaging of this file.  Please review the following information to
      ** ensure the GNU General Public License version 3.0 requirements will be
      ** met: http://www.gnu.org/copyleft/gpl.html.
      **
      **
      ** $QT_END_LICENSE$
      **
      ****************************************************************************/
      
      #include "../../linux-g++/qplatformdefs.h"
      
  3. QT_QPA_DEFAULT_PLATFORM variable set to Linux Framebuffer and if your hardware design supports something else you may want to change it. Or you can always control it thru QT_QPA_PLATFORM env. variable and leave default to simplest 'linuxfb'. You may also want to modify CFLAGS and CXXFLAGS here.
  4. Set CROSS_COMPILE variable and source Xilinx tools settings:

    export CROSS_COMPILE=arm-xilinx-linux-gnueabi-
    source /opt/Xilinx/Vivado/2013.4/settings64.sh

  5. Now we can run Qt 'configure' utility, Below, configuration from my building script. Notice I disabled OpenGL ES support since my hardware don't have it yet, but your might, so you may want to include egl support.
  6. ./configure -prefix /opt/Qt/5.2.1 \
    	-device linux-arm-xilinx-zynq-g++ \
    	-device-option CROSS_COMPILE=arm-xilinx-linux-gnueabi- \
    	-release \
    	-no-qml-debug \
    	-reduce-relocations \
    	-qt-zlib \
    	-qt-libpng \
    	-qt-libjpeg \
    	-qt-freetype \
    	-qt-harfbuzz \
    	-qt-pcre \
    	-no-xcb \
    	-qt-xkbcommon \
    	-no-opengl \
    	-no-eglfs \
    	-no-kms \
    	-confirm-license \
    	-opensource \
    	-no-icu \
    	-no-pch \
    	-verbose
    
  7. Configure will build 'qmake' first and generate 'Makefiles' for all the components. Check your output in details and verify it match your configuration. Below output in my case:
  8. Configure summary
    
    Building on:   linux-g++ (x86_64, CPU features: mmx sse sse2)
    Building for:  devices/linux-arm-xilinx-zynq-g++ (arm, CPU features: neon)
    Platform notes:
    
                - Also available for Linux: linux-kcc linux-icc linux-cxx
            
    qmake vars .......... styles += mac fusion windows DEFINES += QT_NO_MTDEV 
    DEFINES += QT_NO_LIBUDEV DEFINES += QT_NO_XCB sql-drivers =  sql-plugins =  sqlite qmake switches ......... 
    
    Build options:
      Configuration .......... accessibility audio-backend c++11 clock-gettime clock-monotonic compile_examples 
     concurrent cross_compile evdev eventfd freetype full-config getaddrinfo getifaddrs harfbuzz iconv inotify
     ipv6ifname large-config largefile linuxfb medium-config minimal-config mremap neon nis no-pkg-config pcre 
     png posix_fallocate qpa qpa reduce_exports reduce_relocations release rpath shared small-config xkbcommon-qt zlib 
      Build parts ............ libs examples
      Mode ................... release
      Using C++11 ............ yes
      Using PCH .............. no
      Target compiler supports:
        iWMMXt/Neon .......... no/yes
    
    Qt modules and options:
      Qt D-Bus ............... no
      Qt Concurrent .......... yes
      Qt GUI ................. yes
      Qt Widgets ............. yes
      JavaScriptCore JIT ..... yes (To be decided by JavaScriptCore)
      QML debugging .......... no
      Use system proxies ..... no
    
    Support enabled for:
      Accessibility .......... yes
      ALSA ................... no
      CUPS ................... no
      FontConfig ............. no
      FreeType ............... qt
      HarfBuzz ............... qt
      Iconv .................. yes
      ICU .................... no
      Image formats: 
        GIF .................. yes (plugin, using bundled copy)
        JPEG ................. yes (plugin, using bundled copy)
        PNG .................. yes (in QtGui, using bundled copy)
      Glib ................... no
      GTK theme .............. no
      Large File ............. yes
      mtdev .................. no
      Networking: 
        getaddrinfo .......... yes
        getifaddrs ........... yes
        IPv6 ifname .......... yes
        OpenSSL .............. no
      NIS .................... yes
      OpenGL ................. no
      OpenVG ................. no
      PCRE ................... yes (bundled copy)
      pkg-config ............. no 
      PulseAudio ............. no
      QPA backends: 
        DirectFB ............. no
        EGLFS ................ no
        KMS .................. no
        LinuxFB .............. yes
        XCB .................. no
      Session management ..... yes
      SQL drivers: 
        DB2 .................. no
        InterBase ............ no
        MySQL ................ no
        OCI .................. no
        ODBC ................. no
        PostgreSQL ........... no
        SQLite 2 ............. no
        SQLite ............... yes (plugin, using bundled copy)
        TDS .................. no
      udev ................... no
      xkbcommon .............. yes (bundled copy)
      zlib ................... yes (bundled copy)
    
    NOTE: Qt is using double for qreal on this system. This is binary incompatible against Qt 5.1.
    Configure with '-qreal float' to create a build that is binary compatible with 5.1.
    Info: creating cache file /home/d9/Projects/qt5_build_test/qt-everywhere-opensource-src-5.2.1/qtbase/.qmake.cache
    
    Qt is now configured for building. Just run 'gmake'.
    Once everything is built, you must run 'gmake install'.
    Qt will be installed into /opt/Qt/5.2.1
    
    Prior to reconfiguration, make sure you remove any leftovers from
    the previous build.
    
  9. Build and install Qt. It will be installed in a directory you set as a prefix during configuration.

    cd qt-everywhere-opensource-src-5.2.1/qtbase/
    gmake & gmake install

  10. Now, lets add Qt libraries and couple of Qt example binaries to PetaLinux project. Go to your PetaLinux project directory and create Qt component using 'libs' template.

    petalinux-create -t libs -n qt-5.2.1 --enable

  11. We don't need template created files, so delete them.

    cd components/libs/qt-5.2.1/
    rm libqt*

  12. Copy prebuilt Qt library files to 'lib' subdirectory, qt fonts and plugin directories also to 'lib' and a couple of Qt examples to 'bin' subdirectory:

    cp -Pr /opt/Qt/5.2.1/lib .
    cp -Pr /opt/Qt/5.2.1/plugins/ ./lib/
    mkdir bin
    cp /opt/Qt/5.2.1/examples/widgets/painting/pathstroke/pathstroke bin/pathstroke
    cp /opt/Qt/5.2.1/examples/widgets/mainwindows/mainwindow/mainwindow bin/mainwindow

  13. We also have to set a few enviromental variables on a target rootfs, so lets create 'profile.qt-5.2.1' file. Last one is for 'tslib', so if you don't use it you may delete it. Also, depending on your setup - you may need to change this or add other variables here.
  14. export QT_PLUGIN_PATH=/usr/lib/plugins
    export QT_QPA_FONTDIR=/usr/lib/fonts
    export QT_QPA_PLATFORM_PLUGIN_PATH=/usr/lib/plugins/platforms
    export QT_QPA_PLATFORM=linuxfb
    export QT_QPA_GENERIC_PLUGINS=tslib:/dev/input/event0
    
  15. Now we have to modify our PetaLinux component Makefile. We got nothing to build, but need to install our Qt5 library files to target rootfs.
  16. ifndef PETALINUX
    $(error "Error: PETALINUX environment variable not set. Try to source the settings.sh file")
    endif
    
    include libs.common.mk
    
    LIB=libqt_5_2_1
    
    all: build install
    
    .PHONY: build
    build:
    
    install:
    	#Install libraries and fonts to the rootfs.
    
    	mkdir -p $(TARGETDIR)/usr/lib
    	USER=your_user_name
    	GROUP=your_user_group
    	rsync -rav ./bin/* $(TARGETDIR)/usr/bin/
    	rsync -rav ./lib/* $(TARGETDIR)/usr/lib/
    
    	#Install the script to ensure the font directory is properly specified.
    	mkdir -p $(TARGETDIR)/etc/profile.d
    	cp profile.qt-5.2.1 $(TARGETDIR)/etc/profile.d/profile.qt-5.2.1
    
    clean:
    
  17. Last configuration step is to include 'libstdc++6' to target rootfs, since Qt is a C++ library and depends on it.

    petalinux-config -c rootfs

    Then go to 'Filesystem Packages' -> 'Base' -> 'External-xilinx-toolchain' -> Enable 'libstdc++6'.

  18. Thats it. Rebuild PetaLinux project, transfer image.ub file to SD card. Qt5 library will add about 20M to image size, so it may not fit into reserved space and you may need to adjust appropriate u-boot variable (loadaddr, netstart...). After boot you we can run 'pathstroke' and 'mainwindow' Qt example apps.
  19. zynq9_001

Posted in Linux, MicroZed, Qt, Xilinx Zynq, ZedBoard Tagged with: , , , , , , , , , , , , , ,
15 comments on “Howto build Qt 5.2.1 for Xilinx Zynq.
  1. andycckw says:

    I ran qt5.2.1 on my zedboard (D version) but got the following error. Any idea?

    My linux branch is xilinx-v2013.4.
    My hardware project is created by ISE14.6 which works fine with qt4.7.3.

    zynq> ------------[ cut here ]------------
    WARNING: CPU: 0 PID: 618 at lib/idr.c:527 idr_remove+0x178/0x238()
    idr_remove called for id=3 which is not allocated.
    Modules linked in:
    CPU: 0 PID: 618 Comm: hello Tainted: G W 3.12.0-xilinx-trd-00001-ge07373e #1
    [] (unwind_backtrace+0x0/0x11c) from [] (show_stack+0x10/0x14)
    [] (show_stack+0x10/0x14) from [] (dump_stack+0x84/0xc8)
    [] (dump_stack+0x84/0xc8) from [] (warn_slowpath_common+0x60/0x80)
    [] (warn_slowpath_common+0x60/0x80) from [] (warn_slowpath_fmt+0x2c/0x3c)
    [] (warn_slowpath_fmt+0x2c/0x3c) from [] (idr_remove+0x178/0x238)
    [] (idr_remove+0x178/0x238) from [] (drm_ctxbitmap_free+0x24/0x30)
    [] (drm_ctxbitmap_free+0x24/0x30) from [] (drm_rmctx+0x58/0xe8)
    [] (drm_rmctx+0x58/0xe8) from [] (drm_ioctl+0x2e4/0x430)
    [] (drm_ioctl+0x2e4/0x430) from [] (vfs_ioctl+0x24/0x40)
    [] (vfs_ioctl+0x24/0x40) from [] (do_vfs_ioctl+0x53c/0x584)
    [] (do_vfs_ioctl+0x53c/0x584) from [] (SyS_ioctl+0x38/0x54)
    [] (SyS_ioctl+0x38/0x54) from [] (ret_fast_syscall+0x0/0x30)
    ---[ end trace d16910ce6ab9d846 ]---
    This plugin does not support propagateSizeHints()
    This plugin does not support propagateSizeHints()

    Andy

  2. d9#idv-tech#com d9#idv-tech#com says:

    Looks like a bug for me or you missing some hardware.
    Can you describe you setup in more details? Do you have a framebuffer or directfb device?

    Try 3.8.11 or xilinx 3.12.0 released kernel to verify its not a kernel.
    Make sure you didnt mix Qt 4.7.x and 5.2.x libraries!

    • andycckw says:

      I'm using xilinx 3.12.0 and ADV7511 as the framebuffer device. The display part comes from ADI ADV7511 reference design.

      May I know the way to reproduce your reference in my side? I believe some patches are there.

      Andy

  3. d9#idv-tech#com d9#idv-tech#com says:

    Most likely you have to change "QT_QPA_DEFAULT_PLATFORM" from "linuxfb" to "directfb".

    I'm using default Petalinux 13.10 with 3.8.11 xilinx kernel and USB-to-DVI video adaptor.

  4. d9#idv-tech#com d9#idv-tech#com says:

    No changes in your code.
    And yes, you may need to reconfigure and rebuild Qt.

  5. steph67 says:

    Hi,

    I follow yout how-to and everything works on my target board, great
    I use a USB to HDMI dongle

    Qt display is nice but for the moment i can't use my USB mouse nor KBD to interract with the GUI
    I tried to define the QWS_MOUSE_PROTO variable without success. I am sure the /dev/input/mice is ok i check that with hexdump ...

    Any clue ?

    Regards
    Stéphane

  6. d9#idv-tech#com d9#idv-tech#com says:

    QWS for Q4.x, Qt5 uses QPA - try to set appropriate QPA variables.

  7. z.ali.sharif says:

    My mouse was not working. In fact none of the evdev plugins were working for me.

    The fix was to add the following line in the 'profile.qt-5.2.1' file:

    export QT_PLUGIN_PATH=/usr/lib/plugins

    Thanks for the great guide.
    - Ali

  8. nickppv2000 says:

    thanks for instructions.
    My target is MicroZed board, which I don't expect to be a big difference to ZED board regarding Qt, am I right?
    I ran into few problems with it:
    1. once I do step 4, Qt's qmake stops working with error “qmake: /opt/Xilinx/Vivado/2015.1/lib/lnx64.o/libstdc++.so.6: version ‘GLIBCXX_3.4.20’ not found (required by qmake)”
    Do I even need to run qmake after step 6?

    2. I have to add "-nomake examples" parameter to avoid compiling examples since compilation will fail later on.

    3. Do I need to use -sysroot to make sure that Qt will be build using correct libraries?

    4. why step 7 switches to qtbase?

    5. how do I force linux frame buffer to start? I'm not using petalinux, but kernel which I've built myself. Currently, I don't get /dev/fb0. Any ideas why?

    thank you

  9. d9#idv-tech#com d9#idv-tech#com says:

    Check out my latest post on Qt: http://blog.idv-tech.com/2014/10/15/building-and-configuring-qt5-tslib-and-evtest-for-arm-xilinx-zynq/

    1. You have to install 32bit version of libstdc++ for your distro.
    2. and 4. I guess this is how I skipped building examples and other staff.
    3. If you have a ARM sysroot for example from Yocto - yes. I'm using small build scripts to set all requiered path's and env variables.
    5. Frame buffer have nothing to do with Qt. You get it by loading proper driver for your hardware design(Vivado). Zynq7 don't have graphics hardware - which means you have to build it using PL.

    • nickppv2000 says:

      thank you! updated instruction worked for me with using shell script for building.

      1. Do I need to compile it myself or Xilinx provides it somehow?
      2/4. I was able to build examples on version 5.3.2, but takes way longer
      3. May I ask you to share your scripts? Or did you mean scripts provided in updated instructions?
      5. I understand that frame buffer isn't Qt's responsibility, but Am I right with assumption that Qt will not work without some kind of frame buffer?
      May I ask you to point me to more information about HOW-TO get frame buffer up and running?
      Which IP core do you use?
      Is there any way to get software emulation for frame buffer handled by kernel? (Reason I'm asking, I do have another platform based on ARM9 which doesn't have any GPU embedded. I'm just looking to get Qt working on both platforms with minimal differences)

  10. d9#idv-tech#com d9#idv-tech#com says:

    1. From your Linux distro. Using RPM for RedHat or apt-get for Ubuntu.
    5. Never used it myself, but where is some test-framebuffer in a linux kernel. It's off by default, so you have to reconfigure kernel to enable ot.
    3. Nothing fancy. Just something like that:

    #!/bin/bash

    export CROSS_COMPILE=arm-xilinx-linux-gnueabi-
    source /opt/Xilinx/Vivado/2014.4/settings64.sh

    export QTDIR=/opt/arm/Qt/5.3.2
    export PATH=$QTDIR/bin:$PATH
    export LD_LIBRARY_PATH=/$QTDIR/lib:$LD_LIBRARY_PATH

    qmake

    make

Leave a Reply