How to build Android Kernel 3.14.29 #1 SMP PREEMPT aarch64 - rt2800usb for T95 Amlogic S905 TV box on Linux (Fedora)

Kernel version: 3.14.29-g0492a01-dirty (it01@ubuntu) (gcc version 4.9.2 20140904 (prerelease) (crosstool-NG linaro-1.13.1-4.9-2014.09 - Linaro GCC 4.9-2014.09) ) #1 SMP PREEMPT Thu May 5 00:01:42 CST 2016
Build number: LMY47V.20160516 test-keys
Android 5.1.1 Lolipop

This guide is for the T95 Android TV box (AKA Beelink) but may be used
generally to compile kernel modules for devices not built into the booting kernel.
No flashing required for minor mods but you will need some root accessible
ext fs (linux) file storage to put the modules on.

1. Get the android kernel source version 3.14.29 from the following link

Extract kernel source file arm-src-kernel-2015-11-04-9e845bea41.tar.gz into a suitable folder with plenty (Gb) of space.
It doesn't contain all the code necessary to recreate the original kernel according to the /proc/kallsyms.

2. Get your config.

The flash layout for this box has the kernel and initial ramdisk in partition 12

You can back it up from a terminal/shell on the tv box with

dd if=/dev/block/boot of=/sdcard/boot-mmcblk0p12.bin

copy the /sdcard/boot-mmcblk0p12.bin file to your linux box.

use commands boot-mmcblk0p12.bin or unpackbootimg -i boot-mmcblk0p12.bin
to extract vmlinuz & initrd (ramdisk).

from the source in 1., run the config extract shell script

sh FULL_PATH_TO_SOURCE/scripts/extract-ikconfig boot-mmcblk0p12.bin-zImage > config.txt

3. Install tool chain / cross-compier (Fedora)

sudo dnf install binutils-aarch64-linux-gnu gcc-aarch64-linux-gnu gcc-c++-aarch64-linux-gnu

Note this guide is based on fc20 distro using gcc-4.9 and more recent versions of Fedora will have a
newer compiler which won't build this source! Instead, use Linaro or this one hosted by AML.

4. Check source, config and tool chain is ok by the following

cd arm-src-kernel-2015-11-04-9e845bea41

cp -a config.txt .config

mkdir -p .git/hooks

make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -j4 (where -j4 is based on number of CPU cores on your compiler box).


Should that prove successful, create a modified .config with your chosen modules, in this case RA link rt2800 using gt based config gui:

make ARCH=arm64 menuconfig (or xconfig etc)

Follow the menus Networking -> and add RA link

arch/arm64/boot/ - store of zimage (Image.lzo, rename to zImage). Don't use Image.gz as it doesnt' boot.

You will notice CONFIG_AML_FD628=y is removed from the .config which is due to lack of source code
for the FD628 LED display controller. Thus the display will no longer work with this zimage.


RT2xxx complies ok but can't be configured through iwconfig or allow airodump
(when running linuxdeploy app).
iw command works ok in that it scan networks (but not much more)
This due to lack of WEXT in the kernel so need CONFIG_CFG80211_WEXT=y adding to .config

However, the existing module dhd.ko objects to a vmlinuz kernel compiled with this and will crash (when CPU is under load).
The new kernel zimage will need to be flashed (recovery or boot) so you can load the RT2xxx wireless modules with
wireless extensions support.

Additional help - custom recovery.

The TWRP recovery image file in TWRP_3.0.2-0_Beelink_M18_MX64.rar (md5sum 45565962d6c41815b3a651d533102fd6)
when flashed to recovery partition 6 works fine on the T95 tv box.
Backup your current partition with shell command:

dd if=/dev/block/recovery of=/sdcard/recovery_backup.p6.bin

Install custom recovery with:

dd if=TWRP_3.0.2-0_Beelink_M18_MX64/recovery.img of=/dev/block/recovery