Xavier/JetPack 5.0.2/Compiling Code: Difference between revisions

From RidgeRun Developer Wiki
 
(12 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<noinclude>
<noinclude>
{{Xavier/Head|previous=JetPack 4.1‎/Getting_Started/Components|next=JetPack 4.1/Flashing Board|keywords=jetpack,compiling,compile,building}}
{{Xavier/Head|previous=JetPack 5.0.2‎/Getting_Started/Components|next=JetPack 5.0.2/Flashing Board|metakeywords=jetpack,compiling,compile,building}}


</noinclude>
{{DISPLAYTITLE:NVIDIA Jetson Xavier - Compile and Build JetPack 5.0.2 |noerror}}
<!-- If you want a custom title for the page, un-comment and edit this line:
{{DISPLAYTITLE:NVIDIA Jetson Xavier - <descriptive page name>|noerror}}
-->


Learning to build the BSP and OS components enables developers to customize the software for their specific project needs.
Learning to build the BSP and OS components enables developers to customize the software for their specific project needs.
Line 16: Line 13:
<!--
<!--
We divide this section into the following components:
We divide this section into the following components:
 
{{Review|fix links|fherrera}}
# [[NVIDIA Jetson Orin/JetPack_5.0/Compiling_Code/Kernel | Build the kernel, modules and dtb]]
# [[NVIDIA Jetson Orin/JetPack_5.0/Compiling_Code/Kernel | Build the kernel, modules and dtb]]
# [[NVIDIA Jetson Orin/JetPack_5.0/Compiling_Code/Bootloader | Build the bootloader]]
# [[NVIDIA Jetson Orin/JetPack_5.0/Compiling_Code/Bootloader | Build the bootloader]]
Line 25: Line 22:
==Assumptions==
==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 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: <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.
# The host computer used for the cross-compilation has Jetpack 5.0.2 (L4T 35.1) for Xavier installed. The Jetpack path is: <syntaxhighlight lang=bash> /home/$USER/nvidia/nvidia_sdk/JetPack_5.0.2_Linux_JETSON_XAVIER_NX_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:
# Make sure the following dependencies are installed on your system:
** wget
** wget
Line 50: Line 47:
export TOOLCHAIN_SRC=bootlin-toolchain-gcc-93  
export TOOLCHAIN_SRC=bootlin-toolchain-gcc-93  
export TOOLCHAIN_DIR=gcc-9.3-glibc-2.31
export TOOLCHAIN_DIR=gcc-9.3-glibc-2.31
export KERNEL_SRC=l4t-sources-34-1
export KERNEL_SRC=l4t-sources-35-1
export KERNEL_DIR=kernel-5.10
export KERNEL_DIR=kernel-5.10
export CROSS_COMPILE=$HOME/l4t-gcc/bin/aarch64-buildroot-linux-gnu-
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 JETPACK=$HOME/nvidia/nvidia_sdk/JetPack_5.0.2_Linux_JETSON_XAVIER_NX_TARGETS/Linux_for_Tegra
export KERNEL_OUT=$JETPACK/images
export KERNEL_OUT=$JETPACK/images
export KERNEL_MODULES_OUT=$JETPACK/images/modules
export KERNEL_MODULES_OUT=$JETPACK/images/modules
Line 88: Line 85:
<syntaxhighlight lang=bash>
<syntaxhighlight lang=bash>
cd $JETPACK
cd $JETPACK
./source_sync.sh -k jetson_34.1.1
./source_sync.sh -k jetson_35.1
</syntaxhighlight>
</syntaxhighlight>


=== Method #2: Download via the NVIDIA web page ===
=== 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 [https://docs.nvidia.com/jetson/archives/r35.1/ReleaseNotes/Jetson_Linux_Release_Notes_r35.1.pdf release notes] for information about the specific URLs containing the source code.
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 ==
== 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.
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:
1. Create the directories for the build outputs:
Line 123: Line 104:
make mrproper
make mrproper
</syntaxhighlight>
</syntaxhighlight>


3. Setup the default configuration:
3. Setup the default configuration:
Line 130: Line 110:
</syntaxhighlight>
</syntaxhighlight>


 
{{Review|error here|fherrera}}
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:
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>
<syntaxhighlight lang=bash>
Line 139: Line 119:
5. Build the BSP:
5. Build the BSP:
<syntaxhighlight lang=bash>
<syntaxhighlight lang=bash>
make ARCH=arm64 O=$KERNEL_OUT CROSS_COMPILE=$CROSS_COMPILE -j4
make ARCH=arm64 O=$KERNEL_OUT CROSS_COMPILE=$CROSS_COMPILE -j4 LOCALVERSION="-tegra"
</syntaxhighlight>
</syntaxhighlight>


Line 152: Line 132:
6. Install the modules to the output directory created in step 1:
6. Install the modules to the output directory created in step 1:
<syntaxhighlight lang=bash>
<syntaxhighlight lang=bash>
make modules_install ARCH=arm64 O=$KERNEL_OUT CROSS_COMPILE=$CROSS_COMPILE INSTALL_MOD_PATH=$KERNEL_MODULES_OUT
make modules_install ARCH=arm64 O=$KERNEL_OUT CROSS_COMPILE=$CROSS_COMPILE INSTALL_MOD_PATH=$KERNEL_MODULES_OUT LOCALVERSION="-tegra"
</syntaxhighlight>
</syntaxhighlight>


Line 187: Line 167:


At this point you have the kernel Image, external modules and dtb built and ready to flash.
At this point you have the kernel Image, external modules and dtb built and ready to flash.
===Known Issues===
Failure when running
<pre>
make mrproper
</pre>
On Ubuntu 20 you might get an error saying you should run:
<pre>
sudo apt-get install graphviz python3-venv librsvg2-bin
</pre>
do it. Same goes for:
<pre>
pip install -r ./Documentation/sphinx/requirements.txt
</pre>
In the case of the later command if you see a message similar to this one:
<pre>
  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.
</pre>
Then add that path to your PATH, in this particular case you can do:
<pre>
PATH=$PATH:/home/fernando/.local/bin
</pre>
Adapt the command according to your case.
<!--
<!--
= Re-build the DTB only =
= Re-build the DTB only =
Line 199: Line 207:


<noinclude>
<noinclude>
{{Xavier/Foot|JetPack 4.1‎/Getting_Started/Components|JetPack 4.1/Flashing Board}}
{{Xavier/Foot|JetPack 5.0.2‎/Getting_Started/Components|JetPack 5.0.2/Flashing Board}}
</noinclude>
</noinclude>

Latest revision as of 21:14, 5 April 2023




Previous: JetPack 5.0.2‎/Getting_Started/Components Index Next: JetPack 5.0.2/Flashing Board





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

‎ 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"


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.



Previous: JetPack 5.0.2‎/Getting_Started/Components Index Next: JetPack 5.0.2/Flashing Board