STK1160-howto-linux-sunxi-3 4
STK1160 is the new kernel driver for Easycap like USB AV capture devices.
It is available in the linux kernel from version 3.7 and above, but linux-sunxi
stable kernel is 3.4 . So this driver does not exist native in that kernel.
Contents
Why use stk1160 instead of the old driver easycap ?
One main reason: You can change input channel on your device.
If you have the single channel version you also have and a S-video input. But
with easycap driver you can't switch to that input. The input selection is not
supported by the easycap driver and you will be always on default input 0.
If you have the four channel version you have four AV channels and most likely
you will want to be able to switch between channels. Again old easycap driver
does not have that functionality.
NB: If you don't need changing the input channel you can use the old easycap
driver and there is one benefit: easycap supports two framerate modes: 5 and 25
fps by selecting the proper norm. For example there is norm PAL_BGHN and norm
PAL_BGHN_SLOW, which is the 5 fps mode. And on SBCs this framelimit relieve the
CPU a little bit as the capture streams only five frames per second. The stk1160
supports currently only 25 fps mode.
What do You need before starting
Kernel source.
Config file from your current kernel.
Compiler for the cross compilation.
Getting the kernel source
For the latest stable linux-sunxi 3.4.xx kernel the command is:
git clone -b sunxi-3.4 --depth 1 https://github.com/linux-sunxi/linux-sunxi.git
Wait for the download process to finish.
Getting the config file from your current kernel
While on the device copy the /proc/config.gz to your build machine,
then use gunzip to extract and you now have your current kernel config.
Getting compiler for the cross compilation
On Debian add to your /etc/apt/sources.list
deb http://www.emdebian.org/debian unstable main
then
apt-get update
apt-get install gcc-4.7-arm-linux-gnueabihf
Now you have compiler for the cross compilation.
Compiling stk1160
The stk1160 will be build using backported version provided by media_build, more
info about media_build you can find at the following link:
http://www.linuxtv.org/wiki/index.php/How_to_Obtain,_Build_and_Install_V4L-DVB_Device_Drivers
But for this to work you need to build a new kernel with V4L support as modules,
so you can load the new V4L core from media_build and also patch dma-buf.c/.h in
the kernel tree, because of a missing function there.
Lets get to work ...
Will assume that you have your kernel source tree in ~/linux-sunxi, also that
you have already copied your current kernel config like ~/linux-sunxi/.config .
Preparing the build environment
export CROSS_COMPILE=arm-linux-gnueabihf-
export ARCH=arm
Patching the kernel tree:
The patch is available at:
https://drive.google.com/file/d/0B6S44jnEBxzyQVhUNDFlQ2RnRUU/edit?usp=sharing
Download and execute the following commands:
cd ~/linux-sunxi
patch -p0 < /path/to/dma-buf-vmap.patch
Building the new kernel with V4L core as modules
make silentoldconfig
make menuconfig
Go to Device Drivers -> Multimedia support and mark Video for Linux with m. Exit and choose to save the changes to the config. Based on your build machine use -j with value #threads your CPU is capable, example values: dual-core no HT -j2, dual-core with HT -j4 and so on.
make -j4 uImage
make -j4 INSTALL_MOD_PATH=out modules
make -j4 INSTALL_MOD_PATH=out modules_install
The uImage file is located in linux-sunxi/arch/arm/boot/ The kernel modules are located in linux-sunxi/out/lib/modules/3.x.xx+
Do not rush to update your kernel and modules on your sd-card or nand.
Building media_build
Download this patch for media_build:
https://drive.google.com/file/d/0B6S44jnEBxzydGlELXl4S3I2dzg/edit?usp=sharing
First we will go up one level to home dir as we were in ~/linux-sunxi, then
get latest media_build source and build it.
cd ..
git clone --depth=1 git://linuxtv.org/media_build.git
cd media_build
./build --check
Install missing packages showed from ./build --check and then continue
patch -p1 < /path/to/media_build-makefilepl.patch
make download
make untar
make prepare
DIR=~/linux-sunxi make release
nano v4l/Makefile
find and comment out the line
-include $(obj)/Makefile.sound
because sound modules require PCI support, which sunxi doesn't have
nano v4l/.version
append to the lines starting with
SUBLEVEL:=...
KERNELRELEASE:=...
one plus sign at the end as the kernel versions of linux-sunxi 3.4 stable are
in format 3.4.xx+ , but media_build for some reason omits the + .
mv v4l/.config v4l/.config.orig
nano v4l/.config
Insert the following:
CONFIG_VIDEO_DEV=m
CONFIG_VIDEO_V4L2_COMMON=m
CONFIG_VIDEO_MEDIA=m
CONFIG_VIDEO_V4L2=m
CONFIG_VIDEOBUF_GEN=m
CONFIG_VIDEOBUF_DMA_CONTIG=m
CONFIG_DMA_SHARED_BUFFER=m
CONFIG_VIDEOBUF2_CORE=m
CONFIG_VIDEOBUF2_MEMOPS=m
CONFIG_VIDEOBUF2_VMALLOC=m
CONFIG_VIDEO_CAPTURE_DRIVERS=y
CONFIG_V4L_MEM2MEM_DRIVERS=y
CONFIG_V4L_PLATFORM_DRIVERS=y
CONFIG_VIDEO_SAA711X=m
CONFIG_VIDEO_STK1160_AC97=n
CONFIG_VIDEO_STK1160=m
CONFIG_VIDEO_STK1160_COMMON=m
Save and exit. This is a stripped media_build configuration for stk1160 only.
NB: For audio support for your capture change CONFIG_VIDEO_STK1160_AC97 to y.
make -j4
DESTDIR=~/linux-sunxi/out make install
Installing the new kernel and modules
Now you have the kernel and updated modules with the new V4L core and stk1160.
Copy from ~/linux-sunxi/arch/arm/boot/uImage to your /boot folder on the device.
Then copy the modules folder /linux-sunxi/out/lib/modules/3.x.xx+ to the device.
Blacklisting the old easycap driver:
While on the device create /etc/modprobe.d/easycap-blacklist.conf and add:
blacklist easycap
Save and exit
Reboot the device and all should be ok.
Testing
Insert the capture, check with lsmod for stk1160, check dmesg for any warnings,
errors, unresolved symbols, etc, there should be none. Check if video device was
created under /dev/video0 or /dev/videoX if you have more than one V4L device.
PAL norm is at number 5, by default stk1160 is configured for NTSC.
Known issues
Sometimes you can see in dmesg warning from videobuf2-core.c, but this does not
effect the capturing or streaming. I have not found the reason for the warning,
but as it is not problematic I have left it for now.
Good luck and happy capturing using stk1160 :-)