Thursday, January 22, 2015

X.Org X Server 1.14.5, Debian, i.MX6

Previously I had some success getting the GPU to work on i.MX6 by building X.org from scratch over a Debian armhf deboostrap installation. Nice learning exercise but a little labor intensive. My previous attempt at setting up on Ubuntu with Xorg 1.14.6 (no sources, just dpkg) works at least partially - glxgears and es2gears_x11 run smoothly using the GPU.  

As far as I know X.org 1.15 or later won't work (GPU blobs from 3.10.17-1.0.2 BSP release) ... based on the comment I saw over on Tiny Devices. Thanks to athmsVT, I found out about snapshot.debian.org, which makes it easy to get a debootstrap install that contains "xserver-xorg-core 2:1.14.5-1". The snapshot I am using is precisely the last one prior to adding xserver-xorg-core_1.15:
http://snapshot.debian.org/archive/debian/20140106T095748Z/pool/main/x/xorg-server/

Here goes ...

# debootstrap rootfs to partition on SD card
sudo mkfs.ext4 /dev/sda1

# mounting the freshly-mkfs'd partion:
sudo mount /dev/sda1 /media/rootfs 

# for a non-snapshot install, the following can be used:
sudo debootstrap --arch=armhf jessie /media/rootfs/ \
http://ftp.us.debian.org/debian/

# if host is also armhf system, probably don't need to specify '--foreign' or '--arch' arguments:
sudo debootstrap --arch=armhf jessie /media/rootfs/ \
http://snapshot.debian.org/archive/debian/20140106T095748Z/

sudo chroot /media/rootfs/

# in debootstrap'd rootfs
export LANG=C

# can ignore the "--second-stage" if not building an install for a foreign architecture
# /debootstrap/debootstrap --second-stage

cat /etc/apt/sources.list # main repo already setup in sources.list, e.g.

deb http://snapshot.debian.org/archive/debian/20131213T220007Z jessie main


# suppress "InRelease is expired " warnings if installing from a snapshot
apt-get -o Acquire::Check-Valid-Until=false update  

apt-get install locales dialog ntpdate

# in chroot, this error can be ignored for now ...

E: Can not write log (Is /dev/pts mounted?) - openpty (2: No such file or directory)

# ... but should be configured if continuing to work in chroot, e.g.:

# prior to entering chroot environment ...
sudo mkdir /media/rootfs/run/udev # if not exist

$ cat chroot_env.sh

rootfs=/opt/rootfs
mount -o bind /proc $rootfs/proc
mount -o bind /dev $rootfs/dev
mount -o bind /dev/pts $rootfs/dev/pts
mount -o bind /sys $rootfs/sys
mount -o bind /run/udev $rootfs/run/udev

dpkg-reconfigure locales # en_US.UTF-8 UTF-8


# user must be in group video for galcore access
adduser debian

usermod -a -G video debian

# while you're at it, set a password for root ... 
passwd

# setup serial console in /etc/inittab ... the inittab is otherwise incomplete in 
VERSION="8 (jessie)"
T1:23:respawn:/sbin/getty -L ttymxc1 115200 vt102

# home on separate partition in /etc/fstab (note, depending upon the kernel used, the exact name of the mmcblk device may vary):

/dev/mmcblk0p1   /           auto   errors=remount-ro   0   1
/dev/mmcblk0p2   /home       auto   defaults            0   2


# /etc/network/interface:

auto lo
iface lo inet loopback

auto eth0

iface eth0 inet dhcp

allow-hotplug wlan0

iface wlan0 inet manual
  wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp


#Enable drm, vivante in kernel (
CONFIG_DRM_VIVANTE=m, CONFIG_DRM=m)
echo "vivante" >> /media/rootfs/etc/modules

#Install kernel, modules, firmware in the usual way.
# Make note of comments regarding CONFIG_FHANDLE in my previous post.

sudo make firmware_install INSTALL_FW_PATH=/media/rootfs/lib/firmware

sudo umount /media/rootfs/  

# and reboot ...

# u-boot args for 3.10.17 which need to be saved to flash:

setenv bootargs console=${console},${baudrate} root=/dev/mmcblk0p1  rootfstype=ext4 rootwait video=mxcfb1:off video=mxcfb2:off video=mxcfb3:off video=mxcfb4:off video=mxcfb5:off video=mxcfb0:dev=hdmi,1920x1080M@60,if=RGB16 fbmem=48M vmalloc=400 mxc_hdmi.only_cea=1 coherent_pool=48M

ext2load mmc ${mmcdev}:${mmcpart} ${fdt_addr} boot/${fdt_file}

ext2load mmc ${mmcdev}:${mmcpart} ${loadaddr} boot/${image}
bootz ${loadaddr} - ${fdt_addr}



Did it work?

