Saturday, January 10, 2015

Vivante GPU on i.MX6

Installation of GPU driver on i.MX6 SabreLite. The support libraries for the i.MX6 GPU are available in the Yocto project release for i.MX6: the notes below are for using the binary release files with a Ubuntu rootfs (debootstrap) install.

References:
Frescale Linux 3.10.17_1.0.0 GA Release (registration required)
Direct link to i.MX 6Dual/6Quad Linux Reference Manual (BSP release L3.0.35_4.1.0) uploaded to Freescale forum - Chapter 9 Graphics Processing Unit
Direct link to i.MX 6 Linux Reference Manual (BSP release L3.10.17_1.0.0-ga) uploaded to Freescale forum (Chapter 13 Graphics Processing Unit.)
Summary of L3.10.17_1.0.2 i.MX 6 Yocto Project Patch Release


Installing Xorg

With the system bootstrapped to Ubuntu 13.10, a minimal Xorg 1.14.6 (runs xterm but no window manager) can be installed as follows:

apt-get install --no-install-recommends xserver-xorg-core xserver-xorg-input-all xserver-xorg-video-fbdev
apt-get install xinit

Run startx and make sure an xterm shows up. Make sure the following entry exists in /etc/apt/sources.list and install mesa-utils:

deb http://ports.ubuntu.com/ubuntu-ports saucy universe

With everything setup correctly so far, glxgears -info shows the following:

GL_RENDERER   = Software Rasterizer
GL_VERSION    = 1.4 (2.1 Mesa 9.2.0)
GL_VENDOR     = Mesa Project
GL_EXTENSIONS =
423 frames in 5.1 seconds = 83.247 FPS


Installing Binary GPU Libraries

Download BSP components to use with kernel boundary-imx_3.10.17_1.0.0_ga:

http://downloads.yoctoproject.org/mirror/sources/xserver-xorg-video-imx-viv-3.10.17-1.0.2.tar.gz
http://downloads.yoctoproject.org/mirror/sources/gpu-viv-bin-mx6q-3.10.17-1.0.2-hfp.bin


Setup gpu-viv-bin-

The system may already have files which the content of gpu-viv-bin- will overlap. This can be checked as follows:

debian@arm:~/yocto/gpu-viv-bin-mx6q-3.10.17-1.0.0-hfp/usr$   for fn in `find`; do [ -f /opt/xorg/$fn ] && ls /opt/xorg/$fn && done

On Ubuntu, the existing libraries will need to be removed from arm-linux-gnueabihf-mesa and arm-linux-gnueabihf-mesa-egl. Alternatively, they can be hidden from ld.so by commenting entries in /etc/ld.so.conf.d/arm-linux-gnueabihf_GL.conf etc. (you may see that those are links to corresponding files in  /etc/alternatives/).

On Debian, libGL.so and company are installed into /usr/lib.

My system wanted to prioritize the from-scratched libraries in /opt/xorg, so I had to resort to explicitly setting the library path order in order to pick up the blobs from /usr/lib:

LD_LIBRARY_PATH=/lib/arm-linux-gnueabihf:/usr/lib/arm-linux-gnueabihf:/usr/local/lib:/usr/lib:/opt/xorg/lib


Confirming DRI device

