Nate Sigrist

Installing libGL and friends for Linux 4.9

Discussion created by Nate Sigrist on Jun 11, 2018

This is a how-to for installing GPU binaries for X11 so it can use the Vivante drivers.

 

Make sure your environment variables are set correctly as there will be lots of cross compiling :-)  See the end of this post for help on setting environment variables for cross compiling.  This should be understood before continuing this post.

 

Overview

My setup is currently built with an Arch Linux root file system,

 

wget http://archlinuxarm.org/os/ArchLinuxARM-armv7-latest.tar.gz

# Ignore other board DTBs and mute warnings,

sudo tar xf ArchLinuxARM-armv7-latest.tar.gz \

    -C ${ROOTFS} \

    --warning=no-unknown-keyword \

    --exclude="./boot/dtbs" \

    --exclude="./boot/initramfs-linux.img" \

    --exclude="./boot/zImage"

 

Of course you'll want to use which ever distro works best for you (e.g. Yacto).  Arch Linux comes with a package manager that can install packages without compiling (albeit for generic ARM >< ).

 

The rest of this post will build and install the following required to get Vivante working with X11.

  • Kernel Vivante module 6.2.4 (kernel-module-imx-gpu-viv)
  • Proprietary libgl binaries (imx-gpu-viv)
  • Xorg Vivante extension (xserver-xorg-video-imx-viv)

 

kernel-module-imx-gpu-viv

The first code to compile is the Linux kernel module for galcore.  There is an existing galcore module in the kernel source tree.  I wrestle with understanding which is more beneficial.  I've chosen to use the module code provided by NXP.  The following generates this binary,

 

/usr/lib/modules/$(uname -r)/kernel/drivers/mxc/gpu-viv/galcore.ko

 

Source:
git clone git@github.com:Freescale/kernel-module-imx-gpu-viv.git 
cd kernel-module-imx-gpu-viv
git checkout upstream/6.2.4.p1.0

 

Replace the kernel's version,

rm -rf ${KERNELDIR}/drivers/mxc/gpu-viv

