i try to write basic driver for BPI-R64 in ubuntu 18.04 kernel 5.4.0:
my hello-world-kernel.c :
"
#include<linux/kernel.h>
#include<linux/init.h>
#include<linux/module.h>
static int hello_init(void)
{
printk(KERN_ALERT "Start successful \n");
return 0;
}
static void hello_exit(void)
{
printk(KERN_ALERT "End successful \n");
}
module_init(hello_init);
module_exit(hello_exit); "
my makefile:
"
obj-m += hello_kernel_module.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
"
when i run command “make”, it prints “/lib/modules/5.4.0-BPI-R64-Kernel/build No such file or dictionary . Stop”
what a surprise, when i do “cd /lib/modules/5.4.0-BPI-R64-Kernel”. it exist “build” dictionary ? what happend ?
[second problem]
i replace “/lib/modules/$(shell uname -r)/build” by “/usr/src/BPI-R64-bsp-5.4_built/linux-mt” in Makefile. it work. i insmod file .ko . it still work. but when i rmmod, console prints modules used.if i used modprobe, console prints no modules found, how to uninstall module ?
It’s the answer to your firs question - /lib/modules/<version>/build - a symlink that should point to sources, you may just replace this symlink with correct one (/usr/src/BPI-R64-bsp-5.4_built/linux-mt).
to use modprobe you should to install this module to /lib/modules. Usually make modules_install. IDK why you cant unload exactly your module, but you can alway use rmmod -f to force.
tks bro. i tried rmmod -f but console prints “function not implemented” . i search gg and resulte is : set CONFIG_MODULE_UNLOAD in kernel . How to set CONFIG_MODULE_UNLOAD = yes in kernel ?
using make menuconfig (./build.sh config in Frank’s baranch, i don’t have R64, so idk if any scripts are exists in official BSP)
manually edit .config in your src dir (/usr/src/BPI-R64-bsp-5.4_built/linux-mt/.config should work for you)
simple way - copy it to /lib/modules/<ver>/extra (extra is common dir for 3rd party modules, but as i know you can use any). then run depmod and you can use modprobe.
also you can implement the same in your Makefile
I might miss some details, also it’s a general kernel development quietion so you may refer to kernel docs
Afair build.sh in official repo does not accept params and replace .config via cp with defconfig.
But after starting build.sh there is a menu where you can select change kernel config or similar…then search for the option alex mentioned by pressing / and press 1 to jump to it. Then select it (*) and exit with saving config
Btw do you compile kernel on r64 directly or on host? I guess build-script is only intended for crosscompile (not native on r64)
i run ./build.sh and press 4 for modified, save and load. then i still run ./build.sh and press 3 for Build kernel only. after 15 minutes, it prints Build success! . i check current folder, i dont see new file . i check folder linux-mt and see a list :
modules.builtin,modules.builtin.modinfo,modules.order,System.map,vmlinux ,vmlinux.o .
Idk how the official kernel was installed. But you can try my debian-image with my kernel-repo (module_remove already active). My build.sh asks for installing to sdcard after build…only need to adjust uenv.txt after install
ok, tks u. i have 1 question. after i choose 1 (run ./build.sh), i have folder SD. how to create file .img(i use bpi-copy tools to SDCard) or how write to SDCard?