Banana Pi the Gentoo Way

This guide is going to provide details on how to install Gentoo with a user compiled kernel and Gentoo Stage 3. I have been using Banana Pi's in a clustered distcc cross compiling environment for nearly a year.There has been a lot of controversy about the Banana Pi and it developers. The hardware is a nice board, but some of the practices concerning the methods undertook by the developers concerning business practices and the software side is certainly controversial. Best summed up on the Linux-Sunxi.org/Banana_Pi page.

To provide some clarification on documentation from different sources. Nearly everything provided on the Lemaker websites, and other Banana Pi websites has been copied from the Linux-Sunxi.org pages. While all the direct copies of the Linux-Sunxi.org website have been taken down. I am assuming some copyright infringement issues surfaced. For some reason, Lemaker prefers to maintain their own full kernel git repositories rather than simply having a simple patch repository and providing patches to upstream Linux-Sunxi.org and U-Boot to be included in their git repositories. This practice also makes is more difficult for LeMaker patches to be applied to other kernel sources by the general user base. Some early patches were provided and are included in the Linux-Sunxi.org git repositories, but latter refinements have not been submitted for inclusion.

I have to provide some cautionary advice concerning some of the ready to go images for the Banana Pi, along with some of the git repositories. The LeMaker Gentoo release is not put together very well, specifically when it comes to CFLAGS. It is obvious that they are inexperienced and are not aware of the impact of having incorrect or missing CFLAGS. I have seen countless posts of people spending countless hours attempting to get hardware acceleration working, while the CFLAGS supplied with the LeMaker Gentoo release, will not allow hardware acceleration. At least it did not earlier this year 2015. Here is a post of mine concerning CFLAGS for the Banana Pi.

I have found numerous posts on a number of forums, as well as the Lemaker forums themselves, with claims of malicious content. I my self have not bothered with disseminating any of the so-called official releases, and cannot confirm any of the claims. Considering the clashes and legal disputes over trademarks and domain ownership, along with the claim of open source, when the Banan Pi is certainly not, visit the Linux-Sunxi.org website for more details on that. It may certainly be true that some parties may have injected malicious content in an attempt to harm other participating parties.

The best way to avoid any possible security risks, is to use software that has been reviewed and tested by a reputable process and group. Therefore this guide will provide details on how to compile a kernel from the soc developers git repository (Linux-Sunxi.org), as well as from the Banana Pi (Lemaker) developers git repository. While using a standard Gentoo Arm Stage 3 pulled from an approved Gentoo Mirror.

To speed up compilation, it is suggested that you set up a distcc cross compiling environment on an Amd64 or other faster architecture. Distcc and Distcc/Cross-Compiling. Not all packages will compile on other machines in the cluster, but many will. If you have a number of Banana Pi devices, use the buildpkg feature so that binary packages are built that can then be quickly installed on the other Banana Pi's or distributed to devices in other locations. An NFS mount can be used for to have the packages directory mounted on all the Banana Pi devices on your lan.

This is a work in progress, please bear with me as I review my notes and figure out the best way to present them here. For the time being, here is one of my forum posts, concerning getting the right CFLAGS for the Banana Pi.

Cross Compiling
If you do not have a running arm device/computer to build from, and are running an Amd64 or X86 Desptop/Laptop. You will need to setup a cross compiling environment. Follow the Distcc/Cross-Compiling guide. You may also want to review the Raspberry Pi Cross building. Since compiling on one Banana Pi is not all that speedy you will want to take advantage of faster computers on you network Distcc

When you install your arm crosdev it is important that you use the cflags that you will be using on the Banana Pi. If neon-vfpv4 is not use, you will be losing some performance capability. Here is a link to some detailed information Arm Cortex A Processors & GCC Commands.

You will need to run this command on every machine that is not an Arm device that will be used for distcc.

Preparing The SDCard
Insert your sdcard and run lsblk.

Look for your sdcard, you should see a list of all your drives and mounted partitions with their attachment points starting with sda. I will be using /dev/sdX with X being used as the letter for for your sdcard.

This will clear all the data in the first part of the sdcard to ensure no old data causes any problems.

You need a minimum of two partitions. 1. Boot - 75Mb - 150Mb will do, perhaps larger if you intend on storing a lot of different kernels or other files. 2. Root - Can be the rest of the disk, or you may make a home partition, var partition or can even do a swap partition. Any partition configuation you want.

At the fdisk prompt, delete old partitions and create a new one: a.Type o. This will clear out any partitions on the drive. b.Type p press enter to list partitions. There should be no partitions left. c.Type n press enter, then p press enter for primary, 1 for the first partition on the sdcard/drive press enter, 2048 for the first sector press enter. d.Type +150M and press enter. e.Type p and you will see the first partition listed. f.Type n press enter, then p press enter for primary, 2 for the second partition on the sdcard/drive press enter, press enter to select the default, should be 309248 if you did a 150MB first partion. g.Type p press enter and you should see two partions, first one 150M the second one the rest of your sdcard/disk. h.Type t press enter, type 1 for the first partition press enter, type l press enter, you will see a list, press b and press enter to    select W95 FAT32. i.Type p press enter, you should now see two partitions with the first as W95 FAT32 and the second as Linux. j. Type w press enter to write the partition data to the sdcard/disk.

Now we are going to format the partitions with a file system.

Now mount the partitions so the boot files and system files can be loaded after we complete preparing and building them.

U-Boot
You will need to build a bootloader specific for the Banana Pi. You have a choice of using either the Linux-Sunxi git repositories or the Lemaker git repository. If you prefer to us the Linux-Sunxi repository you might want to check the boards.cfg from LeMaker to see if it has been updated and not provided to upstream Linux-Sunxi. You can simply edit the changes or copy over the LeMaker boards.cfg. You can visit the git repository to check without having to clone both repositories.

If you do not have u-boot-tools installed install it:

Make a build folder to work in. It can be called anything and can be located anywhere you want. Most things can be configured as a regular user, but then have to be compiled as root.

Clone the git repository:

First you need to configure for the Banana Pi:

If you have the Banana Pi Pro

Now you need to compile the bootloader:

Lets put the booatloader in the boot partition. We do not have to, you can keep it anywhere, but it is nice to have it there, as it will always be with the device if it ever needs to be reloaded.

Burn the bootloader into the SD card:

Script.bin
You will now need to make the script.bin file. Once again you can use either the Linux-Sunxi or the LeMaker git repository. To make sure you are using the latest updated .fex file if using Linux-Sunxi get BananPi.fex or BananaPro.fex from the LeMaker repository.

You will now need to make a change to the BananaPi.fex and BananaPro.fex files. Open the file and search for "ctp_det_used":

Compile the Kernel
To get started with a kernel configuration use the sun7i_defconfig. The LeMaker sun7i_defconfig has more things selected, both are a good starting points depending on what all you want configured in the kernel. To get the LeMaker sun7i_defconfig visit their git repository.

There are a lot of things with the LeMaker config selected that are only needed if you intend on attaching various devices to the board. For a smaller kernel go ahead de-select the devices you will not be needing, and or add devices you will be using.

If you prefer to use a GUI for configuring the kernel use one of the below: