Kernel Customization

You can manually rebuild the kernel used for the NVIDIA® Jetson™ Linux Driver Package (L4T). Internet access is required.

Obtaining the Kernel Sources with Git

Prerequisites
You have installed Git. Install Git 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 the source_sync.sh script:
$ ./source_sync.sh
When prompted enter a ‘tag’ name, as provided in the release notes.
You can sync to any Linux tag you like. However, the tag provided in the release notes syncs the sources to the same source revision the release binary was built from. To see a list of the available release tags, use:
$ git tag -l tegra-l4t*

Manually Downloading and Expanding Kernel Sources

As an alternative, you can download the kernel source files and then manually extract them. If possible, it is recommended to instead sync with git.
To manually download and expand the kernel sources
1. In a browser, navigate to:
2. Locate and download the L4T source files for your release.
3. Extract the TBZ2 file.
$ tar -xjf public_sources.tbz2
4. Extract the kernel source file.
$ cd Linux_for_Tegra/source/public
$ tar –xjf kernel_src.tbz2
The kernel source is extracted to the kernel subdirectory.

Building the NVIDIA Kernel

Follow the steps in this procedure to build the NVIDIA kernel.
Prerequisites
You have downloaded the kernel source code.
You have installed the utilities required by the kernel build process.
Install the utilities with the command:
$ sudo apt install build-essential bc
To build the Jetson Linux Kernel
1. Set the shell variable with the command:
$ TEGRA_KERNEL_OUT=<outdir>
Where:
<outdir> is the desired destination for the compiled kernel.
2. If cross-compiling on a non-Jetson system, export the following environment variables:
$ export CROSS_COMPILE=<cross_prefix>
$ export LOCALVERSION=-tegra
Where:
<cross_prefix> is the absolute path of the ARM64 toolchain without the gcc suffix. For example, for the reference ARM64 toolchain, <cross_prefix> is:
<toolchain_install_path>/bin/aarch64-linux-gnu-
See The L4T Toolchain for information on how to download and build the reference toolchains.
Note:
NVIDIA recommends using the Linaro 7.3.1 2018.05 toolchain.
3. Execute the following commands to create the .config file:
$ cd <kernel_source>
$ mkdir -p $TEGRA_KERNEL_OUT
$ make ARCH=arm64 O=$TEGRA_KERNEL_OUT tegra_defconfig
Where:
<kernel_source> directory contains the kernel sources (e.g. kernel-4.9).
4. Execute the following commands to build the kernel including all DTBs and modules:
$ make ARCH=arm64 O=$TEGRA_KERNEL_OUT -j<n>
Where <n> indicates the number of parallel processes to be used. A typical value is the number of CPUs in your system.
5. Replace <release_packagep>/Linux_for_Tegra/kernel/Image with a copy of:
$TEGRA_KERNEL_OUT/arch/arm64/boot/Image
6. Replace the contents of Linux_for_Tegra/kernel/dtb/ with the contents of:
$TEGRA_KERNEL_OUT/arch/arm64/boot/dts/
7. Execute the following commands to install the kernel modules:
$ sudo make ARCH=arm64 O=$TEGRA_KERNEL_OUT modules_install \
INSTALL_MOD_PATH=<top>/Linux_for_Tegra/rootfs/
8. Optionally, archive the installed kernel modules using the following command:
$ cd <modules_install_path>
$ tar --owner root --group root -cjf kernel_supplements.tbz2 \
lib/modules
The installed modules can be used to provide the contents of /lib/modules/<kernel_version> on the target system.
Use the archive to replace the one in the kernel directory of the extracted release package prior to running apply_binaries.sh:
Linux_for_Tegra/kernel/kernel_supplements.tbz2
To sign and encrypt kernel, kernel-dtb, and initrd binary files
Applies to: Jetson Xavier NX series and Jetson AGX Xavier series
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.

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 L4T 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)-ubuntu18.04_aarch64
To build out-of-tree modules, specify the kernel directory as:
/usr/src/linux-headers-$(uname -r)-ubuntu18.04_aarch64
or
/lib/modules/$(uname -r)/build
To prepare the Jetson Linux kernel headers on a non-Jetson system
Extract the following archive and place it in a local directory with the commands:
$ cd <local_src_dir>
$ tar -xjf <top>/Linux_for_Tegra/kernel/kernel_headers.tbz2
You can use the files in this directory to build out-of-tree modules without further action:
<local_src_dir>/linux-headers-$(uname -r)-linux_x86_64
To build out-of-tree modules, specify the kernel directory as:
<local src dir>/linux-headers-$(uname -r)-linux_x86_64
To use a manually built NVIDIA kernel source tree
If you built the NVIDIA kernel from source, use the same source tree when building out-of-tree kernel modules. When building out-of-tree modules, specify $TEGRA_KERNEL_OUT as kernel directory.
To prepare an NVIDIA 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.
1. To extract the kernel source, set any required shell or environment variables, and create the .config file, follow the instructions provided in the following topics:
2. Execute the following command to prepare the kernel source tree for building out-of-tree kernel modules:
$ make ARCH=arm64 O=$TEGRA_KERNEL_OUT -j<n> modules_prepare
Where <n> indicates the number of parallel processes to be used. A typical value is the number of CPUs in your system.
When building out-of-tree modules, specify $TEGRA_KERNEL_OUT as the kernel directory.

