Skip to content

Mali Midgard user space binary drivers

Miouyouyou edited this page Feb 17, 2019 · 6 revisions

License of this document

CC0

Purpose of this document

Understand how to use the Mali user space drivers on Linux. This article is targeted to people using my kernel integrating the Mali GPL kernel-space drivers.

These instructions might also work on other kernels integrating these drivers.

Performing a quick-test

The best way to test the Mali user-space drivers is to :

  • Acquire the Mali Midgard user-space binary drivers including the GBM symbols, from the Rockchip repositories;
  • Generate a bumblebee-like OpenGL programs launcher, using an alias that will use the acquired drivers to get 3D graphics acceleration when using the DRM subsystem;
  • Install the latest version of glmark2 from the glmark2 team Git repository;
  • Execute glmark2-es2-drm with our special launcher;

The quick version

sudo chmod 0666 /dev/mali0
sudo apt install libjpeg-dev libpng-dev pkg-config libudev-dev libdrm-dev libegl1-mesa-dev libgles2-mesa-dev libgbm-dev
git clone --depth 1 https://github.com/glmark2/glmark2
cd glmark2
./waf configure --with-flavors=drm-glesv2
./waf
sudo ./waf install

mkdir -p ~/.local/lib
cd ~/.local/lib
wget https://github.com/rockchip-linux/libmali/raw/29mirror/lib/arm-linux-gnueabihf/libmali-midgard-t76x-r14p0-r0p0-wayland.so -O libmali.so
for file_to_link in libGLESv1_CM.so{,.1,.1.0.0} libGLESv2.so{,.2,.2.0.0} libEGL.so{,.1,.1.0.0} libgbm.so{,.1,.1.0.0} libOpenCL.so{,.1,.1.0.0} libwayland-egl.so{,.1,.1.0.0}; do ln -s libmali.so "$PWD/$file_to_link"; done
echo "alias mali_launch=LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:`echo ~/.local/lib`" >> ~/.bashrc

# If on SSH, uncomment the following line
# chvt 1
# source ~/.bashrc
# If you have a keyboard connected to the system, press CTRL+ALT+F1 and login on the terminal

mali-launch glmark2-es2-drm

The long version

First, we'll determine where to install our drivers. Using .local/lib is a good location for single-user local libraries. We'll create the folder if it's not already created and then get into it, so that the next actions are performed from .local/lib . You can choose to install the libraries elsewhere. Just remember to change the code used by the mali-launch alias afterwards :

mkdir -p ~/.local/lib
cd ~/.local/lib

The Mali Midgard user-space binary drivers are built into one library that provide all the OpenGL ES, EGL, OpenCL and GBM symbols. We'll call this library libmali.so here.

wget https://github.com/rockchip-linux/libmali/raw/29mirror/lib/arm-linux-gnueabihf/libmali-midgard-t76x-r14p0-r0p0-wayland.so -O libmali.so

Now, you can expect every standard OpenGL ES program to look up for library names like libEGL.so, libGLESv2.so, ...; And expect them to never look for a libmali.so library. Ain't gonna happen. So, in order to force these programs to use libmali.so while looking for libEGL.so and libGLESv2.so is to generate symlinks named libEGL.so and libGLESv2.so and point them to libmali.so.

for file_to_link in libGLESv1_CM.so{,.1,.1.0.0} libGLESv2.so{,.2,.2.0.0} libEGL.so{,.1,.1.0.0} libgbm.so{,.1,.1.0.0} libOpenCL.so{,.1,.1.0.0} libwayland-egl.so{,.1,.1.0.0}; do ln -s libmali.so "$PWD/$file_to_link"; done

But that's not all. By default, your system is configured to look for libraries in a specific set of folder, notably /lib, /usr/lib, /usr/local/lib, ... In order to force the system to look for libraries in a specific folder before the usual ones, you'll have to declare an environment variable named LD_LIBRARY_PATH, with a set of path separated by ; characters. This environment variable will force the system (your dynamic linker to be precise) to look for libraries in the paths specified in that variable, before the usual ones. Since typing LD_LIBRARY_PATH=/path/to/your/mali/installation my-program is kind hard for your hands and keyboard, we'll generate a small alias. We'll named it mali-launch . So you'll launch my-program using mali-launch my-program

echo "alias mali_launch LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:`echo ~/.local/lib`" >> ~/.bashrc

Now, we need a program to test this. glmark2 with the DRM renderer is your best bet for a quick test. DRM do not require any additional installation, beside libdrm, which is included in every common distribution. In order to compile and install glmark2, you'll require a few headers and libraries. Most are used to handle image formats (PNG and JPEG) or for hardware detection and use (DRM, Udev). Here's how to install these dependencies on an Ubuntu/Debian system :

sudo apt install libjpeg-dev libpng-dev pkg-config libudev-dev libdrm-dev libegl1-mesa-dev libgles2-mesa-dev

Then we'll just clone the Git repository of glmark2 hosted on Github and build the software from its sources.

git clone --depth 1 https://github.com/glmark2/glmark2
cd glmark2
./waf configure --with-flavors=drm-glesv2
./waf
sudo ./waf install

Now, before we start testing, we'll make sure that our user has access to the graphic card device node, /dev/mali0 . For a long-term use, configure this device node permissions using udev, and adding our user in the proper group using usermod -a -G groupname username configuration is recommended. However, we just want to be sure that it works for now, so we'll just lower the permissions on the device node temporarily :

chmod 0666 /dev/mali0

Then, let's test. First make sure you're a real console, by pushing the keys CTRL+ALT+F1 if you have a keyboard directly connected to the board, or chvt 1 if you're using an SSH connection. If you're using an SSH connection, type chvt 1 instead. Note that if you're doing everything in a single streak, you might have to parse the ~/.bashrc manually in order to use the mali-launch alias command. Do that by executing source ~/.bashrc. Finally type :

mali-launch glmark2-es2-drm

And you should see a fluid pivoting horse statue on the screen, along with a few other tests like a textured box, a color shaded cat statue and others works. If your system reboot while doing this test, your power supply is too weak for your board and you'll have to acquire a better one.