apt-get install sudo ssh

If you want go it from scratch, follow this post.

Onward ...

# confirm versions


root@debian-imx6:/home# apt-cache show xserver-xorg-core
Package: xserver-xorg-core
Source: xorg-server

Version: 2:1.14.5-1

root@debian-imx6:/home# apt-cache show libpixman-1-0
Package: libpixman-1-0
Source: pixman

Version: 0.32.4-1


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

apt-get install --no-install-recommends mesa-utils mesa-utils-extra
apt-get install --no-install-recommends xserver-xorg-dev libxext-dev 


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



:~/gpu-viv-bin-mx6q-3.10.17-1.0.2-hfp/usr$ for f in `find`; do [ -f $f ] && find /usr -name `echo $f | sed 's/.*\///'`  ; done
/usr/include/GL/gl.h       # include/GLES2/gl2.h
/usr/include/GL/glext.h  # include/GLES/glext.h

/usr/lib/arm-linux-gnueabihf/mesa/libGL.so.1




$ dpkg -S libGL.so.1

libgl1-mesa-glx:armhf: /usr/lib/arm-linux-gnueabihf/libGL.so.1

libgl1-mesa-glx:armhf: /usr/lib/arm-linux-gnueabihf/libGL.so.1.2.0


glext.h: mesa-common-dev ... these will come from blobs ... include/GLES


debian@debian-imx6:~$ ls -l /dev/dri/card0
crw-rw---- 1 root video 226, 0 Jan 21 23:00 /dev/dri/card0
debian@debian-imx6:~$ ls -l /dev/galcore
crw------- 1 root root 199, 0 Jan 21 23:00 /dev/galcore

Segmentation fault on tutorial7


https://raw.githubusercontent.com/Freescale/meta-fsl-arm/master/recipes-core/udev/udev-rules-imx/10-imx.rules

#KERNEL=="mxc_galcore", MODE="0666"  # GN: device doesn't exist with my kernel
KERNEL=="mxc_asrc",  MODE="0666"


# should have proper permissions now (tutorial7 will segfault otherwise):
debian@debian-imx6:~$ ls -l /dev/galcore
crw-rw---- 1 root video 199, 0 Jan 22 00:37 /dev/galcore


# On Debian, the following symlinks should be removed:
# from libegl1-mesa
/usr/lib/arm-linux-gnueabihf/libEGL.so.1 \
/usr/lib/arm-linux-gnueabihf/libEGL.so.1.0.0 
# from libgles2-mesa
/usr/lib/arm-linux-gnueabihf/libGLESv2.so.2 \
/usr/lib/arm-linux-gnueabihf/libGLESv2.so.2.0.0

Exit X if it is running, verify something in viv_samples/vdk works correctly in framebuffer.


apt-get install xserver-xorg-dev, libxext-dev

BUILD_HARD_VFP=1 XSERVER_GREATER_THAN_13=1 BUSID_HAS_NUMBER=1 ./fastbuild.sh

/usr/include/libdrm/drm.h # fixup path on snapshot Jessie

#EXA/src/makefile.linux:
#LOCAL_CFLAGS += -I$(sysroot)/usr/include/drm
# change to:
LOCAL_CFLAGS +=  -I$(sysroot)/usr/include/libdrm

cp EXA/src/vivante_drv.so /usr/lib/xorg/modules/drivers


https://raw.githubusercontent.com/Freescale/meta-fsl-arm/master/recipes-graphics/xorg-xserver/xserver-xf86-config/mx6/xorg.conf

# verify if the following is actually needed in xorg.conf:
Section "dri"
  Mode 0666
EndSection

## fire it up and expect the following:


glxgears, es2gears, glmark2-es2 should run in ssh session as non-root.
glmark2 probably a no-show, apparently needs standard libGL or libGAL ... not from package, must have been scratchbuilt
es2tri: should work but hangs X
imx6:~$ es2gears_screen  
EGL_VERSION = 1.4
EGLUT: failed to choose a config


# Debian ... TODO replicate this issue - can't remember what it was (mxc_galcore / udev'd ??)


LIBGL_DEBUG=verbose glxgears


libGL: OpenDriver: trying /usr/lib/dri/vivante_dri.so
drmOpenByBusid: Searching for BusID platform:Vivante GCCore
drmOpenDevice: node name is /dev/dri/card0
drmOpenDevice: open result is 4, (OK)
drmOpenByBusid: drmOpenMinor returns 4
drmOpenByBusid: drmGetBusid reports platform:Vivante GCCore:00
drmOpenDevice: node name is /dev/dri/card1
drmOpenByBusid: drmOpenMinor returns -1003



# be careful of where dpkg has installed Mesa, 
# e.g. /usr/lib/arm-linux-gnueabihf/, /usr/lib/arm-linux-gnueabihf/-mesa

