Thursday, April 14, 2016

OpenCPN on Orange Pi an Allwinner H3 Arm SBC

I ordered a new Orange Pi PC and a Orange Pi One for $15.99 and $9.99 plus shipping. It has an Allwinner H3 CPU with a Mail-400 GPU. They are supposed to perform a little better than the Raspberry Pi 2. So I thought I'd give it a try. The OPi One is a little short on memory for compiling, so I started with the OPi PC.

The details: (as of Apr 15, 2016. Check you revisions.)
There are several choices for an operating system, I chose 's Debian Jessie. This OS is also available for several other H3, A10 and A20 CPUs by Allwinner such as the Banana Pi, CubieBoard, etc. These instructions may be adapted for them. They recommend a real class 10 SD card, not a fake. I this card seems a little slow but it is what is on hand.

Orange Pi PC w/ Samsung 8GB SD class 10, but only 4.2MB/s write speed when copying the image with this:

myrealpc$ sudo dd bs=4M of=/dev/mmcblk0 if=Armbian_5.05_Orangepih3_Debian_jessie_3.4.110_d  esktop.raw

Next boot the OPi PC from the SD card and setup the system. At armbian 5.05 there are several things to setup that will likely be changed in the next release (any day now). Other distributions will have different configurations. In addition to creating users and setting passwords, you should at least do:

orangepipc$ sudo apt-get update
orangepipc$ sudo apt-get upgrade

This was a 79 MB download this time, last week only 48MB.
Next install the necessary commands and libraries for compiling:

orangepipc$ sudo apt-get install build-essential cmake gettext git-core gpsd  
gpsd-clients libgps-dev wx-common libwxgtk3.0-dev libglu1-mesa-dev  
libgtk2.0-dev wx3.0-headers libbz2-dev libtinyxml-dev libportaudio2  
portaudio19-dev libcurl4-openssl-dev libexpat1-dev libcairo2-dev

Get a copy of the current opencpn source code. Change to the directory where you want to store the code, my home dir.And create a build directory.

orangepipc$ cd 
orangepipc$ git clone git://
orangepipc$ cd OpenCPN
orangepipc$ mkdir build
orangepipc$ cd build

Make these changes to the CMakeLists.txt  in order for the Mali-400 drivers to be included:

orangepipc$ nano ../CMakeLists.txt

#  find_path(OPENGLESv1_INCLUDE_DIR GLES/gl.h )
  SET(OPENGLESv1_INCLUDE_DIR "/usr/include/GLES" )

The default swap size for this distribution is 128MB, not nearly enough for opencpn to compile. Therefore I plugged in a USB stick with a linux on it which had a swap partition on partition 5. To temporarily add swap space I did:

orangepipc$ sudo mkswap -f /dev/sda5
orangepipc$ sudo swapon /dev/sda5

The Mali-400 graphics accelerator driver is not found in the directory opencpn is looking for it. So I made a symbolic link to the expected directory. The error was:

 ERROR: /usr/bin/ld: cannot find -lEGL 
orangepipc$ sudo ln -s /usr/lib/mali/ /usr/lib/

The OS should be ready to compile at this point. Use cmake to create the Makefiles for the compile. There are a few options available as per the OpenCPN site:
Default install dir is /usr/local, you can change this by providing the appropriate option to cmake: $ cmake -DCMAKE_INSTALL_PREFIX=/usr ../ If you're not into debugging, change to this to generate a smaller and marginally faster binary: $ cmake -DCFLAGS="-O2 -march=native" ../
It took about 2 hours for the compile. The first time through, just to satisfy me it succeeded, I directly installed opencpn as below.

orangepipc$ cmake ../
orangepipc$ make clean; make -j1
     # go drink some coffee, we're talking about a $15 computer compiling
orangepipc$ make install

It WORKS!! mostly.
I decided to try the optomized compile next so I:

orangepipc$ make clean
orangepipc$ cmake -DCFLAGS="-O2 -march=native" ../ 
orangepipc$ make -j1

orangepipc$ make package

You can then install the package with:

orangepipc$ sudo dpkg -i opencpn_4.2.0-1_armhf.deb 

Installing this way did not include the default world map or tcdata and I haven't heard the ships bells yet.

The map and tcdata can be included by following the instructions here. Or simply copy them in from another copy of opencpn (my Ubuntu15.04 laptop with opencpn 4.2 installed for instance) while you are copying in some charts to view.

There were a number of steps to cleanup the armbian 5.05 for automount the USBsticks etc. that I intend to document on my blog. At the rate the Armbian team is progressing, the OS cleanup will not be necessary for long.