In Ubuntu11.04, you can directly write the driver and compile it. _______________________________________________________________________ Hello. c # include "linux/init. h" # include "linux/module. h" staticinthello_init (void) {printk (KE
In Ubuntu 11.04, you can directly write the driver and compile it.
___________________________________________________________________
Hello. c
# Include "linux/init. h"
# Include "linux/module. h"
Static int hello_init (void)
{
Printk (KERN_INFO "Hello World linux_driver_module \ n ");
Return 0;
}
Static void hello_exit (void)
{
Printk (KERN_INFO "Goodbey linux_driver_module \ n ");
}
Module_init (hello_init );
Module_exit (hello_exit );
_____________________________________________________________________________________
Makefile:
# Makefile 2.6
Ifneq ($ (KERNELRELEASE ),)
# Kbuild syntax dependency relationship of files and target modules are listed here.
Mymodule-objs: = hello. o
Obj-m: = hello. o
Else
PWD: = $ (shell pwd)
KVER? = $ (Shell uname-r)
KDIR: =/lib/modules/$ (KVER)/build
All:
$ (MAKE)-C $ (KDIR) M = $ (PWD)
Clean:
Rm-rf. *. com *. o *. mod. c *. ko. tmp_versions
Endif
_______________________________________________________________
Steps:
1. sudo make all;
2. Generate the hello. ko File
3. insmod hello. ko
4. lsmod. You can see the hello module.
5. rmmod hello. ko