CUDA/NVIDIA missing in Yocto image with custom kernel (DRIVE AGX Orin)

DRIVE OS Version: 6.0.10.0-36101120

Hardware: Nvidia Drive AGX Orin (p3710)

Yocto linux: 3.1 (dunfell)

Kernel version: 5.15.122-rt-tegra

Issue Description:
I am trying to build a DRIVE AGX Orin Yocto (dunfell) image using a non-prebuilt kernel.
I have set the following parameters in my distro configuration:

PREFERRED_PROVIDER_virtual/kernel = “linux-nvidia”
PREFERRED_PROVIDER_kernel = “linux-nvidia”

Additionally, I had to add a packagegroup-bsp.bbappend file in my custom layer to set the BSP_KERNEL value to kernel-modules.
However, when I use the non-prebuilt kernel, the Yocto build does not compile or include CUDA and NVIDIA-related components in the image.

When using the prebuilt kernel, these components are built and included correctly.

I have checked the kernel configuration, and it is the same for both builds. The only difference is the GCC version: the prebuilt kernel uses GCC 9.3, while the custom-built kernel uses GCC 9.5.

I cannot switch to GCC 9.3 because Dunfell only supports GCC 9.5.

Do you have any idea how I can fix the kernel build version to support NVIDIA-related components?

Dear @mate.moricz ,
Does Building the Yocto Project Components for NVIDIA DRIVE Orin | NVIDIA Docs helps? Do you see any issue with the steps in documentation?

Dear @SivaRamaKrishnaNV,

I have read the documentation, but the Yocto kernel build only mentions the following under ( To build NVIDIA Yocto Project-based components | NVIDIA Docs )

Kernel Security Feature Configurations:

  1. The default kernel recipe uses prebuilt components to account for signature matching of the base kernel and Tegra kernel modules. To rebuild the base kernel from the source, launch bitbake on the linux-nvidia recipe manually

I tried to follow the documentation by setting the following variables:

PREFERRED_PROVIDER_virtual/kernel = "linux-nvidia"
PREFERRED_PROVIDER_kernel = "linux-nvidia"

After doing this, I encountered the following error:

ERROR: Nothing RPROVIDES ‘linux-nvidia-prebuilt-tegra-modules’
(but meta-drive6/recipes-core/packagegroups/packagegroup-bsp.bb
RDEPENDS on or otherwise requires it)

I checked the referenced file and found that the following line is responsible for the issue:

# TODO: Remove the KPRIMARY filter when KNEXT goes to 6.x and becomes KSECONDARY
BSP_KERNEL = "${@bb.utils.contains('KERNEL_VER', '${KPRIMARY}',
'linux-nvidia-prebuilt-tegra-modules', 'kernel-modules', d)}"

To work around this, I created a .bbappend file to override the BSP_KERNEL variable and set it explicitly to kernel-modules.

With these changes, the Yocto build completes successfully using a custom-built kernel. However, when I run my application, I get the following runtime error:

App::main caught a std::exception as:
cuInit(0) failed. Check if CUDA is available.

When I use the prebuilt kernel, this error does not occur.

I have verified that the kernel configuration is identical between the prebuilt and custom-built kernels. The only difference I can see is the GCC version: the prebuilt kernel uses GCC 9.3, while the custom kernel is built with GCC 9.5.