Compiling the Kernel (NVIDIA DRIVE OS Linux)
This topic contains instructions for compiling the Linux Kernel Source in your Linux SDKproduct.
Prerequisites
- You have installed the Kernel Source Code (already installed in Docker) and the toolchains:
sudo -E apt install nv-driveos-linux-*_amd64.deb
sudo -E apt install nv-driveos-foundation-toolchains-*_amd64.deb
The top-level directory layout has this appearance:
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" export NV_BUILD_KERNEL_OPTIONS="5.10"
- 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.
bash kernel/scripts/rt-patch.sh apply-patches
- Create an output directory, and then configure the kernel for the
board:
mkdir out-linux make -C kernel O=${PWD}/out-linux clean
If prompted, install the packages:
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 tegra_defconfig
- Build the
kernel:
make -j3 -C kernel O=${PWD}/out-linux
Note:If the preceding command fails, enter the
make
command without thej<number>
option. - 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
- Copy the built modules to the root filesystem 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 filesystem, use the
following Build-FS steps:
- Create a Build-FS JSON with the following
content:
$ cat > update_rfs.CONFIG.json << EOF { "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
toopt
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:
Note:To ensure that all modules are loaded, at the target side, execute these 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. - Copy the built modules to the SDK kernel modules
path:
- If there is a change in the device tree source files, copy the newly
generated DTB
files:
sudo cp ${PWD}/out-linux/arch/arm64/boot/dts/nvidia/<dtb_file> <top>/drive-linux/kernel/preempt_rt/