Skip to main content


What's the best modern guide for hacking on the kernel?

I don't want to learn everything about the internals, I want to iterate on a module quickly.

I feel like I'm missing on a lot of optimizations to shorten the feedback loop.

#Linux #kernel #hardwareEnablement #postmarketOS

in reply to Sonny

Not a kernel hacker so I don't know if it's the best, but this seems like a really nice tool to quickly iterate on the kernel coming out of systemd: https://github.com/DaanDeMeyer/mkosi-kernel

FOSSDEM talk announcing it & showing how it works: https://fosdem.org/2024/schedule/event/fosdem-2024-2209-streamlining-kernel-hacking-with-mkosi-kernel/

@daandemeyer

This entry was edited (1 month ago)
in reply to Sonny

I don't know any good guides, but have a bit of experience with module development for pmOS devices.

What I did was building locally the full kernel and install it on the device together with the modules. Then modify the module, build it individually and push it through ssh to the device. Then in the device rmmod the module and insmod the new version.
Though if you access complex hw you might end up with a locked system and need to reboot. Happened to me a lot of times 😮‍💨

in reply to Alikates

@alikates how do you know if hardware is compatible with reloading the kernel module?
in reply to Sonny

Normally when the kernel has to constantly keep track of the modules and underlying hw state ther could be issues (for example network or display drivers).

If its something simple like an i2c led driver it problably doesn't matter much. At worst the led stays turned on and the config will be overwritten when the module is reloaded

in reply to Alikates

In my case one of the modules I helped develop was a charging driver, and the kernel needed to constantly keep track of battery voltage, temperature, if USB charger is connected... Maybe this is more of an in-between case, but when I unloaded it the other monitoring drivers were usually unhappy :P
in reply to Alikates

@alikates makes sense

I'm hacking on a couple of modules for virtual buttons and GPIOs to get a tablet mode switch working.

That should be fine.

in reply to Sonny

In that case, make sure in the deinit function (if you have one) you release the irq reservations and unmap the GPIO registers. Otherwise the next time you reload the module it could think the resources are unavailable.
Good luck with it!