Forum > Unix
Developing a Kernel Module
nicolap:
Hi all,
I would like to write a Kernel Module in Freepascal, anyone has esperience?
All that I found is an outdated page stating that it's possibile.
I'm using fpc 3.2.2 on a Raspberry Pi Zero 2 W :P
Thanks
Nicola
MarkMLl:
Frankly, I would advise you to not do this.
The internal kernel APIs are somewhat fluid, and development relies heavily on preconfigured tools and makefiles. You need only to watch the effort to integrate Rust with kernel development to see this.
To a very large extent, kernel modules (at least routine ones, e.g. to support custom hardware), are written with reference to existing ones. Attempting to use a language for which there is not already copious "prior art" in the field will cause nothing but grief.
If you attempt to reach out to the kernel developers you will get derision rather than support, and don't expect much better from the RPi community.
The only time I've needed a kernel module was when accessing temperature sensors etc. on a SPARC system, and that was around 20 years ago.
Unless you have a /very/ good reason, in any field it's best to study prior art and to comply with established conventions when extending it. In the case of the kernel that amounts to C or Rust, and realistic choices are not all that different when programming e.g. an embedded Arduino or similar single-board computer.
MarkMLl
Bogen85:
--- Quote from: nicolap on December 02, 2024, 05:37:05 pm ---I would like to write a Kernel Module in Freepascal, anyone has esperience?
All that I found is an outdated page stating that it's possibile.
--- End quote ---
Possible, yeah.... Practical? No.
--- Quote from: MarkMLl on December 03, 2024, 09:13:27 am ---Frankly, I would advise you to not do this.
--- End quote ---
As would I, for all the reasons Mark shared.
Unless you are pursuing this as purely academic one time "adventure" (YOLO?), it is not worth it.
* Your module will never be accepted by kernel.org
* Your module likely won't compile after a few months (or weeks?) after you update kernel sources
* If you decided to target a so called LTS kernel, you will have to rewrite much of your module later when the next LTS release comes out
* Unless only you is going to use this on your own machines, it is unlikely that you will convince many others to run your exact LTS kernel variant and install your module
* If you are doing this for a product you will need to hire a full time Linux developer (or more than one depending on the complexity of the module) who will need to interface with the kernel.org community. You likely won't find one willing to put up with the ridicule and derision from kernel.org over writing a Linux kernel module in Pascal.
* Hardware vendors with out of tree Linux modules have dedicated Linux developer teams. (Ones that don't can't reasonably maintain them for long)
* Developing a module for Linux is only practical in the long run for most people if the plan is to get the module into the mainline kernel, which means acceptance of your module by the kernel.org community.
Maintaining a windows kernel module is far easier. (And I'm not a windows or a Microsoft advocate). Dealing with driver signing (self signed or WHQL) is far easier (in the short and long term) than dealing with kernel.org and other issues surrounding a Linux kernel module that will always be out of tree.
However, if writing a kernel module (or something akin to it) in Pascal is still something you really want to do, there are a couple more "practical" (you decide how practical...) approaches you could take...
* https://ebpf.io/what-is-ebpf/ Of course to be feasible this would require a pas2ebpf (similar to what pas2js does)...
* https://www.kernel.org/doc/html/v6.0/driver-api/uio-howto.html Linux user-space I/O, this is the most practical option in my opinion if you really need this
Bogen85:
Apart from the "never be accepted" and "derision and ridicule" because the Linux kernel module is being done in Pascal, everything else applies to any out of kernel.org kernel module source. In other words, any kernel module that is not intended to be handed over to kernel.org when it gets running initially, where the discussions to do this are started when the kernel module is started be be developed.
MarkMLl:
It might be possible to isolate some of the /technical/ process- i.e. the API against which a kernel module is to be linked- by using DKMS. I've used that for a couple of modules in my Github repo with success, but never got around to following up upstream changes somebody later made (which of course implies that intimacy with Git is a prerequisite for anything kernel-related).
That doesn't help with the /understanding/ process. I intentionally held off commenting in case anybody in this community was sufficiently confident that such a thing could be done: while I see https://wiki.lazarus.freepascal.org/linux/kernel/module_development (which is presumably the page to which OP refers) I'd point out that it's had no significant attention since 2011 which is /yonks/ as far as Linux is concerned.
OP: what /exactly/ are you trying to do, why do you believe you need a kernel module, and why do you think it's plausible to write it using FPC?
MarkMLl
Navigation
[0] Message Index
[#] Next page