Learning Linux has been a while, has been disorganized. I don't know what I learned or what I did. Now take a step-by-step look at the Linux-driven learning process. From the simplest to see the beginning.
First, we write a simplest module. Edit HELLO_MODULE.C
#include <linux/module.h> #include <linux/sched.h> #include <linux/kernel.h> Module_license ("GPL"); int text_init (void) { PRINTK ("<0>" "Hello World"); return 0; } void Text_cleanup (void) { PRINTK ("<0>goodbye World"); } Module_init (Text_init); Module_exit (Text_cleanup); |
Write makefile
Ifneq ($ (kernelrelease),) Obj-m: = HELLO_MODULE.O Else #KERNELDIR: =/home/sinew/Desktop/linux-2.6.30.4-ces2440 Kerneldir: =/usr/src/linux-headers-3.8.0-19-generic/ pwd:=$ (Shell PWD) All Make-c $ (Kerneldir) m=$ (PWD) modules Clean RM-RF *.ko *.o *.mod.c *.mod.o *.symvers endif |
Where Kerneldir needs to be set to your kernel source path.
Then use the Insmod command to deposit modules: Insmod Hello_nodule.ko
Using Lsmod, you can see your newly inserted module.
Using Rmmod to remove modules: Rmmod hello_module
The simplest driver is complete.