Building External Kernel Modules

If cross-compiling, ensure that the CROSS_COMPILE environment variable is set as described in previous sections.
Execute the following commands to build an out-of-tree kernel module:
$ cd <path_to_module_source>
$ make ARCH=arm64 –C <kernel_directory> M=$(pwd)
Execute the following commands to strip unneeded symbols from the kernel module:
$ <tool_chain_path>/aarch64-linux-gnu-strip -–strip-unneeded <path-of-kernel-module.ko>

How To Enable PMIC-WDT

To enable PMIC-WDT:
1. Change ODM data: set ODM data bits 17:16 to 0b10 before flashing in conf file. (This enables PMIC-WDT and disables Tegra-WDT.)
In the file sudo vim p2771-0000.conf.common, replace 0x1090000 with 0x10a0000.
2. Enter the command:
echo 0 > /sys/module/kernel/parameters/panic
3. Enter the command:
cat /dev/watchdog
or
echo c > /proc/sysrq-trigger
(The latter command causes the system to crash.)
4. Wait for two minutes. The device reboots. With this reboot, UART logs begin to appear in the mb2 logs:
[0000.203] I> pmic: reset reason (nverc) : 0x2

Using the L4T Real-Time Kernel Package

Applies to: Jetson AGX Xavier series only
NVIDIA® Jetson AGX Xavier™ series processors officially support the NVIDIA real-time kernel from release 32.5. This section explains how to install and remove L4T real-time kernel packages on your system through the NVIDIA repository.
Prerequisites
You must upgrade all L4T packages to the same point release version as the real-time kernel.
To install the real-time kernel package
1. Open the apt source configuration file in a text editor, for example:
$ sudo vi /etc/apt/sources.list.d/nvidia-l4t-apt-source.list
2. Add a new entry for the rt-kernel repo:
deb https://repo.download.nvidia.com/jetson/rt-kernel r<rel> main
Where <rel> is the current release number, e.g 32.6.1.
3. Enter this command:
$ sudo apt update
4. Install the real-time kernel packages:
$ sudo apt install nvidia-l4t-rt-kernel nvidia-l4t-rt-kernel-headers
5. Reboot
To remove the real-time kernel package
1. Enter this command:
$ sudo apt remove nvidia-l4t-rt-kernel nvidia-l4t-rt-kernel-headers
2. Reboot.
To switch to a different kernel
Once you have installed the real-time kernel on your device, you may want to switch between the real-time kernel image and the original generic kernel image without re-installing or removing kernel packages. You can do this by editing /boot/extlinux/extlinux.conf and setting the DEFAULT property to specify the kernel you want to boot. Set DEFAULT to real-time for the real-time kernel, or to primary for the generic kernel.
TIMEOUT 30
DEFAULT real-time