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


No comments:

Post a Comment