RaspberryPiWithQt5WebEngine: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
(Initial page)
 
(adding first draft)
Line 1: Line 1:
This is quick guide to how setup qtwebengine on raspberry pi3 running Raspbian Stretch with webgl support using VC4 open source drivers.
This is simple and basic guide to how setup self compiled qtwebengine on raspberry pi3 running Raspbian Stretch with webgl support using VC4 open source drivers.


The setup is tested on Rasberry3 model B, and qt version we are going to compile is 5.13.. We are going to use newest open source VC4 Gallium3D driver instead of old close source binaries from Broadcom.
==Setup==
 
The setup is tested on Rasberry3 model B, and qt version we are going to compile is 5.13.1. We are going to use newest open source VC4 Gallium3D driver instead of old close source binaries from Broadcom.
We are not going to use Bradcom toolchain since it has old 4.8 gcc compiler and to compile qtwebengine we need at least gcc 5.0. Raspbian Stretch ships with Binutils 2.28, GCC 6.3.0 and Glibc 2.24. Since
we would like to use same Glibc version and try to avoid getting a lot of issues when trying to compiler older Glibc 2.24 with some more modern GCC, we are going to simply mirror rasbian setup and reuse the same versions
as Raspbian ships. Therefore we start with downloading sources and raspbian image.
 
* let's create our workspace
 
<code lang="bash">
mkdir -p ~/workspaces/raspberrypi-raspbian/image
mkdir -p ~/workspaces/raspberrypi-raspbian/toolchain/sources
mkdir -p ~/workspaces/raspberrypi-raspbian/qt/qt5
</code>
 
<code lang="bash">
cd ~/workspaces/raspberrypi-raspbian/image
wget https://downloads.raspberrypi.org/raspbian/images/raspbian-2019-04-09/2019-04-08-raspbian-stretch.zip
cd ~/workspaces/raspberrypi-raspbian/toolchain/sources
wget https://ftpmirror.gnu.org/binutils/binutils-2.28.tar.bz2
wget https://ftpmirror.gnu.org/gcc/gcc-6.3.0/gcc-6.3.0.tar.gz
tar xf gcc-6.3.0.tar.gz
tar xf binutils-2.28.tar.bz2
</code>
 
Please note , most likely you would like to download corresponding sha1 to verify the archives.
 
==Sysroot==
 
To be able to compile things we need a part of sysroot to be present on our build machine. As shown here you could simply start your Raspbian on the boards and then rsync
over the network required libs and includes to host machine. Here is alternative way of doing the same but by mounting the image via loop device.
The reason we need a copy it that we want to modify the adjust the symlinks on our sysroot.
 
* first lets extract Raspbian image
 
<code lang="bash">
cd ~/workspaces/raspberrypi-raspbian/image
unzip 2019-04-08-raspbian-stretch.zip
</code>
 
* check the partition layout and note start sector of root partition (img2)
 
<code lang="bash">
fdisk -u -l 2019-04-08-raspbian-stretch.img
 
Disk 2019-04-08-raspbian-stretch.img: 3.2 GiB, 3481272320 bytes, 6799360 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xcd48578f
Device                          Boot Start    End Sectors  Size Id Type
2019-04-08-raspbian-stretch.img1      8192  96042  87851 42.9M  c W95 FAT32 (LBA)
2019-04-08-raspbian-stretch.img2      98304 6799359 6701056  3.2G 83 Linux
</code>
 
* mount the root partition
 
<code lang="bash">
mount -o loop,ro,offset=$((512*98304)) -t ext4 2019-04-08-raspbian-stretch.img  /media/card/
</code>
 
* rsync what we need
 
<code lang="bash">
cd ~/workspaces/raspberrypi-raspbian/
mkdir -p sysroot/usr
rsync -avz /media/card/lib sysroot
rsync -avz /media/card/usr/include sysroot/usr
rsync -avz /media/card/usr/lib sysroot/usr
</code>
 
* adjust symlinks to be relative
 
<code lang="bash">
wget https://raw.githubusercontent.com/Kukkimonsuta/rpi-buildqt/master/scripts/utils/sysroot-relativelinks.py
chmod +x sysroot-relativelinks.py
./sysroot-relativelinks.py sysroot
</code>
 
==Toolchain==
 
