Linux Driver - (a) driving review

Linux Driver - (a) driving review

A, Linux drivers

  • Linux is an open source project outstanding success, with the application of the increasingly widespread, Linux has been sought after by more and more software developers. But after downloading from the official online face down the Linux source code, we will find the Linux world is so huge, the amount of code is so huge. To learn, Linux in the end where to start?

    Before a very famous book about Linux, see the author mentioned two good breakthrough that can help us better access to the Linux world - and network drives.

    Then I will be in the study and exchange of attitudes here to share this post from the beginning of some some knowledge about Linux driver related, some are from the book or my other blog to see some of my own programming experience, I these are integrated into the record here together.

  • Driven development of the Linux kernel level development, so he asked for the program will be more high. Because, we are a very small flaws are likely to lead to the collapse of the system. Of particular note is the pointer used in the kernel development process, each step must clearly know whether the pointer is pointing to where, as well as the address of its visit is legitimate.

  • Like with bare metal development, driver development also requires interrupt handling. Interrupt driver in the kernel is divided into interrupt context, i.e., go to respond to the interrupt portion, a portion to process the interrupt. (This part of the follow-up will describe in detail, here is a proposed concept)

  • The driver is to be called the upper application, so we should provide a good API to the upper application, for the upper program to call. Of course, this is the core driver of the matter, although we are system-level programming it? Of course we want to run the above program we provide a suitable environment and hardware-driven interface to it.

  • A class driver has a specific template driver, later called unified framework for driving it. All drivers have a similar mode of implementation, it is to construct the core data structure, and then registered with the kernel. Writing drivers, in fact, to learn these core data structures and associated set of API (note that this sentence behind this sentence is basically around to explain is implementation-dependent drive). Similarly, we in the preparation of the kernel driver should make full use of the existing kernel implementation rather than trying to re-build.

Two, Linux driven classification

Of course, above mentioned, the corresponding drive different frame of different device types are different, then the drive frame in Linux is divided into, what does? In fact, Linux drivers are divided into the following three:

Character device ; accessing device is a device such as a byte stream in accordance with the (equivalent) to be accessed, this feature is achieved by a character device driver. Character drivers to achieve at least open (), close (), read () and write () system call. For example: character terminal (/ dev / console) and serial port (/ dev / ttySo and similar devices) are two character device, they can be a good description of the concept of "flow". Character device can be accessed through the device node, such as: / dev / tty1 and / dev / lp0 like. The only difference between these device files and normal files that access to common files can have mobile access position, while most characters can only sequential access device is a data channel. However, there are also devices having character data characteristics, their access position may be moved back and forth. Such a device is e.g. framebuffer, APP or lseek access map can grab the entire image.

Block device : the device is a so-called block can only transmit a full or more complete blocks every read or write, and each block contains 512 bytes (two or more bytes of data). Character devices and the like, the device is accessed through the block / dev directory of the file system node. Block device, for example to accommodate filesystem on the disk. Block and character device is the way to chant internal management data kernel, that is, an interface between the driver and the kernel, the kernel, and the interface block character device driver completely different device.

Network equipment : network equipment it, and two above are not the same. Of course, it is to be more complicated. We know things have to go through any network interface to form a network, a network interface is able to host and other devices to exchange data. Interface is usually a hardware device, but usually it may be a pure software device, such as loopback (loopback) interface. The network interface is the network subsystem of the kernel driver is responsible for sending and receiving data packets. Since not a stream-oriented devices, and therefore the network device interface is mapped to the node in the filesystem (such as / dev / tty1) more difficult. Unix network interface access method is still assign them a unique name (for example: rth0), but the name of the corresponding node does not exist in the filesystem. Communication kernel and network drivers, completely different from the communication between the kernel and the device and a block character devices, the kernel function and a set of call-related data packets instead of the above-mentioned read and write and the like.

Well, we've driven have a clear classification of the Linux device in the heart by the above analysis.

  • Linux drivers are based on some standard GNU C development, which contains a number of extensions and some standard GNU C of C language syntax. (GNU it is currently the world's largest open source software organization. Want to know specific small partners can go online to see Soso)

  • Of course, you want to have a basic understanding of the Linux kernel small partner can look at my other blog post, there are some basic introduction to the Linux kernel:

    https://blog.csdn.net/wit_732/article/details/102806376

  • Finally, some of the network address mentioned in the article, I put them posted here, for inspection use

    GNU C standard related documents: https://www.kernel.org/doc/Documentation/CodingStytle

    Linux code to download the original document: https://www.kernel.org/

发布了49 篇原创文章 · 获赞 15 · 访问量 9260

Guess you like

Origin blog.csdn.net/wit_732/article/details/102881266