[Nexus 9 General] sonicadvance1:
This is really the meat of the guide. Building the kernel correctly is half the battle with running a full Linux distribution on the device. We are going to be pulling our kernel from the official Android repository and changing the default configuration to suit our needs.

Steps Overview

Clone kernel with git

Configure environment for cross-compiling

Configure the kernel for building correctly

Test run kernel

1) Clone the kernel using git

This step will take quite a bit of time since it is fairly large.

git clone https://android.googlesource.com/kernel/tegra.git
cd tegra

2)*Checkout the correct branch

git checkout android-tegra-flounder-3.10-lollipop-release

3)*Set environment variables for cross-compiling the Linux kernel

export ARCH=arm64
export CROSS_COMPILE=aarch64-linux-gnu-

4) Configure the kernel

make flounder_defconfig
make menuconfig

This will bring up a menu just like how the buildroot menu came up. We need to set a few options to make sure everything comes up correctly on the Nexus 9.

General setup->Cross-compiler tool prefix->aarch64-linux-gnu-

General setup->Initramfs source file(s)-><The cpio file that was built in the buildroot>

Mine was '/home/ryanh/work/N9_Kernel_Tutorial/buildroot/output/images/rootfs.cpio'

Device Drivers->Character devices->Virtual Terminal

Device Drivers->Generic Driver Options->Maintain a devtmpfs filesystem to mount at /dev

Device Drivers->Generic Driver Options->Automount devtmpfs at /dev...

Device Drivers->Network device support->Wireless LAN->Firmware path->/lib/firmware/fw_bcmdhd.bin

Device Drivers->Network device support->Wireless LAN->NVRAM path->/etc/wifi/bcmdhd.cal

Device Drivers->Character devices->Virtual terminal

Device Drivers->Watchdog Timer Support->Tegra watchdog (Disable it)

Device Drivers->Staging drivers->Android->Put the FIQ debugger into console mode by default

Device Drivers->Graphics support->Tegra Framebuffer driver

Device Drivers->Graphics support->Console display driver support->Framebuffer Console support

Device Drivers->Graphics support->Console display driver support->Map the console to the primary display device

Device Drivers->Graphics support->Console display driver support->Framebuffer Console Rotation

We've got to enable the tegra watchdog otherwise the device will reboot automatically every two minutes.

The few other things are needed for a sane Linux environment and also setting the initramfs file as our root filesystem.

5)*Compile the kernel

make -j5

If you're lucky it will build without error and you'll have a file in 'arch/arm64/boot/' named 'Image.gz-dtb' which is the final kernel file.

With this file we should be able to boot a kernel with a buildroot automatically mounted.

Test run the kernel!

This is where I recommend having your headphone UART cable, because this won't update the screen at all and it will seem like it has locked up. The cable is fairly easy to make with a little bit of know how about soldering and electronics, and will save you from tearing out your hair trying to figure out what went wrong.

Without the cable you won't be able to see any output, so either build the cable or skip this step.

To see output from the cable you need to connect to it with either gnu screen or minicom

sudo screen /dev/ttyUSB0 115200

To boot the kernel reboot in to the bootloader and then boot the kernel using fastboot

adb reboot bootloader
fastboot -c "console=ttyFIQ0,115200n8 rw" boot arch/arm64/boot/Image.gz-dtb

Once you do this, over the UART cable you'll see the Linux kernel booting and have a buildroot login terminal.

The default username is 'root' without any password.

Welcome to Buildroot
buildroot login: root
# uname -a
Linux buildroot 3.10.40-ga3846f1 #2 SMP PREEMPT Sat Dec 27 06:15:13 CST 2014 aarch64 GNU/Linux

This shows that the kernel is booting properly and jumping in to our buildroot correctly.

To go back in to Android from this area just type reboot in to the terminal instance.