NVIDIA Jetson Xavier - Building the Kernel from Source

From RidgeRun Developer Wiki



Previous: JetPack 5.0.2/Compiling Code Index Next: JetPack 5.0.2‎/Compiling Code/Bootloader








Learning to build the BSP and OS components enables developers to customize the software for their specific project needs.


This section will guide you through the process of building the BSP and OS components for the NVIDIA Jetson Xavier. For this section you are going to need Jetpack 5.0.2 for Xavier installed on your host computer, we assume that you got this installed following through our Getting Started and Installing Jetpack sections.


Assumptions

  1. The build of the BSP/OS components source code will be performed by cross-compiling on a host computer running a Linux OS.
  2. The host computer used for the cross-compilation has Jetpack 5.0.2 (L4T 34.1) for Xavier installed. The Jetpack path is:
     /home/$USER/nvidia/nvidia_sdk/JetPack_5.0_DP_Linux_DP_JETSON_AGX_ORIN_TARGETS/Linux_for_Tegra
    This is the default path where the SDK Manager installs the Jetpack 5.0.2 tools for the Xavier. If you chose to install Jetpack on a different path, make sure to adjust the instructions accordingly.
  3. Make sure the following dependencies are installed on your system:
    • wget
    • lbzip2
    • build-essential
    • bc
    • zip
    • libgmp-dev
    • libmpfr-dev
    • libmpc-dev
    • vim-common # For xxd

In Debian based systems you can run the following:

sudo apt install wget lbzip2 build-essential bc zip libgmp-dev libmpfr-dev libmpc-dev vim-common


Define the Environment Variables

Open a terminal and run the following commands to export the environment variables that will be used in the next steps:

export TOOLCHAIN_SRC=bootlin-toolchain-gcc-93 
export TOOLCHAIN_DIR=gcc-9.3-glibc-2.31
export KERNEL_SRC=l4t-sources-34-1
export KERNEL_DIR=kernel-5.10
export CROSS_COMPILE=$HOME/l4t-gcc/bin/aarch64-buildroot-linux-gnu-
export JETPACK=$HOME/nvidia/nvidia_sdk/JetPack_5.0.2_DP_Linux_JETSON_Xavier_TARGETS/Linux_for_Tegra
export KERNEL_OUT=$JETPACK/images
export KERNEL_MODULES_OUT=$JETPACK/images/modules

Get the Toolchain

If you haven't already, download the toolchain. The toolchain is the set of tools required to cross-compile the Linux kernel. You can get the toolchain running the following snippet in the terminal:

cd $HOME
mkdir -p $HOME/l4t-gcc
cd $HOME/l4t-gcc

# Reuse existing download, if any
if ! test -e ${TOOLCHAIN_SRC}.tar.gz; then 
wget -O ${TOOLCHAIN_SRC}.tar.gz https://developer.nvidia.com/embedded/jetson-linux/bootlin-toolchain-gcc-93
tar -xf ${TOOLCHAIN_SRC}.tar.gz
fi

Please note that as a new kernel version becomes available, it might be necessary to use updated toolchain versions as well.


Download BSP sources

The BSP sources are provided by NVIDIA and include the kernel, modules, and device tree source files. At RidgeRun we often need to modify and rebuild these sources to develop our customer's projects. You can use one of the two following methods to obtain the BSP sources:

Method #1: Download via the sources_sync script

NVIDIA provides a script to clone the BSP sources, this script is included in Jetpack. To download kernel sources, execute the following commands in a terminal:

cd $JETPACK
./source_sync.sh -k jetson_34.1.1

Method #2: Download via the NVIDIA web page

The BSP sources can be downloaded from the Jetson Download Center, in a package called plubic_sources.tbz2. The following commands can be executed in the terminal to download and extract the BSP sources into your Jetpack directory:

cd $JETPACK
mkdir -p sources && cd sources
wget https://developer.nvidia.com/embedded/l4t/r34_release_v1.1/sources/public_sources.tbz2
tar -xvf public_sources.tbz2 Linux_for_Tegra/source/public/kernel_src.tbz2 --strip-components=3
tar -xvf kernel_src.tbz2

Build the Kernel, Modules, and DTB

This subsection will guide you through the steps of building the BSP sources to generate the kernel Image, the external modules, and the device tree blob.

1. Create the directories for the build outputs:

mkdir -p $KERNEL_MODULES_OUT

2. Clean the environment:

cd $JETPACK/sources/kernel/$KERNEL_DIR
make mrproper


3. Setup the default configuration:

make ARCH=arm64 O=$KERNEL_OUT tegra_defconfig


4. Optionally, you can customize the kernel configuration by modifying the settings in the menuconfig. The menuconfig can be opened by running the following command:

make ARCH=arm64 O=$KERNEL_OUT menuconfig


5. Build the BSP:

make ARCH=arm64 O=$KERNEL_OUT CROSS_COMPILE=$CROSS_COMPILE -j4


6. Install the modules to the output directory created in step 1:

make modules_install ARCH=arm64 O=$KERNEL_OUT CROSS_COMPILE=$CROSS_COMPILE INSTALL_MOD_PATH=$KERNEL_MODULES_OUT


7. Backup the binaries that come installed by default in Jetpack:

BKUP_DATE=`date "+%Y_%m_%d_%H_%M_%S"`
mv $JETPACK/kernel/Image{,.$BKUP_DATE}  
mv $JETPACK/kernel/kernel_supplements.tbz2{,.$BKUP_DATE}
mv $JETPACK/kernel/dtb{,.$BKUP_DATE}


8. Copy the binaries built to the default locations expected by the flashing tool:

cd $KERNEL_OUT
cp ./arch/arm64/boot/Image $JETPACK/kernel/
cp -r ./arch/arm64/boot/dts $JETPACK/kernel/dtb


9. Update the kernel modules in the kernel supplements tarball:

cd $KERNEL_MODULES_OUT
tar --owner root --group root -cjf $JETPACK/kernel/kernel_supplements.tbz2 lib/modules


10. Install tegra binaries:

cd $JETPACK
sudo ./apply_binaries.sh

At this point you have the kernel Image, external modules and dtb built and ready to flash.



Previous: JetPack 5.0.2‎/Compiling Code Index Next: JetPack 5.0.2‎/Compiling Code/Bootloader