"Linux kernel Design and implementation" Chapter 17th study Notes

Source: Internet
Author: User

17th chapter, Equipment and modules

17.1 Device Type

1. Block Device (Blkdev):

Addressing is in blocks and typically supports relocation operations. Accessed through special files called "Block device Nodes".

2. Character device (Cdev):

Non-addressable, providing only streaming access to data. Accessed through a special file called a "character device node."

3. Network Equipment (Ethernet devices):

Provides access to the network. It is not accessed through device nodes, but through special interfaces such as the socket API.

17.2 Modules

17.2.1 Hello,world

(1) the Hello_init () function is the entry point of the module.

All initialization functions of the module must conform to the following form:

Int my_init (void);

It can be marked as a static type.

(2) the Hello_exit () function is the Exit function of the module.

The Exit function is responsible for undoing the INIT function and everything that is done during the module life cycle, essentially cleaning up the work.

All initialization functions of the module must conform to the following form:

void My_exit (void);

It can also be marked as a static type.

17.2.2 Building Blocks

The first step in building a module is to decide where to manage the module's source code.

(1) placed in the kernel source tree

(2) outside the kernel code

17.2.3 Mounting Module

The Make Modules_install build command is used to install the compiled module into the appropriate directory, which usually needs to run with root privileges.

17.2.4 Generating Module dependencies

There is a dependency between Linux modules.

17.2.5 Loading Module

The simplest way to load a module is through the Insmod command, which is to request the kernel to load the module.

Insmod Module.ko (Here Module.ko is the module name to load)

The Unload module can use the Rmmod command.

Rmmod Module

17.2.6 Managing configuration options

The first line of the configuration option defines the configuration target that the option represents;

The second line declares the compilation option type;

The third line specifies the default options for this option.

17.2.7 module Parameters

(1) Define a module parameter can be completed by Macro Module_param ():

Module_param (Name,type,perm);

(2) You must define a variable before using the macro

(3) Typically, a charp type is required to define a module parameter (a string)

17.2.8 Exporting symbol tables

In the kernel, exporting kernel functions requires the use of special Instructions: Export_symbol () and EXPORT_SYMBOL_GPL ().

The exported kernel function can be called by the module, and the non-exported function module cannot be called.

To export a symbol, simply follow the Export_symbol () directive after declaring the function.

17.3 Device Model

"Linux kernel Design and implementation" Chapter 17th study Notes

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.