Photo by Kevin Horvat on Unsplash

Setup gcc environment :

$sudo apt-get install build-essential

Code for init and exit the module :



Install module、remove module :

$sudo insmod init.ko
$lsmod | grep -i init.ko
$sudo rmmod init

Look for dmesg(display all messages from the kernel ring buffer) :

$dmesg | tail

After short introduce for init the module now let’s create char device driver

Auto create device file

At the beginning of writing linux device driver, most of the time we manual create device file by using mknod, but actually linux kernel provides an api to atuo generate device file under /dev/

class_create() : create a class put under sysfs once it creates we could call device_create() to create under /dev.

#check /dev is auto generate or not
$ls -al /dev/my_dev