This comprehensive tutorial covers Linux device driver development from basics to advanced topics.
-
01-basics.md - Kernel Modules & Fundamentals
- Kernel vs userspace
- Module initialization/cleanup
- Module parameters
- Symbol exports
- Best practices
-
02-char-drivers.md - Character Device Drivers
- Device numbers (major/minor)
- cdev structure
- File operations
- Device classes and udev
- Multiple devices
-
03-file-operations.md - Advanced File Operations
- ioctl implementation
- poll/select mechanisms
- llseek operations
- mmap (memory mapping)
- Async I/O
-
04-memory.md - Memory Management
- kmalloc/kfree
- vmalloc/vfree
- Slab allocator
- Page allocation
- DMA-capable memory
- Per-CPU variables
-
05-concurrency.md - Locking & Synchronization
- Atomic operations
- Spinlocks
- Mutexes
- Semaphores
- Read-write locks
- Completions
- RCU
-
06-interrupts.md - Interrupt Handling
- IRQ registration
- Top-half/bottom-half
- Tasklets
- Work queues
- Threaded interrupts
- MSI/MSI-X
-
07-dma.md - Direct Memory Access
- DMA addressing
- Coherent vs streaming DMA
- DMA mapping APIs
- Scatter-gather DMA
- DMA pools
- Address masks
-
08-platform-drivers.md - Platform Device Drivers
- Platform device model
- Device tree basics
- Platform resources
- Power management
-
09-11-advanced-debugging.md - Advanced Topics
- Block device drivers
- Network device drivers
- Debugging techniques
- ftrace, KASAN, KGDB
- Performance profiling
examples/ - Compilable code samples
01-hello/- Basic kernel module02-chardev/- Character device with read/write- Makefiles for easy building
- Detailed READMEs with test instructions
# Install kernel headers
sudo apt-get install linux-headers-$(uname -r)
# Install build tools
sudo apt-get install build-essential
# Optional: debugging tools
sudo apt-get install crash kexec-tools# Clone or navigate to tutorial directory
cd /path/to/drv
# Read the main README
cat README.md
# Start with basics
cat 01-basics.md
# Try first example
cd examples/01-hello
make
sudo insmod hello.ko
dmesg | tail
sudo rmmod hello- Read: 01-basics.md
- Code: examples/01-hello
- Read: 02-char-drivers.md
- Code: examples/02-chardev
- Experiment with modifications
- Read: 03-file-operations.md, 04-memory.md
- Read: 05-concurrency.md
- Build more complex drivers
- Practice error handling
- Read: 06-interrupts.md, 07-dma.md
- Read: 08-platform-drivers.md
- Read: 09-11-advanced-debugging.md
- Work on real hardware projects
✅ Kernel Architecture - Module system, memory management
✅ Device Drivers - Character, block, network devices
✅ Hardware Interaction - MMIO, interrupts, DMA
✅ Synchronization - Locks, atomics, wait queues
✅ Debugging - printk, ftrace, KASAN, KGDB
✅ Best Practices - Error handling, coding style, safety
- Always test in VMs or dedicated test hardware
- Never test on production systems
- Keep backups before loading kernel modules
- Use version control for your driver code
- Check kernel log (
dmesg) for errors - Be prepared to reboot if system hangs
make- Build modulesinsmod/rmmod- Load/unload modulesdmesg- View kernel logmodinfo- Module informationlsmod- List loaded modules
ftrace- Function tracingperf- Performance profilingcrash- Crash dump analysisKGDB- Kernel debuggersparse- Static analysis
- "Linux Device Drivers" by Corbet, Rubini, Kroah-Hartman
- "Linux Kernel Development" by Robert Love
- "Understanding the Linux Kernel" by Bovet & Cesati
Found errors or have improvements?
- Test all code before submitting
- Follow kernel coding style (
checkpatch.pl) - Add detailed explanations
Follow Linux kernel coding standards:
# Check your code
./scripts/checkpatch.pl --no-tree --file your_driver.c
# Key points:
# - Tabs for indentation (not spaces)
# - 80 character line limit (flexible)
# - Clear variable names
# - Comments explain "why", not "what"- Read Kernel Source - Study existing drivers
- Join Community - Linux kernel mailing lists
- Contribute Patches - Fix bugs, add features
- Write Drivers - For your hardware projects
- Keep Learning - Kernel evolves constantly
- 11 Chapters covering all major topics
- 100+ Code Examples with detailed comments
- 2000+ Lines of example code
- Complete Working Samples ready to compile
- Theory + Practice approach throughout
After completing this tutorial, you should be able to:
- Write character device drivers
- Handle hardware interrupts
- Implement DMA transfers
- Debug kernel code effectively
- Read and understand kernel source
- Contribute to kernel projects
- Develop drivers for custom hardware
Remember:
- Start simple and gradually increase complexity
- Test thoroughly in safe environments
- Read kernel code for best practices
- Ask questions in kernel communities
- Share knowledge with others
The kernel is a journey, not a destination. Enjoy the exploration!
Tutorial Version: 1.0
Last Updated: December 2025
Target Kernel: 5.15+ / 6.x
License: Educational - Free to use and adapt
For questions, updates, or feedback, refer to the Linux kernel documentation and community resources.