Post

Introduction to Linux kernel Character Device Drivers

Learning how to interface between user space and the kernel using Character Drivers.

Introduction to Linux kernel Character Device Drivers

Introduction

Continuing the FLUSP kernel course (MAC0470/5856), I followed the Introduction to Linux kernel Character Device Drivers tutorial.

After the simple “hello world” modules, this was my first real driver. The goal was to create a basic character device (simple_char) that shows up in /dev/ and lets user-space programs read and write data.

What I Did

I added drivers/misc/simple_char.c with the usual file_operations (open, read, write, release) and a small kernel buffer. Used alloc_chrdev_region() + cdev for dynamic major number registration — no more fighting for static majors.

Quick additions to Kconfig and Makefile, built as module, copied to the VM.

Testing

Inside the VM:

1
2
3
modprobe simple_char
dmesg | grep simple_char
sudo mknod /dev/simple_char c 237 0

Then two tiny C programs: one to write a string, another to read it back. It worked!

Challenges

  • Had to check /proc/devices every time to get the right major.

What I Learned

  • Character devices are the classic bridge between kernel and user space via the filesystem.
  • file_operations is where the magic happens.
  • Always protect data movement between kernel and user space.
This post is licensed under CC BY 4.0 by the author.