How to build NVIDIA a Jetson Xavier NX Kernel

From RidgeRun Developer Wiki



Previous: Introduction/Getting_Started Index Next: GStreamer/Accelerated_Elements






Introduction to compiling NVIDIA Tegra Jetson Xavier NX source code L4T 32.4.3

This wiki page contains instructions to download and build kernel source code for Jetson Xavier NX, several parts of this wiki were based in the document: NVIDIA Jetson Linux Developer Guide 32.4.3 release.

L4T 32.4.3 is used by JetPack 4.4.

Build NVIDIA Jetson Xavier NX kernel source code

Download and install the Toolchain

NVIDIA recommends using the Linaro 7.3.1 2018.05 toolchain for L4T 32.4.3 (Jetson Linux Driver PackageToolchain)

Download the pre-built toolchain binaries: gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz and locate them under $HOME/l4t-gcc, or alternatively execute on console:

mkdir -p $HOME/l4t-gcc
cd $HOME/l4t-gcc
wget http://releases.linaro.org/components/toolchain/binaries/7.3-2018.05/aarch64-linux-gnu/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz

Execute the following commands to extract the toolchain:

tar xf gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz

Download the kernel sources for L4T 32.4.3

Manually downloading sources from NVIDIA Jetson Download Center

mkdir -p $HOME/l4t-sources/xavier-nx/
cd $HOME/l4t-sources/xavier-nx
wget https://developer.nvidia.com/embedded/L4T/r32_Release_v4.3/sources/T186/public_sources.tbz2 # be sure to download the correct sources, since on JP4.3 the only changes are between nano-tx1/tx2-xavier-nx

Execute the following commands to extract the kernel sources:

tar -xvf public_sources.tbz2
cd Linux_for_Tegra/source/public
JETSON_XAVIER_NX_KERNEL_SOURCES=$(pwd)
tar -xf kernel_src.tbz2

Apply corresponding patches (if any) and follow to the next section.

Obtaining the Kernel Sources with Git

You can use the "source_sync.sh" script under the NVIDIA Jetpack 4.4 "Linux_for_Tegra" installation directory.

# $NVIDIA_JP_4.4_INSTALL_DIR is the installation directory defined when you installed NVIDIA Jetpack with the sdkmanager tool.
cd $NVIDIA_JP_4.4_INSTALL_DIR/JetPack_4.4_Linux_JETSON_XAVIER_NX_DEVKIT/Linux_for_Tegra/
./source_sync.sh
JETSON_XAVIER_NX_KERNEL_SOURCES=$NVIDIA_JP_4.4_INSTALL_DIR/JetPack_4.4_Linux_JETSON_XAVIER_NX_DEVKIT/Linux_for_Tegra/sources/

This will download the bootloader and kernel.

When syncing, you'll be asked for a tag, lets use tegra-l4t-r32.4.3 for both Kernel and uboot.

Apply corresponding patches (if any) and follow to the next section.

Compile Jetson Xavier NX kernel and dtb (device tree blob)

cd $JETSON_XAVIER_NX_KERNEL_SOURCES
TOOLCHAIN_PREFIX=$HOME/l4t-gcc/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-
TEGRA_KERNEL_OUT=$JETSON_XAVIER_NX_KERNEL_SOURCES/build
KERNEL_MODULES_OUT=$JETSON_XAVIER_NX_KERNEL_SOURCES/modules

make -C kernel/kernel-4.9/ ARCH=arm64 O=$TEGRA_KERNEL_OUT LOCALVERSION=-tegra CROSS_COMPILE=${TOOLCHAIN_PREFIX} tegra_defconfig
make -C kernel/kernel-4.9/ ARCH=arm64 O=$TEGRA_KERNEL_OUT LOCALVERSION=-tegra CROSS_COMPILE=${TOOLCHAIN_PREFIX} menuconfig

here you have to select the modules you want to compile, for example for libguvc something like this is required:

 -> Device Drivers
    -> USB support (USB_SUPPORT [=y]) 
        -> USB Gadget Support (USB_GADGET [=y]) 
            -> USB Gadget Drivers (<choice> [=m])

Now compile the kernel image, dtbs and modules:

make -C kernel/kernel-4.9/ ARCH=arm64 O=$TEGRA_KERNEL_OUT LOCALVERSION=-tegra CROSS_COMPILE=${TOOLCHAIN_PREFIX} -j$(nproc) Image
make -C kernel/kernel-4.9/ ARCH=arm64 O=$TEGRA_KERNEL_OUT LOCALVERSION=-tegra CROSS_COMPILE=${TOOLCHAIN_PREFIX} -j$(nproc) dtbs
make -C kernel/kernel-4.9/ ARCH=arm64 O=$TEGRA_KERNEL_OUT LOCALVERSION=-tegra CROSS_COMPILE=${TOOLCHAIN_PREFIX} -j$(nproc) modules
make -C kernel/kernel-4.9/ ARCH=arm64 O=$TEGRA_KERNEL_OUT LOCALVERSION=-tegra INSTALL_MOD_PATH=$KERNEL_MODULES_OUT modules_install

Install L4T 32.4.3 kernel image on the Jetson Xavier NX

This guide assumes that the user already has the JetPack 4.4 Jetson Xavier NX installed with NVIDIA sdk-manager. This link contains details about how to install NVIDIA SDK Manager.

