How to rebuild and flash a kernel for NVIDIA Jetson TX2

jwatte's picture

I wish this brief overview had been available when I first got my TX2, for how to rebuild a kernel and flash it.

There are a number of various bits and pieces of information on the internet, but this information changes with each release, so here's my version:

You need to download the NVIDIA kernel sources ("Linux for Tegra") as well as the sample root file system. These are available from the NVIDIA Jetson downloads section.
Then you need to configure them and build the kernel.
Then you need to use flash.sh to flash your Jetson (this will re-install the "initial" file system, wiping all files you've previously put on the Jetson.)

Note that the first time you build the kernel, you need to do "sudo make O=... ARCH=... tegra18_defconfig" before you build.

You also need to edit the .config file before you actually build, after "make tegra18_defconfig" to enable the drivers you need. For example if it says
# CONFIG_USB_SERIAL is not set
Change it to this:
CONFIG_USB_SERIAL=y

Here is a script I use to re-build the kernel:

cd /usr/local/jetson/tx2-3.0/64_TX2/Linux_for_Tegra_tx2/sources/kernel/kernel-4.4
set -e
set -u
export TEGRA_BASE=/usr/local/jetson/tx2-3.0/64_TX2/Linux_for_Tegra_tx2
export TEGRA_KERNEL_OUT=$TEGRA_BASE/kernel
export CROSS_COMPILE=/usr/bin/aarch64-linux-gnu-
export ARCH=arm64
# If this is the first time, first do
# make O=$TEGRA_KERNEL_OUT ARCH=$ARCH tegra18_defconfig
# and then edit the file $TEGRA_BASE/kernel/.config to enable drivers
# you need.
make O=$TEGRA_KERNEL_OUT ARCH=$ARCH modules_prepare
make O=$TEGRA_KERNEL_OUT ARCH=$ARCH zImage
make O=$TEGRA_KERNEL_OUT ARCH=$ARCH dtbs
make O=$TEGRA_KERNEL_OUT ARCH=$ARCH modules
make O=$TEGRA_KERNEL_OUT ARCH=$ARCH modules_install INSTALL_MOD_PATH=$TEGRA_BASE/rootfs
cd $TEGRA_BASE/rootfs
tar cvfj $TEGRA_BASE/kernel/fresh-modules.tbz lib/modules
cd $TEGRA_BASE
cp kernel/arch/arm64/boot/dts/*.dtb kernel/dtb/
./apply_binaries.sh

And heere's the command to flash the Jetson over USB once you've built the kernel, and pressed RECOVERY+RESET on the Jetson:

cd /usr/local/jetson/tx2-3.0/64_TX2/Linux_for_Tegra_tx2
sudo ./flash.sh -t jetson-tx2 mmcblk0p1

Flashing will take quite a while (10-30 minutes.)
After flashing, you will want to log into the new image and sudo apt-get update, sudo apt-get dist-upgrade to get up to date.
Personally, I've created my own rootfs image that has newer versions of things and some settings I want (vimrc and so forth) that I use when flashing. You'll probably want to do that yourself, too.