linux-device-driver Getting started with linux-device-driver

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Remarks

This section provides an overview of what linux-device-driver is, and why a developer might want to use it.

It should also mention any large subjects within linux-device-driver, and link out to the related topics. Since the Documentation for linux-device-driver is new, you may need to create initial versions of those related topics.

Hello World device driver

hello_world.c

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>

#define AUTHOR  "Bruce Lee"
#define DESC    "Hello World driver"

static int __init init(void)
{
    printk(KERN_DEBUG "Hello World\n");
    return 0;
}

static void __exit deinit(void)
{
    printk(KERN_DEBUG "Goodbye World\n");
}

module_init(init);
module_exit(deinit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR(AUTHOR);
MODULE_DESCRIPTION(DESC);
 

Makefile:

KDIR ?= /lib/modules/`uname -r`/build
obj-m += hello_world.o

all:
        make -C $(KDIR) M=$(PWD) modules

clean:
        make -C $(KDIR) M=$(PWD) clean
 

How to compile:

$ make
 

How to insert the module:

$ sudo insmod hello_world.ko
 

How to see print messages

$ dmesg
 

How to list module/s

$ lsmod | grep hello_worls
 

How to remove the module

$ sudo rmmod hello_world
 

Installation or Setup

Detailed instructions on getting linux-device-driver set up or installed.



Got any linux-device-driver Question?