To compile qt we need cross-compiler toolchian. There are many excellent tools to compile a toolchain for you like for example crosstool-ng or buildroot, however
here we will compile gcc from scratch. Compiling a compiler is a bit tricky and requires few steps like:
 
* install linux headers, headers are required to make system calls from c library
* building biuntils to get cross-linker, cross-assembler and some other tools using your host compiler
* building first stage / bootstrap gcc, this basic compiler only with c language support and static linking
* building c library using first stage compiler
* building second stage gcc which uses c library and support for dynamic lining and c++ language
 
We already have a glibc compiled in our sysroot shipped by Rasbian , so we are going to cheat here a bit and skip boot strapping of gcc and building glibc itself.
We can simply use sysroot directly and just compile linker and final cross-compiler.
 
* first we do initial setup
 
<code lang="bash">
export WORKSPACE_ROOT=~/workspaces/raspberrypi-raspbian/toolchain
export PREFIX=${WORKSPACE_ROOT}/toolchain
export TARGET=arm-linux-gnueabihf
export SYSROOT=${WORKSPACE_ROOT}/../sysroot
export PATH=${PREFIX}/bin:$PATH
mkdir -p ${PREFIX}
cd ${WORKSPACE_ROOT}
 
</code>
 
* lets build linker and assembler
 
<code lang="bash">
mkdir -p build/binutils
pushd build/binutils
../../sources/binutils-2.28/configure --target=${TARGET} --prefix=${PREFIX} --with-arch=armv6 --with-fpu=vfp --with-float=hard --disable-multilib
make -j12
make install
popd
</code>
 
* we need extra GMP, MPFR and MPC libraries to be able to build gcc. This can be easily setup by running script in gcc source directory.
 
<code lang="bash">
cd ~/workspaces/raspberrypi-raspbian/toolchain/sources/gcc-6.3.0
contrib/download_prerequisites
</code>
 
* lets now build gcc
 
<code lang="bash">
mkdir -p build/gcc2
pushd build/gcc2
../../sources/gcc-6.3.0/configure --prefix=${PREFIX} --target=${TARGET} --with-sysroot=${SYSROOT} --enable-languages=c,c++ --disable-multilib --enable-multiarch --with-arch=armv6 --with-fpu=vfp --with-float=hard
make -j12
make install
popd
</code>
 
=Compiling Qt=
 
As shown here we could do top level build of qt , but instead we are going to do prefix module builds just to show alternative way of building qt.
WE just need three modules to have webenigne up and running qtbase, qtdeclarative and qtwebenigne.
What is importnat is to configure qt with linux-rasp-pi3-vc4-g++ device , since this specs contains newer vc4 opengl drivers.
We also compile two backends for qpa, xcb to run it whin Rasbian window manager and eglfs to run as fullscreen single application.
 
* get qtbase, configure, compile and install
 
<code lang="bash">
cd ~/workspaces/qt/qt5
git clone git://code.qt.io/qt/qtbase.git
git checkout 5.13.1
mkdir -p ~/workspaces/qt/build/qtbase
cd ~/workspaces/qt/build/qtbase
~/workspaces/qt/qt5/qtbase/configure -release -opengl es2 -device linux-rasp-pi3-vc4-g++ \
-device-option CROSS_COMPILE=~/workspaces/raspberrypi-raspbian/toolchain/toolchain/bin/arm-linux-gnueabihf- \
-opensource -confirm-license -nomake tests -nomake examples -verbose -no-pch -eglfs -xcb \
-sysroot /home/stefan/workspaces/raspberrypi-raspbian/sysroot \
-prefix /usr/local/qt/5.13 \
-extprefix /opt/qt/5.13/raspbian/sysroot \
-hostprefix /opt/qt/5.13/raspbian
 
make
make install
</code>
 
* get qtdeclarative
 
<code lang="bash">
cd ~/workspaces/qt/qt5
git clone git://code.qt.io/qt/qtdeclarative.git
git checkout 5.13.1
mkdir -p ~/workspaces/qt/build/qtdeclarative
cd ~/workspaces/qt/build/qtdeclarative
/opt/qt/5.13/raspbian/bin/qmake ~/workspaces/qt/qt5/qtdeclarative.5.13
make
make install
</code>
 
* get qtwebengine
 
