Linux Device Driver Development Learning (3): Building and running Modules (unfinished)

Source: Internet
Author: User


Starting with this chapter, all the basic concepts of module and kernel programming are introduced and a complete module is written to practice these basic overviews

Read.


3.1 Building a test environment


Since all test codes are based on the Ubuntu 14.04.2 Desktop 3.16.0-30-generic Core, it is best to

Linux official website to download a copy of the source code for this version of the kernel. In addition, it is recommended to install your Ubuntu desktop environment inside the virtual machine, which

Hardware damage or critical data loss due to misoperation. For more test environment details, refer to the blog post:

Ubuntu 14.04.2 + VMware builds Linux-driven development environment


3.2 Hello World Module


The following code is a complete Hello World module.

#include <linux/init.h> #include <linux/module.h>module_license ("Dual BSD/GPL"), Static int Hello_init (    void) {PRINTK (Kern_alert "Hello, world\n"); return 0;} static void Hello_exit (void) {PRINTK (Kern_alert "Goodbye, cruel world\n");} Module_init (Hello_init); Module_exit (Hello_exit);

The module has two functions, Hello_init () is called when the module is loaded into the kernel, and Hello_exit () is called when the module is removed from the kernel.

The Macros Module_init and module_exit respectively put functions Hello_init () and Hello_exit () into two specific segments (sections), so that when the modules are linked to the kernel, the kernel can know that they are functions that are used for module loading/removal, respectively. and the Macro Module_license statement

The permissions of the module, and if you do not make a license statement, the kernel will complain.



This article is from the "Jimokuangxiangqu" blog, make sure to keep this source http://4594296.blog.51cto.com/4584296/1791050

Linux Device Driver Development Learning (3): Building and running Modules (unfinished)

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.