# check dependencies with ldd:
# glmark2, glxgears -> libGL-> libGAL 
# glmark2-es2, es2gears -> libEGL -> libGAL; libGLESv2 -> libGAL, libEGL

# example of wrong libGL being found:
debian@debian-imx6:~$ LIBGL_DEBUG=verbose glxgears
libGL: screen 0 does not appear to be DRI2 capable
libGL: XF86DRIGetClientDriverName: 4.1.0 vivante (screen 0)
libGL: OpenDriver: trying /usr/lib/arm-linux-gnueabihf/dri/tls/vivante_dri.so
libGL: OpenDriver: trying /usr/lib/arm-linux-gnueabihf/dri/vivante_dri.so
libGL error: dlopen /usr/lib/arm-linux-gnueabihf/dri/vivante_dri.so failed (/usr
/lib/arm-linux-gnueabihf/dri/vivante_dri.so: cannot open shared object file: No
such file or directory)
libGL: OpenDriver: trying ${ORIGIN}/dri/tls/vivante_dri.so
libGL: OpenDriver: trying ${ORIGIN}/dri/vivante_dri.so
libGL error: dlopen ${ORIGIN}/dri/vivante_dri.so failed (${ORIGIN}/dri/vivante_d
ri.so: cannot open shared object file: No such file or directory)
libGL: OpenDriver: trying /usr/lib/dri/tls/vivante_dri.so
libGL: OpenDriver: trying /usr/lib/dri/vivante_dri.so
libGL error: driver exports no extensions (/usr/lib/dri/vivante_dri.so: undefine
d symbol: __driDriverExtensions)
libGL error: failed to load driver: vivante
libGL: OpenDriver: trying /usr/lib/arm-linux-gnueabihf/dri/tls/swrast_dri.so
libGL: OpenDriver: trying /usr/lib/arm-linux-gnueabihf/dri/swrast_dri.so

~$ ldd /usr/bin/glxgears  | grep 'libGL\.'
        libGL.so.1 => /usr/lib/arm-linux-gnueabihf/libGL.so.1 (0
rm /usr/lib/arm-linux-gnueabihf/libGL.so.1
~$ ldd /usr/bin/glxgears  | grep 'libGL\.'
        libGL.so.1 => /usr/lib/libGL.so.1 (0x76e78000)


# also need to be vigilant following some installs with links being re-created in /usr/lib/arm-linux-gnueabihf/:


debian@debian-imx6:~$ ldd /usr/bin/es2gears

        libGLESv2.so.2 => /usr/lib/arm-linux-gnueabihf/libGLESv2.so.2 (0x76f39000)
        libEGL.so.1 => /usr/lib/arm-linux-gnueabihf/libEGL.so.1 (0x76db5000)
rm /usr/lib/arm-linux-gnueabihf/libEGL.so.1

# es2gears runs happily, but blank window:
rm /usr/lib/arm-linux-gnueabihf/libGLESv2.so.2


# Finally ... should see something like this:

~$ LIBGL_DEBUG=verbose es2gears -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:
813 frames in 5.0 seconds = 162.503 FPS
811 frames in 5.0 seconds = 162.168 FPS


# and 

debian@debian-imx6:~$ glxinfo
name of display: :0.0
display: :0  screen: 0
direct rendering: Yes
server glx vendor string: SGI
server glx version string: 1.4
server glx extensions:
    GLX_ARB_multisample, GLX_EXT_import_context, GLX_EXT_texture_from_pixmap,
    GLX_EXT_visual_info, GLX_EXT_visual_rating, GLX_MESA_copy_sub_buffer,
    GLX_OML_swap_method, GLX_SGIS_multisample, GLX_SGIX_fbconfig,
    GLX_SGIX_pbuffer, GLX_SGI_make_current_read
client glx vendor string: Vivante Corp
client glx version string: 1.4


# libjpeg8


glxgears # will run in software if libGL is /usr/lib/arm-linux-gnueabihf/libGL.so.1


libGL error: failed to load driver: vivante

rm /usr/lib/arm-linux-gnueabihf/libGL.so.1


#  ... but ... glmark-es2 runs but no window then X is hosed
debian@debian-imx6:~$ 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 2012.08
=======================================================
    OpenGL Information
    GL_VENDOR:     Vivante Corporation
    GL_RENDERER:   Vivante GC2000
    GL_VERSION:    OpenGL ES 2.0
=======================================================



### what about ubuntu (13.10, Xorg 1.14.6)?

ubuntu@arm:/etc/X11$ LIBGL_DEBUG=verbose es2gears -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_cubemap_image EGL_KHR_gl_renderbuffer_image EGL_KHR_lock_surface
EGL_CLIENT_APIS = OpenGL_ES OpenVG
EGLUT: failed to create context


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)












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.


