Setting up a Yocto build with Qt5 for Raspberry Pi 2/3 with official touchscreen

Update 2:

I’ve updated the post to work with the Krogoth┬árelease of Yocto/Poky, and with the Raspberry Pi 3.

Update:

I’ve updated the post to work with the Jethro release of Yocto/Poky, all with the help of your helpful comments!

Introduction

In this post I intend to provide easy instructions for how to build an image for running Qt Qml applications on a Raspberry Pi 2 with the official 7″ multi-touch screen. It probably helps if you have used Yocto or Open Embedded before, but it shouldn’t be a must. Feel free to ask questions in the comments and I’ll try to answer and makes things clearer in the post if needed.

Getting the layers

First of all we need to get the different layers involved. I like to keep the layers in a directory called sources, keeping them in a separate directory makes it easy to grep for things in them when I need to.

mkdir -p ~/rpi/sources
cd ~/rpi/sources

git clone -b krogoth git://git.yoctoproject.org/poky
git clone -b krogoth git://git.openembedded.org/meta-openembedded
git clone -b master git://git.yoctoproject.org/meta-raspberrypi
git clone -b krogoth https://github.com/meta-qt5/meta-qt5.git
git clone -b krogoth https://github.com/erikboto/meta-erborpi.git

Preparing the build configuration

Next thing to do is to create a build environment using the setup script that comes with poky. This will create example configuration files that we will modify to add our extra layers, and to build for the Raspberry Pi 2/3.

cd ~/rpi/
source sources/poky/oe-init-build-env rpi-build

We now need to add a couple of rows to local.conf that configures the build for us.

# Set the correct target machine, change to raspberrypi2 if you have one of those
echo 'MACHINE = "raspberrypi3"' >> conf/local.conf

#Prefer version 4.x of the kernel
echo 'PREFERRED_VERSION_linux-raspberrypi = "4.%"' >> conf/local.conf

# Don't use X11 and wayland
echo 'DISTRO_FEATURES_remove = "x11 wayland"' >> conf/local.conf

# Use systemd as init system
echo 'DISTRO_FEATURES_append = " systemd"' >> conf/local.conf
echo 'VIRTUAL-RUNTIME_init_manager = "systemd"' >> conf/local.conf

In order to enable the new layers bblayers.conf needs to be modified, in meta-erborpi/misc/ there’s a version you can use.

cp ~/rpi/sources/meta-erborpi/misc/bblayers.conf conf/bblayers.conf

Building the image

In meta-erborpi there’s an image based on the minimalistic core-image but with the addition of Qt5 and qmlscene that can be used to launch Qml applications. It also comes with an example Qml application which shows the use of up to four simultaneous touch points. Note that both Qt and the touchscreen support more than these four points. The image is called core-image-qt

To start the build

cd $BUILDDIR
bitbake core-image-qt

This will take a long time but will hopefully finish without any errors. The resulting image is found in ~/rpi/rpi-build/tmp/deploy/images/raspberrypi2/core-image-qt-raspberrypi2.rpi-sdimg.

Write the image to an SD-micro

The result of the build is an image that can be written directly to an SD-micro using e.g. dd. Make sure you use the correct target device instead of /dev/sdX, otherwise you might erase you local harddrive!

dd if=~/rpi/rpi-build/tmp/deploy/images/raspberrypi2/core-image-qt-raspberrypi3.rpi-sdimg of=/dev/sdX bs=4M

Boot and launch the example application

Insert the SD-micro into the Raspberry Pi 2 and boot it up, after some time you should see a login prompt where you can log in using the user root with no password.

Use systemctl to launch the touchpoints Qml example.

systemctl start touchpoints

In order to make the Qml example start automatically on boot use the following

systemctl enable touchpoints

Final words

By now you should have a working Yocto build to start experimenting with Yocto and the Raspberry Pi 2/3 with the official 7″ multi-touch screen. I intend to do some follow-up posts building on this one, where I extend the minimal image and describe how you can generate an SDK that you can use with QtCreator to build for, and automatically deploy to, the Raspberry Pi 2/3 over a network connection.

This entry was posted in Programming. Bookmark the permalink.

