Hi,

I often read on the net from users of the Linux os in particular that they have written a driver for a particular hardware that they want to use in conjunction with a particular flavour/version of Linux. But how they manage to do that so easily (sorry if it is a difficult task) as it seems to me. Hope some one can explain this to me in simple terms, just to satisfy my curiosity. thanks.

Dani AI

Generated

Built on 's point to about reusing existing source, the short practical roadmap below explains how many Linux users actually get a driver working and what to watch for. It shows common discovery steps, a minimal kernel-module skeleton, and concrete debugging cautions—useful years after the original thread when kernel APIs and tooling may have changed.

Typical workflow followed by hobbyists and integrators:

  • Identify the device: lsusb -v or lspci -nn to capture vendor/device IDs and class. Search the kernel tree and modinfo for similar drivers.
  • Gather documentation: chipset datasheets and any vendor application notes. If no datasheet exists, reverse-engineer by observing traffic (USB sniffers, logic analyzers) or by studying similar drivers.
  • Decide kernel-space vs user-space: use a kernel module for tight integration or UIO/libusb for simpler user-space drivers (common for USB devices).
  • Prototype in userspace when possible, then adapt a nearby driver in the kernel source as a template rather than starting from zero.
  • Build and test against the exact kernel version: make -C /lib/modules/$(uname -r)/build M=$(PWD) modules; load with insmod/modprobe and watch dmesg.

Minimal kernel-module skeleton (start-point for experimentation):

#include <linux/module.h>
#include <linux/init.h>

static int __init mydrv_init(void)
{
    pr_info("mydrv: init\n");
    return 0;
}

static void __exit mydrv_exit(void)
{
    pr_info("mydrv: exit\n");
}

module_init(mydrv_init);
module_exit(mydrv_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("example");

Practical cautions and debugging tips:

  • Test in a VM or on non-critical hardware first; kernel bugs can crash the whole machine.
  • Use pr_debug/pr_err and dmesg -w or dynamic debug instead of printf-style prints.
  • Be careful with sleeping contexts, IRQ handling, and locking; wrong use commonly causes hangs.
  • Watch firmware licensing: shipping proprietary blobs may have legal limits.
  • Kernel APIs change; tie development to a specific kernel tree and follow Linux kernel documentation or an established reference like Linux Device Drivers (LDD3) for patterns and conventions.

Recommended Answers

All 2 Replies

Drivers by nature are complex, because they have to talk directly with the hardware in C. For example, on Windows, you don't seem to see very many people writing their own drivers for hardware.

In the open source world however, much of the ground work is done for you already. For example, you can take a working driver for hardware that's a similar model to the one you want to write and tweak it a little bit. Knowing the right tweaks can usually be found on the net, given the vast amount of scan codes and such for different devices.

No, I've never written one so I can't tell you exactly how easy or hard it is. But it's amazing what you can do when you share source code. :)

In the open source world however, much of the ground work is done for you already. For example, you can take a working driver for hardware that's a similar model to the one you want to write and tweak it a little bit. Knowing the right tweaks can usually be found on the net, given the vast amount of scan codes and such for different devices.
:)

Cheers mate, very good and easy to understand kind of reply. Brilliant. Thanks a lot.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.