I’ve updated the post to work with the Krogoth release of Yocto/Poky, and with the Raspberry Pi 3.
I’ve updated the post to work with the Jethro release of Yocto/Poky, all with the help of your helpful comments!
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
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.
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
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
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.