evgueni
Posts: 9
Joined: Wed Oct 26, 2016 8:56 am
Location: Wellingborough, UK

In search of Buildroot + Kivy recipe

Wed Jun 12, 2019 3:35 pm

I am cross-compiling a custom linux using Buildroot and integrating Kivy with it as a custom package. Eventually I hope to strip back the build to a bare minimum in order to optimise for fast cold start into a Kivy app.

I get as far as functional image with Kivy installed but even the simplest Kivy app (the example at https://kivy.org/#home) fails to load with various error messages about not being able to get 'window provider' or 'text provider' or 'X server', depending on what OpenGL, GLES X11 etc options that I include / omit from the build. I am completely out of my depth with this, can anyone help? Is there a known good defconfig resulting in functional Kivy with Buildroot? Is addinional configuring required beyond Buildroot defconfig to get Kivy to work?

My Buildroot defconfig looks like this:

Code: Select all

BR2_arm=y
BR2_cortex_a7=y
BR2_ARM_FPU_NEON_VFPV4=y
BR2_TOOLCHAIN_BUILDROOT_GLIBC=y
BR2_TOOLCHAIN_BUILDROOT_CXX=y
BR2_TARGET_GENERIC_HOSTNAME="kivy"
BR2_TARGET_GENERIC_ISSUE="Welcome to Kivy"
BR2_INIT_SYSTEMD=y
BR2_TARGET_GENERIC_ROOT_PASSWD="secret"
BR2_SYSTEM_DHCP="eth0"
BR2_ROOTFS_USERS_TABLES="/path/to/users_file"
BR2_ROOTFS_POST_BUILD_SCRIPT="board/raspberrypi2/post-build.sh"
BR2_ROOTFS_POST_IMAGE_SCRIPT="board/raspberrypi2/post-image.sh"
BR2_LINUX_KERNEL=y
BR2_LINUX_KERNEL_CUSTOM_GIT=y
BR2_LINUX_KERNEL_CUSTOM_REPO_URL="https://github.com/raspberrypi/linux.git"
BR2_LINUX_KERNEL_CUSTOM_REPO_VERSION="rpi-4.20.y"
BR2_LINUX_KERNEL_DEFCONFIG="bcm2709"
BR2_LINUX_KERNEL_CUSTOM_LOGO_PATH="/path/to/logo.jpg"
BR2_LINUX_KERNEL_LZO=y
BR2_LINUX_KERNEL_DTS_SUPPORT=y
BR2_LINUX_KERNEL_INTREE_DTS_NAME="bcm2709-rpi-2-b"
BR2_LINUX_KERNEL_DTB_OVERLAY_SUPPORT=y
BR2_LINUX_KERNEL_NEEDS_HOST_OPENSSL=y
BR2_PACKAGE_GSTREAMER=y
BR2_PACKAGE_GST_PLUGINS_BASE=y
BR2_PACKAGE_GST_PLUGINS_BASE_PLUGIN_PANGO=y
BR2_PACKAGE_GSTREAMER1=y
BR2_PACKAGE_GSTREAMER1_MM=y
BR2_PACKAGE_GST1_PLUGINS_BASE_PLUGIN_ALSA=y
BR2_PACKAGE_GST1_PLUGINS_BASE_PLUGIN_PANGO=y
BR2_PACKAGE_GST1_PLUGINS_GOOD=y
BR2_PACKAGE_GST1_PLUGINS_GOOD_ZLIB=y
BR2_PACKAGE_GST1_PLUGINS_BAD=y
BR2_PACKAGE_GST1_PLUGINS_UGLY=y
BR2_PACKAGE_GIT=y
BR2_PACKAGE_MAKE=y
BR2_PACKAGE_PKGCONF=y
BR2_PACKAGE_NTFS_3G=y
BR2_PACKAGE_MESA3D=y
BR2_PACKAGE_SDL2=y
BR2_PACKAGE_SDL2_GFX=y
BR2_PACKAGE_SDL2_IMAGE=y
BR2_PACKAGE_SDL2_MIXER=y
BR2_PACKAGE_SDL2_TTF=y
BR2_PACKAGE_XORG7=y
BR2_PACKAGE_RPI_FIRMWARE=y
# BR2_PACKAGE_RPI_FIRMWARE_INSTALL_DTB_OVERLAYS is not set
BR2_PACKAGE_PIGPIO=y
BR2_PACKAGE_RNG_TOOLS=y
BR2_PACKAGE_PYTHON=y
BR2_PACKAGE_PYTHON_PY_PYC=y
BR2_PACKAGE_PYTHON_UCS4=y
BR2_PACKAGE_PYTHON_KIVY=y
BR2_PACKAGE_PYTHON_PIGPIO=y
BR2_PACKAGE_PYTHON_PIP=y
BR2_PACKAGE_PYTHON_PYGAME=y
BR2_PACKAGE_PYTHON_PYGAME_IMAGE=y
BR2_PACKAGE_PYTHON_PYGAME_FONT=y
BR2_PACKAGE_PYTHON_PYGAME_MIXER=y
BR2_PACKAGE_PYTHON_PYOPENSSL=y
BR2_PACKAGE_PYTHON_PYUDEV=y
BR2_PACKAGE_PYTHON_RPI_GPIO=y
BR2_PACKAGE_GNUTLS=y
BR2_PACKAGE_GNUTLS_TOOLS=y
BR2_PACKAGE_LIBOPENSSL_BIN=y
BR2_PACKAGE_LIBOPENSSL_ENGINES=y
BR2_PACKAGE_LIBCURL=y
BR2_PACKAGE_CURL=y
BR2_PACKAGE_LIBCURL_VERBOSE=y
BR2_PACKAGE_AVAHI=y
BR2_PACKAGE_DROPBEAR=y
# BR2_PACKAGE_DROPBEAR_CLIENT is not set
BR2_PACKAGE_SUDO=y
BR2_PACKAGE_NANO=y
BR2_TARGET_ROOTFS_EXT2=y
BR2_TARGET_ROOTFS_EXT2_4=y
BR2_TARGET_ROOTFS_EXT2_SIZE="750M"
# BR2_TARGET_ROOTFS_TAR is not set
BR2_PACKAGE_HOST_DOSFSTOOLS=y
BR2_PACKAGE_HOST_GENIMAGE=y
BR2_PACKAGE_HOST_MTOOLS=y
BR2_PACKAGE_HOST_PKGCONF=y
With the above options the failure mode is this:

Code: Select all

[INFO   ] [Logger      ] Record log in /home/pi/.kivy/logs/kivy_19-06-12_2.txt
[INFO   ] [Kivy        ] v1.10.1
[INFO   ] [Python      ] v2.7.15 (default, Jun 12 2019, 13:57:22)
[GCC 7.4.0]
[INFO   ] [Factory     ] 194 symbols loaded
[INFO   ] [Image       ] Providers: img_tex, img_dds, img_pygame, img_gif (img_pil, img_ffpyplayer ignored)
[INFO   ] [Text        ] Provider: pygame
[INFO   ] [Window      ] Provider: pygame(['window_egl_rpi'] ignored)
[ERROR  ] [Window      ] Unable to use pygame
[ERROR  ] [Window      ] The module raised an important error: 'No available video device
'

User avatar
topguy
Posts: 5566
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: In search of Buildroot + Kivy recipe

Thu Jun 13, 2019 9:06 am

Code: Select all

Provider: pygame(['window_egl_rpi'] ignored)
I think this is a good starting point for investigation/googling/kivy.forums..

evgueni
Posts: 9
Joined: Wed Oct 26, 2016 8:56 am
Location: Wellingborough, UK

Re: In search of Buildroot + Kivy recipe

Thu Jun 13, 2019 12:45 pm

Thank you @topguy, you are right about that and I have been doing a lot of googling. The problem is that it takes such a long time to try out different combinations of packages (compilation time can be hours). There are further clues in Joseph Kogut's python-kivy patch (v5) that I turned up in my search. (I think) I reproduce the patch in my config.in and .mk files (below) for kivy. But so far this has not helped me..

Config.in:

Code: Select all

config BR2_PACKAGE_PYTHON_KIVY
	bool "python-kivy"
	depends on BR2_PACKAGE_HAS_LIBGL
	select BR2_PACKAGE_HOST_PYTHON_CYTHON
	select BR2_PACKAGE_LIBPNG
	select BR2_PACKAGE_MTDEV
	select BR2_PACKAGE_PYTHON_DOCUTILS
	select BR2_PACKAGE_PYTHON_PYGMENTS
	help
	  A software library for rapid development of
	  hardware-accelerated multitouch applications.

	  http://kivy.org

comment "python-kivy needs an OpenGL provider"
	depends on !BR2_PACKAGE_HAS_LIBGL   

python-kivy.mk:

Code: Select all

PYTHON_KIVY_VERSION = 1.10.1
PYTHON_KIVY_SITE = $(call github,kivy,kivy,$(PYTHON_KIVY_VERSION))
PYTHON_KIVY_SETUP_TYPE = distutils
PYTHON_KIVY_LICENSE = MIT
PYTHON_KIVY_LICENSE_FILES = LICENSE
PYTHON_KIVY_DEPENDENCIES = host-python-cython libgl

ifeq ($(BR2_PACKAGE_GSTREAMER),y)
PYTHON_KIVY_DEPENDENCIES += gstreamer
PYTHON_KIVY_ENV += USE_GSTREAMER=1
else
PYTHON_KIVY_ENV += USE_GSTREAMER=0
endif

ifeq ($(BR2_PACKAGE_HAS_LIBEGL),y)
PYTHON_KIVY_DEPENDENCIES += libegl
PYTHON_KIVY_ENV += USE_EGL=1
else
PYTHON_KIVY_ENV += USE_EGL=0
endif

ifeq ($(BR2_PACKAGE_SDL2)$(BR2_PACKAGE_SDL2_X11)$(BR2_PACKAGE_SDL2_IMAGE)$(BR2_PACKAGE_SDL2_MIXER)$(BR2_PACKAGE_SDL2_TTF),yyyyy)
PYTHON_KIVY_DEPENDENCIES += sdl2 sdl2_image sdl2_mixer sdl2_ttf
PYTHON_KIVY_ENV += USE_SDL2=1
PYTHON_KIVY_ENV += KIVY_SDL2_PATH=$(STAGING_DIR)/usr/include/SDL2
else
PYTHON_KIVY_ENV += USE_SDL2=0
endif

ifeq ($(BR2_PACKAGE_WAYLAND),y)
PYTHON_KIVY_DEPENDENCIES += wayland
PYTHON_KIVY_ENV += USE_WAYLAND=1
else
PYTHON_KIVY_ENV += USE_WAYLAND=0
endif

ifeq ($(BR2_PACKAGE_XLIB_LIBX11)$(BR2_PACKAGE_XLIB_LIBXRENDER),yy)
PYTHON_KIVY_DEPENDENCIES += xlib_libX11 xlib_libXrender
PYTHON_KIVY_ENV += USE_X11=1
else
PYTHON_KIVY_ENV += USE_X11=0
endif

define PYTHON_KIVY_REMOVE_EXAMPLES
	rm -rf $(TARGET_DIR)/usr/share/kivy-examples
endef

PYTHON_KIVY_POST_INSTALL_TARGET_HOOKS += PYTHON_KIVY_REMOVE_EXAMPLES

$(eval $(python-package))

evgueni
Posts: 9
Joined: Wed Oct 26, 2016 8:56 am
Location: Wellingborough, UK

Re: In search of Buildroot + Kivy recipe

Mon Jun 17, 2019 11:28 am

Ok I am now further along with this, thanks to James Moore's excellent contribution https://groups.google.com/forum/#!searc ... qUk8PXBgAJ

I am using Buildroot-2019.02.2. James Moore's patch is incorporated in Kivy 1.11.0, which I think is the last version that still supports Python 2.7 ( I want this, so I specify Kivy 1.11.0 in python-kivy but otherwise copy what James Moore has done). Specifying a particular version of Cython for the build may or may not be necessary, I chose to go along with that. There is a segmentation fault problem which may be due to the particular combination of kernel and Kivy versions that I chose. The workaround is to tell Kivy to use <gl> backend as documented here https://github.com/kivy/kivy/issues/6007 and it works for me. I am now able to load the simple Hello World app from Kivy home page. Must log in as root else I get "failed to open vchiq instance" error.

I still need to figure out how to replicate Raspbian's touch screen and backlight control support. I have a lot to learn. My defconfig is reproduced below but I noticed that the options that are forced by "select" statements in Config.in file for Python-Kivy package do not show up in defconfig. So defconfig does not necessarily tell you everything you need to know.

Code: Select all

BR2_arm=y
BR2_cortex_a7=y
BR2_ARM_FPU_NEON_VFPV4=y
BR2_CCACHE=y
BR2_TOOLCHAIN_BUILDROOT_GLIBC=y
BR2_GCC_VERSION_8_X=y
BR2_TOOLCHAIN_BUILDROOT_CXX=y
BR2_TARGET_GENERIC_HOSTNAME="<redacted>"
BR2_TARGET_GENERIC_ISSUE="Welcome to <redacted>"
BR2_INIT_SYSTEMD=y
BR2_TARGET_GENERIC_ROOT_PASSWD="<redacted>"
BR2_SYSTEM_DHCP="eth0"
BR2_ROOTFS_USERS_TABLES="/path/to/users/file/users"
BR2_ROOTFS_POST_BUILD_SCRIPT="board/raspberrypi2/post-build.sh"
BR2_ROOTFS_POST_IMAGE_SCRIPT="board/raspberrypi2/post-image.sh"
BR2_LINUX_KERNEL=y
BR2_LINUX_KERNEL_CUSTOM_GIT=y
BR2_LINUX_KERNEL_CUSTOM_REPO_URL="https://github.com/raspberrypi/linux.git"
BR2_LINUX_KERNEL_CUSTOM_REPO_VERSION="rpi-4.20.y"
BR2_LINUX_KERNEL_DEFCONFIG="bcm2709"
BR2_LINUX_KERNEL_CUSTOM_LOGO_PATH="/path/to/logo/mylogo.jpg"
BR2_LINUX_KERNEL_LZO=y
BR2_LINUX_KERNEL_DTS_SUPPORT=y
BR2_LINUX_KERNEL_INTREE_DTS_NAME="bcm2709-rpi-2-b"
BR2_LINUX_KERNEL_DTB_OVERLAY_SUPPORT=y
BR2_LINUX_KERNEL_NEEDS_HOST_OPENSSL=y
BR2_PACKAGE_NTFS_3G=y
BR2_PACKAGE_DIRECTFB=y
# BR2_PACKAGE_DIRECTFB_DEBUG_SUPPORT is not set
# BR2_PACKAGE_DIRECTFB_KEYBOARD is not set
# BR2_PACKAGE_DIRECTFB_PS2MOUSE is not set
# BR2_PACKAGE_DIRECTFB_SERIALMOUSE is not set
BR2_PACKAGE_SDL=y
BR2_PACKAGE_SDL_IMAGE=y
BR2_PACKAGE_SDL_IMAGE_JPEG=y
BR2_PACKAGE_SDL_IMAGE_PNG=y
BR2_PACKAGE_SDL_MIXER=y
BR2_PACKAGE_SDL_TTF=y
BR2_PACKAGE_SDL2=y
BR2_PACKAGE_SDL2_OPENGLES=y
BR2_PACKAGE_SDL2_IMAGE=y
BR2_PACKAGE_SDL2_MIXER=y
BR2_PACKAGE_SDL2_TTF=y
BR2_PACKAGE_RPI_FIRMWARE=y
BR2_PACKAGE_RPI_FIRMWARE_X=y
BR2_PACKAGE_PIGPIO=y
BR2_PACKAGE_RNG_TOOLS=y
BR2_PACKAGE_PYTHON=y
BR2_PACKAGE_PYTHON_UCS4=y
BR2_PACKAGE_PYTHON_KIVY=y
BR2_PACKAGE_PYTHON_PIGPIO=y
BR2_PACKAGE_PYTHON_PYUDEV=y
BR2_PACKAGE_PYTHON_RPI_GPIO=y
BR2_PACKAGE_PYTHON_SETUPTOOLS=y
BR2_PACKAGE_AVAHI=y
BR2_PACKAGE_DROPBEAR=y
# BR2_PACKAGE_DROPBEAR_CLIENT is not set
BR2_PACKAGE_SUDO=y
BR2_PACKAGE_NANO=y
BR2_TARGET_ROOTFS_EXT2=y
BR2_TARGET_ROOTFS_EXT2_4=y
BR2_TARGET_ROOTFS_EXT2_SIZE="200M"
# BR2_TARGET_ROOTFS_TAR is not set
BR2_PACKAGE_HOST_DOSFSTOOLS=y
BR2_PACKAGE_HOST_GENIMAGE=y
BR2_PACKAGE_HOST_MTOOLS=y

evgueni
Posts: 9
Joined: Wed Oct 26, 2016 8:56 am
Location: Wellingborough, UK

Re: In search of Buildroot + Kivy recipe

Wed Jun 19, 2019 8:46 am

Figured out that backlight and touchscreen support are already enabled. What was missing was a single line in board/raspberrypi2/genimage-raspberrypi2.cfg telling buildroot to copy the overlays folder across:

Code: Select all

      "rpi-firmware/overlays",
Touch input now works and "echo [0..255] > /sys/class/backlight/rpi_backlight/brightness" now has the desired effect.

Return to “Advanced users”