Hacker News

Top stories

Live mirror
30 storiesupdated just nowView source snapshot
  1. Hacking OpenAI(hacktron.ai ↗)
    33comments
  2. Astra for Law(openai.com ↗)
    429comments
  3. Bonsai 2 27B: Near-Lossless Compression in a 9x Smaller Footprint(prismml.com ↗)
    106comments
  4. Waymo in Singapore(waymo.com ↗)
    9comments
  5. Bend – A language that blocks AI mistakes via proof, on CPU and GPU(bend-lang.com ↗)
    184comments
  6. Hister: A private search engine for the pages you visit and the files you keep(github.com/asciimoo ↗)
    141comments
  7. Alibaba releases Qwen 3.8 Omni Flash(qwen.ai ↗)
    24comments
  8. Wax motor(wikipedia.org ↗)
    57comments
  9. Pre-Greek: The lost language hidden within Ancient Greek(linguisticdiscovery.com ↗)
    discuss
  10. Fujitsu launches made-in-Japan next-generation CPU FUJITSU-MONAKA(global.fujitsu ↗)
    205comments
  11. Telstra outage: The night a network decided the year was 2006(netnod.se ↗)
    10comments
  12. Shapelearn Qwen 3.8 27B (13.1 GB VRAM)(byteshape.com ↗)
    discuss
  13. Ask A Monk – A digital wilderness for thoughts with no immediate answer(askamonk.online ↗)
    10comments
  14. Apple detectives solved mystery of ancient tree and rewrote the history of fruit(scientificamerican.com ↗)
    discuss
  15. Code Scans(devin.ai ↗)
    2comments
  16. How to Write with an LLM(sockpuppet.org ↗)
    55comments
  17. Flet 1.0 – Build cross-platform apps in Python(flet.dev ↗)
    39comments
  18. Diplodocus, Long Thought Exclusively American, Turns Up in Spain(sci.news ↗)
    27comments
  19. The most important product decision is what you don't build(liamnugent.me ↗)
    23comments
  20. How Uber Protects Against Retry Storms(uber.com ↗)
    31comments
  21. I Put Nam A2-Lite Inside an iRig HD X(playtaurus.com ↗)
    4comments
  22. CrowdSec Source Code Leak(crowdsec.net ↗)
    42comments
  23. Khipu (Quipu) Field Guide(khipufieldguide.com ↗)
    discuss
  24. Why I didn’t sign the Fields medallists’ letter(gowers.wordpress.com ↗)
    331comments
  25. How do we prevent mathemathics from devolving into the Medieval Era of secrecy?(mathoverflow.net ↗)
    74comments
  26. Better Icon and Label Alignment(ishadeed.com ↗)
    2comments
  27. Infinite-Parameter LLMs: Generating and Adapting Weights from Live Data(arxiv.org ↗)
    38comments
  28. Rate limits on GitLab.com are changing(about.gitlab.com ↗)
    109comments
  29. Zettascale (YC S24) Is Hiring ASIC/FPGA Engineers to Build Chips for ASI(zscc.ai ↗)
    discuss
  30. The American Religion of Self-Storage Facilities(newyorker.com ↗)
    362comments

The Linux Kernel Module Programming Guide

154 pointsby 5y agogithub.com
30 comments
5y agoHN ↗

Just a warning if you do embedded work with Linux (RPi, Beaglebone, etc)... this guide doesn't cover the Devicetree APIs. Doesn't even acknowledge their existence.

5y agoHN ↗

The author is pretty open to any kind of criticisms and suggestions. It would be great if you open an issue to inform him the missing contents.

5y agoHN ↗

Thanks for submitting issue(s). The motivation of updating "The Linux Kernel Module Programming Guide" was for educational purpose. I agree with the idea to mention new kernel features such as Devicetree.

5y agoHN ↗

RPi is barely embedded work. It's almost always micro-desktop Linux.

5y agoHN ↗

True. But there are some of us working on ARM platforms that aren't RPi that need to hack drivers.

Anyone working with a SOM, for example, will want to customize the DT for their carrier board. And then your EE finds a cheaper controller chip somewhere. And then your display supplier switches captouch parts on you mid-production.

Sorry, was I venting there?

(And just a tip, don't break bad on the Pi here. For many people this is the only ARM platform worth working with. And definitely don't make fun of the lack of peripherals on the thing)

5y agoHN ↗

You're right. I was trying to write up a cpufreq driver for the Nintendo 3DS and found that LKMPG's complete lack of DT info astounding.

