OpenBSD on the A20-OLinuXino-LIME2

Posted on 2020-07-02

This guide will explain how to get OpenBSD to run on the A20-OLinuXino-LIME2 Rev. K single-board computer by Olimex. We will go through modifying and compiling U-Boot to make the LAN port work, as well as following OpenBSD's -current branch to get all the security fixes.

Prerequisites

To download and compile U-Boot, you will need around 500MB of free space. You will also need a serial cable to connect to the board since HDMI is not used by default. Olimex provides an USB-Serial cable that will work just fine for getting everything set up.

This guide also assumes that you are using a Linux system, in my case Debian, but I am sure that you can adapt it to other distributions or other operating systems. It will just require more work looking up information on your part.

U-Boot

The hardware of the OLinuXino LIME2 has been changed throughout its numerous revisions. My board revision is K and since revisions H and newer have a different Ethernet solution, it does not work with the default config that mainline U-Boot provides for the LIME2. To solve this, we have to add a few lines to the relevant config and then compile U-Boot ourselves to get Ethernet working with the newer revisions.

Preparing your system

Since my main machine is running Debian, these are the commands I run to set it up for compiling U-Boot:

dpkg --add-architecture armhf
apt update
apt install g++-arm-linux-gnueabihf
apt install build-essential git debootstrap u-boot-tools device-tree-compiler

Instructions for a few other distributions

These commands set you up for cross-compiling for the armhf architecture, as well as the basic tools for compiling in general. You will likely get a few errors about missing dependencies once you actually start compiling U-Boot, it my case I was missing bison, flex, ncurses and swig (the package names are libbison-dev, flex, libncurses-dev and swig on Debian), but for you this may vary. If your compilation stops with an error, try to scan it for "[blah] missing" or something along those lines, and then try to figure out what that package is called in your distribution. But first, let's get U-Boot!

Getting U-Boot

First, clone the repository:

git clone git://git.denx.de/u-boot.git

Then, let's set it to the branch of the latest stable release. At the time of writing it's v2020.04, though v2020.07 already has several release candidates and will likely be out soon, so keep an eye out for that!

git checkout v2020.04

That's it, we now have the U-Boot repository in a state that we can work with.

Configuring and Compiling

As mentioned above, we need to edit the board's config file to get the Ethernet port to work. Since my LIME2 model has eMMC memory, I will use the A20-OLinuXino-Lime2-eMMC_defconfig, but if you have a device without eMMC, simply use the regular A20-OLinuXino-Lime2_defconfig file. Edit all the below commands accordingly!

So, in my case I am editing the file configs/A20-OLinuXino-Lime2-eMMC_defconfig in the u-boot folder and adding the following lines:

CONFIG_PHY_MICREL=y
CONFIG_PHY_MICREL_KSZ90X1=y
CONFIG_GMAC_TX_DELAY=3

Save the file, and from inside the u-boot directory, execute these commands to build U-Boot for your board. Again, adjust the board config name according to whether you have eMMC or not:

make CROSS_COMPILE=arm-linux-gnueabihf- A20-OLinuXino-Lime2-eMMC_defconfig
make CROSS_COMPILE=arm-linux-gnueabihf-

If you encounter errors, remember to check whether they are due to missing dependencies and install whatever is missing to make it compile properly. Once it is done compiling you will see a new file called u-boot-sunxi-with-spl.bin in the u-boot directory. This is the file that we need to flash to our device!

Obtaining OpenBSD

Pick the mirror that is closest to you for downloading the files. I went with the binary for the Cubieboard2 since it is also an Allwinner A20 based board and it seems to work fine. You can download the files with wget, replacing the URL with the one of your mirror of choice:

wget https://cdn.openbsd.org/pub/OpenBSD/6.7/armv7/miniroot-cubie-67.fs
wget https://cdn.openbsd.org/pub/OpenBSD/6.7/armv7/SHA256

Now, let's verify the integrity of the file we downloaded:

sha256sum -c --ignore-missing SHA256

It should return miniroot-cubie-67.fs: OK.

Flashing

With the integrity confirmed, we can flash the two files to the micro SD card with dd. Use lsblk to determine which device is your micro SD card, in my case it was mmcblk0. Adapt the output device name if yours is different, the following commands will erase the contents of the device completely so make sure to get the device right!

sudo dd if=miniroot-cubie-67.fs of=/dev/mmcblk0 bs=1m
sudo dd if=u-boot-sunxi-with-spl.bin of=/dev/mmcblk0 bs=1k seek=8
sudo sync

sync ensures that all files are completely written to the microSD card before we unmount and detach it. When all that is done, we can stick the microSD card into the LIME2 and start installing!

Booting and installing

Before we boot the device, we need to connect our serial cable. The LIME2 has three small pins next to the Ethernet port labelled TX, RX and GND. Connect the RX plug of your connector to the TX pin, the TX plug to the RX pin and the GND plug to the GND pin of the board. Check the instructions of your serial cable to figure out which colour corresponds to which line if they are not labelled. In the case of Olimex's cable:

Blue  = GND
Green = RX
Red   = TX

Now we can start the serial connection in our terminal. I use screen for this purpose (use the correct baud number for your cable):

sudo screen /dev/ttyUSB0 115200

If we now turn on the device, we should get the output to our terminal and be able to input things to the device.

Once all this is done, we can simply proceed with the installation. If you have a model with eMMC, it should show up as sd1 in the installer, with sd0 being the microSD card. Installing to and booting from eMMC worked just fine for me, so it should work for you too.

Getting security fixes

Since syspatch does not work for armv7, we will need to use alternative means to apply the errata. There are several ways to do it that are documented in the FAQ section about security updates, I personally chose to just run -current by updating the system to the latest snapshot. This can easily be done with the command sysupgrade -s without building from source. I also recommend subscribing to the "announce" mailing list to get security advisories, as well as having a look at the FAQ page for the -current branch for breaking changes before running sysupgrade -s.

Using HDMI

HDMI is not enabled by default, but if you want to use it, you can do it very easily. If you just want to do it once, you can simply type set tty fb0 at the OpenBSD boot prompt, but it will not persist after reboot. To make the change permanent, create the file /etc/boot.conf with the same contents:

doas echo "set tty fb0" >> /etc/boot.conf

Rebooting now will enable you to use HDMI with an USB keyboard instead of the serial connector.

Conclusion

As you see, it is not all that hard to get it running once you figure out the steps. All that is needed is a simple modification of U-Boot to get Ethernet to function. If you have any questions or suggestions along the way though, feel free to contact me via email. Have fun hacking! :)