Building Kura - #3

TL;DR:

Last time, we'd just built the Kura OLinuXino installer. I'll admit, I couldn't sleep last night and decided to have a go at getting the installer working.

Surprise; it didn't work out of the box!

First of all I needed to actually install Java which, for some reason, isn't included in the deb's dependencies list.
It seems obvious to put it there, but none of the targets have it as a dependency, so I can't help wonder if there's a good practical reason to miss it out. I'll have a think about this and come back to it.

So let's manually install Java to the OLinuXino:

# apt-get update
# apt-get install default-jre
...
...
update-alternatives: error: error creating symbolic link `/usr/share/man/man1/rmid.1.gz.dpkg-tmp': No such file or directory  
...
... (General messages of failure)

Oh no, what happened?
The default OLinuXino image has man pages disabled in dpkg with the file /etc/dpkg/dpkg.cfg.d/01_nodoc, presumably to save space. This means that not only are there no man pages, but there are also no man page directories either.
It looks a hook expects there to be a /usr/share/man/man1 directory.
The workaround:

# mkdir /usr/share/man/man1
# apt-get install default-jre
...
...
(Success)

So Java is installed, but now we're faced with a 'Cannot allocate memory' error when trying to load up Kura. This is because Kura is trying to reserve 512MB, as can be seen in the jvm invocation at /opt/eclipse/kura/bin/start_kura_background.sh:

...
...
  nohup java -Xms512m -Xmx512m -XX:MaxPermSize=64m \
        -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/kura-heapdump.hprof \
        -XX:ErrorFile=/var/log/kura-error.log \
        -Dkura.os.version=debian \
...
...

512MB is the total compliment of the OLinuXino, so it makes sense that it wouldn't be able to be reserved. This file is generated by the distrib/src/main/ant/build_equinox_distrib.xml ant script.

Some grepping around led me to where this number initially comes from (in distrib/pom.xml, under the olinuxino profile):

<property name="kura.mem.size" value=512m" />  

Easily enough fixed; with the value set to 256m Kura's able to start, albeit with some problems.
The dhcp server is erroring out in /var/log/syslog. It complains it can't access its leases database, /var/lib/dhcp/dhcpd.leases .
This didn't exist, so I add some lines to ensure it exists in kura_install.sh:

mkdir -p /var/lib/dhcp/  
touch /var/lib/dhcp/dhcpd.leases  

Seems to work, and we now have a dhcp server running; next problem!

/var/log/kura.log reveals that Kura is trying to call the 'iwlist' program to inspect my Wifi dongle's scan results. This is part of the wireless-tools debian package, and was not installed by default. I added it to the deb dependency list in distrib/pom.xml:

...
<project.raspbian.dependencies>hostapd, isc-dhcp-server, iw, dos2unix, bind9, unzip, ethtool, telnet, wireless-tools</project.raspbian.dependencies>  
...

The wpa_supplicant configuration file which Kura creates depends on the existence of the group, 'wheel'. Another addition in kura_install.sh ensures this group exists:

grep -e '^wheel:' /etc/group || {  
    echo "'wheel' group not found. Creating..."
    addgroup wheel
}
From the top

Now the installer has the fixes in, the whole process to follow, after copying the .deb to the device:

# mkdir -p /usr/share/man/man1
# apt-get install default-jre
...
# dpkg -i kura_2.0.0-SNAPSHOT_olinuxino_installer.deb 
Selecting previously unselected package kura.  
(Reading database ... 41718 files and directories currently installed.)
Preparing to unpack kura_2.0.0-SNAPSHOT_olinuxino_installer.deb ...

Installing Kura...

Unpacking kura (2.0.0-SNAPSHOT) ...  
dpkg: dependency problems prevent configuration of kura:  
 kura depends on hostapd; however:
  Package hostapd is not installed.
 kura depends on isc-dhcp-server; however:
  Package isc-dhcp-server is not installed.
 kura depends on iw; however:
  Package iw is not installed.
 kura depends on dos2unix; however:
  Package dos2unix is not installed.
 kura depends on bind9; however:
  Package bind9 is not installed.
...

That last error is okay, we just need to pull the packages in with apt:

# apt-get -f install

This installs everything and finishes installing Kura. A reboot and we're done.

After connecting the board to my home router and waiting for boot, we are able to get to the web interface (login is admin:admin):
Kura Web UI

One more thing before I call this done; there's a usb gadget port present on the OLinuXino. It'd be neat if a DHCP server was running on there by default, meaning you could plug it into your PC's USB port and go. The g_ether module is already loaded by default, so it's perhaps just a matter of adding some lines to distrib/src/main/resources/olinuxino/kuranet.conf in order to make this happen by default:

net.interface.usb0.config.nat.masquerade=true  
net.interface.usb0.config.dhcpServer4.passDns=true  
net.interface.usb0.config.dhcpServer4.enabled=true  
net.interface.usb0.config.ip4.status=netIPv4StatusEnabledLAN  
net.interface.usb0.config.nat.enabled=true  
net.interface.usb0.config.nat.dst.interface=unknown  

Reinstall, and it doesn't work. Arrgh!
Turns out the IP configuration for the usb0 interface needs placing into the /etc/network/interfaces file, and the dhcpd config added to the installer. A couple of hours more investigation and grepping shows a number of files we need to add stuff to in order to make everything work properly.

The network configuration in Kura is split across the kuranet.conf file, various Linux configuration files and the OSGi configuration snapshot file. Network configuration is apparently a very messy business; who knew?

One last thing; we must disable the Debian network-manager in kura_install.sh, so it doesn't interfere with Kura's network management.

...
update-rc.d network-manager remove  
...
PHEW

As far as this blog series goes, I'm going to leave it here. I've got my working installer and the port that I wanted. I also have a far clearer understanding of Kura's build process (and how it might be improved). Next thing I'll probably do is figure out how best to deal with different OLinuXino models, such that I don't make a mess. I still haven't written the OpenJDK DIO GPIO file for this reason.