Compiling the Kernel (NVIDIA DRIVE Linux)
This topic contains instructions for compiling the Linux Kernel source in your Linux PDK product.
Prerequisites
• You have unpacked the Kernel Source Code:
bash drive-t186ref-linux-*-oss-src.run
bash drive-t186ref-foundation-*-toolchain.run
This script creates this directory:
drive-oss-src
The top-level directory layout has this appearance:
hardware
toolchains
drive-oss-src
drive-t186ref-foundation
drive-t186ref-foundation_src
drive-t186ref-linux
drive-t186ref-linux_src
To compile the kernel
1. Set up the environment macros: The LOCAL_VERSION environment variable appends -tegra to the kernel version and modules.
export ARCH=arm64
export CROSS_COMPILE=<
top>/toolchains/tegra-4.9-nv/usr/bin/aarch64-gnu-linux/aarch64-gnu-linux-
export CROSS32CC=<top>/toolchains/gcc-arm-none-eabi-4_8-2014q3/bin/arm-none-eabi-gcc
export LOCALVERSION="-tegra"
2. Set the kernel source directory as the current working directory:
cd <top>/drive-oss-src
3. Enter the following command to apply the rt-patches.
bash kernel/scripts/rt-patch.sh apply-patches
4. Create an output directory, and then configure the kernel for the board:
mkdir out-t186ref-linux
make -C kernel O=${PWD}/out-t186ref-linux clean
5. Add the following command:
make -C kernel O=${PWD}/out-t186ref-linux tegra_gnu_linux_defconfig
6. Build the kernel:
make -j3 -C kernel O=${PWD}/out-t186ref-linux
Note: | If the above command fails, enter the make command without the j<number> option. |
7. To flash the built images, copy the compressed (zImage) and uncompressed (Image) kernel images to the kernel top directory with the following commands:
cp ${PWD}/out-t186ref-linux/arch/arm64/boot/zImage <top>/drive-t186ref-linux/kernel-rt_patches
cp ${PWD}/out-t186ref-linux/arch/arm64/boot/Image <top>/drive-t186ref-linux/kernel-rt_patches
Caution: Before copying the new kernel images, create a backup of the default kernels provided.
8. Consolidate the built kernel modules in the build directory with the following commands:
export INSTALL_MOD_PATH=${PWD}/out-t186ref-linux
make -C kernel O=${PWD}/out-t186ref-linux modules_install
9. (Applies to: Ubuntu targetfs) Copy the built modules to the root filesystem path with the following commands:
sudo cp -a ${PWD}/out-t186ref-linux/lib/modules/* <top>/drive-t186ref-linux/targetfs/lib/modules
Note: | To ensure that all modules are loaded, at the target side, execute the commands: depmod-a sync The sync command must be executed as superuser. From the next boot onward, the kernel modules are auto-loaded on boot. |
10. If there is a change in the device tree source files, copy the newly generated DTB files:
cp <top>/drive-oss-src/out-t186ref-linux/arch/arm64/boot/dts/<dtb_file> <top>/drive-t186ref-linux/kernel
Where <dtb_file> is one of the following, depending on the platform (below).
For DRIVE PX 2 (P3407)
tegra186-vcm31-p3407-0000-a0<x>-00-base-vm.dtb
For DRIVE PX 2 (P2379)
• For Tegra-A
tegra186-vcm31-p2379-0000-c0<x>-00-base-a-safety-vm.dtb
tegra186-vcm31-p2379-0000-c0<x>-00-base-a-air-cooled-safety-vm.dtb
• For Tegra-B
tegra186-vcm31-p2379-0000-c0<x>-00-base-b-safety-vm.dtb
tegra186-vcm31-p2379-0000-c0<x>-00-base-b-air-cooled-safety-vm.dtb
Where <x> is your actual board number as specified in the Release Notes.