Build kernel module out-of-tree for Jetson


I’m trying to build a camera driver kernel module out-of-tree for the Jetson, I’m using the Nano for now to be exactly but other variants with the same kernel will be necessary. I used this example.

The Makefile:


ccflags-y += -I$(SRC_TREE)/drivers/media/platform/tegra/
obj-m	+= ar0521.o

	make -C $(KERNEL_PATH) M=$(PWD) modules
	make -C $(KERNEL_PATH) M=$(PWD) clean

To begin is the KERNEL_PATH right? Because I don’t think there is a kernel binary at that location, but most guides say there should be one with the name ‘build’. Where is the kernel binary located on Balena firmware?

Then the SRC_TREE is not the real one received from Balena, I additionally installed these headers from NVIDIA because the one from Balena were missing some headers. Is this a bug or am I looking at the wrong location?

Kind regards,

Hey @clint, that example Makefile looks fine to me but when the actual build step is performed, it’s using the Makefile included with the kernel headers (not the one packaged with the example module). The kernel path is expected to be empty in these cases as we don’t ship the kernel source with the image.

The important logic is actually in where it downloads the kernel headers from our S3 storage and runs make -C "$tmp_path" modules_prepare first.

Another non-official example you could look at is where I build wireguard out-of-tree. It doesn’t have as many features but it may be more clear where the important pieces are.

Also importantly, if our kernel headers package is missing something we would love to know so we can fix them!

Hi @clint!

Just checking in on whether you’ve been able to try out Kyle’s suggestions, and successfully build the module?

Kind regards

Hi @AlidaOdendaal and @klutchell ,

I managed to build the kernel module, the next step is to test the module. For this to work, I have to replace the camera definition in the device tree, compile it to a device tree binary and get the device tree binary on the Balena device.

I lost track in all the docs to manage this with the right kernel sources, any suggestions?

I read some docs about replacing device tree overlay on the fly for Raspberry Pi but is this also available with Jetson Nano?

Any guidance would be appreciated.

Kind regards,

HI @Clint, on the Jetson Nano you can test this by placing your custom compiled device tree in /mnt/sysroot/active/current/boot/ and then, in the dashboard specify the device tree name (i.e mycustom.dtb). After you validate your device-tree changes you can open a PR to include it with the Jetson Nano image in the device repo. Here’s an example PR that does this: jetson-dtbs: Add imx477 dtb for CTI Photon Nano · balena-os/balena-jetson@c0cd185 · GitHub