Kernel Customization ¶
You can manually rebuild the kernel used for the NVIDIA ® Jetson™ Linux. You must have Internet access for this.
Obtaining the Kernel Sources with Git ¶
Prerequisites ¶
-
You have installed Git. You can install with the following command:
$ sudo apt install git-core
-
Your system has the default Git port 9418 open for outbound connections.
To Sync the Kernel Sources ¶
-
Get the kernel source by running
source_sync.sh
:$ ./source_sync.sh
Enter a tag name when the script prompts you. The proper tag name is specified in the Release Notes . This tag name syncs the sources to the source revision from which the release binary was built.
You can sync the sources to any other Linux tag if you need to do so. To see a list of the available release tags, enter this command in the kernel source repository:
$ git tag -l tegra-l4t\*
Manually Downloading and Expanding Kernel Sources ¶
As an alternative to syncing the kernel sources, you can download the kernel source files and then manually extract them. If possible, NVIDIA recommends that you sync with Git instead.
To Manually Download and Expand the Kernel Sources ¶
-
In your browser, go to https://developer.nvidia.com/embedded/jetson-linux-archive .
-
Locate and download the Jetson Linux source files for your release.
-
Extract the
.tbz2
file:$ tar -xjf public_sources.tbz2
-
Extract the kernel source file:
$ cd Linux_for_Tegra/source/public $ tar –xjf kernel_src.tbz2
This extracts the kernel source to the
kernel/
subdirectory.
Building the Kernel ¶
Before you build the kernel you must install the Jetson Linux build utilities. Enter the command:
$ sudo apt install build-essential bc
To Build the Kernel ¶
-
Sync or download and expand the kernel sources, and install the kernel build utilities, as described above.
-
If you are cross-compiling on a host system (for example, anything other than the Jetson device for which you are building), export the following environment variables:
$ export CROSS_COMPILE_AARCH64_PATH=
$ export CROSS_COMPILE_AARCH64= /bin/aarch64-buildroot-linux-gnu- See Jetson Linux Toolchain for information about how to download and build the reference toolchains.
-
Enter the command:
$ mkdir kernel_out
Where
kernel_out
is the directory where the compiled kernel is to be written. -
Build the kernel:
$ ./nvbuild.sh -o $PWD/kernel_out
Note
nvbuild.sh
is only included in thekernel_src.tbz2
tar file that is part ofpublic_sources.tbz2
. If the kernel sources were synced from the Git server, you need to manually copynvbuild.sh
from the tar file. -
Replace
Linux_for_Tegra/rootfs/usr/lib/modules/$(uname -r)/kernel/drivers/gpu/nvgpu/nvgpu.ko
with a copy of this file:$kernel_out/drivers/gpu/nvgpu/nvgpu.ko
-
For the device tree, replace the files in
Linux_for_Tegra/kernel/dtb/
with a copy from:$kernel_out/arch/arm64/boot/dts/nvidia/
-
Replace
Linux_for_Tegra/kernel/Image
with a copy of this file:$kernel_out/arch/arm64/boot/Image
Optionally, archive the installed kernel modules:
$ cd
$ tar --owner root --group root -cjf kernel_supplements.tbz2 lib/modules You can use the installed modules to provide the contents of
/lib/modules/
on the target system. Before you run/ apply_binaries.sh
, make a copy of this archive to replace the one at this location on the target device:Linux_for_Tegra/kernel/kernel_supplements.tbz2
To Build the Real-Time Kernel ¶
Apply RT patches to the kernel:
./kernel-5.10/scripts/rt-patch.sh apply-patches
Complete steps 2-6 as described in the previous section.
Signing and Encrypting the Kernel, the kernel-dtb, and the initrd Binary Files ¶
To support Secure Boot, the kernel, kernel-dtb, and initrd binary files must be signed and encrypted with keys to generate encrypted binary files and signature files.
See the topic Secure Boot .
Preparing to Build External Kernel Modules ¶
These procedures describe how to prepare a set of kernel headers, or a kernel source tree to allow building an out-of-tree kernel module.
To Prepare the Jetson Linux Kernel Headers on a Jetson System ¶
On a Jetson system you can use the files in this directory to build out-of-tree modules without further action:
/usr/src/linux-headers-$(uname -r)-ubuntu20.04_aarch64
or:
/lib/modules/$(uname -r)/build/
To Prepare the Jetson Linux kernel Headers on a Non-Jetson System ¶
-
Extract the archive and place it in a local directory with the commands:
$ cd
$ tar -xjf /Linux_for_Tegra/kernel/kernel_headers.tbz2 Where
You can use the files in this directory to build out-of-tree modules:
/linux-headers-$(uname -r)-linux_x86_64/ To build out-of-tree modules, specify the kernel directory as:
/linux-headers-$(uname -r)-linux_x86_64/
To Use a Manually Built Kernel Source Tree ¶
-
If you built the kernel from source, use the same source tree to build out-of-tree kernel modules. When building out-of-tree modules, use
$TEGRA_KERNEL_OUT
as the kernel directory.
To Prepare a Kernel Source Tree that is not Built ¶
You can build out-of-tree modules that are compatible with a Linux kernel source tree without building the entire kernel image.
-
To extract the kernel source, set any required shell or environment variables, and create the
.config
file, follow the instructions provided in these topics: -
Enter this command to prepare the kernel source tree for building out-of-tree kernel modules:
$ make ARCH=arm64 O=$TEGRA_KERNEL_OUT -j
modules_prepare Where `` `` is the number of parallel processes to be used. NVIDIA recommends using the number of CPUs in your system.
When building out-of-tree modules, point
$TEGRA_KERNEL_OUT
to the kernel directory.
To Build External Kernel Modules ¶
-
If you are cross-compiling the kernel, ensure that the
CROSS_COMPILE
environment variable is set as described in preceding sections.
-
Enter these commands to build an out-of-tree kernel module:
$ cd
$ make ARCH=arm64 –C M=$(pwd) Enter these commands to strip unneeded symbols from the kernel module:
$
/aarch64-linux-gnu-strip -–strip-unneeded
To Build Display Kernel Modules ¶
-
If you are cross-compiling the kernel, ensure that the
CROSS_COMPILE
environment variable is set as described in preceding sections. -
Export the required variables as per the Linux kernel module compilation steps:
$ export LOCALVERSION= "-tegra"
-
If building for RT-Kernel, make sure to set IGNORE_PREEMPT_RT_PRESENCE:
$ export IGNORE_PREEMPT_RT_PRESENCE = 1
-
Untar the file nvidia_kernel_display_driver_source.tbz2, which contains the display source code
-
cd NVIDIA-kernel-module-source-
-
Make the modules with following command:
$ make \ modules \ SYSSRC=
\ SYSOUT= \ CC=$(CROSS_COMPILE_AARCH64)gcc \ LD=$(CROSS_COMPILE_AARCH64)ld.bfd \ AR=$(CROSS_COMPILE_AARCH64)ar \ CXX=$(CROSS_COMPILE_AARCH64)g++ \ OBJCOPY=$(CROSS_COMPILE_AARCH64)objcopy \ TARGET_ARCH=aarch64 \ ARCH=arm64 Modules are built under “NVIDIA-kernel-module-source-
/kernel-open”.
Using the Jetson Linux Real-Time Kernel Package ¶
Starting with release 35.1, Real-Time Kernel support is provided with Developer-Preview quality for the following platforms:
-
Jetson Xavier AGX
-
Jetson Xavier NX
-
Jetson Orin AGX
-
RT Latency Tuning Please apply these settings for Jetson AGX Xavier after RT kernel boot to get the best latency value. echo 100 > /sys/kernel/debug/tegra_mce/rt_window_us echo 20 > /sys/kernel/debug/tegra_mce/rt_fwd_progress_us echo 0x7f > /sys/kernel/debug/tegra_mce/rt_safe_mask