Compile the driver in Ubuntu11.04

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.