<code lang="bash">
cd ~/workspaces/qt/qt5
git clone git://code.qt.io/qt/qtwebengine.git
git checkout 5.13.1
git submodule --init
mkdir -p ~/workspaces/qt/build/qtwebengine
cd ~/workspaces/qt/build/qtwebengine
/opt/qt/5.13/raspbian/bin/qmake ~/workspaces/qt/qt5/qtwebengine.5.13
make
make install
</code>
 
=Deploy=
 
* first lets extract Raspbian on sd card sdX (replace sdX with proper device on your machine)
 
<code lang="bash">
unzip -p 2019-04-08-raspbian-stretch.zip | sudo dd of=/dev/sdX bs=4M
</code>

Revision as of 12:48, 24 September 2019

This is simple and basic guide to how setup self compiled qtwebengine on raspberry pi3 running Raspbian Stretch with webgl support using VC4 open source drivers.

Setup

The setup is tested on Rasberry3 model B, and qt version we are going to compile is 5.13.1. We are going to use newest open source VC4 Gallium3D driver instead of old close source binaries from Broadcom. We are not going to use Bradcom toolchain since it has old 4.8 gcc compiler and to compile qtwebengine we need at least gcc 5.0. Raspbian Stretch ships with Binutils 2.28, GCC 6.3.0 and Glibc 2.24. Since we would like to use same Glibc version and try to avoid getting a lot of issues when trying to compiler older Glibc 2.24 with some more modern GCC, we are going to simply mirror rasbian setup and reuse the same versions as Raspbian ships. Therefore we start with downloading sources and raspbian image.

  • let's create our workspace
mkdir -p ~/workspaces/raspberrypi-raspbian/image
mkdir -p ~/workspaces/raspberrypi-raspbian/toolchain/sources
mkdir -p ~/workspaces/raspberrypi-raspbian/qt/qt5
cd ~/workspaces/raspberrypi-raspbian/image
wget https://downloads.raspberrypi.org/raspbian/images/raspbian-2019-04-09/2019-04-08-raspbian-stretch.zip
cd ~/workspaces/raspberrypi-raspbian/toolchain/sources
wget https://ftpmirror.gnu.org/binutils/binutils-2.28.tar.bz2
wget https://ftpmirror.gnu.org/gcc/gcc-6.3.0/gcc-6.3.0.tar.gz
tar xf gcc-6.3.0.tar.gz
tar xf binutils-2.28.tar.bz2

Please note , most likely you would like to download corresponding sha1 to verify the archives.

Sysroot

To be able to compile things we need a part of sysroot to be present on our build machine. As shown here you could simply start your Raspbian on the boards and then rsync over the network required libs and includes to host machine. Here is alternative way of doing the same but by mounting the image via loop device. The reason we need a copy it that we want to modify the adjust the symlinks on our sysroot.

  • first lets extract Raspbian image
cd ~/workspaces/raspberrypi-raspbian/image
unzip 2019-04-08-raspbian-stretch.zip
  • check the partition layout and note start sector of root partition (img2)
fdisk -u -l 2019-04-08-raspbian-stretch.img

Disk 2019-04-08-raspbian-stretch.img: 3.2 GiB, 3481272320 bytes, 6799360 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xcd48578f
Device                           Boot Start     End Sectors  Size Id Type
2019-04-08-raspbian-stretch.img1       8192   96042   87851 42.9M  c W95 FAT32 (LBA)
2019-04-08-raspbian-stretch.img2      98304 6799359 6701056  3.2G 83 Linux
  • mount the root partition
mount -o loop,ro,offset=$((512*98304)) -t ext4 2019-04-08-raspbian-stretch.img  /media/card/
  • rsync what we need
cd ~/workspaces/raspberrypi-raspbian/
mkdir -p sysroot/usr 
rsync -avz /media/card/lib sysroot
rsync -avz /media/card/usr/include sysroot/usr
rsync -avz /media/card/usr/lib sysroot/usr
  • adjust symlinks to be relative
wget https://raw.githubusercontent.com/Kukkimonsuta/rpi-buildqt/master/scripts/utils/sysroot-relativelinks.py
chmod +x sysroot-relativelinks.py
./sysroot-relativelinks.py sysroot

Toolchain

