Making Modifications to Nvidia Shield TV Kernel — Part 2


terminal

In part 1, I have talked about compiling the unmodified kernel for the Nvidia Shield TV provided by Nvidia. But what if you would like to make some changes to the kernel? I am going to show you a method to modify the Shield TV kernel that is non-developer friendly (you still need command line though).

Modify Kernel Configurations

Before starting, you must have at least went through the Setup and Syncing portion from part 1. I recommend working with a clean checkout of the “nvidia open source” files. If all you have done is compile the kernel and built the boot image that still counts as a clean checkout.

Slow Method (safer, cleaner, less error prone with compile) 

cd ~/shield-open-source

# backup the original kernel config file
cp kernel/arch/arm64/configs/tegra21_android_defconfig ~/tegra21_android_defconfig.original

# build a boot image without changing anything
mp bootimage -j3

# overwrite the defconfig with the full kernel config file that was created during compile
cp out/target/product/t210/obj/KERNEL/.config kernel/arch/arm64/configs/tegra21_android_defconfig

# rebuild the boot image again without any changes
mp bootimage -j3

# copy full kernel config file into kernel directory for making modifications
cp out/target/product/t210/obj/KERNEL/.config kernel/.config
cd kernel
make menuconfig ARCH=arm64

# make your changes to the kernel

# find out what CONFIG values were added or removed from the config file
scripts/diffconfig ../out/target/product/t210/obj/KERNEL/.config .config > CONFIGDIFF.txt

# make a copy of both config file to save time in case of mistake
cp ../out/target/product/t210/obj/KERNEL/.config ~/config-kernel-out
cp .config ~/config-kernel

# copy back the original defconfig
cp ~/tegra21_android_defconfig.original arch/arm64/configs/tegra21_android_defconfig

# cleanup kernel tmp files created by menuconfig
make mrproper

# manually edit arch/arm64/configs/tegra21_android_defconfig by carefully adding the difference between the two config files
# recorded in CONFIGDIFF.txt
# use your favorite text editor to make edits
vim arch/arm64/configs/tegra21_android_defconfig

# build the boot image to make sure the changes work
mp bootimage -j3

# remove CONFIGDIFF.txt or move the file outside of shield-open-source directory
# to remove file
rm CONFIGDIFF.txt

# to move the file
mv CONFIGDIFF.txt ~/CONFIGDIFF.txt

Note: For the best compile result use -j#, where # is the number of CPU cores + 1 (e.g. My virtual machine is using 2 cores so I used -j3)

Fast Method (may cause errors compiling)

cd shield-open-source/kernel

# get current kernel config
make tegra21_android_defconfig ARCH=arm64

# edit config to your needs
make menuconfig ARCH=arm64

# overwrite old config with the generated one
cp .config arch/arm64/configs/tegra21_android_defconfig

# clean up temporary files
make mrproper

# build boot image
mp buildimage -j3

NoteIf the “mp” command does not work it is because your setup configurations to compile was lost. This can happen when you shutdown your machine. To set up the paths again follow the following command lines on terminal:

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

Testing Modified Kernel

A simple way to test if your modified kernel works is to flash the boot image containing your kernel into your Shield TV. You can find out how to flash your Shield TV with the boot image in part 1. If there is no problem, the Shield TV will boot into Android TV and the new modifications will also take effect.

Congratulations on modifying the Nvidia Shield TV kernel. Until next post, take care and have fun coding.


About Steven To

Steven To is a software developer that specializes in mobile development with a background in computer engineering. Beyond his passion for software development, he also has an interest in Virtual Reality, Augmented Reality, Artificial Intelligence, Personal Development, and Personal Finance. If he is not writing software, then he is out learning something new.