Linux: compile and generate the kernel module (Video Teaching from the country embed)

Source: Internet
Author: User

Kernel moduleCodeFile

File YYYY. C (yyyy can have the same name or different name as module XXXX)
(Something similar to a template)
# Ifndef _ KERNEL __
# DEFINE _ KERNEL __
# Endif

# Ifndef module // removed when added directly to the kernel. It is retained when the module is generated.
# Define Module
# Endif

# Include <*. h>

...

Module_license ("GPL"); // license declaration, used to inform the kernel that this module has a license
Module_author ("You name"); // the author's statement (optional)
Module_description ("aaaa"); // module description (optional)
Module_version ("V1.0"); // module version (optional)
Module_alias ("a bbbb module"); // module alias (optional)

Static int _ Inti xxxx_init (void)
{
}

Static void _ Inti xxxx_exit (void)
{
}

... // Other functions
...

Module_init (xxxx_init );
Module_exit (xxxx_exit );

Kernel-compiled makefile

Makefile
(Something similar to a template)
Ifneq ($ (kernelrelease ),)
OBJ-M: = XXXX. o
XXXX-objs: = YYYY. O (if there are other source files to continue adding zzzz. O...) (for example, if yyyy = XXXX and there is only one source file, this row can be removed)
Else
Kdir: =/lib/module/2.6.28.6/build
ALL:
Make-C $ (kdir) M = $ (PWD) Modules
Clean:
Rm-f *. Ko *. O *. Mod. O *. Mod. C *. symvers
Endif

Here,/lib/module/2.6.28.6/build is the directory generated by the kernel code tree, and the number of kernel codes is created:

Http://blog.csdn.net/leaglave_jyan/article/details/6652444

After editing the source file and makefile, run make in the directory to compile and generate the XXXX. Ko file of the module.

Use insmod XXXX. Ko to add

 

 

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.