Etna viv

From Wandboard Wiki
Revision as of 13:43, 30 December 2014 by Tapani (Talk | contribs) (Created page with "= etna_viv (still under Construction) = The fresh and experimental open source driver to replace the proprietary Vivante blobs. It needs mesa to work which renders to a frameb...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

etna_viv (still under Construction)

The fresh and experimental open source driver to replace the proprietary Vivante blobs. It needs mesa to work which renders to a framebuffer device. So there is no DRI driver for this yet. This article shall provide the necessary steps on how to build etna_viv, and later how to build mesa as well. These two components should enable you to build powerful 3D applications without the curse of Vivante.

Motivation

Since I needed better debug tools for my graphics environment I decided to give etna_viv a shot. This Page describes how to build the whole thing for the Wandboard Quad. May be there are some differences between the other boards but I cannot tell you since I don't have them. I'd rather like someone else checks this out and adds the results on this page.

Prequesites

In order to build etna_viv you have to install at least the arm-gcc compiler from your repository. The Libraries are optional if you want to build the examples too.

GCC

You have to install the GCC Compiler Suite for Cross Compiling (on Ubuntu/Mint):

apt-get install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf

LIBZ (optional)

You have to cross compile and integrate LibZ into the previously installed Compiler Toolchain (you could link against it using Environement Variables but I'm lazy and since I may need them again I might as well integrate them)

1. Get the Sources from here

2. uncompress them into a directory of your choice

3. open the directory in a terminal of your choice

4. set the compiler executables:

export CC=arm-linux-gnueabihf-gcc
export AR=arm-linux-gnueabihf-ar
export STRIP=arm-linux-gnueabihf-strip
export RANLIB=arm-linux-gnueabihf-ranlib

5. configure the package:

./configure --prefix=/usr/arm-linux-gnueabihf

6. you may see what's coming but im still telling you :) :

make
sudo make install

7. Profit: you've successfully installed zlib into your compiler tool chain

LIBPNG (optional)

Long story short the etna_viv uses pnglib which needs zlib in order to build its samples:

1. Get the sources from here

2. configure the package after decompression:

./configure --host=arm-linux-gnueabihf CC=arm-linux-gnueabihf-gcc \
AR=arm-linux-gnueabihf-ar STRIP=arm-linux-gnueabihf-strip \
RANLIB=arm-linux-gnueabihf-ranlib CPPFLAGS="-mfpu=neon -I/usr/arm-linux-gnueabihf/include" \
--prefix=/usr/arm-linux-gnueabihf/ LDFLAGS="-L/usr/arm-linux-gnueabihf/lib"

3. build via:

make
sudo make install

Pitfall:In my case it failed building because it could not find a "zconf.h". So I symlinked this file from /usr/include/x86_64-linux-gnu/ where it is placed. If you encounter the same problem just make a symlink to this file an place it in the /usr/include directory.

4. profit now you should be able to build the etna_viv source

Building etna_viv

1. check out the source repository via git:

git clone https://github.com/laanwj/etna_viv.git

or download the zip on github

2. fix makefiles: all the makefiles are missing the pthread LD reference so they will not link. Fix this by opening Makefile.inc which is located in the top level of the source directory. Add -lpthread to LDFLAGS += $(PLATFORM_LDFLAGS) $(COMMON_FLAGS) -lm (the last line). I also filed this as a bug and it is likely to be fixed soon. The maintainer also sugessted to use -pthread (without the l) to be added to the GCCFLAGS, since it at least built fine on my machine without I leave it as it is.

The author fixed this so if you pulled your repository recently you can now proceed to the next step

2. create an include directory in the top level of the source directory and add the OpenGL/EGL/KHR include directories to them. Problem is where to get those. I found a OpenGL ES emulator library on my computer and used those includes. You can check out the Mesa Repository here for etna_viv (you'll need it anyways soon) and use the include files provided.

3. place a script called "setup.sh" source (src) directory of the etna_viv package. Containing this:

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
export GCCPREFIX="arm-linux-gnueabihf-"
export PLATFORM_CFLAGS="-I/usr/arm-linux-gnueabihf/include -I${DIR}/include"
export PLATFORM_CXXFLAGS="-I/usr/arm-linux-gnueabihf/include -I${DIR}/include"
export PLATFORM_LDFLAGS="-L/usr/arm-linux-gnueabihf/lib -ldl -L${DIR}/lib"
# These point to the vivante libs that are only used for reverse engineering
export PLATFORM_GL_LIBS="-lEGL -lGLESv2 -L${TOP}/lib/egl -Xlinker --allow-shlib-undefined"
# Set GC kernel ABI to dove (important!)
#export GCABI="dove"      # 0.8.0.3184
export GCABI="imx6_v4_1_0"

it is basically the script from the README.md but I changed the last line to export GCABI="imx6_v4_1_0". This information is based on the BSP you use. Since I want to develop on a yocto image of the development branch, I have to use the Freescale Community BSP 4.1.0.

You may have the change it matching yours. Don't forget to set +x or else the script will not execute.

4. call the script (with both dots in front of them):

. ./setup.sh

now you have setup your build environment.

5. call (yes you know the drill):

make

Building Mesa

Preface

I use yocto to build my runtime image so it is highly unlikely that the etna_viv driver is included. It eventually becomes but integrated as it becomes more stable but until now we have to do it the hard way. Which involves setting paths and symlinking stuff. So before you continue I recommend building a core-image-base (of the development branch) with yocto. It's quite straight forward and you should not have any trouble if you follow the tutorial.This is necessary because mesa needs some parts from the OS to work. Also it does some dirty work for you like building libudev which is a dependency of mesa. I also recommend not to place the resulting libs in the arm-linux-gnuabihf compiler directory since the libs are highly platform dependent and therefore you may want to keep things clean for other platforms than the wandboard.

Requirements

to build mesa you need to build libexpath and libdrm.

expat

You need to build expat for mesa so first of all download it here. Also You need to have cvs (once upon a time, there was a ...) and cmake and best cmake-gui installed in order to build expat. Because the configure script does not work, is why you need to use cmake. But it is a good tool with a nice user interface so no harm done.

1. Install these components. On a ubuntu like OS this will be:

sudo apt-get install cvs cmake cmake-gui

2. After installing this you need to download expat. The webpage tells you how just follow the instructions.

3. once this is done open the folder created by cvs and create two sub folders into it. build and install. cmake always builds out of the source tree so this is what the folders are for.

4. start cmake-gui. Here you enter the paths where the sources are and where the build goes. So specify your expat directory and then set the build directory to the expat/build folder. The locations where to do this are easy to find.

5. after hitting configure cmake-gui asks you what measures it should use to build. Of course you want a cross build for ARM so "specify native compilers" and then set the following:

c: /usr/bin/arm-linux-gnueabihf-gcc
c++: /usr/bin/arm-linux-gnueabihf-g++

this may differ depending which compilers you use. So set the appropriate binaries matching your compiler. I used the same one here, I used in the rest of the article. Hit finish to close the window.

6. The last setting is to tell cmake where to install the files. This is what the install directory is for. So set the CMAKE_INSTALL_PREFIX Variable in list box below the paths to the expat/install directory.

7. hit configure again followed by generate. Which generates the makefiles. Start building by opening the expat/build directory in a terminal. It is build and installed with the well known make commands.

make
make install

8. now you are ready to build the next library.

libdrm

1. To build libdrm you first pick the latest archive from here 2. Then decompress it and this enter this configure command:

./configure --target=${TARGET} --host=${TARGET} --disable-cairo-tests

3. make and sudo make install the thing.

4. you are done with the prequel.

building Mesa

I assume you followed my advice and builded a yocto core-base-image. This downloads a lot of libraries and compiles them and afterwards. Also dd-ing the image onto the target SD card will be helpful.

1. Check out the repository

2. create a "setup.sh" file with execute permissions containing this:

#!/bin/bash
DIR=... # path to target headers and libraries
GIT_PROJDIR=/home/kneo/System/git-checkouts
ETNAVIV_BASE="${GIT_PROJDIR}/etna_viv"
ETNAVIV_LIB="${ETNAVIV_BASE}/src/etnaviv" # important!
ETNAVIV_INC="${ETNAVIV_BASE}/src" # important!

ARMGCCHOME=/usr/arm-linux-gnueabihf

export TARGET="arm-linux-gnueabihf"

export CFLAGS="-I${ARMGCCHOME}/include -I${ETNAVIV_INC} -I${GIT_PROJDIR}/expat/install/arm/include"
export CXXFLAGS="-I${ARMGCCHOME}/include -I${ETNAVIV_INC} -I${GIT_PROJDIR}/expat/install/arm/include"
export LDFLAGS="-I${ARMGCCHOME}/lib -L${ETNAVIV_LIB} -L${GIT_PROJDIR}/expat/install/arm/lib"
export LIBDRM_LIBS="-L${ARMGCCHOME}/lib -ldrm"

export ETNA_LIBS="-letnaviv" # important!
export LIBTOOL_FOR_BUILD="/usr/bin/libtool" # important!

export LIBUDEV_CFLAGS="${GIT_PROJDIR}/yocto-wandboard/fsl-community-bsp/build/tmp/sysroots/wandboard-quad/usr/include"
export LIBUDEV_LIBS="${GIT_PROJDIR}/yocto-wandboard/fsl-community-bsp/build/tmp/sysroots/wandboard-quad/lib -ludev"

I have a structure for my projects because, I'm lazy, as I mentioned earlier. So If you spread your files all over your system you have to match the paths in this file in order to build mesa.

3. You need to symlink libudev in the /yocto-wandboard/fsl-community-bsp/build/tmp/sysroots/wandboard-quad/lib directory to libudev.so, since it contains version number and thus the stuborn ld will not find it. Symlinking fixes that.

4. call the following ./configure:

/configure --target=${TARGET} --host=${TARGET} --enable-gles2 \
--enable-gles1 --disable-glx --enable-dri --enable-egl \
--with-gallium-drivers=swrast,etna --with-egl-platforms=fbdev \
--enable-gallium-egl --enable-debug --with-dri-drivers= \
--prefix=${GIT_PROJDIR}/mesa-etnaviv/build

changing the path to your system applies here too.

5. build & install via:

make
make install

6. congratulations! you are now have an ARM mesa cross build with an integrated etna_viv driver.

Deploying

Now that you are done you need to copy all the stuff we just built onto your device.

1. Since I used a yocto image this includes some work since the partitions of my image are to small to keep all this stuff. So using parted or gparted to increase the size of the data partition of the SD card are helpful.

2. Once done you can copy the compiled libs from the build directory into the /usr/ prefix of your SD card. should be easy to find since there are only two paritions. One with a directory struction (Data partition) and one with a single file (Boot partition).

3. Copy the built etna_viv directory in the /home/root directory of the SD card.

4. safely remove the SD card and insert it into your wandboard.

5. try the examples shipped in the etna_viv directory.

FYI: I'm told that "the samples hang" if your screen resolution height is not dividable by 8. If you have a 1080p screen you can safely ignore this advice but it should be fixed soon see this as another pitfall though.

Research Updates (look here for latest infos)

  • --------

The disappointing part is that for now only the examples from the 2dtest work which spill out some image into the /tmp/ directory on the SD card. The 3D examples are not working yet. As well as the utilities of the reverse engineering framework. So there is the next construction site. I'll look into it as soon as I'm free of exams so free to test this tutorial through and feed me back if your find some errors or encounter pitfalls not mentioned here.

  • Update 18.3.2014:

This is taking longer than expected. I'm currently working through a lot of files, as I try to figure out what doesn't work why. No luck so far. Yocto isn't a big help either. Since it misses some linux kernel files I need to build a working etna_viv. I downloaded the Freescale Community BSP 4.0.0 to see if there are files hidden.

  • Update 19.3.2014:

It seems the Yocto BSP is kind of ancient.Even though I wanted to use the master branch. The good thing is: I finally found the missing gc_*.h files for within the jungle of the yocto directory structure, yet there are still files missing. Compared to the "include" folders shipped with etna_viv there are a lot of files missing.

This brings me to the conclusion that the yocto image uses outdated BSP files. The header files also mention "confidential" stuff instead of the GPL header the newer files have. So my next step is to find out how to convince yocto how to use a more recent BSP and kernel. I think I'm a big step closer to a working driver.


  • Update 25.03.2014

I built the kernel 3.10 using yocto just to find out it uses the same old BSP files. I need to figure out how to integrate a newer Version of the Freescale Linux BSP into yocto. Doing that I'm hopefully able to build a working Version of Mesa and Etna_viv. If you look through the files shipped with Etna_viv you find out that the header files used in yocto builds are somewhat different. There are even files missing. To fix that a kernel build with the "new" is needed in order to operate correctly.

Still a big under construction sign on this page. So stay tuned and contribute if you can.

So long ...