The running kernel must be built with CONFIG_DRM_VIVANTE=m and CONFIG_MXC_GPU_VIV=y (add 'vivante' to /etc/modules'). Verify that vivante and drm modules are loaded. 

Install '/etc/udev/rules.d/10-imx.rules' (from FSL github) and verify the rule for /dev/galcore i.e. "KERNEL=="galcore", MODE="0660", GROUP="video":

One additional rule to add:
KERNEL=="mxc_asrc",  MODE="0666"


Verify that the device nodes appear as follows ...

crw-rw---- 1 root video 226, 0 Jan 10 17:31 /dev/dri/card0
crw-rw-rw- 1 root root 199, 0 Jan 10 17:18 /dev/galcore

Also, make sure your user had been added to group 'video' e.g.

sudo usermod -a -G video ubuntu

(Remember this hint when glxgears stubbornly defers to rasterizer instead of GC2000!)


od /dev/dri/card0 # this works while X running, otherwise 'Invalid argument'


Testing with Vivante (FB) tutorials
Before trying to build the Vivante EXA driver for Xorg, first try to test GPU acceleration in the framebuffer. Exit X if it is running.

Refer to Table 13-2 of i.MX 6 Linux Reference Manual for overview of the GPU Library structure. For each library, a symbolic link must be made from either the X11 or the framebuffer version to the soname (this was documented a bit more explicitly in the L3.0.35_4.1.0 Linux manual):

        cd /usr/lib
        rm libGAL.so
        rm libEGL.so
        rm libEGL.so.1
        rm libVIVANTE.so
        sudo ln -s libGAL-fb.so libGAL.so
        sudo ln -s libEGL-fb.so libEGL.so
        sudo ln -s libEGL-fb.so libEGL.so.1
        sudo ln -s libVIVANTE-fb.so libVIVANTE.so

Be sure to change to the directory containing the tutorial e.g. 'opt/viv_samples/vdk/' otherwise it will fail silently if it unable to open any files it is expecting to exist in the current working directly.

Tutorial may also fail silently if ld.so paths are not setup properly, or udev rules not configured correctly (refer to previous section).


Testing with X

Refer to Chapter 18 of Linux Reference Manual L3.10.17_1.0.0-ga for background information. Assuming the library sonames need to be relinked to the -x11 versions:

        cd /usr/lib
        rm libGAL.so
        rm libEGL.so
        rm libEGL.so.1
        rm libVIVANTE.so
        rm libGLESv2.so
         ln -s libGAL-x11.so libGAL.so
         ln -s libEGL-x11.so libEGL.so
         ln -s libEGL-x11.so libEGL.so.1
         ln -s libVIVANTE-x11.so libVIVANTE.so
         ln -s libGLESv2-x11.so libGLESv2.so
         ln -s libGLESv2-x11.so libGLESv2.so.2


Building the Vivante Xorg EXA Driver

apt-get install xserver-xorg-dev

If $xorg is something different from default i.e. "/usr" it could present a problem, as system include files are referenced in the following manner:

 -I$(sysroot)/usr/include

If the $xorg string does not end in 'usr', then it requires modification to all occurrences of $(sysroot)/usr in EXA/src/makefile.linux

In addition, the path to libdrm includes may need modified e.g.

LOCAL_CFLAGS += -I$(sysroot)/include/libdrm

If all is well, vivante_drv.so will be built with the following compile line (addition of sysroot= if necessary):

BUILD_HARD_VFP=1 XSERVER_GREATER_THAN_13=1 BUSID_HAS_NUMBER=1 ./fastbuild.sh sysroot=/opt/xorg

Install the EXA driver:

sudo cp EXA/src/vivante_drv.so /opt/xorg/lib/xorg/modules/drivers/


The Vivante driver must be enabled in /etc/X11/xorg.conf - the file may not even exist on the system yet since it is typically not needed for the default framebuffer driver. A minimal xorg.conf is adequate to get my system working.

After firing up xorg (startx or window manager if one is installed), verify in Xorg.log that Vivante is loaded:

[  1610.413] (II) VIVANTE: driver for vivante fb: VivanteGC500, VivanteGC2100,
        VivanteGCCORE

You should not see this:

[    90.587] (II) GLX: Initialized DRISWRAST GL provider for screen 0

Everything should now be in place for glxgears.

debian@arm:~$ glxgears -info
GL_RENDERER   = Vivante GC2000
GL_VERSION    = 2.1 2.0.1
GL_VENDOR     = Vivante Corporation
GL_EXTENSIONS = WGL_ARB_extensions_string WGL_EXT_extensions_string WGL_EXT_swap_control GL_EXT_texture_env_add GL_ARB_multitexture GL_ARB_multi
...
875 frames in 5.0 seconds = 174.912 FPS


If things are not setup correctly, glxgears does not perform as expected (e.g. jerky display) or possibly not at all. If Xorg confirmed to have loaded VIVANTE, and glxgears output appears as below (uses software rasterizer), and the framebuffer tutorials worked, it's likely a permissions problem (check that your user is added to group video ... you were warned!)

debian@arm:~$ glxgears -info
libGL error: open DRM failed (Operation not permitted)
libGL error: reverting to (slow) indirect rendering
GL_RENDERER   = Software Rasterizer
GL_VERSION    = 1.4 (2.1 Mesa 9.2.0)
GL_VENDOR     = Mesa Project
GL_EXTENSIONS =
423 frames in 5.1 seconds = 83.247 FPS


Chapter 18 of Linux Reference Manual L3.10.17_1.0.0-ga makes it pretty clear that the drm-update-arm.patch must be applied to libdrm ("adding the ARM lock implementation", which might be a compelling reason to build xorg-xserver from source.

Next exercise is to build glmark2 and mesa-utils.


10 comments:

  1. Hi Glenn,

    Thanks for your post.
    I am testing with vivante(fb) tutorials.So, i am only following the steps given for "confirming dri device" and "testing with fb". But, still hardware acceleration i am not able to see.
    Do i need to install xserver-xorg-video-imx-viv-3.10.17-1.0.2.tar.gz for compiling even with fbdev libraries?
    Is there anything else i need to do?

    Thanks in advance

    ReplyDelete
  2. xserver-xorg-video-imx-viv-3.10.17-1.0.2.tar.gz isnt needed for what you are doing and X shouldn't be running. Are the kernel modules drm and vivante loading and also grep syslog for Galcore. THis is for linux 3.10.17 on i.MX6q?

    ReplyDelete
  3. Hi Glenn,

    I've been struggling over and over to try and get this to work
    Sadly i've pretty much done everything you've suggested, and yet all i get is a "driver exports no extensions (missing symbol __driDriverExtensions)" error and XOrg decides to revert to swrast....

    Can you help me out ? I'm starting to get pretty desperate from all this

    ReplyDelete
  4. Hello Fira,
    You can take a look at this post:
    http://pushpopmov.blogspot.com/2015/01/glmark-and-mesa-demos-xorg-from-scratch.html
    ... where I reported encountering similar error on driDriverExtensions, as I recall running into this kind of problem when the library loader is finding the package installed libGL before the one installed from the Freescale binaries. If you haven't already, take a look at my later blogs in the series - it's a bit wordy but hopefully you would get a working system if you can replicate those steps. Good luck!
    -GN

    ReplyDelete
  5. hi Glenn,
    thank you for this tutorial, it is one of the most helpful that I have found so far. Anyway I still have some problems getting my X11 system to use the vivante stuff. I followed your stept to the point where X should load the driver that I've build. My display goes fuzzy and I see in Xorg.0.log the following lines:

    [ 831.394] (II) EXA(0): Driver registered support for the following operations:
    [ 831.394] (II) Solid
    [ 831.394] (II) Copy
    [ 831.394] (II) Composite (RENDER acceleration)
    [ 831.394] (II) UploadToScreen
    [ 831.394] (EE) VIVANTE(0): internal error: GPU Ctx Init Failed
    [ 831.394] (EE) VIVANTE(0): internal error: initExaLayer failed in FBDevScreenInit()
    [ 831.394] (II) VIVANTE(0): Init SHM pixmap support
    [ 831.394] (==) VIVANTE(0): Backing store enabled
    [ 831.395] (==) VIVANTE(0): DPMS enabled
    [ 831.395] (II) VIVANTE(0): RandR 1.2 enabled, ignore the following RandR disabled message.
    [ 831.395] drmOpenDevice: node name is /dev/dri/card0
    [ 831.395] drmOpenDevice: open result is 11, (OK)
    [ 831.396] drmOpenDevice: node name is /dev/dri/card0
    [ 831.396] drmOpenDevice: open result is 11, (OK)
    [ 831.396] drmOpenByBusid: Searching for BusID platform:Vivante GCCore:00
    [ 831.396] drmOpenDevice: node name is /dev/dri/card0
    [ 831.396] drmOpenDevice: open result is 11, (OK)
    [ 831.396] drmOpenByBusid: drmOpenMinor returns 11
    [ 831.396] drmOpenByBusid: drmGetBusid reports platform:Vivante GCCore:00
    [ 831.396] (II) [drm] DRM interface version 1.4
    [ 831.396] (II) [drm] DRM open master succeeded.
    [ 831.396] (II) VIVANTE(0): [drm] Using the DRM lock SAREA also for drawables.
    [ 831.396] (II) VIVANTE(0): [drm] framebuffer handle = 0x44400000
    [ 831.397] (II) VIVANTE(0): [drm] added 1 reserved context for kernel
    [ 831.397] (II) VIVANTE(0): X context handle = 0x1
    [ 831.397] (II) VIVANTE(0): [drm] installed DRM signal handler
    [ 831.397] (II) VIVANTE(0): [DRI] installation complete
    [ 831.397] (--) RandR disabled
    [ 831.434] (II) SELinux: Disabled on system
    [ 831.439] (II) AIGLX: Screen 0 is not DRI2 capable
    [ 831.439] (EE) AIGLX: reverting to software rendering
    [ 831.453] (II) AIGLX: Loaded and initialized swrast
    [ 831.453] (II) GLX: Initialized DRISWRAST GL provider for screen 0
    [ 831.456] (II) VIVANTE(0): Setting screen physical size to 211 x 127
    [ 831.460] (EE)
    [ 831.460] (EE) Backtrace:
    [ 831.460] (EE)
    [ 831.461] (EE) Segmentation fault at address 0x0
    [ 831.461] (EE)
    Fatal server error:
    [ 831.461] (EE) Caught signal 11 (Segmentation fault). Server aborting
    [ 831.461] (EE)

    have you ever seen something like this or could give me a hint how to go on?

    ReplyDelete
  6. Hi Christian,
    I noticed you're getting the " GPU Ctx Init Failed" and "initExaLayer" errors. Maybe Xorg is running into problems with the version of vivante_drv.so. The system I am running now has binaries from gpu-viv-bin-mx6q-3.10.31-1.1.0-beta-hfp, and vivante_drv.so is built from xserver-xorg-video-imx-viv-3.10.31-1.1.0-beta. This is on Xorg 1.16.4 - these aren't exactly the newest versions, so if you are using something different, well .. YMMV as they say. Good luck, -GN.

    ReplyDelete
  7. Hi,

    We have 3 GUI windows created through x11 and vivante driver used to update FB0. All the UI windows configured with RGBA format. UI windows are composited and updated to FB0 with RGB values for the pixels and A(alpha is not updated to FB0). We have taken the screen shot of X11 root window image that is having RGBA informations. So Vivante is the next level to update it to FB0. So what should be checked for this problem or can we configure FB0 handle to X11 root window directly?

    ReplyDelete
  8. Hi Glenn,

    We have configured X11 windows as RGBA and FB0 is configured with 32 bit per pixel and we have configured Local alpha in pixel mode to FB0, so that it blend with FB1 through FB0 alpha values. and we have configured xorg to use vivante dricer. But when we update the X11 window with RGBA, the output to the FB0 is updated with RGB only. Alpha values are not updated. Have you seen this problem any where?

    ReplyDelete
  9. Hello Glenn,

    I do have installed ubuntu rootfs on imx6 device and now adding Vivante GPU support:

    > wget http://www.nxp.com/lgfiles/NMG/MAD/YOCTO//xserver-xorg-video-imx-viv-5.0.11.p7.4.tar.gz
    > tar –xf xserver*
    > cd xserver-org-video-imx*
    > ./fastbuild.sh BUILD_HARD_VFP=1 XSERVER_GREATER_THAN_13=1
    make: Entering directory '/root/gpu_pack/xserver-xorg-video-imx-viv-5.0.11.p7.4/EXA/src'
    gcc -DCOMMIT="`git log -n 1 --format=%H``git diff-index --quiet HEAD || echo '-dirty'`" -DFIX_NO_MI_BACKINGSTORE -fvisibility=hidden -fPIC -DPIC -DFREESCALE_EXTENSION -I. -I.. -I//usr/include -I//usr/include/xorg -I//usr/include/pixman-1 -I./vivante_gal -I./vivante_fbdev -I./vivante_util -I./vivante_exa -I./vivante_extension -I//usr/include/drm -mfpu=vfp -mfloat-abi=hard -march=armv7-a -marm -O2 -Werror -o vivante_extension/vivante_ext.o -c vivante_extension/vivante_ext.c
    fatal: your current branch 'master' does not have any commits yet
    fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree.
    Use '--' to separate paths from revisions, like this:
    'git [...] -- [...]'
    vivante_extension/vivante_ext.c:50:21: fatal error: swaprep.h: No such file or directory
    compilation terminated.
    makefile.linux:82: recipe for target 'vivante_extension/vivante_ext.o' failed
    make: *** [vivante_extension/vivante_ext.o] Error 1
    make: Leaving directory '/root/gpu_pack/xserver-xorg-video-imx-viv-5.0.11.p7.4/EXA/src'

    Please can you advice why ./fastbuild.sh run with error ?
    What possibly missing from compile?

    ReplyDelete
  10. I have some issues with Vivante GPU.
    Why is it must to have setting CONFIG_DRM_VIVANTE=m and CONFIG_MXC_GPU_VIV=y? What would it mean if you would use config with CONFIG_DRM_VIVANTE=y?

    ReplyDelete