I'm very new in Openwrt-based development. I need to write a custom kernel module that will use Netfilter. I've previously written kernel modules for ubuntu. But I don't even know how to start for OpenWrt. I just wrote a basic Hello World-type kernel module and tried to compile it. But I couldn't do that, as build-essential files ain't there. And, so I got:
root@OpenWrt:~/nf# make
make -C /lib/modules/5.10.146/build M=/root/nf modules
make[1]: *** /lib/modules/5.10.146/build: No such file or directory. Stop.
make: *** [Makefile:4: all] Error 2
root@OpenWrt:~/nf#
I'd really appreciate it if anyone helps me by saying what things I really need to study/try first to be able to write my kernel module for OpenWrt.
FYI, I using RPi 3 Model B.
Writing a linux kernel is the same for any distro as long as you consider compiling from source. The only difference might be the "build system" or especially for OpenWrt, the fact that most of the time there is cross-compiling involved.
Or: patch whatever Kconfig and Makefile in the respective subsystem you want to have your kernel module and add all the source files to "files" in you target folder.
Create your own working OpenWrt image for your target and take it from there. For debugging your code it’s almost a necessity to have serial acccess to your device and be familiar how to recover from a soft brick.
Since you said you were developing kernel modules before, but didn’t find the wiki linked, maybe familiarize yourself with the basics I just mentioned before attending to write (or port) other modules to “OpenWrt”.
Thank you. I've set up the build system. And tried to make the kernel driver that you linked here but got this:
root@vision:~/openwrt/package/kernel/mt7621-qtn-rgmii# make
Makefile:17: /package.mk: No such file or directory
make: *** No rule to make target '/package.mk'. Stop.
root@vision:~/openwrt/package/kernel/mt7621-qtn-rgmii#
As I have set up the build system, I want to cross-compile a sample kernel module and load it into my physical device as an experiment. Is there any source like that?
Then it's easy, basically the same as building an image.
Just after that, you add a package and can compile whatever you want.
You can use the mt7621-qtn-rgmii as an example
Is every kernel module a package? Can't I write a kernel module and generate the .ko by cross-compilation and take the .ko file and load it to the real device?
FYI, my RPi device is running an image alredy.
In OpenWrt yes, the easiest way is to make it a package and then you can take its .ko as output or just install it as a package
Otherwise you would have to patch the kernel