23 ms·
Writing userspace USB drivers for abandoned devices
- Nzen 7y agotl;dr Ben Cox bought a vga in => webcam out device that its parent company hadn't updated the linux drivers in a while. This details his journey of using tcpdump, et al, to analyze the sent packets. Eventually, he simulates the usb firmware and fpga download such that he can use the device. A quick, engaging read that was an appropriate level for this non C programmer. Looking through his archive, I recognize his bgp battleship post from last year on HN.
- jsharf 7y agoThis seems pretty formal/professional for an HN comment. Is there some reason you're writing summaries of HN posts with this degree of effort? Also, thanks.
- wott 7y ago> This seems pretty formal/professional for an HN comment. That's pretty much n-gate summary format :-)
- Nzen 7y agoIt's one of the contexts in which I'm willing to be the change I want to see. It's disappointing to click on the comments for a post and no one (especially the submitter) has told me what I'll learn/experience. And yet, there it was, four hours old, ten points up and no comments. So I give it a skim and it's really good. Now I want others to read it. Spending five or so minutes polishing three sentences is basically free for me and positive sum (unless I do a bad job). Cynically, tl;dr submission summaries are how I've chosen to feed the beast until it grants me downvoting power.
- mLuby 7y agoThis TL;DR made me actually read the post, so thanks for the summary.
- horsecranium 7y agoThanKs!
- rburhum 7y agoThe device itself is not that interesting, but I just love the level of detail that describes the reverse engineering process. Excellent blog post!
- moftz 7y agoIt seems like the hardware could be repurposed to be a multichannel DAQ or even a VHF SDR. It's a neat device considering how cheap it is.
- aportnoy 7y agoHow does one learn how to write device drivers under Linux?
- jsharf 7y agoGoogle search "lkmpg pdf" It's part of tldp (also google searchable)
- aportnoy 7y agoI think that’s what I was looking for, thank you so much! I hope not much has changed since when it was written…
- pkaye 7y agoSomething a little more recent but still dated unfortunately. https://lwn.net/Kernel/LDD3/ https://lwn.net/Kernel/LDD3/ I guess there is not much of an audience for books these days.
- nitrogen 7y agoIt's been about 10 years since I've done any Linux kernel development, but often you can get the rest from the documentation folder in the kernel tree, plus the source code of a similar module also in tree.
- pjc50 7y ago> "lkmpg pdf" I wonder how someone from the outside is supposed to know that's the magic string to google.
- sigstoat 7y agothere's more than one query for most pages. that one also turns up for "linux kernel programming" which strikes me an utterly non-magical query.
- 7y ago
- sulam 7y agoBGR instead of RGB seems to be very common in hardware land. Anyone know why?
- spease 7y agoBest answer I found is this: https://retrocomputing.stackexchange.com/questions/3023/why-bgr-color-order https://retrocomputing.stackexchange.com/questions/3023/why-... There was apparently an HN thread as well https://news.ycombinator.com/item?id=17808191 https://news.ycombinator.com/item?id=17808191
- danmg 7y agoBasically, little endian vs big endian but for frame buffer devices instead of CPUs.
- phendrenad2 7y agoReminds me of this: https://www.theinquirer.net/inquirer/news/1047633/one-writes-linux-drivers-235-usb-webcams https://www.theinquirer.net/inquirer/news/1047633/one-writes... ("One man writes Linux drivers for 235 USB webcams")
- ChuckNorris89 7y agoWow, cool thanks for sharing. Very interesting read.
- joewee 7y agoI have a few devices with no public drivers of any kind. Thinking about how to develop drivers on Linux, I’m guessing I should lookup into the chipsets used on the board and see if those companies have drivers I can use as a starting point?
- nwallin 7y agoDoes it have Windows drivers? If it does, you can set up a VM, set the device as passthrough, and sniff the traffic to it. Then it's not really any different than reverse engineering a network protocol or file format. What are they, out of curiosity?
- djsumdog 7y agoI would have given up long before the point this person got to. This is pretty damn amazing, and could gain a little bit of life from these old, closed, binary blob, everything in software devices. Tons of kudos for doing this. On a side note, I wish there was a more standard way to deal with Linux kernel modules. The ABI incompatibility leaves a ton of dead old hardware out there for non-maintained kernels. In an ideal world without tons of binary blobs and .o files out there; this wouldn't matter. You could recompile everything for the latest version. You might have to fill in some missing symbols or swap out deprecated functions, but it'd be considerably easier than this. That was the ideal behind open source; that we could always be able to figure out how our stuff works, and it seems like today we only have open source middle ware, and so much close source stuff build on top of open source stuff.
- tux3 7y agoI coincidentally just finished writing some userspace libusb code for the first time today! Nothing as impressive or interesting as TFA, just enough to let the thing boot on Linux to the point where proprietary half-working drivers can take over. It'd be a stretch to call my epson scanner abandoned hardware, but considering the quality of official drivers, only a small one.
- xg15 7y agoHang on, did he just buy essentially a freely reprogrammable FPGA with built-in RAM, A/D converter and USB support - for $20? Seems to me, you could do a lot more with those devices, now that the wire protocol is known. (Edit) It doesn't appear that he decoded the bitstream format though, so some more work would be needed before you could use it as a general-purpose FPGA.
- benjojo12 7y agoIt was actually 20 pounds for 10 ish, so it comes out even cheaper. Sadly it seems that was just a stroke of luck, since I can't find anyone else selling them anywhere near that cheap now
- sigio 7y agoI have one lying around here somewhere... nice to know I can finally use it :)
- jack12 7y agoYeah, a 16K Spartan 6, 64MBytes of DDR3 RAM, and an FX2LP USB High-Speed controller is a pretty terrific repurposed FPGA dev board in the vein of the chubby75 or panologic, even if the high-speed ADC turns out to have too many limitations / too weird signal conditioning (i.e. is too VGA-focused) to be very useful (but VGA probably at least means a pair of I2C pins is exposed on the DSUB-15, right?). Considering the FX2LP is already wired up to load the bitstream to the FPGA, and expects to on every power-up, that's a huge bonus for a dev board. Even if the binary blob of FX2LP firmware provided in the manufacturer's drivers does checksums, signature checks, etc. to make changing the bitstream data difficult, it would be pretty simple to write a new firmware to allow uploading of any custom bitstream (see: fx2lib), since it's such a well-known and widely-hacked chip -- maybe you can even manage to trick Xilin's ISE into believing it's a real Xilinx "USB Platform Cable" (FPGA JTAG programmer) since at least some of them use an FX2 for their USB interface. With a generic bitstream uploader utility for the FX2 you wouldn't even need to deal with any hardware modifications or even need to buy and connect a JTAG programmer if you were just starting out. And with everything being uploaded on every reset of the devboard, you don't have to worry about bricking anything either, since you just power-cycle the devboard to bring the programmer AND FPGA back to their default waiting-for-firmware/"rescue" mode. But while the article says he got a lot of them (at least 3 from the photo) for $25 total, it looks like they're more typically ~$50+S/H each on ebay, which is less exciting. The same company seems to have moved on to 'av.io'-branded USB3 devices now, which from a quick glance/binwalk of the downloadable firmware package (inspired by this article) appears to have FX3 USB Super-Speed controllers, and Spartan FPGAs. But it's designed to store the FX3 firmware and FPGA bitstream on the device itself (to allow it to boot up as a UVC webcam with no drivers required on the host, like this article was hoping would be the case for the older device), so it would require a bit more reverse engineering to figure out how to kick the FX3 into firmware update mode to replace the FX3 firmware with a custom bitstream uploader. But it's a ton more expensive, and who knows what generation and size of FPGA or how much and what sort of memory it would have.
- jason0597 7y agoIt's things like these that sometimes make me think of all those businesses that rely on some ancient Windows XP machine because it's the only thing that supports the proprietary drivers for the engineering machine they bought nearly 2 decades ago for hundreds of thousands of pounds. If instead the drivers were open source (and the relevant controller software for that machine), they could more easily move over to a more recent operating system that doesn't run the risk of being infected with some virus (think Wannacry) I imagine also how more difficult it would be for someone to reverse engineer the drivers for something a lot more complex than a VGA-to-webcam box.
- ChuckNorris89 7y agoWell yes, open source firmware and drivers would be cool but for most companies that's part of their proprietary IP and they think that making it open would make their product easier to copy/exploit by competitors. Since it cost them lots of time and money to develop there's no way your gonna convince management to just make it open unless you're some stinking rich FAANG Co. and those HW product sales are not your main source of income. Just look how locked down Broadcom documentation and even datasheets are. Everything is under NDA. HW business make money by selling more HW so making you buy their latest product just for the latest updates even though the 10 year old one still does the job is a viable business model for them. Source: I worked in the hw industry and it's how they think.
- lvl4x 7y agoIs it just how they think, or is it the reality of the business? Would be cool if manufacturers would make old versions of sourcecode public after a couple of years, and the final version when a product goes out of production.
- unlinked_dll 7y agoI think for a lot of software businesses there is a truism that "your competition doesn't want your code, they think you're morons and you think they're morons." But in the hardware game there is a lot of counterfeiting. There is rarely any shame or consequence when it comes to outright IP theft. Making it easier to access the firmware makes it easier for someone to counterfeit your widget.
- ChuckMcM 7y agoFWIW, I haven't done a lot of reverse engineering but I have written code to drive the USB peripherals for a few microcontrollers in the ST and NXP series and the techniques discussed in the article are just as applicable when trying to debug what the heck is going on in your USB code. I always get something interesting out of them.
- Yajirobe 7y agoHow do you learn how to do something like this?
- qiqitori 7y agoThere are many ways to get somewhere, but here's a general list of things you have to do: 1) Think for a little bit about what you have got and what you want to do 2) Do research. Has this been done before? Have similar things been done before? (Usually the answer is yes to either question) 2) Think whether it's theoretically possible to do what you want to do with the information and parts you have (in this case: there is a working driver for Linux and Windows, but they're closed-source) 3) Fixing computer things usually involves a lot of debugging (tracing). Will tracing help us out here? What tracing tools/skills do you have, what tracing tools/skills would you like to have? Often you'll need to extend the tracing skills/tools you already have, but normally you don't want to spend too much time on this. (In this case, we can trace without any specialized equipment -- we just need a virtual machine.) 4) Once you have the appropriate traces, take a good look at them (you'll probably want some scripting abilities here) and see if you notice any patterns (e.g. "lots of data after this", "just a little data after this", "this bit of data is always the same", etc.) 5) If you don't know what to do at this point, maybe go back to the tracing step
- codeulike 7y agoProper hacking. That diagonally skewed image is familiar to me from old game writing days when sprites were written straight to screen memory - you soon learn that if it comes out skewed, you've probably got an off-by-one bug on the horizontals.
- hamburglar 7y agoToday I learned that you can use wireshark to analyze USB packets. Neat. Besides the cool-hack-factor, this kind of article is especially great when it teaches you something.
- Touche 7y agoThis is the kind of article that keeps me coming back to HN.
- droithomme 7y agoFantastic write-up of intense hacker stuff. Thanks, this is good stuff.
- jdnenej 7y agoThe thing I am looking forward to most when I retire is having the time to fuck around with random projects like this.
- codedokode 7y agoIf Linux had stable kernel-to-driver interface, that driver could work today.
- Iolaum 7y agoIf the driver had been mainlined it would still work today. https://www.kernel.org/doc/Documentation/process/stable-api-nonsense.rst https://www.kernel.org/doc/Documentation/process/stable-api-...
- codedokode 7y agoWhat if the vendor would prefer not to disclose source code? All drivers cannot be included into the kernel, even if they were, this would be a lot of code and who is going to maintain it? This document shows how unfriendly is Linux to third-party code. Either you contribute into giant monolitic kernel, or your device won't work with next major kernel release. > Depending on the version of the C compiler you use, different kernel > data structures will contain different alignment of structures That doesn't make sense. How does Microsoft use structures in their API then? Furthermore, unlike Windows software, you cannot compile Linux kernel with any compiler except for GCC [1]. It doesn't comply with C standards. > Depending on what kernel build options you select, a wide range of > different things can be assumed by the kernel > - different structures can contain different fields That looks like poor design. Why care about non-standard configuration? Let those who use it solve the problems themselves which would be the true open source way. > Linux runs on a wide range of different processor architectures. > There is no way that binary drivers from one architecture will run > on another architecture properly. Supporting i386 is enough. Nobody is going to insert a PCI device into a smartphone. If there will be new CPU architectures, one can use i386 emulator. > As a specific examples of this, the in-kernel USB interfaces have > undergone at least three different reworks over the lifetime of this > subsystem They could make 3 versions of API and adapters that would support drivers written against older versions of API. I think the real reason is that designing API is hard, and Linux developers have no interest in this. They care only about server platforms and those platforms have open-source drivers because they need Linux. Nobody cares that your USB webcam doesn't work because you don't connect webcam to a server. I think that Linux could also rely on existing Windows drivers that exist for almost every device. Linux could provide an environment similar to Windows kernel, and run those drivers in a sandbox. For many devices, this is the only sane way to have them working with Linux. [1] https://stackoverflow.com/questions/20600497/which-c-version-is-used-in-the-linux-kernel https://stackoverflow.com/questions/20600497/which-c-version...
- tombert 7y agoI know virtually nothing of low-level programming, so bare with me; to a lay person, can someone explain why drivers are every closed source? Isn't a driver inherently a loss-leader for some kind of hardware product, and wouldn't it be better for the manufacturer to have it open-source so that more people could contribute to it? I'm not asking this passive-aggressively, if someone knows the answer to this I'd really like to hear it.
- malnourish 7y agoA simple answer is that, from a business perspective, closed source is simply easier. It's likely the default way they handle their code. And at least for GPUs, drivers are pitched as a feature and may contain secrets worth protecting in the eyes of the business.
- hatsubai 7y agoSometimes, it just doesn't make sense. For example, I write and maintain the Linux kernel modules for one of the largest, most popular, and most powerful land vehicles in the world. It wouldn't make sense for us to release these to the open source community because it requires specific hardware that we make, specific FPGA firmware that we interface with, and it will only work with specific software we make. So there's at least one case where it wouldn't make sense to release this, and that's not even getting into the security aspect of things.
- HeyLaughingBoy 7y agoIn addition to the very good replies you already got, sometimes it just wouldn't make a difference. In some environments, if the code was not developed using a particular process (my experience is with regulated medical devices), it may as well not exist, because putting it into production would be in violation of Federal law. There are also small niche products where most of the IP is in the driver: lose control of that and you're on your way to being out of business.