Sunday, March 8, 2015

X.org Patched and Packaged for i.MX6 on Debian

In the previous installment, I described how to build a minimal xserver using X.org modular build script, in order to incorporate a supposedly critical patch to xf86drm.h for the arm architecture. Following on to that experiment, X.org will now be installed mostly from .deb packages, using the Debian package builder to create patched versions of libdrm, mesa, and xorg-server. The motivation for this is to avoid creating a system from a mix of source-built and package-installed software, which generally proves to be a pain to maintain. Unfortunately, for accelerated GPU support, the only viable option is the binary package released by Freescale through the Yocto project - this will introduce another set of headaches (always fighting with ldconfig for priority of /usr/lib/libGL.so etc.), due to not being packaged per Debian or Ubuntu standards. 

Take a look at my previous post.for advice on creating a chroot environment - as is highly recommended for package building - to ensure that the packages are built on a clean system with all dependencies correctly met. The primary purpose of the chroot is solely to make software builds. However, it's worth noting that by the time you work through all the steps, you'll have pretty much everything installed in the chroot to actually run the graphical server. In fact, it's even possible to install and run with GPU acceleration in this chroot configuration (but pretty certain that the GPU support should NOT be installed on the clean build system ... see notes on glmark below).

Configuring this system with the minimum amount of package rebuilding, being very careful of the order of packages installed, and ensuring that the patched packages are actually installed, requires a fair amount of familiarity/creativity with dpkg and aptitude which is not given in great detail here ... may improve or simplify as I expand my knowledge of these tools.

Before entering the chroot environment, it is strongly suggested to create the various standard system mount points - they're not always needed but it's a real good idea: 

sudo mkdir $chroot/run/udev # must be created manually

mount --bind /proc $chroot/proc
mount --bind /run/udev $chroot/run/udev
mount --bind /dev $chroot/dev
mount -t devpts none $chroot/dev/pts
mount --bind /sys $chroot/sys # needed for proper 'LoadModule: "evdev"'

# suggest adding a little sugar to shell prompt in the chroot:
# echo >> $chroot/home/user/.bashrc ...
text=" xorg_drm"
export PS1='\[\e[1;32m\]\u@\h:\w${text}$\[\e[m\] '

With the following additions to $chroot/etc/apt/sources.list, xorg-xserver-1.15.0 will be installed (compatibility with Kernel and i.MX6-Vivante-GPU-blobs 3.10.31 series). :

deb http://snapshot.debian.org/archive/debian/20140320T161557Z/ jessie main
deb-src http://snapshot.debian.org/archive/debian/20140320T161557Z/ jessie main

Using some information found over at hackedbellini to incorporate the following setup:

cat $chroot/etc/apt/preferences.d/xorg-xserver
Package: xserver-*
Pin: origin "snapshot.debian.org"
Pin-Priority: 1001

Force mesa-9.2 series (problems encountered with location of .drirc in mesa-10.1.0, which can probably be sorted out with a little more effort):

Package: *mesa-*
Pin: origin "snapshot.debian.org"
Pin-Priority: 1001

Package: *-mesa*
Pin: origin "snapshot.debian.org"
Pin-Priority: 1001

# Switch into the chroot environment and continue setup ... 
# suppress "Valid-Until" warnings from apt-get:
apt-get -o Acquire::Check-Valid-Until=false update 

# Get some prerequisites installed (there may be more):
apt-get install build-essential fakeroot devscripts

The Debian build system is plenty well documented in other places so expect a lot of details to be glossed over. 

On the build system, a lot of packages will be installed by apt-get build-dep, but there are also notes on packages installed explicitly by apt-get install (but be careful in case the information is not complete). 

Building and installing patched libdrm
By default, the package system will build some sub-modules such as nouveau and radeon that aren't needed on i.MX6, or may have to be present to satisfy other package dependencies. See debian/rules and my previous post for ideas on configurable options that can be disabled. Getting on with it ...

cd pkgsrc/libdrm 
apt-get source libdrm
wget https://raw.githubusercontent.com/Freescale/meta-fsl-arm/master/recipes-graphics/drm/libdrm/mx6/drm-update-arm.patch

cd libdrm-2.4.52
dpkg-checkbuilddeps # not a bad idea to check what dependencies will be installed

apt-get build-dep libdrm

cp  ../drm-update-arm.patch debian/patches/80-drm-update-arm.patch
echo 80-drm-update-arm.patch >> debian/patches/series
debuild -b -uc -us

dpkg-buildpackage -b -j4 -us -uc  # alternative to debuild - note -j option to use those cores!

Should see something like this happening in the configuration phase:

Applying patch 10_drm-update-arm.patch
patching file xf86drm.h

