Challenge

Project 1 - Develop the full featured char driver as a loaded module

  • Kconfig build system
    • The module should be added to the Kernel configuration of the Kconfig build system with tristate option.
  • Char driver should be of
    • Open --> Only one user is allowed to open the device. Other users should be blocked.
    • Read and write operation: store the data to the dynamically allocated memory and read from it.
    • Seek is able to move the offset of read/write location.
    • Max memory size: configurable through compile time and load time.
    • Blocked read/write: whenever data is not available to read, driver should wait till it is available. Similarly, during writing, when enough memory is available,.
    • /proc/char_driver_size --> Create the proc file char_driver_size, which should reflect the size of memory allocated to the char driver.

### Project Overview

This project focuses on developing a Linux Kernel Module (LKM) that integrates into the Kernel's configuration Kconfig build system with a `tristate` option. The main objective is to create a robust character device driver that showcases advanced features typically found in such modules.

### Key Features of the Character Driver

1. **Single-User Access:**

- The driver enforces a restriction where only one user can open the device at any given time. If another user attempts to open it, they are blocked until the device is released.

2. **Read/Write Operations:**

- The driver provides functionality to store data in dynamically allocated memory and retrieve it. The size of the allocated memory can be configured at both compile-time and load-time.

3. **Seek Functionality:**

- The driver supports seeking operations, allowing the user to adjust the offset of the read/write location within the allocated memory.

4. **Blocked I/O Operations:**

- The driver implements blocking mechanisms for read and write operations:

- **Blocked Read:** If data is not available to be read, the driver waits until data becomes available.

- **Blocked Write:** If there isn’t enough memory available to write data, the driver waits until memory becomes available.

5. **Procfs Integration:**

- A `/proc` entry (`/proc/char_driver_size`) is created to allow users to monitor the size of memory allocated to the character driver. This provides a convenient interface for understanding the driver's memory usage.

### Project Goals

- **Kernel Module Development:**

- Students will learn to write, compile, install, and remove loadable Linux Kernel Modules.

- **Advanced Character Device Driver:**

- The module developed will feature advanced capabilities such as single-user access, dynamic memory management, blocked I/O operations, and seek functionality.

### Key Highlights

- **Linux Kernel Module Utilities:**

- The project will cover the use of essential kernel module utilities like `insmod`, `modprobe`, and `rmmod`.

- **Character Device Driver Creation:**

- Students will learn to create character device drivers, including managing major and minor numbers, and using `mknod` to create device files.

- **User-Space Interaction:**

- The project will involve interacting with the character device using user-space applications like `cat` and `echo`, providing practical experience in driver usage.

- **Virtual File System (procfs):**

- Integration with `procfs` will help students understand virtual file systems and how to communicate information between kernel space and user space.

### Deliverables

1. **Linux Kernel Module (`.ko` file):**

- The final compiled kernel module that can be loaded into the kernel.

2. **Makefile:**

- The Makefile used to compile the kernel module, which will include necessary instructions to build the module within the kernel build system.

3. **Procfs Entry:**

- The `/proc/char_driver_size` entry that reflects the memory size allocated to the character driver.

4. **User Application:**

- A user-space application that interacts with the character driver, demonstrating read, write, and seek operations.

### Expected Outcomes

- **Module Compilation and Installation:**

- Students will be able to compile and install the LKM using standard kernel utilities.

- **Character Device Driver Creation:**

- Students will successfully create a character device driver and link it with the Linux device system.

- **Blocked/Non-blocked Read Mechanisms:**

- Understanding and implementation of different read mechanisms, including blocking and non-blocking I/O.

- **Procfs Learning:**

- Gaining insights into the virtual file system, particularly how to use `procfs` for kernel-to-user communication.

This project serves as a comprehensive introduction to Linux Kernel Modules and character device drivers, covering both foundational concepts and advanced features.

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.