24 Responses to Setting up a Yocto build with Qt5 for Raspberry Pi 2/3 with official touchscreen

  1. Matthew Cattell says:

    Will eglfs backend support an ordinary HDMI non-touch monitor? I am trying to get a touchscreen but there’s a waiting list.

  2. Wolf says:

    Hello,
    I’ve tried your configuration to set up the 7” touch screen with my raspberry pi 2. Somehow I’m don’t get a serial output if the rpi-ft5406 overlay is activated under config.txt. I guess in this case the raspberry isn’t booting as the green LED blinks only two times shortly after I power the device up.
    All other overlays work, I only have this problem with rpi-ft5406.
    I use Yocto fido, the version of the Kernel is 4.1.8. My bblayers.conf is the same as yours, I’ve only added meta-openembedded/meta-ruby, otherwise it won’t compile.
    The touchscreen works with the Raspbian Jessie image, therefore nothing is wrong with my hardware.
    It would be great if you could help me solving this issue.

    • admin says:

      I can’t think of anything that will help you, other than to make sure that the driver for the rpi-ft5406 is built and available. That’s the only reason I can think of that might mess up the boot if the overlay is activated.

  3. I tried this build on a clean ubuntu 14.04 machine on AWS tonight/this morning and have some feedback. I hope you don’t mind :) .

    1. For a clean build you need the following stuff installed:


    sudo apt-get update -y
    sudo apt-get dist-upgrade -y
    sudo apt-get install -y build-essential git automake autoconf flex
    sudo apt-get install -y chrpath diffstat texinfo libsdl1.2-dev libsdl2-dev

    2. I had issues with libsdl-native, for some reason it doesn’t pick it up, but I’ve previously built using a locally provided libsdl-native, so this solved it for me:


    echo "ASSUME_PROVIDED += " libsdl-native " >> conf/local.conf

    3. The git clone winds up with master repositories all over, which didn’t really work nicely for me. I backed up to jethro branches, and everything worked more or less after that.

    I hope this is helpful, now I just need to test the image on a target… :)

    • admin says:

      Yeah I wrote the stuff shortly before jethro was released, and I had the intention of updating the post after release. But then other stuff got in between so I never got around to it. Great to hear that it works with jethro though, I’ll see if I can find the time to make a test and then move forward with a post about setting up QtCreator for developing and deploying to target.

    • admin says:

      You should do a write-up of how you do yocto builds on AWS, that will probably be interesting topic for lots up people!

  4. I just want to confirm that the generated image works on rpi2.
    Thanks for the writeup :)

  5. sn00p says:

    Thanks for the write up, I’ve tried it on the latest ubuntu and with the latest yocto release and it all works fine for the Raspberry Pi 2.

    A couple of questions (I’m new to yocto and openembedded) that hopefully somebody knows the answer to…

    I’ve managed to enable some extra stuff by adding lines to my local.conf file:

    EXTRA_IMAGE_FEATURES = “debug-tweaks ssh-server-openssh splash”
    PACKAGECONFIG_append_pn-qtbase = ” accessibility”
    CORE_IMAGE_EXTRA_INSTALL_append = “openssh-sftp-server psplash init-ifupdown qtdeclarative-qmlplugins qtquickcontrols-qmlplugins qtgraphicaleffects-qmlplugins”

    but for the life of me I cannot seem to get the following to happen.

    1.) Bring up eth0 at boot automatically
    2.) show the psplash boot screen as it boots

    I’ve disabled the raspberry pi logo and also the GPU color test, so the pi is just showing a completely blank screen until it has finished booting, at which point the login prompt appears.

    Any ideas on how I can achieve either of these things? (I’m currently having to login to the pi and manually do and ifup so that I can then connect with qtcreator to develop)

    Thanks

    • sn00p says:

      To answer my own question about psplash…..

      I’m using systemd and it doesn’t seem that psplash is compatible, so the bb file sets it as masked.

      if I manually unmask it and boot, I do get the psplash screen appear, but not a lot happens (i.e no progress bar updates) and I have to switch to another console to login.

      Humn….

      • sn00p says:

        OK!

        For anybody else struggling with these issues, removing the following lines from the above instructions:

        echo ‘DISTRO_FEATURES_append = ” systemd”‘ >> conf/local.conf
        echo ‘VIRTUAL-RUNTIME_init_manager = “systemd”‘ >> conf/local.conf

        This will make the built image use SysVInit rather than systemd.

        (I manually removed the lines from my local.conf as I already had a “working” image, although switching init managers seems to cause a rebuild of the entire system).

        Once you’re using SysVInit, both the splashscreen and ethernet issues go away, you get the lovely psplash boot screen with progress bar and also ethernet is up after boot.

        Once again, thanks for the write up on this! I have a cross toolchain built and can build/auto deploy and run code on the Pi from qtcreator.

        • admin says:

          Thanks for adding info about how you solved the issue you saw!

          I’ve never tried psplash, so there I can’t contribute with any info. But regarding getting the network up with systemd you can use a .network file, see http://www.freedesktop.org/software/systemd/man/systemd.network.html. There’s quite a few examples at the end, e.g.:

          Example 1. /etc/systemd/network/50-static.network
          [Match]
          Name=enp2s0

          [Network]
          Address=192.168.0.15/24
          Gateway=192.168.0.1

          Example 2. /etc/systemd/network/80-dhcp.network
          [Match]
          Name=en*

          [Network]
          DHCP=yes

          I’m just more used to using systemd, which is why I default to using that. But there’s nothing wrong with older sysvinit-style script either.

          • sn00p says:

            No problem! It’s always annoying when somebody just replies with “I fixed it” without an explanation for the rest of the world!

            I’ve also created a new layer which modifies the cmdline.txt config.txt files to disable the GPU test and also the raspberry pi kernel logo. It also changes the psplash logo to my own one.

            So my image boots from power up to console (and eventually the app I’m developing) with no superflous screens or images, just the splashscreen.

            I’m learning!

  6. sn00p says:

    The touchscreen was not working on mine, I had a bit of a poke around and the overlay is missing from meta-raspberry pi.

    I fixed this my adding the following to my local.conf (You could do this in a layer bbappend)

    KERNEL_DEVICETREE_append = ” overlays/rpi-ft5406-overlay.dtb”

    As I’m using sysvinit, the command in the original instructions doesn’t work, so to test the touchscreen use:

    cd /opt/example
    /usr/bin/qt5/qmlscene -platform eglfs touchpoints.qml

    Hopefully you should then have a working touchscreen.

  7. sn00p says:

    Me again!

    The raspberry pi meta layer uses a kernel commit from back in october, this means that the kernel that is built does not support control of the LCD backlight.

    I rebuilt my image yesterday using the very latest commit from the raspberry pi linux kernel repository and it seems to be working perfect for me and now I can control the backlight.

    It’s easy to change, you can edit your local.conf so that it includes the following lines

    PREFERRED_VERSION_linux-raspberrypi = “4.1.%”
    SRCREV_pn-linux-raspberrypi = “79dbbb6df7d6e16501f30a9ee97d62588c052a57”

    The commit revision I used was the latest one from yesterday, although you can check here:

    https://github.com/raspberrypi/linux

    and pick a commit that takes your fancy.

    (You’ll need to add the rpi-backlight-overlay.dtb to the overlays folder on the boot partition and add “dtoverlay=rpi-backlight” to config.txt to enable the kernel module at boot otherwise you’ll have to manually load the kernel module after boot.)

  8. Carlos Xammar says:

    Hi, my touchscreen came with drivers, this tutorial will make it work or not ?

  9. Giovanni Bauermeister says:

    Thanks man! Great article and just to confirm, it works!

    I got running on the raspberry an application I did once but for iMX6
    https://www.youtube.com/watch?v=fto66r1GLrA

    • Giovanni Bauermeister says:

      Just for the record. I tried on krogoth branches, but could not make it work. Dont know if I did something wrong. Maybe you could try as well and if it works make a tutorial for us!

  10. Paul Creaser says:

    I know this tutorial is quite old, so things have significantly changed since it was written.

    I tried it for the Krogoth branch. It produced numerous errors, including errors caused by the Python getVar API change, and commits breaking the build …

    The getVar was fixed by changing the source code in meta-raspebrrypi. An error regarding a missing bcm module/component was fixed by reverting to a version in 2016 November.

    At this stage I get an error at the final stage when creating the sd image.

    Jethro simply reports

    Cloning into ‘meta-erborpi’…
    fatal: Remote branch jethro not found in upstream origin

    Is there a reliable branch which can be used to create this image?

  11. Jignesh says:

    I want to build yocto with python GUI based.
    So i can start a my python application in start up.
    Is this possible in image that has builded with above steps?
    No, How to do it?

Leave a Reply

Your email address will not be published. Required fields are marked *