NVIDIA Jetson Orin - JetPack 5.0.2 - Compiling Code - Kernel

From RidgeRun Developer Connection
Jump to: navigation, search



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


Nvidia-preferred-partner-badge-rgb-for-screen.png






In this section, you will find how to get the Jetson Orin AGX BSP sources and cross-compile to generate the kernel image and modules.


Prerequisites

Make sure you are ready to build the BSP by checking our Assumptions section.


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.1_DP_Linux_JETSON_AGX_ORIN_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.

Note: Before launching the sources build, check our known issues subsection (at the end of this section) to work around any issues that apply to your Jetpack version and avoid build failures.


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

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


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

We found the following errors during the BSP build using Jetpack 5.0-DP and 5.0.1-DP:

1. Missing osi_core.h

The error message is the following:

In file included from /home/$USER/nvidia/nvidia_sdk/JetPack_5.0.1_DP_Linux_JETSON_AGX_ORIN_TARGETS/Linux_for_Tegra/sources/kernel/nvidia/drivers/net/ethernet/nvidia/nvethernet/ether_linux.c:19:
/home/$USER/nvidia/nvidia_sdk/JetPack_5.0.1_DP_Linux_JETSON_AGX_ORIN_TARGETS/Linux_for_Tegra/sources/kernel/nvidia/drivers/net/ethernet/nvidia/nvethernet/ether_linux.h:62:10: fatal error: osi_core.h: No such file or directory
   62 | #include <osi_core.h>
      |          ^~~~~~~~~~~~
compilation terminated.

This error occurs due to a missing symbolic link in the kernel sources, to fix it run the following command in the terminal:

ln -s ${JETPACK}/sources/kernel/nvethernetrm ${JETPACK}/sources/kernel/nvidia/drivers/net/ethernet/nvidia/nvethernet


2. Missing dtsi file

The error message is the following:

In file included from /home/$USER/nvidia/nvidia_sdk/JetPack_5.0.1_DP_Linux_JETSON_AGX_ORIN_TARGETS/Linux_for_Tegra/sources/kernel/kernel-5.10/arch/arm64/boot/dts/../../../../../../hardware/nvidia/platform/t23x/concord/kernel-dts/tegra234-p3701-0000-p3737-0000.dts:17:0:
/home/$USER/nvidia/nvidia_sdk/JetPack_5.0.1_DP_Linux_JETSON_AGX_ORIN_TARGETS/Linux_for_Tegra/sources/kernel/kernel-5.10/arch/arm64/boot/dts/../../../../../../hardware/nvidia/platform/t23x/concord/kernel-dts/cvm/tegra234-p3701-0000.dtsi:19:10: fatal error: t234-common-cvm/tegra234-cvm-p3701.dtsi: No such file or directory
 #include <t234-common-cvm/tegra234-cvm-p3701.dtsi>
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

To work around this issue, you can execute the following commands:

mkdir $JETPACK/sources/hardware/nvidia/platform/t23x/common/kernel-dts
mv $JETPACK/sources/hardware/nvidia/platform/t23x/common/t234* $JETPACK/sources/hardware/nvidia/platform/t23x/common/kernel-dts



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