Tuesday, January 13, 2015

Xserver from scratch on i.MX6

Working through tutorials on Beyond Linux® From Scratch - Version 7.4, and building the X Window System from source on MX6. These instructions are for Xorg-Server-1.14.3 and GPU blobs from 3.10.17-1.0.2 BSP release. With this setup, glmark-es2 and other demos seem to run properly with the Vivante hardware.

Create a minimal rootfs but do not install anything xorg from the distro.

Refer to the official instructions and setup the build environment. Using XORG_PREFIX=/usr/local in this example. The following would be read into the environment to prepare for building:

# Functions to help us manage paths.  Second argument is the name of the
# path variable to be modified (default: PATH)
pathremove () {
        local IFS=':'
        local NEWPATH
        local DIR
        local PATHVARIABLE=${2:-PATH}
        for DIR in ${!PATHVARIABLE} ; do
                if [ "$DIR" != "$1" ] ; then
                  NEWPATH=${NEWPATH:+$NEWPATH:}$DIR
                fi
        done
        export $PATHVARIABLE="$NEWPATH"
}

pathprepend () {

        pathremove $1 $2
        local PATHVARIABLE=${2:-PATH}
        export $PATHVARIABLE="$1${!PATHVARIABLE:+:${!PATHVARIABLE}}"
}

pathappend () {

        pathremove $1 $2
        local PATHVARIABLE=${2:-PATH}
        export $PATHVARIABLE="${!PATHVARIABLE:+${!PATHVARIABLE}:}$1"
}

export -f pathremove pathprepend pathappend



# if Xorg is to be installed somewhere other than the default /usr, it will require some
# additional setup to the environment 

XORG_PREFIX=/opt/X11
XORG_CONFIG="--prefix=$XORG_PREFIX \
             --sysconfdir=/etc \
             --localstatedir=/var \
             --disable-static"
export XORG_PREFIX XORG_CONFIG


pathappend $XORG_PREFIX/bin             PATH
pathappend $XORG_PREFIX/lib/pkgconfig   PKG_CONFIG_PATH
pathappend $XORG_PREFIX/share/pkgconfig PKG_CONFIG_PATH

pathappend $XORG_PREFIX/lib             LIBRARY_PATH
pathappend $XORG_PREFIX/include         C_INCLUDE_PATH
pathappend $XORG_PREFIX/include         CPLUS_INCLUDE_PATH

# single quotes will prevent XORG from expanding 
ACLOCAL="aclocal -I $XORG_PREFIX/share/aclocal"

export PATH PKG_CONFIG_PATH ACLOCAL LIBRARY_PATH C_INCLUDE_PATH CPLUS_INCLUDE_PATH



Add $XORG_PREFIX/lib to the /etc/ld.so.conf file if necessary (e.g. for Debian):

echo "$XORG_PREFIX/lib" >> /etc/ld.so.conf.d/xdev.conf

sudo mkdir $XORG_PREFIX $XORG_PREFIX/lib
sudo ldconfig


# most of the following tools will probably need to be installed:
apt-get install curl vim sudo gcc make bzip2 python lzop bc git libncurses5-dev
apt-get install flex libtool automake pkg-config bison check
apt-get install gettext libxml2-dev python-libxml2 libexpat1-dev libfreetype6-dev libpng12-dev \
intltool libpixman-1-dev libgcrypt11-dev  libfontconfig1-dev intltool g++ xsltproc
apt-get install libudev-dev # silently disabled udev in xserver configure without this

Follow BLFS instructions to get started installing the following modules:
  • util-macros-1.17.1
  • Xorg Protocol Headers
  • libXau-1.0.8
  • xcb-proto-1.8
  • libxcb-1.9.1 # might need xdmcp
  • Xorg Libraries - all at once or try to piece it out to get as far as MesaLib 
    • xtrans-1.2.7
    • libX11-1.6.2
    • libXext-1.3.2 
    • libXfixes-5.0.1
    • libXdamage-1.1.4

