Building DKMS modules with custom kernel

My carrier board requires that I build a patched kernel and DTBs. After building the kernel, I copy the products into the L4T kernel/ directory so that they get flashed later:

cp arch/arm64/boot/Image "L4T/kernel/"
cp arch/arm64/boot/dts/*.dtb "L4T/kernel/dtb/"

However, if I want to install any DKMS packages, I also need to provide the Linux kernel headers.

It’s not enough to make headers_install from the kernel tree and copy the include/ directory into the rootfs, because I also need to have files like Kconfig, Kbuild, and other files that are not included.

Alternatively I could install nvidia-l4t-kernel-headers, but it depends on nvidia-l4t-kernel which will overwrite my custom kernel.

What is the expected way that I can use a custom kernel and also be able to install DKMS modules?

Here’s one hacky approach, which is to patch nvidia-l4t-kernel-headers to not install the kernel image:

#!/bin/bash -eu

# This script is executed inside the rootfs chroot during
# For DKMS modules, we need the kernel headers installed. NVIDIA provides these in the
# nvidia-l4t-kernel-headers package, but it depends on the nvidia-l4t-kernel
# package, which we don't want to install because we have a custom kernel.
# Therefore, we need to modify the package so it doesn't install the kernel
# image, just the headers.

export DEBIAN_FRONTEND=noninteractive

# Download the nvidia-l4t-kernel-headers package
cd /tmp
apt-get download nvidia-l4t-kernel-headers

# Unpack it into a temporary directory
dpkg-deb -R nvidia-l4t-kernel-headers_*.deb nvidia-l4t-kernel-headers/
rm -f nvidia-l4t-kernel-headers_*.deb

# Modify dependencies to eliminate nvidia-l4t-kernel
sed -i '/^Depends/ { s/\([:,]\s*\)nvidia-l4t-kernel\s*\((.*)\)\?\(\s*,\s*\)\?/\1/; s/,\s*$// }' \

# Package it back up and install
dpkg-deb -b nvidia-l4t-kernel-headers/ nvidia-l4t-kernel-headers-patched.deb
dpkg -i nvidia-l4t-kernel-headers-patched.deb

# Hold back the nvidia-l4t-kernel-headers package, so upstream repo changes do
# not undo our work here.
apt-mark hold nvidia-l4t-kernel-headers

# Clean up
rm -Rf nvidia-l4t-kernel-headers/ nvidia-l4t-kernel-headers-patched.deb

Hi, glad that you found a workaround.
We’ll check if there’s a better solution.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.