Skip to content

A simple character device driver implemented as loadable Linux kernel module.

Notifications You must be signed in to change notification settings

vivek-viswam-rv/device-driver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

A Simple Linux Device Driver

A simple character device driver to practice Linux device driver development. The device driver was implemented as a loadable Linux kernel module.

Supported operations

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

Steps to get it running

  1. Use the Makefile to generate the loadable module
  2. Load the compiled module using modeprobe
  3. Check if the driver is registered sucessfully through dmesg command
  4. Remove the module after use

Steps executed by the driver for setup

A glimpse of the inner working of the device driver

  1. The driver executes init_module function on loading the module
    • The device is registered as a character device
    • Prints device driver registration status to the kernel output
  2. On opening the device for Supported operations the driver updates a counter to keep track of device usage count.
  3. 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"
  4. On closing the device, the deivce_release function of the driver is executed
    • The driver decrements the counter(open instances count)
  5. If the user tries to write to the device, the driver prints a KERN_ALERT level message on kernel output, with the message - "Write operation unsupported"
  6. If the user tries to remove the module, the device is unregistered and a KERN_INFO level message is printed to the kernel output, with the message - "Device unregistered"

To see the kernel output run dmesg in the terminal

About

A simple character device driver implemented as loadable Linux kernel module.

Topics

Resources

Stars

Watchers

Forks