Compiling an Android kernel can seem scary at first. It turns out it is not as difficult as you may think. I want to show you that anyone with some experience with a terminal and some programming background can do it (at least for the Nvidia Shield TV kernel).
DISCLAIMER: Please understand I am not responsible for any damage that may incur from following this tutorial. By flashing the boot image compiled you may risk harming your Shield TV. Make sure you have the recovery boot image provided by Nvidia before starting.
Setup
The system I am using to compile the kernel is on a virtual machine. The virtual machine setup:
- Program: VirtualBox
- OS: Ubuntu 16.04 64-bit (32-bit will fail to compile kernel)
- At least 30GB of storage after setting up virtual machine
- Host Machine: Windows 10 Pro
Note: 64-bit is a must and the Nvidia Shield TV kernel download is roughly 26GB
You also need to have openjdk 7.x installed on your system that will be doing the compile. At the time of this post, openjdk 8.x is the latest, but only openjdk 7.x will successfully compile the kernel. If you already have openjdk 8.x installed, do not worry. Just follow the following steps on the terminal to install openjdk 7.x and keep openjdk 8.x
If you are using an older version of Linux, you can go to http://source.android.com/source/initializing.html to set up your environment. Make sure you install openjdk 7 as that is the requirement by the Nvidia Shield TV kernel.
Installing openjdk 7.x
sudo add-apt-repository ppa:openjdk-r/ppa sudo apt-get update sudo apt-get install openjdk-7-jdk
To set openjdk 7 as the default one to use
sudo update-java-alternatives
Installing other packages and compiler
sudo apt-get install joe bc git git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev gcc-multilib g++-multilib \ libc6-dev-i386 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z-dev ccache libgl1-mesa-dev libxml2-utils xsltproc unzip \ python-networkx ccache openjdk-7-jdk libproc-processtable-perl patchutils mercurial # configure ccache -- this speeds up sub-sequential builds mkdir ~/ccache_dir echo "export USE_CCACHE=1" >> ~/.bashrc echo "export CCACHE_DIR=~/ccache_dir" >> ~/.bashrc source ~/.bashrc # set ccache size ccache -M 50G
Compiling the kernel
The following consists of Nvidia’s instructions and modifications I have experimented with to build the kernel successfully:
Syncing
mkdir ~/shield-open-source cd ~/shield-open-source repo init -u git://nv-tegra.nvidia.com/manifest/android/binary.git -b rel-24-foster-r7-partner -m tlk/t210.xml repo sync -j3
Note: The common standard for -j# is to put the number of cores on your machine plus one. For example, I let my virtual machine use two cores so I used -j3.
Building kernel and boot image
warning: it can take a while to compile (took about 2 hours for me)
cd ~/shield-open-source export TOP=$(pwd) cd vendor/nvidia/licensed-binaries ./extract-nv-bins.sh cd $TOP . build/envsetup.sh setpaths lunch foster_e_hdd-userdebug mp bootimage -j3
Note: use “foster_e-userdebug” instead if you have the non-pro (16GB) version of the Shield TV
Flash build to device
Preparations
Once the compile process finishes, you can find your built kernel and boot image in the directory “~/shield-open-source/out/target/product/t210”. The kernel is already part of the boot.img and this is what you want to flash into your Nvidia Shield device. To prepare for flashing the newly built boot image, you will need to install the following:
- adb (Android Debug Bridge)
- fastboot
Both of them can be found at xda-developers.
For flashing the boot image, I had to move the boot.img to my host machine. For the terminal, I was using Cygwin, but window’s cmd would work too.
Flashing boot image
- Navigate to where you installed adb and fastboot (for me it was at “C:/Program Files x86/Minimal ADB and Fastboot/”)
- Move boot.img to your host machine if you are using virtual machine for compiling
- Connect the Shield TV to your host machine via micro-USB
- Put Shield TV into bootloader mode
adb reboot bootloader
- If you have not unlocked your bootloader before you will need to unlock it first. This process takes about two hours on the 500GB version.
fastboot oem unlock
- Hold down the power touch button for 4 seconds to confirm
- Once the unlocking process finishes, you can flash your boot image to the Shield TV
fastboot flash boot boot.img fastboot reboot
- The Shield TV will reboot and boot into normal Android TV afterward if the boot image was properly built
Issues and Solutions
I had experienced some problems to get the boot image working. Below are problems I had encountered and how I was able to solve it:
Problem: After flashing the boot image, the Shield TV got stuck in boot loop or nothing displays on-screen
Solution: The first boot after flashing may have a chance to get stuck. Restarting (power cycling) the device by unplugging power would solve the problem.
Problem: Boot loop or blank screen still persist after power cycling the Shield TV multiple times
Solution: The boot image was probably not built successfully. Rebuild the boot image again then reflash.
Problem: You just want to get your Shield TV working again
Solution: Flash the boot image (“boot.img”) provided by Nvidia for the Shield TV. Afterward, just reboot and your Shield TV will be as good as new or at least be working again.
NOTE: If your Shield TV is stuck in boot loop and you cannot use adb to get into bootloader mode, you have to do it the hardware way. Follow the procedure in this video to get into bootloader mode then flash the boot.img from Nvidia.
Congratulations on building the Shield TV kernel and boot image.
Did you find this post helpful? If so, share it with others so they can benefit too.
Was there any step(s) that I did not cover? How was your experience working with the Android kernel? Feel free to leave a comment.
Also, to stay in touch, you can follow me on twitter. Until the next post, take care.