0% found this document useful (0 votes)
10 views8 pages

LDD Basics

Device drivers basic code

Uploaded by

iamshreyanshk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views8 pages

LDD Basics

Device drivers basic code

Uploaded by

iamshreyanshk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Simple kernel module program

Contents:
1. Write basic LDD Program(hello.c).
2. Write Makefile
3. Compilation stages.
• module_init is the entry point of the kernel
modules and hello_module_init function is
registered with module_init.
• So, hello_module_init function is executed
when this module is inserted into the kernel.

• Similarly, module_exit is the exit point of


kernel modules and hello_module_exit
function is registered with module_exit.
• So, hello_module_exit function is called
when this module is removed from the
kernel.
To compile and build this module, we need to create the Makefile:

obj-m := hello.o

all:
make -C /lib/modules/`uname -r`/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
Now run the make command it will create the
module hello.ko:

$ make
commands: # To load module run below command
$ sudo insmod hello.ko
# To remove the module
$ sudo rmmod hello
Thanks,

You might also like