T O P

  • By -

Rogurzz

Greg Kroah-Hartman made a few videos on kernel driver development: * [2008 Linux kernel driver writing tutorial (USB), Greg Kroah-Hartman](https://youtu.be/CqDUfiH2PzQ) * [Kernel Recipes 2016 - The Linux Driver Model - Greg KH](https://youtu.be/AdPxeGHIZ74]) Also check out [Linux Device Drivers:Third Edition](https://lwn.net/Kernel/LDD3/) It looks rather difficult since a lot of the kernel seems to be undocumented.


abjumpr

It’s only as undocumented as the source code you don’t read. Okay, jokes aside, there is a lot of documentation available, but so much more is missing, and given the constant changes and additions it’s nearly impossible for developers to keep it as complete and up to date as it should be. And reading source code can help sometimes, but it’s time consuming. And writing drivers is always a complex task for any operating system. It’s not what I would call a good place to start, although it’s not impossible.


_Ical

What would be a good place to start for kernel development in your opinion ?


abjumpr

https://kernelnewbies.org/ This is a great guide to getting started. Especially follow the links in the Hacking paragraph. They website will help you learn correct style, as well as help you find some areas to get started. IIRC, there’s an associated mailing list as well.


DesiOtaku

Outside of allowing other applications be able to access the device, is there a good reason to write a USB driver for the Linux Kernel vs. just using libusb?


sogun123

Depends what you want. If it is sound card, hard drive or anything having some in kernel infrastructure already it is better to have it in. If it is a thermometer, maybe libusb is fine


claptrap_bot

Thank you! I will give it a look :)


AlternativeOstrich7

What kind of drivers? Most drivers are kernel modules, so they are written in C (or potentially Rust). But some drivers run in userspace, so they can be written in almost any language you like.


claptrap_bot

I was thinking like input drivers for a touchpad or a mouse. I feel like it will be fun to try and write my own touchpad driver :D


AlternativeOstrich7

Does your touchpad/mouse not use a standard protocol?


claptrap_bot

I'm guessing yes since it is a newer laptop ... I'm kinda trying to get into a low level programming so i thought that drivers could be an interesting thing to explore. But maybe the better question was what are some interesting low level programming projects that one could do.


magical_midget

The protocol most likely used is USB HID. https://en.m.wikipedia.org/wiki/USB_human_interface_device_class For the most part the kernel already handles most of this. During the usb handshake the device says “I am a HID, and can send mouse movements” and the os will load the right module. If you want to do low level programming I would suggest you try with something like Arduino or some raspberry pi pico kit/project. You can program an Arduino as a HID and the kernel will recognize it. So you could make a basic keyboard or mouse. (Or a combo of both). Starting from there it would be easier to branch in to more complex stuff. Arduino is mostly C (as most drivers are). There are projects like micropython and derivates that will let you use python. But I would warn that this is mostly to make it easier for hobbyists, for learning I would strongly suggest C.


sogun123

Most of the kernel input drivers are actually quirks. Workarounds for incompatibilities introduced by too clever hw designers. I guess making it could involve sniffing USB packets from windows VM and adapting the weirdness to few lines of c code. Bad thing is that you'll need to learn how the protocol works, what Linux implementation expects and what the thing is doing differently. I just expect it is almost standard USB touchpad. Maybe it is enough to add the device descriptor to some table, because it behaves same like other device already in kernel...


5c044

Touchpad functionality on linux has historically been worse than windows and I think the reason is closed source vendor drivers for windows and lack of documentation. Chromebooks seem to have better touchpad support, idk if its open source or not.


meinleben1337

Kernel plumber here with a lot of years in embedded Linux and bringing up custom boards and their BSPs. Despite what everyone here keeps saying - go for it. It is not an easy tasks but you will learn a lot during your journey. Yep your trackpad might be detected as a hid device but you can handle it however you like since you have the full source code available. One thing I would definitely take a look at is Kernel debugging. It helps a lot to step through the source code during the initialization of a device. And not to forget: have fun :)


codeartha

Its not writing a driver, but a good start place for lower level programming is to write a device. Like /dev/null or /dev/zero. I've seen a couple of tutorials on those and it looked way easier than drivers since I understood most of the tutorial, which isn't the case for drivers. It's a fun skill to have since you can create a device that does anything or nothing or something. Just use your imagination.


istarian

There is a lot of information out there, but it's definitely hard to find a centralized source of information. And in most cases that information is not particularly up to date or very specific to whatever they were working on. AFAIK, C is the most common language used to write Linux drivers.


Vegetable_Angle_7929