To compile qt we need cross-compiler toolchian. There are many excellent tools to compile a toolchain for you like for example crosstool-ng or buildroot, however here we will compile gcc from scratch. Compiling a compiler is a bit tricky and requires few steps like:

  • install linux headers, headers are required to make system calls from c library
  • building biuntils to get cross-linker, cross-assembler and some other tools using your host compiler
  • building first stage / bootstrap gcc, this basic compiler only with c language support and static linking
  • building c library using first stage compiler
  • building second stage gcc which uses c library and support for dynamic lining and c++ language

We already have a glibc compiled in our sysroot shipped by Rasbian , so we are going to cheat here a bit and skip boot strapping of gcc and building glibc itself. We can simply use sysroot directly and just compile linker and final cross-compiler.

  • first we do initial setup
export WORKSPACE_ROOT=~/workspaces/raspberrypi-raspbian/toolchain
export PREFIX=${WORKSPACE_ROOT}/toolchain
export TARGET=arm-linux-gnueabihf
export SYSROOT=${WORKSPACE_ROOT}/../sysroot
export PATH=${PREFIX}/bin:$PATH
mkdir -p ${PREFIX}
cd ${WORKSPACE_ROOT}
  • lets build linker and assembler
mkdir -p build/binutils
pushd build/binutils
../../sources/binutils-2.28/configure --target=${TARGET} --prefix=${PREFIX} --with-arch=armv6 --with-fpu=vfp --with-float=hard --disable-multilib
make -j12
make install
popd
  • we need extra GMP, MPFR and MPC libraries to be able to build gcc. This can be easily setup by running script in gcc source directory.
cd ~/workspaces/raspberrypi-raspbian/toolchain/sources/gcc-6.3.0
contrib/download_prerequisites
  • lets now build gcc
mkdir -p build/gcc2
pushd build/gcc2
../../sources/gcc-6.3.0/configure --prefix=${PREFIX} --target=${TARGET} --with-sysroot=${SYSROOT} --enable-languages=c,c++ --disable-multilib --enable-multiarch --with-arch=armv6 --with-fpu=vfp --with-float=hard
make -j12
make install
popd

Compiling Qt

As shown here we could do top level build of qt , but instead we are going to do prefix module builds just to show alternative way of building qt. WE just need three modules to have webenigne up and running qtbase, qtdeclarative and qtwebenigne. What is importnat is to configure qt with linux-rasp-pi3-vc4-g++ device , since this specs contains newer vc4 opengl drivers. We also compile two backends for qpa, xcb to run it whin Rasbian window manager and eglfs to run as fullscreen single application.

  • get qtbase, configure, compile and install
cd ~/workspaces/qt/qt5
git clone git://code.qt.io/qt/qtbase.git
git checkout 5.13.1
mkdir -p ~/workspaces/qt/build/qtbase
cd ~/workspaces/qt/build/qtbase
~/workspaces/qt/qt5/qtbase/configure -release -opengl es2 -device linux-rasp-pi3-vc4-g++ \
-device-option CROSS_COMPILE=~/workspaces/raspberrypi-raspbian/toolchain/toolchain/bin/arm-linux-gnueabihf- \
-opensource -confirm-license -nomake tests -nomake examples -verbose -no-pch -eglfs -xcb \
-sysroot /home/stefan/workspaces/raspberrypi-raspbian/sysroot \
-prefix /usr/local/qt/5.13 \
-extprefix /opt/qt/5.13/raspbian/sysroot \
-hostprefix /opt/qt/5.13/raspbian

make
make install
  • get qtdeclarative
cd ~/workspaces/qt/qt5
git clone git://code.qt.io/qt/qtdeclarative.git
git checkout 5.13.1
mkdir -p ~/workspaces/qt/build/qtdeclarative
cd ~/workspaces/qt/build/qtdeclarative
/opt/qt/5.13/raspbian/bin/qmake ~/workspaces/qt/qt5/qtdeclarative.5.13
make
make install
  • get qtwebengine
cd ~/workspaces/qt/qt5
git clone git://code.qt.io/qt/qtwebengine.git
git checkout 5.13.1
git submodule --init
mkdir -p ~/workspaces/qt/build/qtwebengine
cd ~/workspaces/qt/build/qtwebengine
/opt/qt/5.13/raspbian/bin/qmake ~/workspaces/qt/qt5/qtwebengine.5.13
make
make install

Deploy

  • first lets extract Raspbian on sd card sdX (replace sdX with proper device on your machine)
unzip -p 2019-04-08-raspbian-stretch.zip | sudo dd of=/dev/sdX bs=4M