Monday, January 5, 2015

Debootstrap on i.MX6 Sabre Lite

My notes on installation of the root filesystem (RFS) on Freescale i.MX6 based SBCs (most on Boundary Devices BD-SL-i.MX6 aka Sabre Lite). This post was first written to document experiences with deboot-strapping Debian (Jessie), and since then I have also experimented with Ubuntu 13.10 Saucy, as it provided Xorg-server 1.14.6. Unfortunately I have not been able to get es2gears-x11 running on Ubuntu.

While making these notes I was following a debootstrap tutorial written for Olimex and did not bother repeating a lot of the details. I debootstrap the new rootfs on a spare card, using the same Sabre Lite board (running Debian Wheezy) as a host. The instructions on the Olimex blog include the details needed to bootstrap on a host of different architecture than the target.

I perform the installation with distro=jessie and use the following configuration of /etc/apt/sources.list to set my package sources to US servers:

cat << EOT > /etc/apt/sources.list
deb http://ftp.us.debian.org/debian/ $distro main contrib non-free
deb http://ftp.us.debian.org/debian/ $distro-updates main contrib non-free
deb http://security.debian.org/ $distro/updates main contrib non-free
EOT


My locale is en_US.UTF-8

While creating the RFS, I add a user in the standard way i.e. adduser debian.

Creation of /etc/fstab is absent from the instructions in the blog ... I use the following setup, which allows me to easily delete and re-install the RFS at a whim (important requirement for development), while keeping /home isolated from the RFS on it's own partition:

/dev/mmcblk0p1   /           auto   errors=remount-ro   0   1
/dev/mmcblk0p2   /home       auto   defaults            0   2

For Debian (see below for Ubuntu), the serial console login is enabled on Sabre Lite with the following line added to /etc/inittab:

T1:23:respawn:/sbin/getty -L ttymxc1 115200 vt102

One problem emerged with the first boot on the new RFS - the system failed to spawn a login process on the serial port (/dev/ttymxc1), although the login was working fine through the attached monitor/keyboard ... the following messages were observed on the serial console:

[ TIME ] Timed out waiting for device dev-ttymxc1.device.
[DEPEND] Dependency failed for Serial Getty on ttymxc1.

After enabling CONFIG_FHANDLE in my kernel (boundary-imx_3.10.17_1.0.0_ga) and rebuilding, I could login on the serial port.

With ethernet working and openssh-server already installed during the debootstrap process, I could get busy updating the system and installing some essential software packages:

apt-get install curl vim sudo gcc make bzip2 python lzop bc git libncurses5-dev
apt-get install flex libtool automake pkg-config bison 



There is one (apparently harmless) quirk observed with the new system:

[FAILED] Failed to start Login Service.
See 'systemctl status systemd-logind.service' for details.

This is possibly related to a bug in jessie. It seems that "standard system utilities" is not installed in the minimal debootstrap process - the bug report states that there is no negative effect on the boot process so long as the "System-V" init package is installed. A little more web crawling seems to indicate that there is something to do with tasksel, but I'm relatively new to Debian so leave it alone for now. (Update 1/22/2015 GN: noticed there is not a complete inittab installed so getty is not being called on tty[1-4])


Atheros WLAN working after firmware install:

usb 2-1.2: ath9k_htc: Failed to get firmware htc_9271.fw
(apt-get install firmware-atheros)


Here is some guidance on the u-boot parameters:

setenv bootargs console=${console},${baudrate} root=/dev/mmcblk0p1  rootfstype=ext4 rootwait video=mxcfb1:off video=mxcfb2:off video=mxcfb3:off video=mxcfb4:off video=mxcfb5:off video=mxcfb0:dev=hdmi,1920x1080M@60,if=RGB16 fbmem=48M vmalloc=400 mxc_hdmi.only_cea=1 coherent_pool=48M

ext2load mmc ${mmcdev}:${mmcpart} ${fdt_addr} boot/${fdt_file}
ext2load mmc ${mmcdev}:${mmcpart} ${loadaddr} boot/${image}
bootz ${loadaddr} - ${fdt_addr}


For Ubuntu, the instructions are practically identical ... just a few differences.

sudo debootstrap --arch armhf saucy rootfs/

# etc/apt/sources.list:
deb http://ports.ubuntu.com/ubuntu-ports saucy main
#deb http://ports.ubuntu.com/ubuntu-ports/ saucy-updates main universe multiverse
deb http://ports.ubuntu.com/ubuntu-ports saucy universe # mesa-utils


Serial port is enabled as follows:
# /etc/init/serial.conf
start on stopped rc RUNLEVEL=[2345]
stop on runlevel [!2345]
respawn
exec /sbin/getty 115200 ttymxc1


Jury is still out as to which distro is better to get the GPU stuff working on i.MX6..