Linux kernel driver Hello

Source: Internet
Author: User

1, PRINTK the priority of printing output

#define Kern_emerg "<0>"/* Emergency message, prompt before system crash, indicates system is not available */
#define Kern_alert "<1>"/* report message that you must take immediate action */
#define KERN_CRIT "<2>"/* critical condition, usually involving severe hardware or software operation failure */
#define KERN_ERR "<3>"/* error condition, driver. Common Kern_err to report hardware errors */
#define Kern_warning "<4>"/* warning condition to warn of possible problems */
#define KERN_NOTICE "<5>" * * Normal but important conditions are used to alert for security-related messages */
#define KERN_INFO "<6>"/* prompt information, such as when the driver starts, print hardware information */
#define KERN_DEBUG "<7>"/* Debug-level messages */

These things the kernel print out the basic message, but it is important to note that the macro definition can be displayed on the terminal, but it is certain that you use these macro definitions in debugging, must be displayed in some places, metaphor in the log and other files under the display.

2,makefile a few key statement descriptions

Make-c $ (Kerneldir) m=$ (PWD) modules

The meaning of this sentence:

-C is the Execute directory that changes make,

$ (kerneldir) is the path of your native kernel

m=$ (PWD) modules This enables makefile to return to the module source directory before attempting to generate the module. The direct point is to change the makefile in the same directory as the modules to M, execute make instructions.

kerneldir:=/usr/src/kernels/2.6.25-14.fc9.i686

This directory address is the correct address for your virtual machine. Note 2.6.25-14.fc9.i686 This is the name of the folder that corresponds to the/usr/src/kernels of your Linux host

OBJ-M:=HELLO.O target file Dependent hello.o

Start writing code:

/*hello_module.c*/#include<linux/init.h>#include<linux/kernel.h>#include<linux/module.h>Module_license ("Dual BSD/GPL");Static intHello_init (void) {PRINTK (Kern_emerg"Hello, Linux driver!\n"); return 0; }Static voidHello_exit (void) {PRINTK (Kern_emerg"Hello Diver Exit!\n"); }module_init (Hello_init); Module_exit (hello_exit);

Makefile file

Watch your. c file and your makefile in the same directory.

Execute make

Add:

1,makefile's writing:

Note Clean:

Make-c $ (Kerneldir) subdirs=$ (PWD) Clean

This can all clear other files, leaving only makefile and my.c, hehe!

1,linux Driver Development Experience Chapter Hello

Http://www.cnblogs.com/xmphoenix/archive/2011/10/24/2223148.html

2, Linux system ko module compilation

http://blog.csdn.net/elfylin/article/details/5908265

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.