A simple linux device driver that can be run on both x86 and edge device (specifically most compatible with Raspberry Pi) as Rpi 's OS is easier to configure Tested on a normal linux system as well.
note: GPIO drivers are specific to Rpi / Any other SBC with similar numbering
This project contains Linux kernel modules developed from scratch for the Raspberry Pi 4B. It includes:
- A basic character device driver
- A GPIO control module for toggling LEDs via sysfs
- Drivers for usb
Designed to demonstrate low-level interaction with Linux kernel space using loadable kernel modules (LKM), targeting embedded systems and hardware-near control.
- Platform: Raspberry Pi 4B (64-bit Debian OS), Ubuntu 24.04 LTS
- Language: C
- Kernel Version: 5.x
- Interfaces:
insmod,sysfs,udev,/dev/ - Tools:
make,modprobe,dmesg,cat,echo
- Registers a custom char device in
/dev/rpi_drv - Supports basic
open,read,write,closeops - Controls a user-defined GPIO pin via sysfs
- Cleanly handles
module_initandmodule_exit
-
sudo apt update
-
sudo apt upgrade -y
-
sudo apt install -y raspberrypi-kernal-headers
// for installing the kernal headers
-
sudo apt install -y build-essential
-
sudo reboot
//for opening of a fresh kernel
// 4. is necessary as we are running c scripts therefore it requires gcc , make (most probably preinstalled)
Then check the conents of the build folder:

after the running of the initial kernel:
the generated .ko file can be used to load/ unload the kernel module (lkm):
-
for chosing of a number , it should be a number that was not listed in ls proc/devices
-
Kernel modules can register block or character devices (in the traditional unix sense, "device" is a word with many meanings) in the kernel, using a routine like register_blkdev together with a string that is supposed to identify the device.
-
It's possible to use any string for that purpose, and these strings show up in the /proc/devices file (which is just a textual representation of this kernel table).
-
//which are different from the major and minor numbers shown in /dev
-
After the generation of device number and loading , it can be checked by
-
cat /proc/devices | grep my_device_nr
$ ls /dev/ -al
shows the device in the list after the creation of the node . cat /proc/devices doesnt confirm the device creation (node) only the number associted.
So the loading of the .ko file (lkm) of the corresponding device is necessary for the accessing of that device for either read/write
- initially when the corresponding kernel module for major no. 90 was not loaded but for 104 , it is unable to access the file.
output messages:
Issues: https://www.notion.so/Issues-16b3175a5f4380b3bb9fc1a1f0b49a01
shows the output response when the read_write LKM is loaded into the kernel.
So a dummy driver with a major number of 234, minor 0 is registered in the list of device drivers.

calling it by the node name given in the program (otherwise had to be made by the sudo mknod c/b
command.
and changing permissions.

writing and reading the contents of the driver.
USB Device drivers:
- For some reason the connection and the removal is detected only once -> directly from continuous dmesg ->matched on vendor id and product ID.
The collected message for registering the device -> During insertion of the kernel module.






