Summary of the third edition of Linux driver development

Source: Internet
Author: User

I. Device Drivers

1
: What is the difference between a mechanism and a policy? mechanism: "What kind of function is required?" And Policy: "How to use these functions ".

2
: Primitive: Refers to a program composed of several machine commands. The program cannot be interrupted during execution until the modification is completed.

3
: Kernel features:

1>
: Process Management: Creates and revokes processes and communicates with external devices. Communication Methods between different processes: signals, pipelines, and inter-process communication primitives. The basic functions of the entire kernel during inter-process communication. In addition, how to share control processes

CPU
The scheduler is also part of process management.

2>
: Memory Management: memory is one of the important resources of computers. Memory Management strategist is a key factor that determines system performance. Different parts of the kernel use the same set of system calls interactively with the memory management subsystem.
.

3>
: File System:
Linux
Every object in can be viewed as a file

4>
: Device Control: All device control operations are performed by Code related to the controlled device. This code is called a device driver.

5>
: Network functions and network functions must also be managed by an operating system, because most network functions are irrelevant to specific processes.

4
:
Linux
One of the excellent features: the ability to dynamically expand the kernel at runtime, that is, we can add new features to the system at system runtime.

5
: Module
: The code added to the kernel during runtime is called a module.
(Module)
, Each module has the target code
(
For the linked
)
.

6
: Device module category:
UNIX
System devices include character devices, Block devices, and network interfaces.

1>
: Character devices send and receive data in the form of characters.
Is implemented by the character device driver. Block devices are in the form of a buffer zone.

2>
:
Linux
Allows reading and writing Block devices like character devices to transmit data in multiple bytes at a time.

3>
: Network Interface: Any network transaction must go through a network interface, that is, a device that can exchange data with other hosts. This interface is usually a hardware device or a pure software device, such as a loop.
(Lookback)
Interface


Note:
SCSI
:
Small Computer System Interface
(Small Computer System Interface)

7
: The file system except the driver
Linux
The most important module type in the system determines how to organize information on Block devices to represent directories and file trees. A file system is a software driver that maps the underlying data structure to the High-Level Data Structure and determines the file name length and information stored in the directory item.

Ii. build and run the module

1
: Kernel items: including functions, variables, header files, and macros.

2
:
Module. h
The file contains a large number of functions and symbol definitions required to load the module.
Init. h
Initialize and clear functions

3
: Module initialization function: registers any function provided by the module. The function should be declared as static because it is not visible outside of a specific file.

4
: If a module does not define a cleanup function
The kernel will not allow it to be detached.

5
: For details about the module parameters, see 46 pages of the third edition of driver development.

3. Character Device Driver

1: scull (simple character utility for loadding localities)-operate some memory allocated from the kernel

2: Primary and Secondary ID: the ID of the driver associated with the device. The device has this driver for management.

3: most basic driver operations include three important kernel parameters: file_operatoins file (file structure) inode

4: each opened file in the system has an associated struct file (file structure, in the kernel space), which is created when open is available.

5: In the kernel source code, FLE is called the file structure, while filp is called the structure pointer.

6: inode structure: the kernel is used internally to represent files.

7: Use register_chrdev (unsigned int major, const char * Name, struct file_operations * FoPs)
Function to register character Devices

8: The Directory of the currently loaded module is/sys/module.

9: module parameters. The parameters required by the driver vary with different systems. If a driver controls the old hardware, we should also be explicitly told where to find the hardware I/O port or I/O memory.

Address. In this case, you need to use the module parameters when loading the module.

10: System calling is the most basic way for user-level programs to access the kernel.
. The driver is also an important way for user space to interact with kernel information.

11: memory image: maps the memory of a specific part of the kernel to the memory space of a user-level program. That is to say, the kernel space shares the same memory space as the user space.

12: each process has a heap space. The memory dynamically allocated by malloc is actually obtained from the heap space of the process.
.

13:/sys/module contains the currently loaded Module

14: The driver associated with the ID of the master device, which is managed by the driver. The number is used by the kernel to determine the device to be referenced.

15: macro definition in/usr/include/Linux/kdev_t.. If the device number is known, the primary and secondary device numbers can be obtained, and the primary and secondary device numbers can be obtained.

16: the device's chief account should be dynamically allocated.

1

17: kernel memory operation function: void * kmalloc (size_t size, INF flags) flags: The parameter describes how to allocate memory. Void kfree (void * PTR)

18: function for Data Interaction between kernel space and user space: Unsigned long copy_to_user (void _ User * To, const void * From, unsigned Long Count)

Unsigned long copy_from_user (void * To, void _ User * From, unsigned Long Count)

19: the actual device method: The read method is to copy data from the device to the user space.

Chapter 4: kernel debugging technology

1: printk_ratelimit (): this function should be called before you think that duplicate messages may be printed. If the return value of this function is not 0, print the messages. Otherwise, the messages will be thrown away and the messages will not be printed.

2: run the vmstat command to view memory usage in real time.

3:/proc file system a file system created by a special software. The kernel is used to output messages to the outside world. Each file in the/proc file is bound to a kernel parameter. This file system is widely used in Linux. Commands such as PS top are extracted from the file system.

4: the original purpose of the/proc file system is to provide information about processes running in the system.

5: The strace command is a good tool for displaying system calls issued by all user space programs. Displays not only system calls, but also call parameters and return values in the form of symbols.

6: The strace command (tracking the debugging program) obtains information from the kernel itself. The trace information is often used as a fault report for application developers. It is also important for Kernel programmers.

7: The read system can only get 4000 bytes at a time.

8: strace is very useful for identifying system call errors, and can accurately indicate the parameter called by the system. Perror calls in applications are often not detailed enough.

9: Oops: kernel crash is the message generated (system panic) dereference: obsolete

10: sysrq magic keys are used to understand the current running status of the system. If the system is suspended or you are diagnosing some weird kernel-related problems, it is very important to use the sysrq key.

11. kernel debugger and debugging tool

1>: debug with GDB 2>: KDB kernel debugger 3>:

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.