How to add a loadable kernel module (LKM) to JetPack 6.x
Keywords: NVIDIA Jetson, JetPack, kernel customization, kernel modules, NVIDIA oot
Description
This wiki page explains how to add a camera driver as a loadable kernel module on NVIDIA platforms running JetPack 6.x.
Adding loadable kernel module
Take nv_customcam as the example camera driver to be added as a loadable kernel module. For adding a new LKM the following kernel modifications are required:
- Add the driver source files: nv_customcam.c and nv_customcam.h
- Add register mode-table configuration file for the sensor's operating modes: customcam_mode_tbls.h.
- Add a Kconfig entry for the driver.
- Update Makefile to compile driver.
Adding the source and header files
1. Add source code file nv_customcam.c to directory nvidia-oot/drivers/media/i2c/.
2. Add header file nv_customcam.h to directory nvidia-oot/include/media/.
3. Add register mode-table configuration file customcam_mode_tbls.h to directory nvidia-oot/drivers/media/i2c/.
Intergrating the driver into the kernel build system
1. Add a new entry to Kconfig file in directory kernel/kernel-jammy-src/drivers/media/i2c/. This defines a configuration option that controls whether the module is built and how it is included on the kernel.
config NV_VIDEO_CUSTOMCAM
tristate "Custom cam"
depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
help
This driver supports CUSTOMCAM camera sensor.
To compile this driver as a module, choose M here: the module
will be called CUSTOMCAM.
2. Add the following line to file defconfig in directory kernel/kernel-jammy-src/arch/arm64/configs/ to configure the kernel for building the CUSTOMCAM driver as a module.
CONFIG_NV_VIDEO_CUSTOMCAM=m
3. Modify Makefile inside directory nvidia-oot/drivers/media/i2c/ to build the new camera module added. Add the following line inside the Makefile.
obj-$(CONFIG_NV_VIDEO_CUSTOMCAM) += nv_customcam.o
Building the NVIDIA out-of-tree modules
First build the kernel to update the kernel configuration file.
1. Go to Linux_for_Tegra/source directory. Set the following environment variables:
export CROSS_COMPILE=$HOME/l4t-gcc/aarch64--glibc--stable-2022.08-1/bin/aarch64-buildroot-linux-gnu-
export KERNEL_HEADERS=$PWD/kernel/kernel-jammy-src
export KERNEL_OUTPUT=$PWD/kernel_out
2. Build the kernel.
make -C kernel
Wait for the kernel to build. The kernel build will be under kernel_out set with environment variable KERNEL_OUTPUT. You can verify the changes to the files defconfig and the Kconfig inside kernel_out/.config. You should see this set:
CONFIG_NV_VIDEO_CUSTOMCAM=m
3. Set the install path environment variable.
export INSTALL_MOD_PATH=<PATH_TO>/Linux_for_Tegra/rootfs/
4. Build the NVIDIA OoT modules:
make modules
Compiled files will be under directory: nvidia-oot/drivers/media/i2c/. You should see file: nv_customcam.ko.
Installing the NVIDIA out-of-tree modules
1. Install the module.
sudo -E make modules_install
After this the module should be inside directory: Linux_for_Tegra/rootfs/usr/lib/modules/5.15.148-tegra/updates/drivers/media/i2c/.
From this point the kernel module is ready for use. You can either:
1. Flash the board.
2. Copy the module to the board using scp.
scp $INSTALL_MOD_PATH/usr/lib/modules/5.15.148-tegra/updates/drivers/media/i2c/nv_customcam.ko nvidia@<board-ip>:/tmp
2.1 Inside the board:
sudo cp /tmp/nv_customcam.ko /lib/modules/5.15.148-tegra/updates/drivers/media/i2c/
sudo depmod -a 5.15.148-tegra
2.2 Load the module
sudo modprobe nv_customcam
Need Further Support?
📞 Book Consultation Call: Show Calendar!
📩 Contact Via Email: support@proventusnova.com
🌐 Visit Our Website: ProventusNova.com
