HACKER Q&A
📣 matt3210

Looking for a resource on Linux kernel module development


I'd like to break into this area in my next role and I'm looking for resources to learn about this over the next few weeks so I can try to get a role in the area. My context is embedded linux.



👤 jfdi
What kind of resource are you looking for?

Have you already gotten started with your LLM of choice, and need something more?


👤 scrollaway
You could look for existing active current or ex kernel module developers and pay for a couple hours of their time to guide you through the weeds and give you early pointers. This is my approach when breaking into a new field if I have access to people.

👤 Hackbraten
If you prefer reading, you may want to look into Kaiwan N. Billimoria’s books:

https://www.packtpub.com/authors/kaiwan-n-billimoria

I’m halfway into their first Linux Kernel Programming book and like it so far.


👤 asicsp
See also:

Linux kernel and its insides (https://0xax.gitbooks.io/linux-insides/content/index.html)


👤 beeburrt
Maybe Joseph Kong's books?

Designing BSD Rootkits

https://nostarch.com/rootkits.htm

FreeBSD Device Drivers

https://nostarch.com/bsddrivers.htm

Playing Games With Kernel Memory ... FreeBSD Style

http://phrack.org/issues/63/7.html#article


👤 nottorp
Semi related piece of advice:

Also get a random raspberry pi and a simple peripheral for it: some 1 wire temperature sensor or something on i2c.

Then ignore the existing drivers and do your own. Do a character device and have a read from it trigger a read in kernel and copying of the data to user space, maybe in human readable form.

Should be good practice.

And for general embedded Linux development you also want to take a look at Yocto.


👤 mfrw
Linux Kernel Development by Robert Love is something I would encourage going through if you are unsure about what you don't know.

Although it's based on 3.x kernel, it still is pretty relevant.

Good Luck!


👤 oasisaimlessly
With VFIO, there is increasingly little need for writing in-kernel device drivers. You can do everything in userspace with better DX and without having to deal with kernel API breakage.

If you want to try out VFIO, you could try writing a userspace program that interfaces with some simple PCI device, like a serial card.


👤 wilburm
Since you’re in embedded Linux, I’d suggest some of the bootlin learning material. Something like an i2c or spi driver might be good.

QEMU is nice for learning because you can more easily debug kernel code with gdb.


👤 tux3
You could try looking up the tasks of the Eudyptula Challenge.

More than half the value was in sending mails and getting feedback, but it's still a great introduction that gradually gets you used to more and more complicated kernel dev

There are solutions lying around on the internet for the various tasks, but I'd advise not looking. The kernel is sparsely documented (some areas, rigorously undocumented), so a bit of experience searching and figuring out how to get the information on your own is genuinely valuable


👤 smashed
Since your context is embedded Linux, I would recommend following Raspbian development for general purpose SBC embedded Linux or OpenWRT for smaller, more specialized devices.

Both systems have code bases and build systems that will build root filesystem and kernels for a wide range of devices.

By following development of a device (aka target) that interests you, you will see how drivers are stabilized with various patches applied over time.


👤 yxre
I am also learning about the linux kernel, but not in an embedded context. Here are some good resources I have found.

https://man7.org/tlpi/ This book is considered the best overview of linux kernel interface. Its old, but still gives a broad coverage of topics.

https://lkml.org/ Browsing LKML is really helpful since it shows you where current development is happening and how kernel devs think. Some conversations get very advanced and nuanced.

https://kernelnewbies.org/ is a good starting place for starting to compile and deploying kernel builds

Other than that, reading and tracing the source is probably the most productive thing to do for an experienced dev to do


👤 Roark66
I second advice to focus on embedded systems, but I'd stay away from raspberry pi. I'd much prefer something you could debug easily from outside. There are plenty of arm chips one can debug with openocd and gdb. Sometimes being able to debug a running kernel from the outside can make a huge difference when troubleshooting.

If also choose some class of device and get to know it. Many Linux drivers are very similar across a class of devices. For example CSI cameras on top of V4L. Thankfully the code in the Linux kernel is very readable. Also it is well documented online.

I definitely recommend a good ide too.


👤 cvccvroomvroom
There's a book on the topic.

978-0672329463


👤 westurner
- "The Linux Kernel Module Programming Guide" (2023) https://news.ycombinator.com/item?id=35782630

- Still trying to find the How To Build a Formally Verified Kernel Module from Zero tut

Edit:

- /? Kernel module https://hn.algolia.com/?dateRange=all&page=0&prefix=true&que...

- "Linux Kernel Module written in Scratch (a visual programming language for kids)" (2022) https://news.ycombinator.com/item?id=31921996 (EduBlocks is Scratch with Python blocks and/or text code)