A simple character device driver to practice Linux device driver development. The device driver was implemented as a loadable Linux kernel module.
| Operation | Description |
|---|---|
| Open | Opens the hardware/software device |
| Read | Reads the contents input by hardware/software device |
| Write | Currently not supported, but could be enabled by modifying device_write function in hello_device.c file |
| Close | Close the hardware/software device, to prevent further use |
- Use the Makefile to generate the loadable module
- Load the compiled module using
modeprobe - Check if the driver is registered sucessfully through
dmesgcommand - Remove the module after use
A glimpse of the inner working of the device driver
- The driver executes
init_modulefunction on loading the module- The device is registered as a character device
- Prints device driver registration status to the kernel output
- On opening the device for Supported operations the driver updates a counter to keep track of device usage count.
- On reading from the device, the driver outputs the message stored in the message buffer
msg- Content of message buffer - "Hello World from hello_device"
- On closing the device, the
deivce_releasefunction of the driver is executed- The driver decrements the counter(open instances count)
- If the user tries to write to the device, the driver prints a
KERN_ALERTlevel message on kernel output, with the message - "Write operation unsupported" - If the user tries to remove the module, the device is unregistered and a
KERN_INFOlevel message is printed to the kernel output, with the message - "Device unregistered"
To see the kernel output run dmesg in the terminal