NVIDIA Jetson Xavier - Compile and Build JetPack 5.0.2
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
- The build of the BSP/OS components source code will be performed by cross-compiling on a host computer running a Linux OS.
- The host computer used for the cross-compilation has Jetpack 5.0.2 (L4T 35.1) for Xavier installed. The Jetpack path is:
/home/$USER/nvidia/nvidia_sdk/JetPack_5.0.2_Linux_JETSON_XAVIER_NX_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. - 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-35-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_Linux_JETSON_XAVIER_NX_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_35.1
Method #2: Download via the NVIDIA web page
The BSP sources can be downloaded from the NVIDIA git server. Consult section 4.1 of the release notes for information about the specific URLs containing the source code.
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
fherrera: error here (please remove this box when addressed) |
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 LOCALVERSION="-tegra"
Note: the number next to the -j flag in the previous command tells make how many recipes to execute simultaneously. You can increase this value for the kernel build to finish faster but using more system resources. |
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 LOCALVERSION="-tegra"
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.
Known Issues
Failure when running
make mrproper
On Ubuntu 20 you might get an error saying you should run:
sudo apt-get install graphviz python3-venv librsvg2-bin
do it. Same goes for:
pip install -r ./Documentation/sphinx/requirements.txt
In the case of the later command if you see a message similar to this one:
WARNING: The script docutils is installed in '/home/fernando/.local/bin' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location. WARNING: The script pybabel is installed in '/home/fernando/.local/bin' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location. WARNING: The scripts sphinx-apidoc, sphinx-autogen, sphinx-build and sphinx-quickstart are installed in '/home/fernando/.local/bin' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Then add that path to your PATH, in this particular case you can do:
PATH=$PATH:/home/fernando/.local/bin
Adapt the command according to your case.