Compiling the Kernel (Kernel 5.15)
This topic contains instructions for compiling the Linux kernel source in your Linux SDK product.
Prerequisites
You have installed the Kernel source code (already installed in Docker) and the toolchain:
sudo -E apt install nv-driveos-linux-*_amd64.deb
sudo -E apt install nv-driveos-foundation-toolchains-*_amd64.deb
The top-level directory layout looks as follows:
drive-foundation
drive-linux
Drive-linux_src
toolchains
To Compile the Kernel
-
Set up the environment macros: The
LOCAL_VERSION
environment variable appends-tegra
to the kernel version and modules.export ARCH=arm64 export CROSS_COMPILE=${PWD}/toolchains/aarch64--glibc--stable-2022.03-1/bin/aarch64-buildroot-linux-gnu- export LOCALVERSION="-tegra"
-
Set the kernel source directory as the current working directory:
cd <top>/drive-linux/kernel/source/oss_src
-
Enter the following command to apply the rt-patches.
cd kernel/scripts bash generic-rt-patch.sh apply-patches cd ../../
-
Create an output directory, and then configure the kernel for the board:
If prompted, install the packages:mkdir out-linux make -C kernel O=${PWD}/out-linux clean
-
sudo apt-get install imagemagick graphviz dvipng python3-venv fonts-noto-cjk latexmk librsvg2-bin texlive-xetex
-
/usr/bin/python3 -m venv sphinx_2.4.4 . sphinx_2.4.4/bin/activate
-
pip install -r <top>/drive-linux/kernel/source/oss_src/kernel/Documentation/sphinx/requirements.txt
-
sudo apt-get install flex
-
sudo apt-get install bison
-
-
Add the following command:
make -C kernel O=${PWD}/out-linux defconfig
-
Build the kernel:
make -j3 -C kernel O=${PWD}/out-linux
Note: If the preceding command fails, enter themake
command without thej<number>
option. -
Build OOT modules:
make -C ${PWD}/out-linux M=${PWD}/nvidia-oot/ srctree.nvidia-oot=${PWD}/nvidia-oot/ srctree.nvidia=${PWD}/nvidia-oot V=1 modules CONFIG_TEGRA_OOT_MODULE=m
- To flash the built images, copy the uncompressed (Image) kernel images to the
kernel top directory with the following command:
sudo cp ${PWD}/out-linux/arch/arm64/boot/Image <top>/drive-linux/kernel/preempt_rt/images/
CAUTION: Before copying the new kernel images, create a backup of the default kernels provided. - Consolidate the built kernel modules in the build directory with the following
commands:
export INSTALL_MOD_PATH=${PWD}/out-linux make -C kernel O=${PWD}/out-linux modules_install make -C ${PWD}/out-t186ref-linux M=${PWD}/nvidia-oot/ modules_install
- Copy the built modules to the root file system path with the following
commands:
- Copy the built modules to the SDK kernel modules
path:
sudo cp -a ${PWD}/out-linux/lib/modules/* <top>/drive- linux/kernel/preempt_rt/modules
- To copy the updated modules into the root file system, use the following
Build-FS steps:
- Create a Build-FS JSON with the following
content:
{ "OS": "linux", "Output": "driveos-updated-rfs", "Base": "\${BASE_DIR}/targetfs.img", "CopyTargets": [ "\${COPYTARGETYAML_DIR}/copytarget-kernel-modules.yaml" ] }
- Execute Build-FS with the preceding configuration to rebuild the
filesystem. Set NV_WORKSPACE to opt of SDK install directory
(containing drive-linux
directory).
$ sudo -E /usr/bin/python3 -B /opt/nvidia/driveos/common/filesystems/build- fs/17/bin/build_fs.py -w ${NV_WORKSPACE}/ -i $PWD/update_rfs.CONFIG.json -o ${NV_WORKSPACE}/drive-linux/filesystem/targetfs-images/ $ sudo rm -f ${NV_WORKSPACE}/drive-linux/filesystem/targetfs-images/targetfs.img $ sudo ln -s ${NV_WORKSPACE}/drive-linux/filesystem/targetfs-images/driveos-updated-rfs.img ${NV_WORKSPACE}/drive-linux/filesystem/targetfs-images/targetfs.img
- Flash the target using the SDK Bootburn tool.
- Create a Build-FS JSON with the following
content:
- Copy the built modules to the SDK kernel modules
path:
Note: To ensure that all modules are loaded, execute the following
commands at the target side:
depmod -a
sync
The sync
command must be executed as superuser.
From the next boot onward, the kernel modules are auto-loaded on boot.