A comprehensive, in-depth guide to Linux device driver development from prerequisites to advanced topics.
TL;DR: High-paying careers ($120k-$180k), work on cool hardware (Tesla, SpaceX, NVIDIA), understand how computers really work, and build amazing IoT/robotics/automotive projects.
Read more: WHY-LEARN-DRIVERS.md - Career paths, real-world applications, success stories, and industry trends.
- π° Career: Device driver developers are in high demand and well-paid
- π Hardware Projects: Build robots, IoT devices, custom hardware
- π§ Understanding: Learn how computers really work at the lowest level
- π Impact: Your code can run on millions of devices
- π Job Security: Essential skill that can't be outsourced or automated
This tutorial is organized into progressive modules, starting from fundamentals:
- 00-prerequisites.md - Essential Knowledge Before Starting
- C programming essentials (pointers, structures)
- Linux system fundamentals
- Computer architecture basics
- Build system basics
- Self-assessment quiz
- 01-basics.md - Kernel Modules & Driver Fundamentals
- Kernel architecture overview
- Kernel vs userspace
- Building and loading modules
- Module parameters and dependencies
-
02-char-drivers.md - Character Device Drivers
- Device registration and management
- Major/minor numbers
- cdev structure and operations
-
03-file-operations.md - File Operations in Detail
- open, release, read, write
- ioctl and unlocked_ioctl
- poll and select mechanisms
- mmap implementation
-
04-memory.md - Memory Management
- kmalloc, vmalloc, and friends
- Memory pools and slabs
- DMA-capable memory
- User-kernel memory transfer
-
05-concurrency.md - Locking & Synchronization
- Spinlocks and mutexes
- Semaphores and completion
- Read-write locks
- RCU (Read-Copy-Update)
- Atomic operations
-
06-interrupts.md - Interrupt Handling
- Requesting and freeing IRQs
- Top-half vs bottom-half
- Tasklets and work queues
- Threaded interrupts
- MSI/MSI-X
-
07-dma.md - Direct Memory Access (DMA)
- DMA mapping APIs
- Coherent vs streaming mappings
- Scatter-gather DMA
- DMA pools
-
08-platform-drivers.md - Platform Device Drivers
- Platform device model
- Device tree bindings
- Resources and IOMEM
- Power management
-
09-11-advanced-debugging.md - Advanced Topics
- Block device drivers
- Network device drivers
- Debugging techniques and tools
-
DEVELOPMENT-SETUP.md - Environment Setup
- VM configuration (VirtualBox, QEMU)
- Required software installation
- Editor setup and workflow
- Debugging environment
-
TROUBLESHOOTING.md - Problem Solving
- Common issues and solutions
- Crash recovery procedures
- Debugging techniques
- Error reference
The examples/ directory contains 9 complete, compilable examples:
- 00-c-review/ - C Programming Fundamentals
- Pointer mastery (essential!)
- Structure fundamentals
- Userspace practice before kernel
- 01-hello/ - Hello World Module
- 02-chardev/ - Character Device
- 03-ioctl/ - Device Control Interface
- 04-memory/ - Memory Allocation
- 05-locks/ - Synchronization (with race conditions!)
- 06-timer/ - Kernel Timers
- 07-procfs/ - /proc Filesystem
- 08-workqueue/ - Work Queues
All examples include:
- Heavily commented source code
- Makefiles for building
- README with usage instructions
- Test programs where applicable
Start here if you're new: 00-prerequisites.md
Take the self-assessment quiz. If you can't answer most questions:
- Review C programming fundamentals
- Practice with examples in
examples/00-c-review/ - Study Linux command line basics
- Return when comfortable
Essential: DEVELOPMENT-SETUP.md
Set up a safe environment:
- VM Setup (VirtualBox or QEMU) - Recommended
- Install Required Packages:
# Ubuntu/Debian
sudo apt-get install build-essential linux-headers-$(uname -r) git
# Fedora/RHEL
sudo dnf install gcc make kernel-devel kernel-headers git
# Arch
sudo pacman -S base-devel linux-headers- Take VM Snapshot before each testing session
- β Complete prerequisites review
- π Read: 00-prerequisites.md
- π» Practice: examples/00-c-review/
- π Read: 01-basics.md
- π» Code: examples/01-hello/
- π Read: 02-char-drivers.md
- π» Code: examples/02-chardev/
- π Read: 03-file-operations.md, 04-memory.md
- π» Code: examples/03-ioctl/, 04-memory/
- π Read: 05-concurrency.md
- π» Code: examples/05-locks/ (see race conditions!)
- π Read: 06-interrupts.md
- π» Code: examples/06-timer/, 08-workqueue/
- π Read: 07-dma.md, 08-platform-drivers.md
- π Read: 09-11-advanced-debugging.md
- π» Code: examples/07-procfs/
- π§ Study TROUBLESHOOTING.md
- π Build your own driver!
- Kernel Code is Dangerous: Bugs can crash the system, corrupt data, or create security vulnerabilities
- Always Test in VMs: Use virtual machines or test hardware for development
- Backup Everything: Keep backups before testing kernel code
- Check Kernel Version: APIs change between kernel versions (this tutorial targets 5.x/6.x kernels)
- No Standard Library: Can't use printf, malloc, etc. (use printk, kmalloc instead)
Before loading ANY kernel module:
- Code is tested in VM
- VM snapshot taken
- Code compiled without warnings
- Reviewed for obvious bugs
- Know how to force reboot (SysRq keys)
- Not on production machine
If system hangs:
- Try:
Ctrl+Alt+F1(switch to console) - Try:
Alt+SysRq+B(force reboot) - Last resort: Power cycle
By completing this tutorial, you will:
- β Understand Linux kernel architecture and driver model
- β Master C programming for kernel development
- β Write character, block, and network device drivers
- β Handle hardware interrupts and DMA operations
- β Implement proper synchronization and locking
- β Debug kernel code effectively
- β Follow kernel coding standards and best practices
- β Navigate and contribute to kernel source code
- Code Comments: Extensive inline comments explain every concept
- Warning Boxes: Highlight common pitfalls and security issues
- Theory Sections: Explain "why" before "how"
- Kernel Version: Code targets modern kernels (5.x/6.x) with notes on compatibility
# 1. Check prerequisites
cd examples/00-c-review && make test
# 2. Hello world module
cd ../01-hello && make
sudo insmod hello.ko
dmesg | tail
sudo rmmod hello
# 3. Character device
cd ../02-chardev && make
sudo insmod simple_char.ko
echo "test" > /dev/simple_char
cat /dev/simple_char
sudo rmmod simple_char
# 4. See race conditions in action!
cd ../05-locks && make
sudo insmod lock_demo.ko
dmesg | tail -50 # Watch unsafe counter lose updates
sudo rmmod lock_demo- 12 Theory Chapters (~65,000 words)
- 9 Working Examples (~2,000 lines of code)
- 4 Practical Guides (Setup, Troubleshooting, Getting Started)
- Complete Self-Assessment Quizzes and exercises
This is a living tutorial. If you find errors or have improvements:
- Test all code before submitting
- Follow kernel coding style (checkpatch.pl)
- Add detailed explanations for complex concepts
- "Linux Device Drivers" by Corbet, Rubini, and Kroah-Hartman
- "Linux Kernel Development" by Robert Love
- "Understanding the Linux Kernel" by Bovet & Cesati
- "The C Programming Language" by K&R
- β Prerequisites through advanced topics
- β Theory AND practice for every concept
- β Real working code, not pseudocode
- β Complete development environment setup
- β VM setup instructions
- β Troubleshooting guide
- β Emergency recovery procedures
- β Common pitfalls highlighted
- β 9 complete examples
- β Race condition demonstrations
- β Userspace test programs
- β Real-world patterns
- β Prerequisites chapter
- β C programming review
- β Self-assessment quizzes
- β Progressive difficulty
New to kernel development? β Start with 00-prerequisites.md
Comfortable with C and Linux? β Jump to 01-basics.md
Need environment setup? β Read DEVELOPMENT-SETUP.md
Having problems? β Check TROUBLESHOOTING.md
Last Updated: December 2025
Target Kernel Version: 5.15+ / 6.x
License: Educational use - adapt and share freely
Happy kernel hacking! π§