Building Linux 4.1 for the Banana Pi

This post is a follow up to my original post Building BananaPi LeMaker Kernel.

If you’re just looking for a vanilla Debian or Ubuntu image for your Banana Pi that utilizes a Linux kernel newer than 3.4.xxx, then stop reading and go to this page maintained by Igor Pečovnik. He provides pre-built Debian and Ubuntu images for a variety of Banana Pi boards.

If you want to manually build an image, he has put the build scripts he uses up on his GitHub repository. While I tried to do everything manually starting from my last post, I ended up building a kernel that would not boot. So I shamelessly stole the kernel configuration from Igor, and the resulting kernel boots.

The GMAC driver which required so much patching for the 3.4 kernel was mainlined in 3.17. As such, these instructions should work for any kernel newer than 3.17. I am building 4.1.3 in my script.

Here is the Jenkins/bash script to build the kernel, modules, and boot goodness you need (a direct link to the .sh file is at the end of the post):

if [ ! -d "linux-4.1.3" ]; then
wget https://www.kernel.org/pub/linux/kernel/v4.x/linux-4.1.3.tar.xz
tar -Jxvf linux-4.1.3.tar.xz
fi
cd linux-4.1.3
wget https://watchmysys.com/blog/wp-content/uploads/2015/07/banana-pi-linux-4.1.3-config.txt -O .config
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- clean
make -j4 ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- LOADADDR=0x40008000 zImage dtbs
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=output modules
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=output modules_install
mkdir -p output/boot/
cp arch/arm/boot/zImage output/boot/
cp arch/arm/boot/dts/sun7i-a20-bananapi.dtb output/boot/
cat > output/boot/boot.cmd < output/boot/uEnv.txt << EOF
fatload mmc 0 0x46000000 zImage
fatload mmc 0 0x49000000 sun7i-a20-bananapi.dtb
setenv bootargs console=ttyS0,115200 [earlyprintk] root=/dev/mmcblk0p2 rootwait panic=10 rootfstype=ext4 rw ${extra}
bootz 0x46000000 - 0x49000000
EOF
mkimage -C none -A arm -T script -d output/boot/boot.cmd output/boot/boot.scr
cd ..
if [ ! -d "u-boot-2015.04" ]; then
wget ftp://ftp.denx.de/pub/u-boot/u-boot-2015.04.tar.bz2
tar -jxvf u-boot-2015.04.tar.bz2
fi
cd u-boot-2015.04
make -s CROSS_COMPILE=arm-linux-gnueabihf- clean
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- Bananapi_defconfig
make -j4 ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-
cp u-boot-sunxi-with-spl.bin ../linux-4.1.3/output/boot/
cd ../linux-4.1.3/
cat > output/boot/uEnv.txt << EOF
fatload mmc 0 0x46000000 zImage
fatload mmc 0 0x49000000 sun7i-a20-bananapi.dtb
setenv bootargs console=ttyS0,115200 [earlyprintk] root=/dev/mmcblk0p2 rootwait panic=10 rootfstype=ext4 rw ${extra}
bootz 0x46000000 - 0x49000000
EOF
tar -C output -cjvf ../linux-bananapi-4.1.3.tar.bz2 boot/ lib/

Here is what the partition layout of my SDHC card:

root@bpi:~# fdisk -l /dev/mmcblk0

Disk /dev/mmcblk0: 7948 MB, 7948206080 bytes
4 heads, 16 sectors/track, 242560 cylinders, total 15523840 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1   *        2048      133119       65536    c  W95 FAT32 (LBA)
/dev/mmcblk0p2          133120    15523839     7695360   83  Linux

Here is the contents of the boot partition (mmcblk0p1, vfat):

root@bpi:~# ls /boot
boot.cmd  boot.scr  sun7i-a20-bananapi.dtb  uEnv.txt  zImage

boot.cmd

fatload mmc 0 0x46000000 zImage
fatload mmc 0 0x49000000 sun7i-a20-bananapi.dtb
setenv bootargs console=ttyS0,115200 earlyprintk root=/dev/mmcblk0p2 rw rootwait panic=10 
bootm 0x46000000 - 0x49000000

uEnv.txt

fatload mmc 0 0x46000000 zImage
fatload mmc 0 0x49000000 sun7i-a20-bananapi.dtb
setenv bootargs console=ttyS0,115200 [earlyprintk] root=/dev/mmcblk0p2 rootwait panic=10 rootfstype=ext4 rw ${extra}
bootz 0x46000000 - 0x49000000

You will need to update u-boot on the SD card to v2015.04. If you use the script I provide above, this file is in boot/u-boot-sunxi-with-spl.bin. You need to write it to the SD card using dd:

dd if=boot/u-boot-sunxi-with-spl.bin of=/dev/mmcblk0 bs=1024 seek=8

