Jump to content

Xavier/JetPack 5.0.2/Compiling Code: Difference between revisions

no edit summary
mNo edit summary
No edit summary
Line 7: Line 7:
-->
-->


This wiki will guide you through the process of building the kernel for the NVIDIA Jetson Xavier. The process is divided into three different steps:
Learning to build the BSP and OS components enables developers to customize the software for their specific project needs.
# [[Xavier/JetPack_4.1/Compiling_Code/Kernel | Build the kernel]]
<br>
# [[Xavier/JetPack_4.1/Compiling_Code/Bootloader | Build the bootloader]]


These steps were tested in a fresh installation of Ubuntu 16.04.


== Dependencies ==
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.
<br>


Make sure the following dependencies are installed on your system:
<!--
We divide this section into the following components:


* wget
# [[NVIDIA Jetson Orin/JetPack_5.0/Compiling_Code/Kernel | Build the kernel, modules and dtb]]
* lbzip2
# [[NVIDIA Jetson Orin/JetPack_5.0/Compiling_Code/Bootloader | Build the bootloader]]
* build-essential
# [[NVIDIA Jetson Orin/JetPack_5.0/Compiling_Code/Bootloader | Customize the Root Filesystem]]
* bc
-->
* zip
 
* libgmp-dev
 
* libmpfr-dev
==Assumptions==
* libmpc-dev
# The build of the BSP/OS components source code will be performed by cross-compiling on a host computer running a Linux OS.
* vim-common # For xxd
# The host computer used for the cross-compilation has Jetpack 5.0.2 (L4T 34.1) for Xavier installed. The Jetpack path is: <syntaxhighlight lang=bash> /home/$USER/nvidia/nvidia_sdk/JetPack_5.0_DP_Linux_DP_JETSON_AGX_ORIN_TARGETS/Linux_for_Tegra </syntaxhighlight> 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:
In Debian based systems you can run the following:
Line 32: Line 42:
sudo apt install wget lbzip2 build-essential bc zip libgmp-dev libmpfr-dev libmpc-dev vim-common
sudo apt install wget lbzip2 build-essential bc zip libgmp-dev libmpfr-dev libmpc-dev vim-common
</syntaxhighlight>
</syntaxhighlight>
== 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:
<syntaxhighlight lang=bash>
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
</syntaxhighlight>
== 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:
<syntaxhighlight lang=bash>
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
</syntaxhighlight>
Please note that as a new kernel version becomes available, it might be necessary to use updated toolchain versions as well.
<br>
== 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:
<syntaxhighlight lang=bash>
cd $JETPACK
./source_sync.sh -k jetson_34.1.1
</syntaxhighlight>
=== Method #2: Download via the NVIDIA web page ===
The BSP sources can be downloaded from the [https://developer.nvidia.com/embedded/l4t/r34_release_v1.1/sources/public_sources.tbz2 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:
<syntaxhighlight lang=bash>
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
</syntaxhighlight>
== 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.
{{Ambox
|type=notice
|small=left
|issue='''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.
|style=width:unset;
}}
1. Create the directories for the build outputs:
<syntaxhighlight lang=bash>
mkdir -p $KERNEL_MODULES_OUT
</syntaxhighlight>
2. Clean the environment:
<syntaxhighlight lang=bash>
cd $JETPACK/sources/kernel/$KERNEL_DIR
make mrproper
</syntaxhighlight>
3. Setup the default configuration:
<syntaxhighlight lang=bash>
make ARCH=arm64 O=$KERNEL_OUT tegra_defconfig
</syntaxhighlight>
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:
<syntaxhighlight lang=bash>
make ARCH=arm64 O=$KERNEL_OUT menuconfig
</syntaxhighlight>
5. Build the BSP:
<syntaxhighlight lang=bash>
make ARCH=arm64 O=$KERNEL_OUT CROSS_COMPILE=$CROSS_COMPILE -j4
</syntaxhighlight>
{{Ambox
|type=notice
|small=left
|issue=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.
|style=width:unset;
}}
6. Install the modules to the output directory created in step 1:
<syntaxhighlight lang=bash>
make modules_install ARCH=arm64 O=$KERNEL_OUT CROSS_COMPILE=$CROSS_COMPILE INSTALL_MOD_PATH=$KERNEL_MODULES_OUT
</syntaxhighlight>
7. Backup the binaries that come installed by default in Jetpack:
<syntaxhighlight lang=bash>
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}
</syntaxhighlight>
8. Copy the binaries built to the default locations expected by the flashing tool:
<syntaxhighlight lang=bash>
cd $KERNEL_OUT
cp ./arch/arm64/boot/Image $JETPACK/kernel/
cp -r ./arch/arm64/boot/dts $JETPACK/kernel/dtb
</syntaxhighlight>
9. Update the kernel modules in the kernel supplements tarball:
<syntaxhighlight lang=bash>
cd $KERNEL_MODULES_OUT
tar --owner root --group root -cjf $JETPACK/kernel/kernel_supplements.tbz2 lib/modules
</syntaxhighlight>
10. Install tegra binaries:
<syntaxhighlight lang=bash>
cd $JETPACK
sudo ./apply_binaries.sh
</syntaxhighlight>
At this point you have the kernel Image, external modules and dtb built and ready to flash.
<!--
= Re-build the DTB only =
Sometimes during development, only the device tree is modified. In order to rebuild only the device tree, you can use the following commands:
<syntaxhighlight lang=bash>
cd $JETPACK/sources/kernel/$KERNEL_DIR
make O=$KERNEL_OUT -j4 dtbs
</syntaxhighlight>
-->


<noinclude>
<noinclude>
{{Xavier/Foot|JetPack 4.1‎/Getting_Started/Components|JetPack 4.1‎/Compiling Code/Kernel}}
{{Xavier/Foot|JetPack 4.1‎/Getting_Started/Components|JetPack 4.1‎/Compiling Code/Kernel}}
</noinclude>
</noinclude>
227

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.