NVIDIA Tegra
NVIDIA Tegra Linux Driver Package

Development Guide
31.1 Release


 
Kernel Customization
 
Obtaining the Kernel Sources with Git
Manually Downloading and Expanding Kernel Sources
Building the NVIDIA Kernel
Preparing to Build External Kernel Modules
Building External Kernel Modules
Kernel Boot Time Optimization
Display Configuration and Bringup
Building the AARCH 64 Toolchain and glibc
You can manually rebuild the kernel used for the L4T package. 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:
https://developer.nvidia.com/embedded/downloads
2. Locate and download the L4T Sources for your release.
3. Extract the TBZ2 file.
$ tar -xjf public_sources.tbz2
4. Extract the kernel source file.
$ cd sources
$ tar -xjf kernel_src-<board>.tbz2
Where <board> is:
NVIDIA® Jetson AGX Xavier™: jetson-xavier
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 Tegra Kernel
1. Set the shell variable with the command:
$ TEGRA_KERNEL_OUT=<outdir>
Where:
<outdir> is the desired destination for the compiled kernel.
The kernel build process may create additional directories adjacent to this directory. Choose a value for <outdir> that is contained within an empty parent directory.
For example:
$HOME/kernel-out/kernel
 
Note:
NVIDIA recommends using the Linaro 6.4.1.2017.08 toolchain.
2. If cross-compiling on a non-Tegra system, export the following environment variable:
$ export CROSS_COMPILE=<crossbin>
Where:
<crossbin> is the prefix applied to form the path to the toolchain for cross compilation targeting arm64, e.g., gcc.
The reference arm64 toolchain is:
<aarch64_toolchain_install>/bin/aarch64-unknown-linux-gnu-
See xavier_toolchain.docx for information on how to download and build the reference toolchains.
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 <defconfig>
Where:
<kernel_source> directory contains the kernel sources.
<defconfig> is:
Jetson AGX Xavier: tegra_defconfig
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 Linux_for_Tera/kernel/Image with:
$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=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
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 Tegra system
Prepare the kernel headers with the following commands:
$ cd /usr/src/linux-headers-$(uname -r)
$ sudo make modules_prepare
When building out-of-tree modules, specify /usr/src/linux-headers-<kernel_version> as both the -C and O= option values.
Preparing the L4T kernel headers on a non-Tegra system
1. Extract the following archive and place it in a local directory with the commands:
<top>/Linux_for_Tegra/kernel/kernel_headers.tbz2
$ cd <local_src_dir>
$ tar -xjf <top>/Linux_for_Tegra/kernel/kernel_headers.tbz2
2. Export the following environment variable:
$ export CROSS_COMPILE=<crossbin>
Where <crossbin> is the prefix applied to form the path to the toolchain binary for cross compilation targeting arm64, e.g., gcc. The reference toolchain is:
<aarch64_toolchain_install>/bin/aarch64-unknown-linux-gnu-
See xavier_toolchain.docxARCH 64 Toolchain and glibc for information on how to download and build the reference toolchains.
3. Prepare the kernel headers with the following commands:
$ cd <local src dir>/linux-headers-<kernel version>
$ make ARCH=arm64 modules_prepare
When building out-of-tree modules, specify <local src dir>/linux-headers-<kernel version> as both the -C and O= option values.
Using a manually built NVIDIA kernel source tree
If you built the NVIDIA Kernel from source, use that source tree when building out-of-tree kernel modules. When building out-of-tree modules, specify the kernel source directory as the -C option value, and $TEGRA_KERNEL_OUT as the O= option value.
Preparing 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.
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:
Obtaining the Kernel Sources with Git
Manually Downloading and Expanding Kernel Sources
Building the NVIDIA Kernel
1. 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 the kernel source directory as the -C option value, and $TEGRA_KERNEL_OUT as the O= option value.
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_source_directory> \
O=<kernel_output_directory> M=$(pwd) modules