Kernel Customization — NVIDIA Jetson Linux Developer Guide 1 documentation (original) (raw)
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
:
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:
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 thekernel/
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:
Wherekernel_out
is the directory where the compiled kernel is to be written. - Build the kernel:
$ ./nvbuild.sh -o $PWD/kernel_out
Notenvbuild.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/<kernel_version>/
on the target system. Before you runapply_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-7 as described in the previous section.
- Install the kernel modules:
$ cd
$ sudo make ARCH=arm64 O=$TEGRA_KERNEL_OUT modules_install INSTALL_MOD_PATH=/Linux_for_Tegra/rootfs/
Ensure there is a new folder with-rt63-
in its name underLinux_for_Tegra/rootfs/usr/lib/modules/
. - Build the display drivers.
Refer to To Build Display Kernel Modules for information about how to build display drivers.
- Copy
nvidia-drm.ko
,nvidia.ko
, andnvidia-modeset.ko
into the following directory:
/Linux_for_Tegra/rootfs/usr/lib/modules/$(uname -r)/extra/opensrc-disp/If this folder does not exist, create it manually.
$(uname -r)
refers to the folder that was created in the previous step where kernel modules are installed.
- In Orin, fix the black screen. This is not required on Xavier.
- Flash the system into your Jetson device.
- At the first boot, log in, type
sudo depmod -a
, and then reboot. The GUI should now be back.
The display is not available upon first boot, so the process of setting user accounts through a serial connection might not be stable. To create user accounts before you flash, use l4t_create_default_user.sh under Linux_for_Tegra/tools/. To use it, run the following command:
$ sudo ./l4t_create_default_user -u -p
For Xavier, if USB devices such as a mouse and a keyboard do not provide a response at boot time, unplug and plug them in again.
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 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<n>
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 <path-of-kernel-module.ko>
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
- Jetson Orin NX and Nano
- RT Latency Tuning
- To get the best latency value, apply these settings for Xavier series after the RT kernel boot.
This step is not applicable for the Orin series.
- To get the best latency value, apply these settings for Xavier series after the RT kernel boot.
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