Mali binary driver

This page describes how to install and set up the binary userspace drivers that a fully working system for sunxi still requires.

= 3D driver and setting up 2D/3D acceleration in X =

The sun4i and sun5i use a Mali400MP1. We have support available for several versions of the mali binary driver stack, even though our kernel tends to come with the R3P0 version. We support framebuffer and X11 as windowing systems.

Mali kernel driver
First get a working display driver.

The default config for the kernel should have the Mali kernel drivers as modules. You should be able to load it by simply running

 modprobe mali

A cleaner solution is to have the module autoloaded at boot, by adding the following to /etc/modules:  ump mali

The default permissions of /dev/ump and /dev/mali make these unusable for normal users. Add a file to /etc/udev/rules.d/, perhaps called 50-mali.rules, with the following content:  KERNEL=="mali", MODE="0660", GROUP="video" KERNEL=="ump", MODE="0660", GROUP="video" This should give a user belonging to the group video the right permissions to use the mali succesfully.

Installing the Mali binary drivers
We have an all in one repository to do this for you, called sunxi-mali.

You need libdri2-dev,xorg-dev,xutils-dev for success build.

 apt-get install build-essential libdri2-dev xorg-dev xutils-dev


 * Some distributions have libdri2 compiled in X11 binary, so there is libdri2 separated in a github repo https://github.com/robclark/libdri2

First we need to clone the repository, which is slightly less straightforward due to our use of git submodules for the actual binaries. Make sure to do this on the target system, and as root, as we will install directly into your system.

 git clone https://github.com/linux-sunxi/sunxi-mali.git cd sunxi-mali git submodule init git submodule update

Now you can descend into sunxi-mali, if all goes well, you should only need to do this:

 make install

This should autodetect the version of the kernel driver, which ABI you are on, and whether you want X11 or framebuffer support (by looking for libX11). It will then build libUMP.so (ARM Mali's Universal Memory Provider), install libUMP and the GLES/EGL binaries into /usr/lib/, and install the UMP and EGL/GLES headers to /usr/include/.

RPM or deb packages are not available yet, for the simple reason that no-one has added spec files or a debian/ build tree to the sunxi-mali tree. If anyone needs a sunday-afternoon project, this is a good one.

Setting up X
If you are using the framebuffer console only, and have verified that the framebuffer version of the Mali binaries was installed, then you can of course skip this section.

The Mali GPU provides acceleration of 3D OpenGL ES2 apps. However, there are also 2D acceleration features inside the A1x such as hardware cursor and the G2D engine to speed up drawing in X. You can enable 2D acceleration in X using the sunxifb driver without having the X11 version of the binary Mali drivers installed. If the X11 version of the Mali binary drivers are installed, the sunxifb driver will automatically detect this and provide OpenGL ES2 integration for 3D apps.

To compile and install the xorg driver, first install the following development packages for building X drivers:

 apt-get install build-essential xorg-dev xutils-dev x11proto-dri2-dev libltdl-dev libtool automake

Now get the sunxifb xf86 driver:

 git clone https://github.com/ssvb/xf86-video-sunxifb.git

The older stable driver, which does not provide 2D acceleration, is available at git://github.com/linux-sunxi/xf86-video-mali.git

Compile and install the sunxifb xf86 driver (this is necessary even if you already had it installed for 2D only):

 autoreconf -vi ./configure --prefix=/usr make make install

Then copy over the default xorg.conf for the sunxifb driver:  cp xorg.conf /usr/share/X11/xorg.conf.d/99-sunxifb.conf

You should now be able to (re)start your xserver, have a quick look through /var/log/Xorg.0.log to verify that the correct driver has been loaded:

... (II) Module sunxifb: vendor="X.Org Foundation" compiled for 1.12.4, module version = 0.3.1 Module class: X.Org Video Driver ABI class: X.Org Video Driver, version 12.1 (II) SUNXIFB: driver for framebuffer: sunxifb (--) using VT number 7 ...

Also make sure that you don't have the following lines in it (if you do, then a clean rebuild and reinstallation of the sunxifb driver is needed):

(II) SUNXIFB(0): no 3D acceleration because the driver has been compiled without libUMP (II) SUNXIFB(0): if this is wrong and needs to be fixed, please check ./configure log

Enabling 2D Acceleration (G2D)
See man sunxifb for configuration options of the sunxifb driver. You can enable G2D acceleration (2D graphics acceleration using the G2D engine) by adding the following line to the Device section of /usr/share/X11/xorg.conf.d/99-sunxifb.conf:

Option         "AccelMethod" "G2D"

However, you need a relatively recent kernel to do this (including the patch https://github.com/linux-sunxi/linux-sunxi/commit/3d49345343a1535b5c787d5d48bc682f300358de). And even with G2D enabled, it is still recommended to have "sunxi_g2d_mem_reserve=0" option in your kernel command line to save memory (see Kernel arguments). That's because the sunxifb driver is currently using G2D only for accelerating operations within framebuffer and does not do custom memory allocations from the G2D reservation pool.

Verifying the EGL/GLES driver stack
From the mali-sunxi repository, you can run:

 make test test/test

And you should be able to see a smoothed triangle, either written out to the top left corner of the framebuffer, or in an X window. The console will tell you which renderer is being used:

... GL Vendor: "ARM" GL Renderer: "Mali-400 MP" GL Version: "OpenGL ES 2.0" ...

Success!

Mesa libraries are still in the way
If your are seeing this:

libEGL warning: failed to create a pipe screen for Mali DRI2 libEGL warning: DRI2: failed to open Mali DRI2 (search paths /usr/lib/arm-linux-gnueabihf/dri)

Then the current best advice is to move the mesa-egl aside:

 mv /usr/lib/arm-linux-gnueabihf/mesa-egl/ /usr/lib/arm-linux-gnueabihf/.mesa-egl/

Awkward, but at least gets you something workable.

Missing X symbols
symbol lookup error: /usr/lib/libGLESv2.so.2: undefined symbol: XextCreateExtension

This is due to bad library dependencies of the libMali.so binary we have been given. We have worked around it in our manually built libUMP.so. Check that the loaded libUMP.so is the manually built one. You can find currently active libUMP.so with "ldd gles2_application" - command

= Media Acceleration driver =

Add info here about getting CedarX running.