Skip to content

Raspberry Pi cross compile

Andreas Bergmeier edited this page Jul 7, 2019 · 4 revisions

Most of my Raspberry Pi Mesa development is done on an x86_64 system, into an NFS root (/home/rpi2). Here is what I hope will be enough information for others to (more or less) replicate what I've done. I'm assuming you've already got the vc4 driver working in your distribution.

Install the cross tools:

sudo apt-get install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf ccache pkg-config-arm-linux-gnueabihf

Note that this will build for armv7, not the v6 hard-float of Raspbian! While we're going to be building against armv7 libs on the host, I've still had luck running these binaries on Raspbian installs. I wish I had a solution using rpi-tools armv6hf cross compiler, but I've never managed to get everything to build with them.

Create a meson cross file. Some day debian will include these in the distro, but not yet. Here's mine ($HOME/src/rpi2/cross):

[binaries]
c = '/usr/lib/ccache/arm-linux-gnueabihf-gcc'
cpp = '/usr/lib/ccache/arm-linux-gnueabihf-g++'
ar = '/usr/bin/arm-linux-gnueabihf-ar'
strip = '/usr/bin/arm-linux-gnueabihf-strip'
pkgconfig = '/usr/bin/arm-linux-gnueabihf-pkg-config'

[host_machine]
system = 'linux'
cpu_family = 'arm'
cpu = 'armv7hl'
endian = 'little'

Make yourself a little meson wrapper script (pi2meson) to set up a cross build:

meson build/ \
    --cross-file=$HOME/src/rpi2/cross \
    --prefix=/usr \
    --libdir=lib/arm-linux-gnueabihf \
    "$@"

Install current libdrm:

sudo apt-get install valgrind
git clone git://anongit.freedesktop.org/mesa/drm
cd drm
pi2meson
ninja -C build/
sudo env DESTDIR=$HOME/rpi2 ninja -C build/ install

Now build and install mesa:

sudo apt-get install \
    flex bison python-mako \
    libxcb-dri3-dev:armhf libxcb-dri2-0-dev:armhf \
    libxcb-glx0-dev:armhf libx11-xcb-dev:armhf \
    libxcb-present-dev:armhf libxcb-sync-dev:armhf \
    libxshmfence-dev:armhf \
    libxdamage-dev:armhf libxext-dev:armhf libxfixes-dev:armhf \
    x11proto-dri2-dev:armhf x11proto-dri3-dev:armhf \
    x11proto-present-dev:armhf x11proto-gl-dev:armhf \
    libexpat1-dev:armhf libudev-dev:armhf gettext

git clone git://anongit.freedesktop.org/mesa/mesa
cd mesa
pi2meson \
  -Dtexture-float=true \
  -Ddri-drivers= \
  -Dgallium-drivers=vc4,swrast \
  -Dvulkan-drivers= \
  -Dllvm=false \
  -Dplatforms=x11,drm,surfaceless \
  -Dlibunwind=false \
  -Dllvm=false \
  "$@"
ninja -C build/
sudo env DESTDIR=$HOME/rpi2 ninja -C build/ install
You can’t perform that action at this time.