More notes:
I was unable to build this kernel running Debian 7 (Wheezy) because binutils is too old. Unfortunately the official repositories do not have a newer version available for Wheezy (slash) I was too lazy to look for a repository that might have a newer version. As such, I upgraded by Jenkins build box to Debian 8 (Jessie) to build this kernel.

Additionally, I had to upgrade from a 1GB SD Card in my Banana Pi to an 8GB SDHC Card because the new u-boot does not seem to like small (non-SDHC) cards.

Banana Pi info:

root@bpi:~# free -m
             total       used       free     shared    buffers     cached
Mem:           996         72        923          0          4         19
-/+ buffers/cache:         48        948
Swap:            0          0          0
root@bpi:~# uname -a
Linux bpi 4.1.3-bananapi #2 SMP Sun Jul 26 15:41:54 CEST 2015 armv7l GNU/Linux
root@bpi:~# lsmod
Module                  Size  Used by
root@bpi:~#

Speed test of the network interface:

# Laptop with Gigabit wired connection, saving to /tmp/ ramdisk
[derp@laptop ~]$ nc -lp 5000 | dd of=/tmp/zerofile
# Banana Pi
root@bpi:~# dd if=/dev/zero bs=1M count=2000 | nc laptop 5000
2000+0 records in
2000+0 records out
2097152000 bytes (2.1 GB) copied, 73.5536 s, 28.5 MB/s

Yes, it is a Gigabit link, but not the fastest. It does seem to be quite stable, and since I am not using my Banana Pi for a bandwidth intensive purpose, this speed is fine for me.

The build script does everything with relative paths, and can be run as a normal user. The output is a tar.bz2 archive containing u-boot binary, boot folder, and kernel modules. You will need sudo/root to install the u-boot bin file with dd as described above.

Download kernel .config: here
Download build script: here
Download u-boot 2015.04: here (SHA1SUM: 8bf4f738ba8aa18ab5d45fca324587f0749f7c10)
Download tar archive with u-boot, kernel, and modules: here (SHA1SUM: d94a8da66ce6d77a1ceb4569740cadf2c8c67e72)

2 thoughts on “Building Linux 4.1 for the Banana Pi

  1. peter

    i’m really curious how you got that working. because although the idea is good, there are a whole bunch of flaws in this concept.

    the reason why i have found this is, because i get the known systemd-logind error because of the missing seccomp activation in the kernel. and that right there is the first flaw. because your .config file doesn’t activate seccomp either. also, i tried to update from 3.4.90 (lemaker v2.0) and this way my banana pi goes dead. installing the according arm7 image => u-boot shows but doesn’t know what to boot.

    so, lets take a closer look at your article:

    problem 1: using the lemaker v2.0 image as basis, i get 2 “linux” partitions, not a first partition in fat. so, i don’t know how you got there. but it’s not default.
    problem 2: wget doesn’t work on my banana pi without “no-check-certificate”.
    problem 3: first make gets me the first error. something like command not found. by the way, make, binutils and uboot-tools, as well as a bunch of other stuff like gcc, python, i think even base-devel … installed
    problem 4: actually, no make command is working
    problem 5: same for mkimage
    problem 6: same problem again with u-boot => make gets me errors. not only the clock error, but again command not found
    problem 7: due to all the errors, dd-ing the boot manager makes no sense.
    problem 8: so, due to the errors, even upgrading from the 3.4.90 kernel to the arm7 kernel and putting everything together 1by1 doesn’t work. because it seems i have no fitting boot manager for it. i guess?

    i’m really curious how this could possibly be working for you. because for me it doesn’t at all.

    also, i would really be happy about being able to use the banana pi at some point, instead of wasting my time correct errors again and again. which i have done for DAYS now.

    by the way, maybe i have missed it. but from this article it is not clear, which linux you are using. so, i’m using arch linux, since i have it running on the notebook i’m writing you from right now too. i also tried lubuntu. besides i’m not happy with it, it crashes on various file transfers. which seems to be the common problem with this particular linux option. i’d still prefer to continue using arch. IF i ever get it running. funny thing by the way: no problems on the raspberry pi. on the banana pi errors never end.

    so, any suggestions … if possible step by step, how an average user with a bit of linux experience can get rid of the systemd-logind (and systemd-networkd, and so on …) errors and actually USE the banana pi … which according to my understanding would basically be the intended purpose for the device anyway???

    Reply
    1. Hal Martin Post author

      > and that right there is the first flaw. because your .config file doesn’t activate seccomp either.

      This article was written over a year ago, and I really doubt that the instructions will still work to build an image today.

      > so, any suggestions … if possible step by step, how an average user with a bit of linux experience can get rid of the systemd-logind (and systemd-networkd, and so on …) errors and actually USE the banana pi

      Yes, go here and download armbian.

      You won’t get rid of systemd, because Debian uses it as the default init system, but your Banana Pi will work and you won’t have to deal with out-of-date instructions from this website.

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *