Getting Started with BananaPI Linux

Single board computers have been very popular in the community due to their low price and high flexibility and Banana Pi board, which is powered by Allwinner A20, is no exception. In this blog post you will find everything you need to prepare a Banana Pi Linux image from scratch.

Board setup

I have a Banana Pi (Foxconn Super Pi clone actually) with a 5″ capacitive touchscreen which is connected to RGB pins with an adapter board. Find the scheme and details of the board here. For internet connectivity i use TL-WN725N (v3) wifi dongle that has RTL8188EU chip.

Build environment

Build OS

To make everything clear, it is important to prepare the same working environment as instructed here. So I started on a fresh Ubuntu 16.04.3 64bit installation and you should do the same (VMware is also possible).

Required packages

On the version of Ubuntu I am currently using have some problems installing the packages and this is why I use aptitude to solve the dependency problems.

Now run the following to prepare the environment.

Here aptitude solves the problems and we must choose where no package stays “not installed”. The solution below works perfect for me.

If everything is ready, let’s go ahead to the image building.

Banana Pi BSP building

The most important parts are Uboot bootloader and kernel building. Run the following to get the repositories for u-boot v2016.09, stable Linux Mainline Kernel v4.15 and firmware files that are necessary for some drivers to operate.

U-boot compilation

The required GCC is version 4.8 for this version of u-boot. This is why we need to hack the Makefile.

Now is the part for LCD and touch settings. Note that the configuration is given for the adapter board of which details are given above.

Finally, run the following to compile the bootloader.

If everything is fine, you can find the u-boot image at ~/u-boot/u-boot-sunxi-with-spl.bin.

Linux mainline kernel for BananaPi

Mainline kernel compilation takes place with respect to defconfig file. Place the this bpi_defconfig file to path: ~/linux-stable/arch/arm/configs/bpi_defconfig without file extension.

Edit the device tree file at: ~/linux-stable/arch/arm/boot/dts/sun7i-a20-bananapi.dts for touchscreen settings. Add the following after i2c2:

Then add the following into section pio:

To activate ft5x06 touchscreen and RTL8188EU wifi driver:

Now everything is ready for compilation.

After successful compilation device-tree binary can be found at ~/linux-stable/arch/arm/boot/dts/sun7i-a20-bananapi.dtb, kernel image file (uImage) is located at ~/linux-stable/arch/arm/boot/uImage  and modules are under ~/linux-stable/output/.

Boot script preparation

Boot script is the file that informs u-boot about the necessary settings, kernel and dtb locations. Run this.

To enable more boot messages you can also use the following but it impacts the performance.

The created boot.cmd  must be converted into boot.scr  with the following tool.

RootFs for BananaPi

There are several ways to create a rootfs but obtaining one is a fast and the most reliable option for a start. Linaro provides rootfs for several distributions and versions and here is a Debian rootfs that works fine.

Bootable SD card preparation

Environment setup

Here we have u-boot, boot script, device-tree-binary, uImage and rootfs in hand. Next step is gathering all together to create our bootable Banana Pi SDcard. First, define the source paths and directories.

Plug your 4GB+ card to the machine (or virtual machine) and find the drive letter using lsblk. Export the card  and p  variables similar to one of the examples below.

Card partitions

Now we need to prepare the SD card partitions.

Run the following commands to write u-boot to the disk.

Partition-1 (boot partition)

Copy the contents to the card.

Partition-2 (rootfs partition)

Copy the contents to the card.

Partition table

Some final touches are necessary for the card to work properly. First we need to create /etc/fstab file.

Network settings

This part is for network connectivity. By default NetworkManager takes care of the network and enables DHCP on eth0 but in example if you want to assign a static ip address to your board, use the following part after changing the settings and uncommenting necessary lines. If you have no idea, ignore the following.

Keyboard settings

To change the default keyboard layout, one can use the following part with the desired language.

Other settings

The following lines are also required.

Now finalize the partition.

First boot

Assuming you have done every step correctly, the next thing to do is plugging the SDcard to your BananaPi and see the result of your patience ?

Final words

This tutorial explains the most basic steps to compile a mainline kernel and u-boot then using an instant rootfs from Linaro project. The next step would be preparing a rootfs using debootstrap or preparing a bootable image file rather than writing directly to the card. I will try to add new titles to this post when i find time. Keep informed and have fun ?