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.

No comments:

Post a Comment