[HN Gopher] Writing a basic Linux device driver when you know no... | |
___________________________________________________________________ | |
Writing a basic Linux device driver when you know nothing about | |
Linux drivers | |
Author : sbt567 | |
Score : 248 points | |
Date : 2025-06-22 10:29 UTC (3 days ago) | |
web link (crescentro.se) | |
w3m dump (crescentro.se) | |
| ianlevesque wrote: | |
| It's a userspace USB HID driver in rust, which is honestly more | |
| interesting/applicable to me than a kernel driver, which is what | |
| I thought it meant from the title. | |
| ahartmetz wrote: | |
| > I also thought I'd message the vendor and ask them if they | |
| could share any specifications or docs regarding their protocol. | |
| To my surprise, Nanoleaf tech support responded to me within 4 | |
| hours, with a full description of the protocol that's used both | |
| by the Desk Dock as well as their RGB strips. | |
| | |
| How cool is that? Too many vendors still think that they have | |
| valuable intellectual property in such relative trivialities. And | |
| that handing out the specs freely helps their competitors more | |
| than themselves. | |
| starkrights wrote: | |
| I had the same reaction. Nano leaf is extremely cool for that. | |
| baby_souffle wrote: | |
| This has to put them in the top 0.01% of companies that make | |
| consumer electronics. | |
| | |
| I can think of only a few companies that bother to publish | |
| any details... And most of them are focused on industrial | |
| customers where it isn't unreasonable to need certain | |
| protocol details for integration or even just compliance with | |
| certain regulatory systems. | |
| | |
| Maybe things are changing? | |
| | |
| I have noticed that some of the LED light controllers you see | |
| on AliExpress are leaning in to open firmware standards. 5 | |
| years ago, you bought the controller and had to flash your | |
| own firmware. Now, there's an option at checkout to select an | |
| open source firmware. Some even have a USB port built in for | |
| flashing! | |
| Teknoman117 wrote: | |
| I almost had that experience with one of the popular PC liquid | |
| cooling hardware vendors around 10 years ago. | |
| | |
| I emailed them saying I'd be interested in developing drivers | |
| for their hardware for Linux as I was a happy customer and was | |
| immediately put in touch with one of the managers and their | |
| engineering team. | |
| | |
| Made quite a bit of progress before the whole thing was shut | |
| down because one of their component vendors threatened them | |
| saying it'd be a breach of their contract with them. | |
| | |
| Apparently that vendor sold a "datacenter" (non consumer) | |
| version of that hardware for which they charged a hefty license | |
| fee for the management software (which was Linux compatible). | |
| | |
| Jokes on them, someone reverse engineered the whole thing with | |
| a USB analyzer years later and published it XD. (not me) | |
| agentkilo wrote: | |
| Yeah that part of the article put a big smile on my face. | |
| | |
| I did the same thing back in college, when I was in a lab. We | |
| wanted to do some research on Wi-Fi signals, and I happened to | |
| own a bunch of Wi-Fi adaptors produced by SomeSmallTech Co. | |
| Ltd., which featured relatively new Atheros chips and didn't | |
| have Linux drivers at the time. | |
| | |
| So I sent an email to the company's public email address, | |
| asking for some datasheets, "for science". To my | |
| disappointment, presumably a PR person replied that they "don't | |
| have a company policy to collaborate with academic research". | |
| (But they did send a quick reply, kudos to that.) | |
| | |
| Funnily enough, years later I ended up working for said | |
| company. Naturally, when I first logged into the company | |
| network, I searched for the datasheets I asked for. There were | |
| "classified" watermarks all over the PDFs :) | |
| wiz21c wrote: | |
| > don't have a company policy to collaborate with academic | |
| research" | |
| | |
| Strangely they all have a tacit policy to build their | |
| products at least partly on the results of academic research. | |
| 2Gkashmiri wrote: | |
| I have a solar inveter from a company, aparticular German | |
| brand. I wanted to use home assistant with it so I needed rs232 | |
| data.. tried the support and they asked me to sign an NDA. | |
| | |
| Okay, cool. I did with a fake name, address and everything and | |
| they sent a file.. | |
| | |
| Turns out the file is available online. | |
| | |
| Facepalm pro Max. | |
| | |
| So my question is, what kind of "IP" is in a data sheet that | |
| needs protection ? And this isnt even some secret product but a | |
| generic solar product sold by millions. | |
| | |
| Rs-232 protocol ? Really ? | |
| wiz21c wrote: | |
| They have asked to the legal team who basically don't know | |
| shit about what us do and who will always take the most | |
| conservative approach possible. So you'll get either: no | |
| answer, a "NO" answer or an "NDA" answer. | |
| Mad_ad wrote: | |
| Was it Alpha-ESS? they make it so stupidly hard to get your | |
| information outside of their smartphone app. | |
| sysmax wrote: | |
| It's not the IP, it's sadly how people react. Some folks will | |
| be appreciative of help, credit to them. Others will | |
| immediately get back how they tried it, it didn't work and now | |
| they need you to rewrite everything, or do their project for | |
| them, or redesign your product to match what they want it to | |
| be. And if you politely refuse, it quickly escalates to threats | |
| of trashing your business through every channel, and other | |
| things. | |
| | |
| So, the safest thing to do is not give details at all, or | |
| "leak" them like another reply in this thread mentions. | |
| jonnypotty wrote: | |
| Thanks for this. Good read and also kinda inspiring. | |
| dabedee wrote: | |
| I really enjoyed the way this post was written, i.e. it includes | |
| the code, how it was run, the false paths, etc. You almost get to | |
| live through the author's journey and how he figured out just | |
| enough to get something working. | |
| kblissett wrote: | |
| I enjoyed this post, but I'm eager to hear what the next step | |
| would be for a real "production" userspace driver. Are these | |
| typically just daemons that are configured to run at start up? | |
| And then some configuration GUI communicates with it over a | |
| socket or something? | |
| shreddit wrote: | |
| > Let's run it again to make sure it was not a fluke! | |
| | |
| I understood that reference | |
| 0xbadcafebee wrote: | |
| I want to run FreeBSD on my laptop, but they don't have a | |
| [complete] driver for my wifi card. I've thought about diving | |
| into AI coding-assistant agents just to see if I could use one to | |
| finish throwing together a working driver... but figuring out the | |
| AI agents is frictiony enough that I'm leaving it be. (I'm not a | |
| VSCode user) | |
| buildbot wrote: | |
| Claude code, being a CLI interface, might be more your style? | |
| Expensive though | |
| fithisux wrote: | |
| AI can also be used to help reverse engineer blobs. | |
| LorenDB wrote: | |
| The author should probably have implemented support in OpenRGB | |
| instead to better benefit others, but this is cool nonetheless. | |
| fracus wrote: | |
| I wish this was done in C so I didn't have to learn Rust. But | |
| maybe it is time to learn Rust. | |
| dralley wrote: | |
| Rust isn't that difficult really. Easier in many ways than C if | |
| you're building normal software and not, like, a library of | |
| fancy data structures. | |
| jeroenhd wrote: | |
| This is using rusb, a Rust wrapper around libusb. libusb is | |
| still written in plain old C: https://libusb.info/ | |
| | |
| If you don't want to learn a different programming language, | |
| you can take the exact same approach in any language you prefer | |
| and play along. You may need to turn the more object oriented | |
| calls into libusb_* calls, but if you're used to programming in | |
| C you probably won't have a problem getting that to work. | |
| VTimofeenko wrote: | |
| Excellent post! I have a Nanoleaf 3d thing that I was hoping to | |
| use as an ambilight-like thing for the TV, but the experience | |
| was... meh. I know about the Hyperion project and hope to set it | |
| up one day, but meanwhile I think I could try to repurpose this | |
| code to control the strip from a Linux box. | |
| rkagerer wrote: | |
| This is awesome! | |
| | |
| But it also makes me a little bit sad. The original parallel port | |
| and even ISA interface seemed so simple by comparison, with less | |
| layers of abstraction. Just run a wire, and write to a port. | |
| | |
| I remember when I was a kid, I found a breakout board in an | |
| electronics store's random clearance parts bin, with an ISA | |
| header on an edge. On a whim I took it home and wire-wrapped a | |
| 7-segment LED onto it. Power and ground were easy. Each segment | |
| was hooked to a data line, through a simple buffer IC. I cheated | |
| and used only a minimal number of address lines to feed the | |
| enable port (guessing through a simple AND gate or something). I | |
| was amazed when I wrote to that address and it worked the first | |
| time! | |
| | |
| I look at a protocol like USB, with hundreds of pages, and | |
| instead of that curious excitement and enablement I felt back | |
| then, I feel a bit overwhelmed. | |
| colechristensen wrote: | |
| I sometimes think about this, starting from scratch with a | |
| computer hardware and software stack that disallowed all of the | |
| layers of abstraction that have built up over the decades. | |
| | |
| Yeah many of the abstractions help with performance but maybe | |
| there's value giving up much of that performance in exchange | |
| for simplicity. | |
| rkagerer wrote: | |
| It would be neat to design a whole new contemporary stack | |
| from scratch. | |
| dmonitor wrote: | |
| This is exactly the kind of simple tutorial I was looking for a | |
| few years ago. I forget what the project was that I wanted this | |
| for, though, haha. Thank you for the writeup! | |
| bhasi wrote: | |
| The title was misleading because the author wrote a userspace | |
| Rust driver and not a Linux kernel driver in C. | |
| amelius wrote: | |
| Upon reading the title I thought this was going to be about how | |
| easy it is to write or modify a Linux driver when using a LLM | |
| even if you know nothing about the subject. | |
| fithisux wrote: | |
| There are many innovative OSes that are killed by the lack of | |
| Device Drivers. | |
| | |
| As a community we must find a way for tackling this issue. | |
| | |
| Micro-Kernels are a solution where one can run different OSes but | |
| they will reuse the same device driver servers. | |
| | |
| But it requires co-ordination and determination. | |
| | |
| Rust can be a solution for sure. | |
| jeroenhd wrote: | |
| Any programming language can be a solution, the programming | |
| language itself isn't the problem. Convincing device driver | |
| programmers around the world to come up with a universal API | |
| that includes all the possible features and works on every OS | |
| is. | |
| | |
| In this case, the cross-platform libusb should make this code | |
| work on either Linux or Windows (if you install the signed | |
| Windows drivers). If other operating systems port libusb, they | |
| get this code for free. | |
| | |
| Most "real" drivers still run in kernel mode, though, and not | |
| even Linux can keep their ABI stable (Windows has to, between | |
| releases, with the aid of compatibility wrappers that only work | |
| for a certain amount of releases). | |
| | |
| It would probably be worth it more forbBespoke operating | |
| systems to implement either the Windows API (like ReactOS does) | |
| or the Linux API (pick an LTS version) to get existing drivers | |
| to work. Unless you pay them, most driver programmers aren't | |
| going to bother with anything than Windows, maybe Linux, | |
| _possibly_ macOS. | |
___________________________________________________________________ | |
(page generated 2025-06-26 08:00 UTC) |