After modifying the kernel config and using the new kernel image, I can not use kernel modules which is compiled on the machine

$ sudo insmod ./test.ko
insmod: ERROR: could not insert module test.ko: Invalid module format

Should I modify the header files of Linux?
How to export Linux header files from kernel source code? such as/usr/src/Linux headers 5.10.104 tegra ubuntu20.04-arch64

Better share how you build the kernel.

  1. create .config
    make ARCH=arm64 LOCALVERSION=“-tegra” O=$BUILD_KERNEL_OUT $KERNEL_DEFCONFIG_NAME

  2. build kernel
    make ARCH=arm64 LOCALVERSION=“-tegra” O=$BUILD_KERNEL_OUT

I need the complete steps and what scripts you use.
Is it JetPack 5 or JetPack 6?

Put the result of modinfo here.

Jetpack 5.1.1

  1. create .config and add some configuration
    make ARCH=arm64 LOCALVERSION=“-tegra” O=$BUILD_KERNEL_OUT $KERNEL_DEFCONFIG_NAME

  2. compile kernel
    make ARCH=arm64 LOCALVERSION=“-tegra” O=$BUILD_KERNEL_OUT

  3. replace Image
    cp $BUILD_KERNEL_OUT/arch/arm64/boot/Image /boot/Image

  4. compile test module
    cd /home/user/test/ && make

  5. install ko
    $ sudo insmod ./test.ko
    insmod: ERROR: could not insert module ./test.ko: Invalid module format

$ modinfo ./test.ko
filename: /home/dev/test/./test.ko
license: GPL
depends:
name: test
vermagic: 5.10.104-tegra SMP preempt mod_unload modversions aarch64
parm: debug: debug level (int)

How is the Makefile for your own module written?
Do you have any issues loading other modules that are packed into the BSP?

Before replacement, this test kernel module is normal.

MONITOR_EXTRA_CFLAGS := -DMODULE
ARCH := $(shell uname -i)
ifneq ($(findstring aarch64,$(ARCH)),)
MONITOR_EXTRA_CFLAGS += -DTARGET_ARM64
endif
ifneq ($(KERNELRELEASE),)
CFLAGS_cpusocket_unbalance.o = -I$(src)
obj-m := test.o
else
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
$(MAKE) CFLAGS_MODULE=“$(MONITOR_EXTRA_CFLAGS)” -C $(KERNELDIR) M=$(PWD) modules
endif
clean:
rm -f core *.o *.a *.s .ko ..cmd *.mod *.mod.c modules.order Module.symvers

Is this folder still linked to the kernel header source?

Yes, this folder is linked to /usr/src/linux-headers-5.10.104-tegra-ubuntu20.04_aarch64/kernel-5.10/

So how can I export the new kernel header source?

Did you reboot the device after installing new kernels?
Your module is now built against the new kernel, but if you don’t reboot, it is still the old kernel that currently runs on the device, which is imcompatible with your module.

I have already rebooted the machine and the kernel is the latest

Then does builiding the module after you reboot with the new kernel make any difference?
Or are you able to do similar things on x86 PC?

yes, I build the module with the new kernel, but it does not work normally.
In x86 machine, I usually replace new kernel header source after updating the new kernel. But I don’t know how to export header files in the Orin kernel code.

Can you check this?

This method can not work, do you know how the tar package kernel_headers.tbz2 generate?

https://docs.nvidia.com/jetson/archives/r34.1/DeveloperGuide/text/SD/Kernel/KernelCustomization.html#:~:text=/Linux_for_Tegra/kernel/-,kernel_headers.tbz2,-Where%20is%20a

What do you mean with cannot work?
Kernel source header is a general Linux thing, and not specific to NVIDIA/Jetson.

Tip: You can unpack the full kernel source at the correct location for headers if you don’t have a “headers specific” package. For example, if you go here:
cd /lib/modules/$(uname -r)

And then check:
ls -ld build

You might find the location is:
/usr/src/linux-headers-$(uname -r)/

You could unpack the kernel source you used at that latter location. This contains more source than needed, but it also includes the headers. Sometimes you’d need to configure it, but most of the time not.

(the uname -r is from the Jetson, not the host PC)

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