Skip to content

Mali Opengl on the libretech cc s905x using FBDEV

Jerome Brunet edited this page Mar 26, 2018 · 1 revision

This technical note is focused on enabling the opengl acceleration provided by the mali on the libretech-cc s905x, through the fbdev userspace api. Fbdev is the legacy interface to the framebuffer, it does not export all the capabilities of a DRM driver. For example, as of today, changing the screen resolution of DRM driver through the fbdev interface is not possible. New application should consider using GBM instead of fbdev.

By itself, enabling the mali on a gxl platform is not a very complicated task. However, setting up the root filesystem from scratch can be a bit confusing. This part has been deliberately omitted in this article.

As an example, we'll run the ioquake 3 arena demo which was showcased at ELC portland in 2017. If you just wish to play quake 3 on your libretech board, please download this image and flash it on an sdcard:

dd if=<your-image.img> of=<path-to-your-sdcard> bs=4M

Plug the sdcard, power on the board and the quake 3 demo should appear on the screen a few seconds later. Plug a keyboard, a mouse and have some frag fun !

The scripts used to build to this demo are available here: Libretech image builder. The setup is based on ubuntu debootstrap. If you are curious about the implementation details of this demo, feel free to checkout the scripts

The rest of this note is meant to provide some explanation about the important components required to enable opengl support, and how to build them.

Building Libretech Linux kernel (v4.14) :

We are using the kernel provided on libretech-linux. This kernel is derived for the v4.14 stable release and is often updated with bug fixes. Compared to the vanilla 4.14 kernel, it contains:

  • Some fixes critical to libretech-cc which are not yet part of the stable release
  • VPU power domain patches - necessary to use u-boot mainline
  • Early USB support for the GXL family by Martin Blumenstingl
  • Early HDMI audio support (WIP)

Here are the steps to build this kernel:

git clone https://github.com/libre-computer-project/libretech-linux.git -b linux-4.14/libretech-cc-master-stable
pushd libretech-linux
make ARCH=arm64 defconfig
sed -i 's/CONFIG_DRM_FBDEV_OVERALLOC=100/CONFIG_DRM_FBDEV_OVERALLOC=300/g' .config

With fbdev, the mali will allocate its buffers directly from the framebuffer device so we need more memory than usual

make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- INSTALL_MOD_PATH=<path-to-your-rootfs> modules_install

Mali support :

This section is the same for fbdev and gbm. It is described here

In addition, we will build other components on top of these libraries so we need to install the headers, including the fddev platform headers:

cp -ar buildroot_openlinux/buildroot/package/meson-mali/include/* <path-to-your-rootfs>/usr/include/
pushd <path-to-your-rootfs>/usr/include/EGL
ln -s ../EGL_platform/platform_fbdev/* .
popd
echo /usr/lib/mali > <path-to-your-rootfs>/etc/ld.so.conf.d/mali.conf

The necessary bits to enable opengl acceleration using the mali are now available ! We just have to use them now. The sections following are about building and running quake 3 on the Libretech platform. If you are not interested in quake 3, feel free to stop reading here.

Libsdl2 :

This patched version of libsdl2 provides a suitable configuration to use the opengl acceleration of the mali through fbdev.

The compilation is assumed to be done natively on the platform or using qemu virtualization. Don't run this on your computer if don't know what you are doing !

# git clone -b meson-gx https://github.com/superna9999/libsdl2-2.0.2-dfsg1
# pushd libsdl2-2.0.2-dfsg1
# ./configure --without-x --enable-video-opengles --disable-video-opengl --enable-video-mali --disable-video-x11 --disable-video-wayland
# make install

IOQuake 3:

The chosen upstream version of ioquake taken contains a few hacks targeting the raspberry pi. These hacks have been replaced so ioquake run our fbdev/mali enabled platform:

# git clone -b meson-gx https://github.com/superna9999/ioq3
# pushd ioq3
# make SDL_LIBS="-L /usr/local/lig -Wl,-rpath,/usr/local/lib -lSDL2" SDL_CFLAGS="-I/usr/local/include/SDL2" PLATFORM_HACK=gles BUILD_RENDERER_OPENGL2=0 USE_RENDERER_DLOPEN=0

Quake3 demo resources :

IOQuake comes without the 3d resources of Quake 3 arena. To get the 3d resources of the full game, you have to buy it. Fortunately, the demo files are available and we can still have some fun with these.

wget https://github.com/superna9999/ioq3/releases/download/working0/baseq3-demo.tar.gz
tar xfz baseq3-demo.tar.gz
mv  baseq3-demo/* <your-rootfs>/ioq3/build/release-linux-aarch64/baseq3
rm -r baseq3-demo

Have some fun:

You should now be ready to have some fun, boot your platform then run

# /ioq3/build/release-linux-aarch64/ioquake3.aarch64

You may see the virtual console and the game "fighting" for the framebuffer. You can stop it by disabling the virtual console binding to fb0:

# echo 0 > /sys/class/vtconsole/vtcon1/bind

or alternatively, you may prevent fbcon from binding to fb0 to begin with. Add fbcon=map:1 to the command line of the kernel

That's it folks !

Resources