At a minimum, install the following from pkgsrc/libdrm (or just do dpkg -i pkgsrc/*\.deb):

dpkg -i libdrm2_2.4.52-1_armhf.deb libdrm-dev_2.4.52-1_armhf.deb libdrm-nouveau2_2.4.52-1_armhf.deb libdrm-radeon1_2.4.52-1_armhf.deb libdrm-omap1_2.4.52-1_armhf.deb

The arm patch should now be merged into /usr/include/xf86drm.h, verify if unsure!

Building mesa against patched system
By default, the package system will build a kitchen-sink Mesalib ... see debian/rules for the configuration options.

mkdir pkgsrc/mesa
cd pkgsrc/mesa
apt-get source mesa

cd mesa-10.1.0  # todo recheck that I have mesa-10 installed

Make sure libdrm dependencies already met - advise verifying that apt agrees that the libdrm dependencies installed by dpkg are actually installed:
dpkg-checkbuilddeps 

apt-get build-dep mesa  # check first with apt-get -s if super paranoid 

debuild -b -uc -us

An odd thing I noticed, was a second configuration phase in the mesa build ... GLESv2 finally appears on the second pass.

        OpenGL:          yes (ES1: no ES2: no)

        OpenGL:          yes (ES1: yes ES2: yes)


If the mesa build completes successfully, the next module to build is xorg-server, which requires a slew of dependencies to be installed. The freshly built mesa libs should be installed ahead of running apt-get build-dep xorg-server. Suggest first running apt-get -s to verify what will be installed. Pretty sure there is a more efficient way but I don't know the tricks yet.

apt-get install libdrm-freedreno1 libelf1 libexpat1  libllvm3.3 libllvm3.5 libwayland-client0 libwayland-server0  libx11-xcb1 libxcb-dri2-0 libxcb-render0 libxcb-shape0 libxcb-xfixes0  libxfixes3

# here's another batch of 'em that can be knocked out now
apt-get install  keyboard-configuration libfontenc1 libfreetype6 libice6 libpciaccess0 libpixman-1-0 libpng12-0 libsm6  libtxc-dxtn-s2tc0 libxaw7 libxcb-glx0 libxdamage1 libxfont1 libxkbfile1  libxmu6 libxpm4 libxshmfence1 libxt6 libxxf86vm1 x11-common x11-xkb-utils  xfonts-base xfonts-encodings xfonts-utils xkb-data 

# keep going 
apt-get install libpthread-stubs0-dev libx11-dev libx11-doc libx11-xcb-dev libxau-dev  libxcb-dri2-0-dev libxcb-glx0-dev libxcb1-dev libxdamage-dev libxdmcp-dev libxext-dev  libxfixes-dev libxxf86vm-dev x11proto-core-dev x11proto-damage-dev x11proto-dri2-dev  x11proto-fixes-dev x11proto-gl-dev x11proto-input-dev x11proto-kb-dev x11proto-xext-dev  x11proto-xf86vidmode-dev xorg-sgml-doctools xtrans-dev

# At some point, the mesa packages can be installed ... or possibly even the whole shebang:
dpkg -i pkgssrc/mesa/*.deb

# expect dpkg to error out on the following, which should be ok.-
# just clean up the staged installs with dpkg -r
 libgl1-mesa-swx11_9.2.2-1_armhf.deb
 libgl1-mesa-swx11-dev_9.2.2-1_armhf.deb
 libgbm-dev
 libgl1-mesa-swx11-dbg:armhf

Building xorg-server against patched system

mkdir pkgsrc/xorg-server

cd pkgsrc/xorg-server

apt-get source xorg-server
cd xorg-server-1.15.0
dpkg-checkbuilddeps

apt-get build-dep xorg-server

debuild -b -uc -us  # dpkg-buildpackage -b -j4 -us -uc

# build-dep should have installed the needed support, but if not:
# double check not all dependencies needed if omitted these: 
# xdmx xdmx-tools xserver-xephyr

apt-get -s install libpciaccess-dev libpixman-1-dev libxkbfile-dev x11proto-dri3-dev x11proto-fonts-dev x11proto-present-dev x11proto-randr-dev x11proto-render-dev x11proto-resource-dev x11proto-scrnsaver-dev x11proto-video-dev x11proto-xf86bigfont-dev x11proto-xf86dri-dev x11proto-xinerama-dev 

Install away ... all except xdmx xdmx-tools xserver-xephyr

Wrapping it up
It doesn't take much more to get a minimal graphical system running - minimum meaning you only get an xterm - but no WM.

apt-get install keyboard-configuration xserver-xorg-video-fbdev xserver-xorg

# Install at least these from the xserver-xorg builds if you 
# haven't already ...

dpkg -i xserver-common_1.15.0-2_all.deb  xserver-xorg-core_1.15.0-2_armhf.deb xserver-xorg-dev_1.15.0-2_armhf.deb

# ...almost there:

apt-get install xinit

Finally, it should be time for the startX moment. Did it work?

What next?
A few more steps are required to enable GPU acceleration in X11 on i.MX6. For bonus points, build .debs for mesa-utils (glxgears, glxinfo) and mesa-utils-extra (es2gears, es2info). They are dependent upon xf86drm.h, although at this time I haven't confirmed the failure mode of the stock packages built against the unpatched header.

AFAIK, source packages not required for these
apt-get install libglew1.10 libglu1-mesa 

apt-get source mesa-utils
apt-get source mesa-utils-extra

Finally, glmark-es2 seems to be available only in source code. Not a problem! Expect complications to arise with the Yocto packages installed on the system e.g. breaks the glmark-es2 build:


In file included from /usr/include/EGL/eglplatform.h:38:0,
                 from /usr/include/EGL/egl.h:39,
                 from ../src/gl-state-egl.h:26,
                 from ../src/main.cpp:48:
/usr/include/EGL/eglvivante.h:242:2: error: #error "Platform not recognized"
 #error "Platform not recognized"

A working build environment for glmark2 can be created on a chroot filesystem, featuring the patched libdrm and those mesa and xorg-server packages (built against the patched libdrm) installed ... DO NOT install the GPU headers or libs from Yocto on your clean chroot filesystem.

To wrap it up, noting the versions of support packages used so far:
http://downloads.yoctoproject.org/mirror/sources/xserver-xorg-video-imx-viv-3.10.31-1.1.0-beta.tar.gz
http://downloads.yoctoproject.org/mirror/sources/gpu-viv-bin-mx6q-3.10.31-1.1.0-beta-hfp.bin

Sunday, February 22, 2015

Modular X.org on i.MX6

Getting X.org to work with the GPU blobs on i.MX6 has been challenging, largely in part to my lack of familiarity with the X.org neighborhood. Things seem to be finally working at least to a degree following an exacting process of patching libdrm-x.x.x/xf86drm.h (affects DRM_SPINLOCK, specific to arm architecture), and then rebuilding MesaLib, xorg-xserver and anything else referencing that header file. As of yet, I have not been able to make any kind of case to confirm or deny the exact failure mode without this patch.

With xorg-xserver-1.15.0 and related/matched packages built from source (mandated by the need to apply DRM_CAS patch to xf86drm.h), along with gpu blobs 3.10.31 series (corresponding to running kernel version)  ... glxgears, es2gears_x11 and glmark-es2 running accelerated. glmark-es2 seems to run correctly in this configuration, the only noticeable peculiarity being one demo suite that runs surprisingly slow (terrain). Packages used in this setup are:

xorg-server-1.15.0
xserver-xorg-video-imx-viv-3.10.31-1.1.0-beta
gpu-viv-bin-mx6q-3.10.31-1.1.0-beta-hfp

Hand-building X.org is enlightening but time consuming. It is slightly more efficient to build X.org with build.sh and automate most or all of the process ... the magic spell is something like:

./util/modular/build.sh -s sudo --check --autoresume resumefile --modfile modfile $PREFIX

Use build.sh -L to dump the names of all X.org packages available for building into a text file for use with the -modfile option. The following list should be adequate to provide a bare development environment with xserver and xterm (a minimum window manager is not included yet):
 cd Download/xorg
 cat > modfile.xorg << "EOF"
 util/macros
 proto/bigreqsproto
 proto/compositeproto
 proto/damageproto
 proto/dri2proto
 proto/fixesproto
 proto/fontsproto
 proto/glproto
 proto/inputproto
 proto/kbproto
 proto/randrproto
 proto/recordproto
 proto/renderproto
 proto/resourceproto
 proto/scrnsaverproto
 proto/videoproto
 proto/x11proto
 proto/xcmiscproto
 proto/xextproto
 proto/xf86dgaproto
 proto/xf86driproto
 proto/xineramaproto
 xcb/proto
 lib/libxtrans
 lib/libXau
 xcb/libxcb   --enable-xinput --enable-xkb
 lib/libX11
 lib/libXext
 lib/libfontenc
 lib/libICE
 lib/libSM
 lib/libXt --with-appdefaultdir=/etc/X11/app-defaults
 lib/libXmu
 lib/libXpm
 lib/libXaw
 lib/libXfixes
 lib/libXdamage
 lib/libXfont --disable-devel-docs
 lib/libxkbfile
 lib/libXxf86dga
 pixman
 mesa/drm --enable-udev --disable-intel --disable-radeon --disable-nouveau
 mesa/mesa  --with-dri-drivers=swrast --disable-gallium-egl --disable-gallium-llvm --disable-gallium-gbm --with-gallium-drivers= --enable-gles2 --disable-gles1
 app/bdftopcf
 app/mkfontdir
 app/mkfontscale
 app/xinit  --with-xinitdir=/etc/X11/app-defaults
 app/xkbcomp
 xserver --with-xkb-output=/var/lib/xkb --enable-config-udev --enable-install-setuid
 driver/xf86-input-evdev
 driver/xf86-video-fbdev
 xkeyboard-config --with-xkb-rules-symlink=xorg
 EOF

If using build.sh to build the source from archive files (by default, it will use git), you must first download the tarballs before running the script (you do not need to extract the tarballs except for some manual patching that is noted below). Beyond Linux® From Scratch - Version 7.5 is used as the reference to create a set of packages compatible with Xorg-Server-1.15.0.

Probable minimum prerequisites:
 apt-get install curl vim gcc make bzip2 python lzop bc git libncurses5-dev flex libtool automake pkg-config bison check gettext python-libxml2 libexpat1-dev libfreetype6-dev libpng12-dev intltool libgcrypt20 intltool g++ xsltproc libudev-dev libpciaccess-dev patch

Shell environment for building and running the the X.org environment:
 export PREFIX=$HOME/xorg # change this as needed
 export PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig:$PREFIX/share/pkgconfig:/usr/lib/arm-linux-gnueabihf/pkgconfig
 export ACLOCAL="aclocal -I $PREFIX/share/aclocal"
 export LD_LIBRARY_PATH=$PREFIX/lib
 export PATH=$PREFIX/bin:$PATH

There are a lot more modules than this ...
 cd xorg/
 git clone git://anongit.freedesktop.org/git/xorg/util/modular util/modular
 curl -O ftp://ftp.x.org/pub/individual/util/util-macros-1.18.0.tar.bz2
 curl -O ftp://ftp.x.org/pub/individual/lib/libXau-1.0.8.tar.bz2
 curl -O http://xcb.freedesktop.org/dist/xcb-proto-1.10.tar.bz2
 curl -O http://xcb.freedesktop.org/dist/libxcb-1.10.tar.bz2
 curl -O http://dri.freedesktop.org/libdrm/libdrm-2.4.52.tar.bz2
 curl -O http://cairographics.org/releases/pixman-0.32.4.tar.gz
 curl -O ftp://ftp.x.org/pub/individual/lib/libXdmcp-1.1.1.tar.bz2
 curl -O ftp://ftp.x.org/pub/individual/driver/xf86-input-evdev-2.8.2.tar.bz2
 curl -O ftp://ftp.x.org/pub/individual/driver/xf86-video-fbdev-0.4.4.tar.bz2
 curl -O ftp://ftp.x.org/pub/individual/app/xinit-1.3.3.tar.bz2
 curl -O ftp://ftp.x.org/pub/individual/data/xkeyboard-config/xkeyboard-config-2.11.tar.bz2
 curl -O ftp://ftp.freedesktop.org/pub/mesa/10.0.3/MesaLib-10.0.3.tar.bz2
 curl -O ftp://ftp.x.org/pub/individual/xserver/xorg-server-1.15.0.tar.bz2
 curl -O ftp://invisible-island.net/xterm/xterm-314.tgz # upgraded (fixes "undefined reference to symbol 'IceSetIOErrorHandler'")

There are a bunch of packages for X.org headers ... scripts ripped off from LFS:
 cat > proto-7.7.md5 << "EOF"
 1a05fb01fa1d5198894c931cf925c025 bigreqsproto-1.1.2.tar.bz2
 98482f65ba1e74a08bf5b056a4031ef0 compositeproto-0.4.2.tar.bz2
 998e5904764b82642cc63d97b4ba9e95 damageproto-1.2.1.tar.bz2
 4ee175bbd44d05c34d43bb129be5098a dmxproto-2.3.1.tar.bz2
 b2721d5d24c04d9980a0c6540cb5396a dri2proto-2.8.tar.bz2
 a3d2cbe60a9ca1bf3aea6c93c817fee3 dri3proto-1.0.tar.bz2
 e7431ab84d37b2678af71e29355e101d fixesproto-5.0.tar.bz2
 c5f4f1fb4ba7766eedbc9489e81f3be2 fontsproto-2.1.2.tar.bz2
 5565f1b0facf4a59c2778229c1f70d10 glproto-1.4.17.tar.bz2
 94db391e60044e140c9854203d080654 inputproto-2.3.tar.bz2
 677ea8523eec6caca86121ad2dca0b71 kbproto-1.0.6.tar.bz2
 2d569c75884455c7148d133d341e8fd6 presentproto-1.0.tar.bz2
 ce4d0b05675968e4c83e003cc809660d randrproto-1.4.0.tar.bz2
 1b4e5dede5ea51906f1530ca1e21d216 recordproto-1.14.2.tar.bz2
 a914ccc1de66ddeb4b611c6b0686e274 renderproto-0.11.1.tar.bz2
 cfdb57dae221b71b2703f8e2980eaaf4 resourceproto-1.2.0.tar.bz2
 edd8a73775e8ece1d69515dd17767bfb scrnsaverproto-1.2.2.tar.bz2
 e658641595327d3990eab70fdb55ca8b videoproto-2.3.2.tar.bz2
 5f4847c78e41b801982c8a5e06365b24 xcmiscproto-1.2.2.tar.bz2
 70c90f313b4b0851758ef77b95019584 xextproto-7.3.0.tar.bz2
 120e226ede5a4687b25dd357cc9b8efe xf86bigfontproto-1.2.0.tar.bz2
 a036dc2fcbf052ec10621fd48b68dbb1 xf86dgaproto-2.1.tar.bz2
 1d716d0dac3b664e5ee20c69d34bc10e xf86driproto-2.1.1.tar.bz2
 e793ecefeaecfeabd1aed6a01095174e xf86vidmodeproto-2.3.1.tar.bz2
 9959fe0bfb22a0e7260433b8d199590a xineramaproto-1.2.1.tar.bz2
 28311ef4edbbbf89f617a7f8a2e5648f xproto-7.0.25.tar.bz2
 EOF
 mkdir proto &&
 cd proto &&
 grep -v '^#' ../proto-7.7.md5 | awk '{print $2}' | wget -i- -c \
   -B http://xorg.freedesktop.org/releases/individual/proto/ &&
 md5sum -c ../proto-7.7.md5

And the same drill for the libs:
 cat > lib-7.7.md5 << "EOF"
 2f14c31ab556fc91039f51a113b38aa2 xtrans-1.3.3.tar.bz2
 c35d6ad95b06635a524579e88622fdb5 libX11-1.6.2.tar.bz2
 4376101e51bb2c6c44d9ab14344e85ad libXext-1.3.2.tar.bz2
 e3c77ca27942ebc5eb2ca99f29363515 libFS-1.0.5.tar.bz2
 471b5ca9f5562ac0d6eac7a0bf650738 libICE-1.0.8.tar.bz2
 499a7773c65aba513609fe651853c5f3 libSM-1.2.2.tar.bz2
 7a773b16165e39e938650bcc9027c1d5 libXScrnSaver-1.2.2.tar.bz2
 03149823ae57bb02d0cec90d5b97d56c libXt-1.1.4.tar.bz2
 41d92ab627dfa06568076043f3e089e4 libXmu-1.1.2.tar.bz2
 769ee12a43611cdebd38094eaf83f3f0 libXpm-3.5.11.tar.bz2
 7446f5fba888672aad068b29c0928ba3 libXaw-1.0.12.tar.bz2
 b985b85f8b9386c85ddcfe1073906b4d libXfixes-5.0.1.tar.bz2
 f7a218dcbf6f0848599c6c36fc65c51a libXcomposite-0.4.4.tar.bz2
 2bd9a15fcf64d216e63b8d129e4f1f1c libXrender-0.9.8.tar.bz2
 1e7c17afbbce83e2215917047c57d1b3 libXcursor-1.1.14.tar.bz2
 0cf292de2a9fa2e9a939aefde68fd34f libXdamage-1.1.4.tar.bz2
 ad2919764933e075bb0361ad5caa3d19 libfontenc-1.1.2.tar.bz2
 b21ee5739d5d2e5028b302fbf9fe630b libXfont-1.4.7.tar.bz2
 78d64dece560c9e8699199f3faa521c0 libXft-2.3.1.tar.bz2
 f4df3532b1af1dcc905d804f55b30b4a libXi-1.7.2.tar.bz2
 9336dc46ae3bf5f81c247f7131461efd libXinerama-1.1.3.tar.bz2
 210ed9499a3d9c96e3a221629b7d39b0 libXrandr-1.4.2.tar.bz2
 45ef29206a6b58254c81bea28ec6c95f libXres-1.0.7.tar.bz2
 25c6b366ac3dc7a12c5d79816ce96a59 libXtst-1.2.2.tar.bz2
 e0af49d7d758b990e6fef629722d4aca libXv-1.0.10.tar.bz2
 2e4014e9d55c430e307999a6b3dd256d libXvMC-1.0.8.tar.bz2
 d7dd9b9df336b7dd4028b6b56542ff2c libXxf86dga-1.1.4.tar.bz2
 e46f6ee4f4567349a3189044fe1bb712 libXxf86vm-1.1.3.tar.bz2
 ba983eba5a9f05d152a0725b8e863151 libdmx-1.1.3.tar.bz2
 b7c0d3afce14eedca57312a3141ec13a libpciaccess-0.13.2.tar.bz2
 19e6533ae64abba0773816a23f2b9507 libxkbfile-1.0.8.tar.bz2
 2dd10448c1166e71a176206a8dfabe6d libxshmfence-1.1.tar.bz2
 EOF
 mkdir lib &&
 cd lib &&
 grep -v '^#' ../lib-7.7.md5 | awk '{print $2}' | wget -i- -c \
   -B http://xorg.freedesktop.org/releases/individual/lib/ &&
 md5sum -c ../lib-7.7.md5

Don't stop now ... xorg/apps:
 cat > app-7.7.md5 << "EOF"
 96a648a332160a7482885800f7a506fa bdftopcf-1.0.4.tar.bz2
 2527344acc60741a709f4858564c5ae6 iceauth-1.0.6.tar.bz2
 c4a3664e08e5a47c120ff9263ee2f20c luit-1.1.1.tar.bz2
 18c429148c96c2079edda922a2b67632 mkfontdir-1.0.7.tar.bz2
 03de3f15db678e277f5ef9c013aca1ad mkfontscale-1.1.1.tar.bz2
 f548e389ff68424947b87785df6a321b sessreg-1.0.8.tar.bz2
 1001771344608e120e943a396317c33a setxkbmap-1.3.0.tar.bz2
 edce41bd7562dcdfb813e05dbeede8ac smproxy-1.0.5.tar.bz2
 5c3c7431a38775caaea6051312a49bc9 x11perf-1.5.4.tar.bz2
 50ee2ec0836c0186b05ec8fdcfd566d0 xauth-1.0.8.tar.bz2
 0066f23f69ca3ef62dcaeb74a87fdc48 xbacklight-1.2.1.tar.bz2
 5812be48cbbec1068e7b718eec801766 xcmsdb-1.0.4.tar.bz2
 09f56978a62854534deacc8aa8ff3031 xcursorgen-1.0.5.tar.bz2
 cacc0733f16e4f2a97a5c430fcc4420e xdpyinfo-1.3.1.tar.bz2
 3d3cad4d754e10e325438193433d59fd xdriinfo-1.0.4.tar.bz2
 5b0a0b6f589441d546da21739fa75634 xev-1.2.1.tar.bz2
 c06067f572bc4a5298f324f27340da95 xgamma-1.0.5.tar.bz2
 f1669af1fe0554e876f03319c678e79d xhost-1.0.6.tar.bz2
 305980ac78a6954e306a14d80a54c441 xinput-1.6.1.tar.bz2
 a0fc1ac3fc4fe479ade09674347c5aa0 xkbcomp-1.2.4.tar.bz2
 37ed71525c63a9acd42e7cde211dcc5b xkbevd-1.1.3.tar.bz2
 502b14843f610af977dffc6cbf2102d5 xkbutils-1.0.4.tar.bz2
 0ae6bc2a8d3af68e9c76b1a6ca5f7a78 xkill-1.0.4.tar.bz2
 9d0e16d116d1c89e6b668c1b2672eb57 xlsatoms-1.1.1.tar.bz2
 9fbf6b174a5138a61738a42e707ad8f5 xlsclients-1.1.3.tar.bz2
 2dd5ae46fa18abc9331bc26250a25005 xmessage-1.0.4.tar.bz2
 5511da3361eea4eaa21427652c559e1c xmodmap-1.0.8.tar.bz2
 6101f04731ffd40803df80eca274ec4b xpr-1.0.4.tar.bz2
 fae3d2fda07684027a643ca783d595cc xprop-1.2.2.tar.bz2
 52c3de0297bf45be6a189dc2e0515638 xrandr-1.4.1.tar.bz2
 b54c7e3e53b4f332d41ed435433fbda0 xrdb-1.1.0.tar.bz2
 a896382bc53ef3e149eaf9b13bc81d42 xrefresh-1.0.5.tar.bz2
 dcd227388b57487d543cab2fd7a602d7 xset-1.2.3.tar.bz2
 7211b31ec70631829ebae9460999aa0b xsetroot-1.1.1.tar.bz2
 1fbd65e81323a8c0a4b5e24db0058405 xvinfo-1.1.2.tar.bz2
 6b5d48464c5f366e91efd08b62b12d94 xwd-1.0.6.tar.bz2
 b777bafb674555e48fd8437618270931 xwininfo-1.1.3.tar.bz2
 3025b152b4f13fdffd0c46d0be587be6 xwud-1.0.4.tar.bz2
 EOF
 mkdir app &&
 cd app &&
 grep -v '^#' ../app-7.7.md5 | awk '{print $2}' | wget -i- -c \
   -B http://xorg.freedesktop.org/releases/individual/app/ &&
 md5sum -c ../app-7.7.md5

A few archives probably require patching.

The main reason for building from source is to patch xf86drm.h in libdrm for ARM:
  cd xorg
  wget https://raw.githubusercontent.com/Freescale/meta-fsl-arm/master/recipes-graphics/drm/libdrm/mx6/drm-update-arm.patch
  mkdir mesa
  cd mesa/
  tar xvjf ../libdrm-2.4.52.tar.bz2
  cd libdrm-2.4.52/
  patch -p1 < ../../drm-update-arm.patch

Patching out dependencies to libpthread-stubs (e.g. libdrm, libxcb):
       
 cd xorg
 wget https://raw.githubusercontent.com/Freescale/meta-fsl-arm/master/recipes-graphics/drm/libdrm/mx6/drm-update-arm.patch
 mkdir mesa
 cd mesa/
 tar xvjf ../libdrm-2.4.52.tar.bz2
 cd libdrm-2.4.52/
 patch -p1 < ../../drm-update-arm.patch
       
 

If you haven't already ... say some magic words, cross your fingers, do some shots:
 ./util/modular/build.sh -s sudo --check --autoresume resumefile --modfile modfile $PREFIX

Before you get to your startx moment ... xterm must be built as it is not provided by build.sh:
       
sed -i '/v0/,+1s/new:/new:kb=^?:/' termcap &&
echo -e '\tkbs=\\177,' >> terminfo &&
TERMINFO=/usr/share/terminfo \
./configure --prefix=$PREFIX     \
    --with-app-defaults=/etc/X11/app-defaults && make
       
 

That's about it for minimalist X.org. Building X from sources this way is still a pain and seems to be problematic when it comes to mixing other things into the system with distro package management (i.e. apt). The most worthwhile alternative to pursue as I see it, get a handle on the packaging tools and make appropriately patched packages for xorg-server, Mesa-lib, and libdrm. Meanwhile, go have a look at building the benchmark utilities.

Monday, January 26, 2015

glmark and Mesa-demos on i.MX6

Accelerated performance of glmark2 and mesa-demos benchmarks on i.MX6 is dependent upon on ARM specific additions to xf86drm.h and so require a patched and scratched X.org installation, e.g. previous post X.org from Scratch. Note that for control, the builds below are done in an X.org environment which is purposely not exposed to the GPU libraries/headers installation, picking up support from the standard MesaLib presumably installed along with X.org from source. The impact of building the utilities against the Freescale supplied headers and libraries is not evident to me at this time.

Mesa sources may have already been patched to provide a couple of the utilities, the outcome of running without GPU support is as expected:

make -C xdemos install

debian@arm:~$ glxgears -info
GL_RENDERER   = Software Rasterizer
GL_VERSION    = 2.1 Mesa 9.2.0
GL_VENDOR     = Mesa Project

debian@arm:~$ glxinfo
name of display: :0.0
Error: couldn't find RGB GLX visual or fbconfig

$ es2gears_x11  -info
libEGL warning: DRI2: failed to authenticate
EGL_VERSION = 1.4 (DRI2)
EGL_VENDOR = Mesa Project
EGL_EXTENSIONS = EGL_KHR_surfaceless_context
EGL_CLIENT_APIS = OpenGL OpenGL_ES OpenGL_ES2 OpenGL_ES3
vertex shader info:
fragment shader info:
info:
159 frames in 5.0 seconds = 31.699 FPS


mesa-demos-8.2.0
The complete mesa-demos package will provide es2_gears among other things.

wget http://downloads.sourceforge.net/project/glew/glew/1.11.0/glew-1.11.0.tgz

make install GLEW_PREFIX=$PREFIX GLEW_DEST=$PREFIX 

curl -O ftp://ftp.freedesktop.org/pub/mesa/glu/glu-9.0.0.tar.bz2

./configure --prefix=$PREFIX --disable-static && make

wget ftp://ftp.freedesktop.org/pub/mesa/demos/8.2.0/mesa-demos-8.2.0.tar.gz
./configure $XORG_CONFIG && make

Be sure to have the prerequisites installed, otherwise there will be trouble:

mesa-demos reports "Package 'glu', required by 'glew', not found"
glew reports missing "glu-9.0.0" ... install from LFS:

Without GPU, es2gears is pretty un-remarkable, but getting through the build is a sign of good things to come:

~$ es2gears_x11
libEGL warning: DRI2: failed to authenticate
EGL_VERSION = 1.4 (DRI2)
vertex shader info:
fragment shader info:
info:
157 frames in 5.0 seconds = 31.207 FPS


glmark2

apt-get install libjpeg-dev

# Retrieve glmark2 source:
git clone https://github.com/glmark2/glmark2.git

# glmark has it's own configuration utility:
./waf configure --with-flavors=x11-gl,x11-glesv2 # drm-gl,drm-glesv2

# CPLUS_INCLUDE_PATH should already be set in the building shell environment, but must be forced to suppress error on src/libmatrix/program.cc:
CPLUS_INCLUDE_PATH=$PREFIX/include:$CPLUS_INCLUDE_PATH ./waf build -v 


Checking for 'x11'                       : yes
Checking for 'gl'                        : yes
Checking for 'egl'                       : yes
Checking for 'glesv2'                    : yes
Checking for 'libdrm'                    : yes
Checking for 'gbm'                       : yes

If everything has built correctly at this time, check the utilities against the FBDEV (non-GPU) driver, or skip ahead to enable GPU support on the system. 

waf will automatically enable/disable features depending upon the installed Mesa configuration that it detects. I suspect that the Debian Mesa package may not enable gles ... this is what my working configuration ends up looking like:

# Note Mesa-9.2.0 configure line (more detail on Mesa configuration below):
autoreconf -fi &&
./configure CFLAGS="-O2" CXXFLAGS="-O2"    \
            --prefix=$XORG_PREFIX          \
            --sysconfdir=/etc \
            --with-dri-drivers=swrast \
            --disable-gallium-egl --disable-gallium-llvm \
            --disable-gallium-gbm \
            --with-gallium-drivers="" \
           --enable-gles2 \
            --disable-gles1 \
            --enable-gbm  # auto?

# result of Mesa-9.2.0 configuration from above:
        prefix:          /usr/local
        exec_prefix:     ${prefix}
        libdir:          ${exec_prefix}/lib
        includedir:      ${prefix}/include

        OpenGL:          yes (ES1: no ES2: yes)
        OpenVG:          no

        OSMesa:          no
        DRI drivers:     swrast
        DRI driver dir:  ${libdir}/dri
        GLX:             DRI-based

        EGL:             yes
        EGL platforms:   x11
        EGL drivers:     builtin:egl_glx builtin:egl_dri2

        llvm:            no

        Gallium:         no

        Shared libs:     yes
        Static libs:     no
        Shared-glapi:    yes

        CFLAGS:          -O2 -Wall -std=c99 -Werror=implicit-function-declaration -Werror=missing-prototypes -fno-strict-aliasing -fno-builtin-memcmp
        CXXFLAGS:        -O2 -Wall -fno-strict-aliasing -fno-builtin-memcmp
        Macros:          -D_GNU_SOURCE -DHAVE_PTHREAD -DHAVE_DLOPEN -DHAVE_POSIX_MEMALIGN -DGLX_INDIRECT_RENDERING -DGLX_DIRECT_RENDERING -DUSE_EXTERNAL_DXTN_LIB=1 -DHAVE_ALIAS -DHAVE_MINCORE -DHAVE_LIBUDEV

        PYTHON2:         python2

        Run 'make' to build Mesa


Without glesv2 enabled:

autoreconf -fi &&
./configure CFLAGS="-O2" CXXFLAGS="-O2"    \
            --prefix=$XORG_PREFIX          \
            --sysconfdir=/etc \
            --with-dri-drivers=swrast \
            --disable-egl --disable-gbm \
            --disable-gallium-egl --disable-gallium-llvm \
            --disable-gallium-gbm \
            --with-gallium-drivers="" \
            --disable-shared-glapi \
            --enable-glx

./waf configure --with-flavors=x11-gl

Should see something like this ...

Checking for 'x11'                       : yes
Checking for 'gl'                        : yes
Checking for 'egl'                       : not found
Checking for 'glesv2'                    : not found
Checking for 'libdrm'                    : yes
Checking for 'gbm'                       : not found

... and glmark2 should work:

    GL_VENDOR:     Mesa Project
    GL_RENDERER:   Software Rasterizer
    GL_VERSION:    2.1 Mesa 9.2.0


Mesa must be configured with egl/gles in order for glmark-es2 to build:

 ./waf configure --with-flavors=x11-gl,x11-glesv2
Checking for 'x11'                       : yes
Checking for 'gl'                        : yes
Checking for 'egl'                       : yes
Checking for 'glesv2'                    : not found

# "--with-egl-platforms=x11,drm" automatically enabled?

autoreconf -fi &&
./configure CFLAGS="-O2" CXXFLAGS="-O2"    \
            --prefix=$XORG_PREFIX          \
            --sysconfdir=/etc \
            --with-dri-drivers=swrast \
            --disable-gbm \
            --disable-gallium-egl --disable-gallium-llvm \
            --disable-gallium-gbm \
            --with-gallium-drivers="" \
            --disable-shared-glapi \
           --enable-gles2  --enable-egl

        OpenGL:          yes (ES1: no ES2: yes)
        OpenVG:          no

        OSMesa:          no
        DRI drivers:     swrast
        DRI driver dir:  ${libdir}/dri
        GLX:             DRI-based

        EGL:             yes
        EGL platforms:   x11
        EGL drivers:     builtin:egl_glx builtin:egl_dri2

Should now have libGLESv2.so.2:

Checking for 'x11'                       : yes
Checking for 'gl'                        : yes
Checking for 'egl'                       : yes
Checking for 'glesv2'                    : yes
Checking for 'libdrm'                    : yes


glapi is also required:

/opt/xorg/lib/libGLESv2.so: undefined reference to `_glapi_get_dispatch'
/opt/xorg/lib/libGLESv2.so: undefined reference to `_glapi_Dispatch'

autoreconf -fi &&
./configure CFLAGS="-O2" CXXFLAGS="-O2"    \
            --prefix=$XORG_PREFIX          \
            --sysconfdir=/etc \
            --with-dri-drivers=swrast \
            --disable-gbm \
            --disable-gallium-egl --disable-gallium-llvm \
            --disable-gallium-gbm \
            --with-gallium-drivers="" \
           --enable-gles2
#            --disable-shared-glapi

        Shared-glapi:    yes


~$ glmark2
** GLX does not support GLX_EXT_swap_control or GLX_MESA_swap_control!
** Failed to set swap interval. Results may be bounded above by refresh rate.
=======================================================
    glmark2 2014.03
=======================================================
    OpenGL Information
    GL_VENDOR:     Mesa Project
    GL_RENDERER:   Software Rasterizer
    GL_VERSION:    2.1 Mesa 9.2.0
=======================================================
** GLX does not support GLX_EXT_swap_control or GLX_MESA_swap_control!
** Failed to set swap interval. Results may be bounded above by refresh rate.
[build] use-vbo=false: FPS: 4 FrameTime: 250.000 ms


glmark2-es2 runs but has other complaints and performs poorly (as expected):

~$ glmark2-es2
libEGL warning: DRI2: failed to authenticate
=======================================================
    glmark2 2014.03
=======================================================
    OpenGL Information
    GL_VENDOR:     Mesa Project
    GL_RENDERER:   Software Rasterizer
    GL_VERSION:    OpenGL ES 2.0 Mesa 9.2.4
=======================================================
[build] use-vbo=false: FPS: 5 FrameTime: 200.000 ms


Mesa must be configured with "--enable-gbm" in order to get glmark-drm and glmark-es2-drm built.



Enabling GPU acceleration

The GPU-laced headers have to be in place for the Vivante EXA driver to build from source ... detailed steps are provided in this post. Some additional notes are below.

With the GPU blobs and headers installed to /usr, it's pretty likely to have overlaps with MesaLib installed to the X.org root, e.g.:

debian@arm:~/gpu-viv-bin-mx6q-3.10.17-1.0.2-hfp/usr$  for f in `find`; do [ -f $f ] && find /usr/local -name `echo $f | sed 's/.*\///'`  ; done
/usr/local/lib/libEGL.so
/usr/local/lib/libGLESv2.so
/usr/local/lib/libGLESv2.so.2
/usr/local/lib/libGLESv2.so.2.0.0
/usr/local/lib/libGL.so
/usr/local/lib/libEGL.so.1
/usr/local/lib/libGL.so.1
/usr/local/include/EGL/eglplatform.h
/usr/local/include/EGL/eglext.h
/usr/local/include/EGL/egl.h
/usr/local/include/GLES2/gl2platform.h
/usr/local/include/GLES2/gl2.h
/usr/local/include/GLES2/gl2ext.h
/usr/local/include/KHR/khrplatform.h
/usr/local/include/GL/gl.h
/usr/local/include/EGL/egl.h
/usr/local/include/GL/glext.h

At a minimum, removing the following symlinks should allow the blob versions to get priority:


# With the GPU enabled blobs installed, the stock ones from installed Mesa need to be disabled from the X.org runtime environment (and again pretty much anytime ldconfig gets run on the system):
 cd $PREFIX/lib

 sudo rm libGL.so libGL.so.1 libGLESv2.so libGLESv2.so.2 libEGL.so libEGL.so.1 libGL.so.1
ldd glmark-es2 # etc. etc.

Before trying out X.org, it should be possible to run the frame-buffer benchmarks in opt/viv_samples/vdk/.

Finally, getting to the EXA driver:

~/Download/xserver-xorg-video-imx-viv-3.10.17-1.0.2
BUILD_HARD_VFP=1 XSERVER_GREATER_THAN_13=1 BUSID_HAS_NUMBER=1 ./fastbuild.sh sysroot=/usr/local # specify sysroot if not /usr

Depending upon the specific "$PREFIX" used for X.org, it may be necessary to patch up some include paths in EXA/src/makefile.linux, FslExt/src/makefile.linux, and util/autohdmi/makefile.linux e.g.:

~xserver-xorg-video-imx-viv-3.10.17-1.0.2$
 for f in `find . -name makefile.linux`; do  sed -e 's/(sysroot)\/usr/(sysroot)/g' -i $f; done

 sed -e 's/\/drm/\/libdrm/' -i EXA/src/makefile.linux

# with pixman-1 installed from dpkg:





/usr/local/include/xorg/miscstruct.h:52:20: fatal error: pixman.h: No such file or directory


# fixup path to /usr/include/pixman-1/pixman.h in makefile


 -I$(sysroot)/include/$(PIXMAN)


# Finally ...

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


# don't forget to enable Vivante
setup /etc/X11/xorg.conf


# relink libraries for x11
switch_to_x11



:~$ LIBGL_DEBUG=verbose glxgears  -info
libGL: OpenDriver: trying /usr/lib/dri/vivante_dri.so
drmOpenByBusid: Searching for BusID platform:Vivante GCCore:00
drmOpenDevice: node name is /dev/dri/card0
drmOpenDevice: open result is 4, (OK)
drmOpenByBusid: drmOpenMinor returns 4
drmOpenByBusid: drmGetBusid reports platform:Vivante GCCore:00
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_multisample GL_ARB_te
... ...
ltisample GL_EXT_texture_array GL_EXT_draw_buffers2 GL_EXT_texture_buffer_object
 GL_EXT_draw_instanced GL_EXT_timer_query
VisualID 184, 0xb8
912 frames in 5.0 seconds = 182.398 FPS


~$ LIBGL_DEBUG=verbose es2gears_x11  -info
drmOpenByBusid: Searching for BusID platform:Vivante GCCore:00
drmOpenDevice: node name is /dev/dri/card0
drmOpenDevice: open result is 5, (OK)
drmOpenByBusid: drmOpenMinor returns 5
drmOpenByBusid: drmGetBusid reports platform:Vivante GCCore:00
EGL_VERSION = 1.4
EGL_VENDOR = Vivante Corporation
EGL_EXTENSIONS = EGL_KHR_reusable_sync EGL_KHR_fence_sync EGL_KHR_image EGL_KHR_
image_base EGL_KHR_image_pixmap EGL_KHR_gl_texture_2D_image EGL_KHR_gl_texture_c
ubemap_image EGL_KHR_gl_renderbuffer_image EGL_KHR_lock_surface
EGL_CLIENT_APIS = OpenGL_ES OpenVG
vertex shader info:
fragment shader info:
info:
853 frames in 5.0 seconds = 170.566 FPS


~$ LIBGL_DEBUG=verbose glmark2-es2
drmOpenByBusid: Searching for BusID platform:Vivante GCCore:00
drmOpenDevice: node name is /dev/dri/card0
drmOpenDevice: open result is 5, (OK)
drmOpenByBusid: drmOpenMinor returns 5
drmOpenByBusid: drmGetBusid reports platform:Vivante GCCore:00
=======================================================
    glmark2 2014.03
=======================================================
    OpenGL Information
    GL_VENDOR:     Vivante Corporation
    GL_RENDERER:   Vivante GC2000
    GL_VERSION:    OpenGL ES 2.0
=======================================================
[build] use-vbo=false: FPS: 396 FrameTime: 2.525 ms



These errors were seen at some point but IDNR what configuration:

debian@arm:~$ glmark2-es2
=======================================================
    glmark2 2014.03
=======================================================
    OpenGL Information
    GL_VENDOR:     Vivante Corporation
    GL_RENDERER:   Vivante GC2000
    GL_VERSION:    OpenGL ES 2.0
=======================================================
[build] use-vbo=false:
[loop] fragment-steps=5:fragment-uniform=true:vertex-steps=5: FPS: 253 FrameTime: 3.953 ms
=======================================================
                                  glmark2 Score: 252
=======================================================
[xcb] Unknown sequence number while appending request
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.
glmark2-es2: ../../src/xcb_io.c:161: append_pending_request: Assertion `!xcb_xlib_unknown_seq_number' failed.
Aborted
~$


Latest results running on 3.10.31 series, the update to "OpenGL ES 3.0" is seen.

debian@arm:~$ !473
LIBGL_DEBUG=verbose glmark2-es2
drmOpenByBusid: Searching for BusID platform:Vivante GCCore:00
drmOpenDevice: node name is /dev/dri/card0
drmOpenDevice: open result is 5, (OK)
drmOpenByBusid: drmOpenMinor returns 5
drmOpenByBusid: drmGetBusid reports platform:Vivante GCCore:00
=======================================================
    glmark2 2014.03
=======================================================
    OpenGL Information
    GL_VENDOR:     Vivante Corporation
    GL_RENDERER:   Vivante GC2000
    GL_VERSION:    OpenGL ES 3.0 V5.0.11.p1.19959
=======================================================
[build] use-vbo=false: FPS: 399 FrameTime: 2.506 ms
[build] use-vbo=true:^C

glxgears slower?
debian@arm:~$ LIBGL_DEBUG=verbose glxgears -info
libGL: OpenDriver: trying /usr/lib/dri/vivante_dri.so
drmOpenByBusid: Searching for BusID platform:Vivante GCCore:00
drmOpenDevice: node name is /dev/dri/card0
drmOpenDevice: open result is 4, (OK)
drmOpenByBusid: drmOpenMinor returns 4
drmOpenByBusid: drmGetBusid reports platform:Vivante GCCore:00
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_multisample GL_ARB_texture_env_add GL_ARB_texture_compression GL_ARB_texture_env_combine GL_ARB_depth_texture GL_ARB_window_pos GL_ARB_vertex_buffer_object GL_ARB_imaging GL_EXT_framebuffer_object GL_EXT_framebuffer_blit GL_EXT_framebuffer_multisample GL_EXT_texture_array GL_EXT_draw_buffers2 GL_EXT_texture_buffer_object GL_EXT_draw_instanced GL_EXT_timer_query
VisualID 191, 0xbf
757 frames in 5.0 seconds = 151.342 FPS
742 frames in 5.0 seconds = 148.313 FPS
^CProcess termination by interupt!