MesaLib-9.2.0

MesaLib should build once libdrm and all the previous dependencies are installed.

On i.MX6, installing libdrm will provide libdrm.so and libkms.so. The GPU driver will come from the FSL blobs.

The drm-update-arm.patch has been applied to libdrm but what will break if it is not?

Build as follows, else it will probably fail to configure unless intel, radeon etc. are explicitly disabled:

autoreconf -fi &&
./configure --prefix=$XORG_PREFIX --enable-udev \
            --disable-intel --disable-radeon --disable-nouveau 


The following command provides a minimum Mesa configuration ("--with-dri-drivers" ensures that glxgears will run in X with the software rasterizer, and is implicitly linked to "--enable-opengl"): 

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 \
            --disable-glx

If all goes well, configure confirms what goes in the build:

        prefix:          /opt/xorg
        exec_prefix:     ${prefix}
        libdir:          ${exec_prefix}/lib
        includedir:      ${prefix}/include

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

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

        EGL:             no

        llvm:            no

        Gallium:         no

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

        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 -DUSE_EXTERNAL_DXTN_LIB=1 -DHAVE_ALIAS -DMESA_EGL_NO_X11_HEADERS

        PYTHON2:         python2

        Run 'make' to build Mesa


This should not be seen if gallium options are disabled as in the configure shown above, otherwise glxgears will run but perform poorly, e.g.:

GL_RENDERER   = Gallium 0.4 on softpipe
GL_VERSION    = 2.1 Mesa 9.2.0
GL_VENDOR     = VMware, Inc.


xorg-server
Install additional tools and build more modules.

apt-get install libgcrypt20-dev libudev-dev libpciaccess-dev libfreetype6-dev intltool

pixman-0.30.2

Xorg Libraries
libXxf86dga-1.1.4
libxkbfile-1.0.8
libfontenc-1.1.2
libXfont-1.4.6

Xorg Applications
mkfontscale-1.1.2
mkfontdir-1.0.7
bdftopcf
xkbcomp-1.3.0.tar.bz2
Xorg Fonts
xkeyboard-config-2.9


Configure and build xorg-xserver:

# --enable-config-udev should not be needed (auto) if libudev intalled
./configure $XORG_CONFIG  --with-xkb-output=/var/lib/xkb  --enable-config-udev  --enable-install-setuid && make clean && make

# Be sure libudev has been installed (see example warning RE udev below), else keyboard 
# and mouse probably will not work ... "--enable-config-udev" should be enabled by default 

configure: error: udev configuration API requested, but libudev is not installed

checking for OPENSSL... no  # is it needed?