5y agoHN ↗

True. But there are some of us working on ARM platforms that aren't RPi that need to hack drivers.

Which has nothing to do with RPi or embedded systems... Not sure if I understand.

And just a tip, don't break bad on the Pi here. For many people this is the only ARM platform worth working with.

Ugh... Cell phones? Or any of the zillion of ARM development boards out there.

5y agoHN ↗

this guide doesn't cover the Devicetree APIs

Is there a guide for that?

5y agoHN ↗

Read the Documentation/devicetree directory in the kernel sources and look at how a few drivers implement their documented bindings.

This isn't a snarky RTFM comment. The usage model file in the kernel documentation gives good motivation for what device trees are used for and their basic structure, and the APIs to pull data from them are straightforward enough that you can probably figure them out by looking at an example.

5y agoHN ↗

A semi-related question: do kernel modules play nicely with device-tree instantiations?

Like let's say I wanted to instantiate an I2C with a custom driver in my device-tree. Can I put the controller's driver in a kernel module that lives in /lib/modules? Or do I need to compile it into the kernel?

5y agoHN ↗

I just did that recently you can load a kernel module the driver will start working and the device will appear (if compatibility is setup correctly). You can remove the module and the device will stop and be removed from /dev.

5y agoHN ↗

yes ive done this recently with both spi and i2c. it works with modules, the hardest part for me was finding the right way to create the device tree so eg, my module got the spi bus over spidev. same with i2cdev if you are not using userspace

5y agoHN ↗

Yep. The device tree and kernel modules are actually two seperate concepts - the former is just a data structure that describes the hardware for a system and the latter is a way of delivering the drivers independently of the kernel.

Just make sure to run `depmod -a` after copying it into /lib/modules.

5y agoHN ↗

nice! I wasn't sure exactly how the ordering happens between (kernel loads the device-tree) and (kernel scans /lib/modules for stuff to autoload).

5y agoHN ↗

There is (or can be) some overlap between the two.

As an example, you may want to create a kernel module that can be configured through the device tree (e.g. binds to an arbitrary SPI/I2C bus, requires hardware-specific config). You can add a node for your module to the device tree and assign it a "compatible" property, which is just an arbitrary string you define to represent your module. If you then make your module export the same string using the MODULE_DEVICE_TABLE macro, the kernel will figure out that your module is the one that implements that node in the device tree, and it will call your module's probe callback to initialize the module, passing in the context from the device tree node (e.g. you can get a reference to the SPI/I2C bus hosting your device).

As I understand it, this is the standard way to implement drivers for devices that sit on buses that don't support automatic detection (e.g. not PCIe / USB).

5y agoHN ↗

Yes, it'll work but device trees are still a little less dynamic than modules, which can be loaded and unloaded, and reconfigured at will. Device Trees still apparently have issues with dynamic reconfiguration. I think branches can be safely added, but removal is still problematic. This apparently is being worked on, so eventually it'll work, I understand.

5y agoHN ↗

In my opinion the best way to do kernel development is to just look at device drivers in kernel sources, study what current drivers do and write your own driver. The kernel supports su much heterogeneous devices and its APIs change continuously that it is practically impossible to write a complete guide on this topic.

5y agoHN ↗

Linux kernel code is extremely high quality too. I read it a lot. Very well structured.

5y agoHN ↗

can you update the Makefile so it generate a PDF only? Also, the "make all" doesn't seems to be working as expected here. Probably missing some dependency.

5y agoHN ↗

Using docker images is the preferable way to set up TeXLive and related packages. Please check the GitHub repository for details.

5y agoHN ↗

Would I be out of line in suggesting DKMS to be used?

I figure it would be close to mandatory for anyone who wanted to distribute their module to others, without having to tell them to rebuild every time their kernel changed.

5y agoHN ↗

Yeah, he needs to float his paragraph boxes so it can change text size when going from portrait to landscape (like rotating mobile device for better viewing).

5y agoHN ↗

Not sure if the eating555 is the author or whether the author is watching this thread...

This is awesome.. my only comment is the first thing I went to do was to copy and paste the code blocks and found end of line whitespace and double line breaks were included (presumably for the line numbering etc.)

e.g.

sudo apt-get update

apt-cache search linux-headers-`uname -r`

5y agoHN ↗

The issue reported by mrmattyboy was resolved. You can now coy-n-paste from generated PDF and HTML files without annoying line numbers.