mkdir ${KERNELDIR}/drivers/mxc/gpu-viv
cp -R kernel-module-imx-gpu-viv-src/* ${KERNELDIR}/drivers/mxc/gpu-viv/

 

Then make sure CONFIG_MXC_GPU_VIV is set and rebuild and install the kernel.  Upon booting with the new kernel, dmesg will show Galcore loading with the new version,

 

$ dmesg | grep -i "galcore"

[ 1.139315] galcore: clk_get vg clock failed, disable vg!
[ 1.141816] Galcore version 6.2.4.150331

 

The galcore clock failure can safely be ignored.

 

imx-gpu-viv

Start by downloading the binary,

wget http://downloads.yoctoproject.org/mirror/sources/imx-gpu-viv-5.0.11.p8.3-hfp.bin

chmod +x imx-gpu-viv-5.0.11.p8.3-hfp.bin

./imx-gpu-viv-5.0.11.p8.3-hfp.bin --force --auto-accept

 

If you have a hard time reading their site try switching to source code view in your browser.  Adding --auto-accept means you are agreeing to their EULA.  I use the following method to place the binaries into my rootfs - it could be written more compactly ><

 

# Select which interface to use (options: fb, x11, dfb, wl)

_EGL=fb

cd imx-gpu-viv-5.0.11.p8.3-hfp

 

pushd gpu-core/usr/lib

# Clean up previous symbolic links from last run
rm -rf libEGL.so* libGAL.so* libGLESv2.so* libVIVANTE.so*

# Create ny symbolic links to point to our desired interface
ln -s libEGL-${_EGL}.so libEGL.so
ln -s libEGL-${_EGL}.so libEGL.so.1
ln -s libEGL-${_EGL}.so libEGL.so.1.0
ln -s libEGL-${_EGL}.so libEGL.so.1.0.0
ln -s libGAL-${_EGL}.so libGAL.so
ln -s libGLESv2-${_EGL}.so libGLESv2.so
ln -s libGLESv2-${_EGL}.so libGLESv2.so.2
ln -s libGLESv2-${_EGL}.so libGLESv2.so.2.0.0
ln -s libVIVANTE-${_EGL}.so libVIVANTE.so

popd

 

# Copy over the Vivante configuration file (Vivante.icd)
sudo cp -R gpu-core/etc ${ROOTFS}


pushd ${ROOTFS}/usr/lib

# Make sure there are no symbolic links.  Also remove the mesa stuff
sudo rm -rf libEGL.so* libGAL.so* libGLESv2.so* libVIVANTE.so mesa/libEGL.so* mesa/libGLESv2.so*

popd

 

pushd gpu-core/usr

CP="sudo cp -r --remove-destination"

${CP} lib/libVDK* ${ROOTFS}/usr/lib/
${CP} lib/libGL.so* ${ROOTFS}/usr/lib/
${CP} lib/libVSC* ${ROOTFS}/usr/lib/
${CP} lib/libGLSLC* ${ROOTFS}/usr/lib/
${CP} lib/libVIV* ${ROOTFS}/usr/lib/
${CP} lib/libGAL* ${ROOTFS}/usr/lib/
${CP} lib/libEGL* ${ROOTFS}/usr/lib/
${CP} lib/libOpen* ${ROOTFS}/usr/lib/
${CP} lib/libGLESv1* ${ROOTFS}/usr/lib/
${CP} lib/libGLESv2* ${ROOTFS}/usr/lib/
${CP} lib/dri/vivante_dri.so* ${ROOTFS}/usr/lib/dri/

${CP} include/EGL ${ROOTFS}/usr/include/
${CP} include/GLES2 ${ROOTFS}/usr/include/
${CP} include/HAL ${ROOTFS}/usr/include/

popd

 

xserver-xorg-video-imx-viv

So far, the kernel driver has been built and the proprietary binaries have been installed.  Now the hooks must be built so X11 will work correctly.  This produces the following,

 

/usr/lib/libfsl_x11_ext.so
/usr/lib/xorg/modules/drivers/vivante_drv.so

 

Grab the source,

 

wget http://downloads.yoctoproject.org/mirror/sources/xserver-xorg-video-imx-viv-5.0.11.p8.3.tar.gz

tar xf xserver-xorg-video-imx-viv-5.0.11.p8.3.tar.gz

 

If you build libdrm then you may need to modify the path,

 

find . -type f -exec sed -i -re 's/(\/usr\/include\/)drm/\1libdrm/g' {} \;

 

I had to remove `xf86DisableRandR' and replace shadowUpdateRotatePackedWeak and
shadowUpdatePackedWeak by simply removing "Weak()" from,
EXA/src/vivante_fbdev/vivante_fbdev_driver.c

 

Then build and install,

 

make XSERVER_GREATER_THAN_13=1 BUILD_HARD_VFP=1 BUSID_HAS_NUMBER=1 \
    sysroot=${ROOTFS} prefix=${ROOTFS}/usr LFLAGS="${LDFLAGS}" && \

sudo -E make prefix=${ROOTFS}/usr install

 

Xorg Configurations

Make sure to include and xorg.conf file with the vivante information,

 

Section "Device"
    Identifier "i.MX Accelerated Framebuffer Device"
    Driver "vivante"
    Option "fbdev" "/dev/fb0"
    Option "vivante_fbdev" "/dev/fb0"
EndSection

Section "Screen"
    Identifier "Default Screen"
    SubSection "Display"
        Depth 24
        Modes "720x1280"
    EndSubSection
EndSection

 

Obviously make sure that Modes and Depth are set according to your needs.  You may comment out Driver "Vivante" if you are not able to get the Vivante drivers to work.

 

Starting X

Some pointers when starting Xorg.  If you are just trying to get things started then make sure the following are done,

 

# Manually load the vivante module,

modprobe vivante

# Make sure the DRI card is accessible by Xorg,
chmod o+rw /dev/dri/card0
Xorg &

export DISPLAY=:0

 

Most likely you will have some issues; don't fret.  If requested, I will show how to build xorg-server to ensure matching ABIs and firmware.

 

 

Cross Compiling Environment Variables

export ARCH=arm
export CPU=armv7l
export MARCH=armv7-a
export MTUNE=cortex-a9
export HOST=arm-linux-gnueabihf

export LINARO_PATH=[Cross compiler root path]
export CROSS_COMPILE=${HOST}-

export ROOTFS=[Path to your ARM root file system]

export CFLAGS="-march=${MARCH} -mtune=${MTUNE} --sysroot=${ROOTFS}"
export CXXFLAGS="${CFLAGS}"

# I prefer GOLD since it is much faster
export LDFLAGS="-march=${MARCH} -mtune=${MTUNE} --sysroot=${ROOTFS} -Wl,-fuse-ld=gold"

export CONF_ARGS="\
    --host=${HOST} \
    --with-sysroot=${ROOTFS} \
    --prefix=/usr \
    --sysconfdir=/etc \
    --localstatedir=/var"
export CONFIGURE="./configure ${CONF_ARGS}"

# Some projects appear to be auto tools but really aren't and will need this defined,
export DESTDIR=${ROOTFS}

# Required for auto tools using pkg-config.  This directs them to the root file system.

# This assumes that you have preserved the install and have not used some other process

# that cleans up /usr/lib/pkfconfig

export PKG_CONFIG_SYSROOT_DIR=${ROOTFS}
export PKG_CONFIG_LIBDIR=${ROOTFS}/lib/pkgconfig:${ROOTFS}/usr/lib/pkgconfig

# Make sure the cross compiler is included in your environment variables.  Notice that

# we've used Linaro here ;-)

export PATH=${BUILD}/$(shell uname -m)/bin:${LINARO_PATH}/bin:${shell echo $${PATH}

# Kernel source

export KERNELDIR=[Path to your kernel source]
export INSTALL_MOD_PATH=${ROOTFS}

Outcomes