Kernel Customization#

You can manually rebuild the kernel used for the NVIDIA® Jetson™ Linux. You must have Internet access for this.

Prerequisites#

  • You have installed Git. You can install with the following command:

    $ sudo apt install git
    
  • Your system has the default Git port 9418 open for outbound connections.

  • You have installed the Linux kernel build utilities. You can install with the following command:

    $ sudo apt install build-essential bc flex bison libssl-dev zstd
    
  • You have installed the toolchain. See Jetson Linux Toolchain for information about how to download and install the reference toolchain.

Obtaining the Kernel Sources#

You can obtain the Jetson Linux kernel sources in the following ways:

  • Sync the sources using Git.

  • download the kernel source files and manually extract them.

NVIDIA recommends that you sync with Git.

To Sync the Kernel Sources with Git#

To get the kernel source, run the source_sync.sh script:

$ cd <install-path>/Linux_for_Tegra/source
$ ./source_sync.sh -k -t <release-tag>

The correct release-tag is specified in the release notes. This tag name syncs the sources to the source revision from which the release binary was built.

To Manually Download and Expand the Kernel Sources#

  1. In your browser, go to https://developer.nvidia.com/embedded/jetson-linux-archive.

  2. Locate and download the Jetson Linux source files for your release.

  3. Extract the .tbz2 file:

    $ tar xf public_sources.tbz2 -C <install-path>/Linux_for_Tegra/..
    
  4. Extract the kernel and the NVIDIA out-of-tree modules source files:

    $ cd <install-path>/Linux_for_Tegra/source
    $ tar xf kernel_src.tbz2
    $ tar xf kernel_oot_modules_src.tbz2
    $ tar xf nvidia_kernel_display_driver_source.tbz2
    $ tar xf nvidia_unified_gpu_display_driver_source.tbz2
    

    This extracts the kernel source to the kernel/ subdirectory, and the NVIDIA out-of-tree kernel modules sources to the current directory.

Building the Jetson Linux Kernel#

  1. Go to the build directory:

    $ cd <install-path>/Linux_for_Tegra/source
    
  2. If you are building the real-time kernel, enable the real-time configuration:

    $ ./generic_rt_build.sh "enable"
    
  3. Run the following commands to build the Jetson Linux kernel and its in-tree modules:

    $ export CROSS_COMPILE=<toolchain-path>/aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-
    $ make -C kernel
    
  4. Run the following commands to install the kernel and in-tree modules:

    $ export INSTALL_MOD_PATH=<install-path>/Linux_for_Tegra/rootfs/
    $ sudo -E make install -C kernel
    $ cp kernel/kernel-noble/arch/arm64/boot/Image \
      <install-path>/Linux_for_Tegra/kernel/Image
    

Building the NVIDIA Out-of-Tree Modules#

  1. Go to the build directory:

    $ cd <install-path>/Linux_for_Tegra/source
    
  2. If you are building the real-time kernel, configure the following variable that pertains to the nvdisplay drivers:

    $ export IGNORE_PREEMPT_RT_PRESENCE=1
    
  3. Run the following commands to build:

    $ export CROSS_COMPILE=<toolchain-path>/aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-
    $ export KERNEL_HEADERS=$PWD/kernel/kernel-noble
    $ export kernel_name=noble
    $ make modules
    
  4. Run the following commands to install:

    $ export INSTALL_MOD_PATH=<install-path>/Linux_for_Tegra/rootfs/
    $ sudo -E make modules_install
    
  5. To update the initramfs, run the following commands:

    $ cd <install-path>/Linux_for_Tegra
    $ sudo ./tools/l4t_update_initrd.sh
    

Note

If you are building natively on a target, to update the the initramfs directly on the target, run the sudo nv-update-initrd command.

Note

To prevent apt upgrade from unintentionally overriding your custom kernel, you need to rename the kernel and initramfs images, and then update extlinux.conf. You can do this either on the host or on the target.

  1. Rename the kernel and initramfs images to any names you prefer:

    On host:

    $ sudo mv <install-path>/Linux_for_Tegra/rootfs/boot/Image <install-path>/Linux_for_Tegra/rootfs/boot/Image.custom
    $ sudo mv <install-path>/Linux_for_Tegra/rootfs/boot/initrd <install-path>/Linux_for_Tegra/rootfs/boot/initrd.custom
    

    On target:

    $ sudo mv /boot/Image /boot/Image.custom
    $ sudo mv /boot/initrd /boot/initrd.custom
    
  2. Update DEFAULT and add an entry for your custom kernel with any LABEL name you prefer in extlinux.conf. Edit <install-path>/Linux_for_Tegra/rootfs/boot/extlinux/extlinux.conf on the host or edit /boot/extlinux/extlinux.conf on the target:

    TIMEOUT 30
    DEFAULT custom
    
    MENU TITLE L4T boot options
    
    LABEL primary
    ...
    
    # Add a new entry to custom kernel
    LABEL custom
        MENU LABEL custom kernel
        LINUX /boot/Image.custom
        INITRD /boot/initrd.custom
        APPEND ${cbootargs}
    

If the nvidia-l4t-kernel Debian package is upgraded during apt upgrade, the value of DEFAULT in extlinux.conf automatically changes to the newly installed kernel (such as DEFAULT primary). So, if you want to continue using your custom kernel, be sure to set DEFAULT again after the upgrade.

Building the DTBs#

  1. Go to the build directory:

    $ cd <install-path>/Linux_for_Tegra/source
    
  2. Run the following commands to build:

    $ export CROSS_COMPILE=<toolchain-path>/aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-
    $ export KERNEL_HEADERS=$PWD/kernel/kernel-noble
    $ make dtbs
    
  3. Run the following commands to install:

    $ cp kernel-devicetree/generic-dts/dtbs/* <install-path>/Linux_for_Tegra/kernel/dtb/
    

Note

If KERNEL_HEADERS points to a source directory rather than an exported headers directory, you will need to run make ARCH=arm64 defconfig scripts or equivalent in order to build dtc.