Compiling Jetson TX2 source code L4T 32.3.1

From RidgeRun Developer Wiki

Introduction

This wiki page contains instructions to download and build kernel source code for Jetson TX2, several parts of this wiki were based in the document: NVIDIA Tegra Linux Driver Package Development Guide 32.3.

L4T 32.3.1 is used by JetPack 4.3 (You can get more information from jetpack-archive).

Build kernel

1. Download and install the Toolchain

NVIDIA recommends using the Linaro 7.3.1 2018.05 toolchain for L4T 32.3 (toolchain)

Download the pre-built toolchain binaries from: http://releases.linaro.org/components/toolchain/binaries/7.3-2018.05/aarch64-linux-gnu/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz and locate them under $HOME/l4t-gcc, or alternatively execute on console:

mkdir -p $HOME/l4t-gcc
cd $HOME/l4t-gcc
wget http://releases.linaro.org/components/toolchain/binaries/7.3-2018.05/aarch64-linux-gnu/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz

Execute the following commands to extract the toolchain:

tar xf gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz


2. Download the kernel sources for L4T 32.3.1

mkdir -p $HOME/l4t-sources/tx2/
cd $HOME/l4t-sources/tx2
wget https://developer.download.nvidia.com/embedded/L4T/r32-3-1_Release_v1.0/Sources/T186/public_sources.tbz2

Execute the following commands to extract the kernel sources:

tar -xvf public_sources.tbz2
cd Linux_for_Tegra/source/public
JETSON_TX2_KERNEL_SOURCES=$(pwd)
tar -xf kernel_src.tbz2

Apply corresponding patches (if any) and follow to the next section.

3. Compile kernel and dtb

cd $JETSON_TX2_KERNEL_SOURCES

TOOLCHAIN_PREFIX=$HOME/l4t-gcc/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-
TEGRA_KERNEL_OUT=$JETSON_TX2_KERNEL_SOURCES/build
KERNEL_MODULES_OUT=$JETSON_TX2_KERNEL_SOURCES/modules

make -C kernel/kernel-4.9/ ARCH=arm64 O=$TEGRA_KERNEL_OUT LOCALVERSION=-tegra CROSS_COMPILE=${TOOLCHAIN_PREFIX} tegra_defconfig
make -C kernel/kernel-4.9/ ARCH=arm64 O=$TEGRA_KERNEL_OUT LOCALVERSION=-tegra CROSS_COMPILE=${TOOLCHAIN_PREFIX} menuconfig

here you have to select the modules you want to compile, for example for libguvc something like this is required:

 -> Device Drivers
    -> USB support (USB_SUPPORT [=y]) 
        -> USB Gadget Support (USB_GADGET [=y]) 
            -> USB Gadget Drivers (<choice> [=m])

Now compile the image, dtbs and modules:

make -C kernel/kernel-4.9/ ARCH=arm64 O=$TEGRA_KERNEL_OUT LOCALVERSION=-tegra CROSS_COMPILE=${TOOLCHAIN_PREFIX} -j$(nproc) Image
make -C kernel/kernel-4.9/ ARCH=arm64 O=$TEGRA_KERNEL_OUT LOCALVERSION=-tegra CROSS_COMPILE=${TOOLCHAIN_PREFIX} -j$(nproc) dtbs
make -C kernel/kernel-4.9/ ARCH=arm64 O=$TEGRA_KERNEL_OUT LOCALVERSION=-tegra CROSS_COMPILE=${TOOLCHAIN_PREFIX} -j$(nproc) modules
make -C kernel/kernel-4.9/ ARCH=arm64 O=$TEGRA_KERNEL_OUT LOCALVERSION=-tegra INSTALL_MOD_PATH=$KERNEL_MODULES_OUT modules_install

Install image on the TX2

This guide assumes that the user already has sdk-manager installed. This link contains details about how to install sdk-manager: https://developer.nvidia.com/nvidia-sdk-manager https://docs.nvidia.com/sdk-manager/download-run-sdkm/index.html

NVIDIA_SDK_MANAGER contains the directory where Nvidia SDK manager was installed. For example:

export NVIDIA_SDK_MANAGER=$HOME/nvidia/nvidia_sdk/

Export the following variables:

JETPACK_4_3_P3310=${NVIDIA_SDK_MANAGER}/JetPack_4.3_Linux_P3310/Linux_for_Tegra/