Not sure this part (/etc/sysconfig doesn't exist in my Jessie bootstrap):
cat >> /etc/sysconfig/createfiles << "EOF"
/tmp/.ICE-unix dir 1777 root root
/tmp/.X11-unix dir 1777 root root


Before installing xorg-xserver, run "make check" to detect missing components or other problems:



XKB: Failed to compile keymap

Keyboard initialization failed. This could be a missing or incorrect setup of xkeyboard-config.

(EE)

Fatal server error:

(EE) Failed to activate core devices.(EE)

(EE)

Please consult the The X.Org Foundation support at http://wiki.x.org for help.

(EE)

FAIL: xtest



# Xorg Drivers

xf86-video-fbdev-0.4.3

xf86-input-evdev-2.8.1


XTERM:
Xorg Libraries

libXt-1.1.4 (libICE-1.0.8 libSM-1.2.2)
libXaw-1.0.12 (libXmu-1.1.2 libXpm-3.5.11)

xinit-1.3.3

# update server location if not /usr/bin, or link it to /usr/bin/X
defaultserver=/usr/local/bin/X

# missing xf86-video-fbdev
[ 93901.576] (EE) Failed to load module "fbdev" (module does not exist, 0) 
[ 93901.576] (EE) No drivers available. 
[ 93901.576] (EE)
Fatal server error: 
[ 93901.576] (EE) no screens found(EE)




# missing xf86-input-evdev-2.8.1



[ 95009.839] (WW) Warning, couldn't open module evdev 
[ 95009.839] (II) UnloadModule: "evdev" 
[ 95009.839] (II) Unloading evdev 
[ 95009.839] (EE) Failed to load module "evdev" (module does not exist, 0)

# missing Modesetting drivers (not installed in BLFS) ?.

[ 95008.617] (II) LoadModule: "modesetting"
[ 95008.619] (WW) Warning, couldn't open module modesetting
[ 95008.619] (II) UnloadModule: "modesetting" 
[ 95008.619] (II) Unloading modesetting 
[ 95008.619] (EE) Failed to load module "modesetting" (module does not exist, 0)












7 comments:

  1. Did you start with a fresh image or start with one of the images from your previous two posts?

    I have been working down a similar path as you. Been trying to get VIVANTE acceleration working with X11 on Jessie/Debian. I have gotten X.org RC7.7 (xserver 1.12) built and running with lightdm, but I could not get hw acceleration going. Due to notes online about needing xserver 1.14.4+, I moved to building from X.org git sources for all but xserver. Version dependencies with Util-macros/Mesa/xserver means you cant just take R7.7 tarballs and drop in xserver 1.14.4+. I have gotten the FB drivers working and am able to run all of the tutorials. Somewhat annoyingly the tutorials want libwayland0-server installed.

    Either in my rebuilding of everything and a slight modifications of my permissions based on what you posted I was able to get past the AIGLX reverting to swrast. Thought I had those right - I appreciate your notes on the topic. Conflicting notes online about it being important.

    Some notes I have:
    - If you are not starting fresh, you will want to reapply the fsl gpu and xserver files after you build mesa/xserver. You will prbably want to install them to your build directory. In your setup, /opt/X11 is setup like another /usr directory
    - You can delete fbdev driver in your /opt/X11/lib/xorg/modules/drivers and it will help find the VIVANTE drivers depending on where you are in the process, but you should not have to do that. I had that happen once, but I cannot remember the root cause.
    - You may want to build mesa/drm and use the yocto DRM patch. Google fsl xf86drm.h and fsl
    - There is another patch out there to correct vivante_drv.so: undefined symbol: miInitializeBackingStore, but I only seem to get that if I start X using sudo/as root.
    - evdev depends on mesa/mesa so you may want to rebuild it
    - Reference "Building The X.org" is generally better than LFS for X. It uses the X.org build.sh that manages a lot of what you setup via your bash profile and xorg.sh. Dump the list of modules to a file that you can use that to add flags too. Then ran the build.sh with pretty much everything besides xserver with the --clone option specified to pull in the source. Then rerun it for just xserver without clone which will allow it to pull it from tar ball you drop in you src directory.
    - Bug in mesa/mesa if you use gaillium (default) and build the raedon drivers (also a default). Raedon driver is expecting a LLVM define that wont be setup for ARM. You avoid this by not using gallium. Note that just doing --enable-dri-drivers will not avoid the issue, --disable-radeon may though.
    - Almost all X/Windows managers have dependencies on X and can create unexpected dependency problems/path issues. I was stupid installing lightdm.
    - That said some of the distro installs seem to do a better job at making sure everything is setup correctly. To include users/permissions/xauth stuff.


    I think in all my building and hacking around I have created some unknown path/incorrect library grabbing/permissions issue, so I may might start from a new boot strap.

    Using X.org build script I generally use the defaults but have set the following:
    mesa/drm --disable-intel --enable-udev
    mesa/mesa --enable-driglx-direct --enable-gles1 --enable-gles2 --enable-glx --with-dri-drivers=noeveau --with-gallium-drivers=noeveau
    xserver --enable-dri2 --enable-dri --enable-glx --enable-glx-tls

    ReplyDelete
    Replies
    1. I autoremoved/purged/removed pretty much all of the apt get stuff I ever installed related to X/mesa/OpenGL/Window managers and tried to take your path from your lastt post. I got startx to run after I got my old Xorg build out of the way. Xterm launches but I lose mouse and keyboard and have to either ssh in or use a serial terminal. I am able to launch xterm with ssh -X -f user@ip xterm. I got mesa-utils installed. The base xserver for Jessie is 1.16, so I will pull 1.14.4 tomorrow. I wanted to remove next to everything before I rebuilt some of my X.org setup. Figured I would try what you got going on Ubuntu on Debian before I committed to hours of rebuilding X.org on an ARM.

      I noticed you choose to use pathappend in your Xorg/Mesa builds you might want to try prepend so you find the stuff you are building first.

      I see some activity on Freescale trying to accomplish this as well.

      Delete
  2. Hi athmsVT,

    Thanks for your notes and comments. This graphics stack business gets pretty snaggly and I am fairly new to it. Please excuse the mess!

    I just now got es2gears/es2-info built and working with the GPU. The setup is Jessie+Xorg-1.14.3. Xorg is from-scratch because I didn't know how to apt-get Xorg 1.14.x in Jessie, and this way at least I can be sure what's in the config.

    The Xorg from scratch thing is enlightening but a pain so I eventually noticed I could apt-get Xorg-1.14.6 in Ubuntu 13.10. I got as far as glxgears running accelerated, after switching gpu-viv-bin and xserver-xorg-video-imx from 1.0.0 to 1.0.2 versions. Could not get glmark2 or es2gears running so I retreated to the scratched setup. It may just be user error ... I'm new here.

    The tricky part of the scratch Xorg was getting the drm and Mesa stuff right. libDRM needs to have all the Intel-Radeon-Nouv stuff deconfigured otherwise it won't play on i.MX6 obviously and Mesa will also run aground. Even after I got xserver running, I discovered that glxgears insisted on using Gallium softpipe. I finally realized I had to go back and rebuild Mesa with everything gallium flavored explicitly disabled, plus set the gallium-drivers to empty.

    Once I discovered how to get the gallium stuff out of the way, I found I could go back to Mesa and enable egl, gles, glapi which was needed to get all glmark2 and mesa-utils built.

    The lost mouse keyboard thing I ran into on my first Xorg-scratch attempt. My minimal system did not have libudev installed when Xorg-server was configured though it happily built anyway.

    When you say "pull 1.14.4" do you mean can be installed with apt-get?

    Good luck!

    -G-

    ReplyDelete
  3. You can try something like this:

    http://hackedbellini.org/linux/downgrade-and-force-some-packages-on-debian-to-a-previous-version/

    Update sources.list to something like:
    deb http://snapshot.debian.org/archive/debian/20140430T102338Z/ jessie main
    #deb ..
    #deb-src ...

    You may want to comment out the other repos for simplicity. apt-get update to get the package info from the snapshot repo . From there using apt-cache showpkg you can find the available versions. It should allow you to run sudo apt-get install package=version.

    ReplyDelete
    Replies
    1. By pull yes I mean via apt-get using an older snapshot as described above.

      Delete
    2. I should say it is not quite that straight forward. You need to ignore the "these packages are old/invalid" message by passing in "-o Acquire::Check-Valid-Until=false" to apt-get update. Then when it takes a little work to make sure you get version dependencies handled. The packages are there, but some of the newest ones will not align with the available packages. For instance I think I had to install libgl1-mesa-glx=10.1.0-5 and libglapi-mesa=10.1.0-5 by hand before installing everything else.

      Delete
  4. I did not know about snapshot.debian.org ... exactly the thing I was looking for, thanks! I have no idea what the compatibility requirements are between the GPU blobs and Xorg - I thought I could try to reproduce what Jas-hacks did if I could get on the same Xorg-server version as his RFS image.

    ReplyDelete