Saturday, October 01, 2011

Setting up Geovision 650 surveliance card in Gentoo

I was trying to turn my old 2.2 Ghz Celeron based computer into a surveillance system. I needed a lot of computing power to be able to record from 4 cameras and to be able to integrate 2 new Vilar IP cameras as well. I chose Gentoo Linux since it does it's job as server OS quite well on my home development server.

So after 3 hours I had a customized installation compiled with -march=native and kernel stripped down to the bare minimum.

I tried to set up my Geovision 650 DVR card starting from the Linux module. I launched make menuconfig and was sure that I'll have everything ready in under an hour. As you can imagine this was not the case :) In the end it took me 2 days to have the card running and I decided to describe the steps.

Gentoo installation
I followed the handbook as usual and the installation was pretty straightforward and went smooth. The GCC configuration spared me the search for the CFLAGS of my CPU and I had to put -march=native to get everything optimized.

USE flags
I intended to use ZoneMinder so I added the needed flags right away (apache, mysql, php, perl). It turned out that to check the input of the card I had to use xawtv, so I enabled X as well.

BT878 / BTTV module
The module I needed was BTTV since Geovision 650 is equipped with two BT878 chips to allow decent capture from its 4 inputs. 

However I was not able to find how to enable the compilation of the driver. I was more astonished than ashamed to find that the answer was the non-existent Infra-red Remote.... Turning the IR support in the kernel enabled the compilation of the module I desperately needed.

I tried so hard to enable BT878 support so I decided to scan all options in kernel configuration screens. I removed a lot of unneeded stuff and between the flags that were unchecked was the one ensuring that my 80GB HDD was able to host single files with size more than 2TB.

I recompiled the kernel and a few modules, replaced the old binaries, rebooted the machine...

Missing kernel features
... and I found myself with read only EXT4 file system. It turned out that the LiveCD I used to create my root partition had large files suppport turned on. In fact the kernel has this by default. Using EXT4 tools seems to pick the kernel settings so before I was able to fit 2TB files on my small HDD and now the kernel was not able to process such files anymore.

I found the solution in this blog and this was one of the reasons to describe my installation problems.

BTTV driver configuration
Gentoo now uses OpenRC to describe and configure modules (/etc/conf.d/modules). I put bttv driver in the list rebooted again to check if the driver will autodetect the card. Yes I know that modprobe would (or actually should) have done the same job but I had to be sure.

What I found was card=0, autodetecting log entry shown by dmesg. So I had to find the correct card settings. Fortunatelly there are a lot of resources out there that hinted to use "card=<number>" parameter of bttv module. The question was what to put as number. Soon I found that 150 provides me with Geovision 600 which is pretty close relative to my GV-650. 

Using my Windows experience I rebooted again and after several seconds found out that nothing changed. So time for modprobe tests with different numers only to find no change in bttv output.

Fortunatelly the bttv sources were sitting quetly on my HDD. A dump of bttv.c showed that GV-600 has 0x96 value which was exactly 150 in decimal. I smiled happily and put the "correct" values in modules configuration: "card=150,150".

The next Windows-style reboot revealed that bttv was not happy with this value as well. I had the same autodetect failure in the logs.

I reported the problem in bugzilla. Meanwhile tried to search internet and found a Russian Google IRC chat that provided needed workaround. It turned out that udev kicked in too early and loaded the module before OpenRC was able to configure it correctly. OpenRC issued modprobe correctly but the module was already there. 

So in the end - not really a bug :) Simply disabling coldplug with rc_coldplug="NO" in /etc.conf.d/udev did the trick.

Testing video input
I installed xawtv to test the output and after 2 hours of experiments I had no idea why the card won't work.

Google found out several configurations working fine with GV600 or GV800 but none with GV650. Strange ... 

I wondered what was the difference between GV600 and GV650. After some research it turned out that GV650 has one more BT878 chip than GV600, and in turn GV800 has 4 in total. 

Consulting the bttv-cards.c file revealed that one of the chips in GV800 is "master" and the rest "slaves". This and the strange mapping between the inputs and the chips in this blog led me to the conclusion that I need to change my bttv configuration to "card=157,158" (master/slave).

Another reboot and suddenly everything worked just fine.

ZoneMinder
The last time I tried to run ZoneMinder on Gentoo was 4 years ago. Too long as it turned out. 

Today the ZoneMinder is nowhere to be found in the repositories and its configuration on your own is not easy. You have to hunt down the location of all dependencies, the libraries ffmpeg is build with and so on.
Well I think I managed to dig all the needed info but configure just stopped with cryptic message about openssl library. Basically it says that the library is on the system but is messed up and unusable by ZoneMinder. 

Seems like I'll have to create a new blog about this :)

id_rsa.pub: invalid format, error in libcrypto

After I upgraded my Linux and got Python 3.10 by default, it turned out that Ansible 2.9 will no longer run and is unsupported together with...