This repository contains a collection of Linux device driver examples designed for learning and experimentation on a standard laptop. These projects cover various aspects of Linux kernel development, including character and block devices, interrupt handling, and interfacing with user space through procfs
and sysfs
.
Objective: Implement a simple character device driver that supports basic read and write operations.
Key Features:
- Registers a character device with the Linux kernel.
- Supports operations like
open
,close
,read
, andwrite
. - Creates a
/dev/simplechar
file for user-space interaction.
Objective: Develop a character device driver that returns pseudo-random numbers.
Key Features:
- Generates random numbers using kernel space functions.
- Provides random numbers through read operations on the
/dev/randomnum
file.
Objective: Create a virtual block device that acts as a ramdisk.
Key Features:
- Implements a block device driver managing a memory buffer.
- Supports read and write operations through the block device interface.
- Mountable as a filesystem using a file like
/dev/vramdisk
.
Objective: Simulate an LED control driver that toggles "LED" state via user commands.
Key Features:
- Implements simple IOCTL commands to control LED states.
- Simulates LED on/off and blink actions, logging the state to the kernel log.
Objective: Interact with user space via the /proc
or /sys
filesystem.
Key Features:
- Creates entries in
/proc
or/sys
to display and control driver states. - Allows read/write operations from user space to modify driver behavior.
Objective: Develop a driver that simulates temperature sensor readings.
Key Features:
- Returns simulated temperature readings in Celsius or Fahrenheit.
- Updates temperature values periodically using kernel timers.
- Allows mode switching via IOCTL.
Objective: Create a driver that handles simulated interrupts.
Key Features:
- Implements an Interrupt Service Routine (ISR).
- Triggers interrupts using kernel timers or software interrupts.
- Logs interrupt handling events using
dmesg
.
Objective: Log keyboard inputs to the kernel log or a specific file.
Key Features:
- Captures and logs keyboard events.
- Filters specific key inputs.
- Logs keypress and key release events.
- Linux Kernel Headers: Ensure that your system has the Linux kernel headers installed.
- Development Tools: Install
gcc
,make
, and other development tools required for compiling kernel modules.
-
Clone the repository:
git clone https://github.com/yourusername/LinuxDeviceDriver.git cd LinuxDeviceDriver
-
Navigate to the desired project directory:
cd BasicCharacterDriver
-
Compile the driver:
make
-
Load the driver:
sudo insmod simplechar.ko
-
Interact with the driver:
echo "Hello, Driver!" > /dev/simplechar cat /dev/simplechar
-
Unload the driver:
sudo rmmod simplechar
- Always ensure you have a backup or are working in a safe environment (e.g., a virtual machine) when testing drivers.
- Modifying kernel space can potentially cause system instability.
Feel free to contribute to this repository by adding new drivers, improving existing code, or enhancing documentation.
This project is licensed under the MIT License. See the LICENSE file for details.