6 ms·
Writing Your First Kernel Module (2019)
- bitcharmer 6y agoHN's front page magic never seizes to amaze me. If you are looking for a introduction on how to write your first kernel module, Google will return pages worth of results with blog post entries, articles and even excerpts from books such as LDD[0]. Yet this brief text gets the reward. Don't get me wrong I absolutely root for people's efforts for popularising kernel dev, just stunned how HN works sometimes. [0] https://lwn.net/Kernel/LDD3/ https://lwn.net/Kernel/LDD3/
- waiseristy 6y agoI think the reality is that news aggregators like HN reward short-form content; a 4 minute read is going to garner more upvotes than a page that links to 18 chapters of dense technical information. That's what the comments are for though! Thanks for linking this lwn page
- deleted 6y ago[deleted]
- _fizz_buzz_ 6y agoIs LDD still up to date?
- PurpleFoxy 6y agoIt hasn’t been updated since about 2004. No idea how much has changed since then but the authors have stated they don’t update it not because it’s still accurate but because they don’t need new kernel devs and it’s a lot of work.
- bitcharmer 6y agoSurprisingly most of it still is. My old modules still compile and work as expected.
- gpanders 6y agoThere are some things out of date for sure, but the bulk of it is still highly relevant. When I was first learning to write kernel drivers, I had LDD open on one screen and the kernel source code open on the other. You can usually look for examples in the source that will help you figure out the “modern” ways of doing things. LDD is indispensable for giving you a solid footing so that you’re not wading into the Linux kernel totally unequipped.
- ai_ja_nai 6y agome too, I'll never understand what posts get the attention :D
- tjoff 6y agoPerhaps a hello-world type of project is preferred when trying to get a first taste for it?
- mhh__ 6y agoMention Rust for those sweet sweet internet points! (I do like Rust, however seeing features D has had for 10 years on the frontpage is a little jarring, although I am channeling that into some blog posts to get the word out)
- shipp02 6y agolinux-kernel-labs[1]. This looks much better if you want to dive deep. Looks more up to date then LDD though I cannot talk about the quality since I haven't actually read it. I just found it when I put it into search. Looks more up to date then LDD though I cannot talk about the quality. [1](https://linux-kernel-labs.github.io/refs/heads/master/ https://linux-kernel-labs.github.io/refs/heads/master/)
- rubenbe 6y agoBecause the code is (largely) the documentation, I recommend people to start reading kernel module sources from the bottom up. The bottom is where the initialization happens. The further you move towards the top of the file the more specific the code becomes (register bashing and magic hardware specific values)
- gpanders 6y agoYes! Speaking from personal experience, I fully endorse this approach.
- Bearcban 6y agodo you have any modules in particular that you think are especially good for learning kernel dev?
- rubenbe 6y agoI can recommend the bootlin course to get started with kernel development. https://bootlin.com/training/kernel/ https://bootlin.com/training/kernel/ Additionally, I often use new drivers "published" on Phoronix as example. They are often quite simple. The complexity usually lies in the reverse engineering the hardware, not really in the driver development. E.g. for the apple magic mouse: https://www.phoronix.com/scan.php?page=news_item&px=Apple-Magic-Mouse-2-Linux https://www.phoronix.com/scan.php?page=news_item&px=Apple-Ma... And for corsair PSUs: https://www.phoronix.com/scan.php?page=news_item&px=Linux-Corsair-PSU-Driver https://www.phoronix.com/scan.php?page=news_item&px=Linux-Co...
- darnir 6y agoI absolutely dislike it when people decide to simply gloss over the licensing parts of code. Code licenses are a crucial component and you should really know and understand the implications of the license you pick. This is even more important in the kernel as it changes the set of symbols available to your module.
- Google234 6y agoYes, any good guide should shown how to circumvent the Kernel’s weird form of DRM. The fact that any high resolution clock is excluded from EXPORT_SYMBOL shows that’s it’s enforced for purely political reasons.
- marcodiego 6y agoWhy images instead of text??? Images can't easily be copy-pasted as text (though in this case I really recommend re-typing). The internet is turning into a sea of wrongly chosen media. Youtube videos are used when a small list of command lines would be enough and images are used when text would be much better.
- the-dude 6y agoIt is maddening. Maybe Medium does not support code markup?
- 1f60c 6y agoIt doesn’t. It does support GitHub Gist embeds, however.
- continuational 6y agoUnfortunately, this fills your post with GitHub ads, so it's not very attractive.
- continuational 6y agoMedium doesn't support code highlighting. It kinda supports unhighlighted code blocks, but that's it.
- ai_ja_nai 6y agoyes, this is due to Medium being a very poor blogging platform for coders. Too bad it is a SEO valkyrie ride