Im a newbie building my first Linux Kernel Module.
So the problem is that I built a raspberry kernel 64bit version 5.4 on Ubuntu22 and use make to create a helloworld_rpi4.ko file. The helloworld_rpi4.ko file is created successfully and then I scp it to the raspberrypi OS (rpi3-b-plus, 64bit-aarch64) that I use on QEMU-6.2. When I tried to sudo insmod
it on the raspberry OS it gave me this error:
`insmod: ERROR: could not insert module helloworld_rpi4.ko: Invalid module format
`
My Makefile:
obj-m += helloworld_rpi4.o
KERNEL_DIR ?= $(HOME)/linux
all:
make -C $(KERNEL_DIR) \
ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- \
M=$(PWD) modules
clean:
make -C $(KERNEL_DIR) \
ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- \
M=$(PWD) clean
deploy:
scp -P 5555 *.ko pi@localhost:/home/pi/.
My source code:
#include <linux/module.h>
static int __init hello_init(void)
{
pr_info("Hello world init\n");
return 0;
}
static void __exit hello_exit(void)
{
pr_info("Hello world exit\n");
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Alberto Liberal <aliberal@arroweurope.com>");
MODULE_DESCRIPTION("This is a print out Hello World module");
I used this code for installing cross_compile:
sudo apt install crossbuild-essential-arm64
I tried to uname -r
on the raspberry os and the version of its kernel is:
**5.4.51-v8+**.
Then I modinfo
the hellowolrd_rpi4.ko and the vermagic
: 5.4.83-v8+ SMP preempt mod_unload modversions aarch64. So the kernel that I built and the one on raspberry is the same but I don't know why it still gave me the error above. Any helps of you would be appreciate!