$NVIDIA_JP_4.4_INSTALL_DIR is the installation directory defined when you installed NVIDIA Jetpack with the sdk-manager tool.

Export the following environment variable:

export JETPACK_4_4_L4T=${NVIDIA_JP_4.4_INSTALL_DIR}/JetPack_4.4_Linux_JETSON_XAVIER_NX_DEVKIT/Linux_for_Tegra/

Copy kernel, device tree, and modules into JetPack 4.4 Jetson Xavier NX installation directory

cd ${JETPACK_4_4_L4T}
# OPTIONAL: Make a backup of the generic JP 4.4 kernel directory for easy "go-back" (execute this only once)
cp -rfv kernel/ kernel-bk-orig
# Copy kernel generated
cp -rfv $JETSON_XAVIER_NX_KERNEL_SOURCES/build/arch/arm64/boot/Image kernel/
# Copy device tree generated
cp -rfv $JETSON_XAVIER_NX_KERNEL_SOURCES/build/arch/arm64/boot/dts/* kernel/dtb/
# OPTIONAL: Make a backup of the generic JP 4.4 rootfs directory for easy "go-back" (execute this only once)
cp -rf rootfs rootfs-bk-orig
# Copy new modules
sudo cp -arfv $JETSON_XAVIER_NX_KERNEL_SOURCES/modules/lib rootfs/

Jetson Xavier NX Recovery Mode

  • Ensure the device is powered off and the power adapter disconnected.
  • Verify the microSD Card is inserted in the Jetson Xavier NX [developer kit version] module.
  • Place a jumper across the Force Recovery Mode pins. These are pins 9 [GND] and 10 [FC REC] of the Button Header [J14].
  • Connect your host computer to the device's USB Micro-B connector.
  • Connect the power adapter to the Power Jack [J16].
  • The device will automatically power on in Force Recovery Mode.
  • Execute on a terminal of your host PC the "lsusb" command and you will see the following output to confirm that the Jetson is in recovery mode:
    • Bus 001 Device 010: ID 0955:7e19 NVidia Corp.
  • Remove the jumper from the Force Recovery Mode pins.

Flash full system (rootfs, kernel and dtb)

Make sure your Jetson Xavier NX is in recovery mode.

For this it's required to use NVIDIA's script 'flash.sh':

For Jetson Xavier NX P3668-0000 (devkit for development; not for production use):

# Flashes QSPI-NOR and microSD card
cd ${JETPACK_4_4_L4T}
sudo ./flash.sh jetson-xavier-nx-devkit mmcblk0p1

For Jetson Xavier NX P3668-0001 (For Development or production use):

# Flashes QSPI-NOR and eMMC
cd ${JETPACK_4_4_L4T}
sudo ./flash.sh jetson-xavier-nx-devkit-emmc mmcblk0p1

Flash DTB only

Make sure your Jetson Xavier NX is in recovery mode.

For this it's required to use NVIDIA's script 'flash.sh':

For Jetson Xavier NX P3668-0000 (devkit for development; not for production use):

# Flashes QSPI-NOR and microSD card
cd ${JETPACK_4_4_L4T}
sudo ./flash.sh -r -k kernel-dtb jetson-xavier-nx-devkit mmcblk0p1

For Jetson Xavier NX P3668-0001 (For Development or production use):

# Flashes QSPI-NOR and eMMC
cd ${JETPACK_4_4_L4T}
sudo ./flash.sh -r -k kernel-dtb jetson-xavier-nx-devkit-emmc mmcblk0p1

Flash Kernel Image only

The image flashed to the kernel partition is actually a U‑Boot image. U‑Boot loads the Linux kernel from /boot/Image in the root file system.

For this reason, you cannot update the Linux kernel image using the ‑k kernel switch. You may update /boot/Image by either of these means:

  • Modify /boot/extlinux/extlinux.conf to add a new boot entry.
  • Follow the instructions and example provided in /boot/extlinux/extlinux.conf. By this means you can always use cp or scp to replace /boot/Image with a custom-built kernel and launch it with U‑Boot.
  • Generate a backup of the actual "/boot/Image" file by renaming it (/boot/Image.BK_ORIG for example), and cp or scp your custom kernel Image file to your Jetson device "/boot" directory. When the board reboots, it will load the new Kernel Image.

So, you just have to copy your custom kernel Image into the Jetson Xavier NX "/boot" directory of the rootfs partition.

You can check it by executing "uname -a" command after the device boots, and check the build date&hour of the kernel Image. Also, you can verify it with "sha1sum" command.

For example:

nvidia@nvidia-desktop:/boot$ uname -a
Linux nvidia-desktop 4.9.140-tegra #1 SMP PREEMPT Fri Aug 7 19:48:20 CST 2020 aarch64 aarch64 aarcx

nvidia@nvidia-desktop:/boot$ sha1sum Image
4a27eaf20c2e6f8ac58d122027778fdcb8cbd3af  Image

Remember to always copy the custom kernel modules built directory to your Jetson device "/lib/modules/" directory. Also, remember to flash your custom kernel DTB changes, so your custom Kernel Image boots without problems.

Please always verify that your custom kernel image sufix (4.9.140-tegra) matches with the modules directory name as shown below:

nvidia@nvidia-desktop:~$ ls /lib/modules/
4.9.140-tegra


Previous: Introduction/Getting_Started Index Next: GStreamer/Accelerated_Elements