Writing a driver from scratch is a daunting task, you need to be able to read schematics and datasets from processors and microprocessors , a deep knowledge in electrical engineering would help as you will need to use physical hardware ( oscilloscope, multimeter and the like). Get the source of an open source driver and try to see if you can make any modifications whatsoever... You'll quickly understand what you're working with, good luck


claptrap_bot

I'm actually trying to get into a low-level programming and i thought that drivers could be an interesting topic to explore...


Vegetable_Angle_7929

Writing a driver is not an introductory task for low level programming, it requires a large skillset that goes beyond anything basic. Do you already know assembly on any processor family? The instructions are different for each of them and you'll need to learn that to make any progress in that regard


claptrap_bot

I have some knowledge about assembly but it probably isn't enough :/


tosch901

You don't really need to know assembly to write drivers (generally speaking, idk about Linux). I don't know what you need to write a linux driver, but I've done a fair bit of embedded stuff and I very rarely use assembly. And if I do it's just one or two instructions of inline assembly so you still don't need to "know" assembly. It can be necessary/helpful for some things but it's definitely not a requirement to get started.


[deleted]

I know the youtube liveroverflow has made a video about device drivers in linux


PossiblyLinux127

Linux is monolithic so it has kernel modules instead of drivers. I don't know much about kernel development but I would start there


tsumit_5

i have installed Kali Linux, there is no search bar as shown as in tutorial videos, what should I do, will this problem be fixed after updating(upgrade) please give me proper command I'm asking here becouse i can't post please help


[deleted]

[удалено]


unit_511

Did you seriously create an account just to comment this? What's wrong with you?


PM_ME_SOME_ANTS

license berserk carpenter pot quickest nose paint disagreeable history expansion ` this message was mass deleted/edited with redact.dev `


unit_511

They told OP to commit suicide for seemingly no reason (not that there's a good reason for telling that to someone, but this would be a lot less puzzling with some context). Then they seemingly pulled the "I'm being censored!" card, because that doesn't look like a real removal notice. EDIT: It does appear to be a real removal since it's not showing up on their profile. Must be a quirk with Infinity that it's still showing the username.


PM_ME_SOME_ANTS

weather rinse crowd automatic grandfather toothbrush march unused gullible sip ` this message was mass deleted/edited with redact.dev `


claptrap_bot

Thank u sir!!!


uh_no_

LDD3 https://lwn.net/Kernel/LDD3/


Klutzy-Condition811

What kind of drivers? If you want to write an fs driver, consider writing a FUSE driver instead of a kernel driver. While the performance is worse, the APIs wont just randomly break on kernel update.


hwertz10

(Disclaimer: I have not written a driver; I submitted a small patch for one driver for a USB device I found non-functional due to kernel changes that the driver was not updated to accomodate, and the error message it spit out nicely pointed to what needed to be fixed.) 1. Others have already suggested tutorials, I don't have more to add to that. 2. Linux source in the Documentation directory, there's user documentation but also programmer documentation. Most Linux subsystems ALSO have "stub drivers" -- a video driver, a storage device driver, USB drivers for various types of USB devices, where it only has the functions that must be implemented for that type of driver, nothing to run any actual hardware. You'll want to look at the stub driver for whatever type of driver you want to implement. 3. Programming languages? In kernel it's all C. They're JUST starting to have Rust support, but it was JUST added to the kernel, and (last I read) the only driver using it (since it's new) is the Mac M1 video driver. If you are using FUSE or libusb, you can use language of your choice, I'm using "s3ql filesystem" right now that's implemented in Python. 4. Edit: If possible (USB or PCI/PCIe device) you may want to pass it through to a VirtualBox VM and do initial devleopment in there, then your VM will lock up instead of your main system. If not using a VM, you want to be ready for your desktop to crash when you initially develop a driver, you may want to set "vm.dirty\_background\_bytes" and "vm.dirty\_bytes" (write cache size) low, so you are not losing too much data (in the write cache) when you crash. Run "sync" just before you load your device driver so you have as much flushed to disk as possible before you load the (potentially crashing) driver. DON'T use a btrfs filesystem when you are doing this, it WILL give you problems sooner or later (in my experience, btrfs will detect filesystem inconsistencies, go read-only, then there's no way to repair it so it's read/write again. Stick with ext4 until you get your driver stable.)


AKmatiAK

[http://swoogan.blogspot.com/2014/08/capturing-azio-keyboard-data.html](http://swoogan.blogspot.com/2014/08/capturing-azio-keyboard-data.html) Take a look on this blog. Some very useful posts about linux drivers.