Compile a Linux device driver for the System Processor

Source: Internet
Author: User
Article Title: compile a Linux device driver for the system processor. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

Introduction

Writing Linux device drivers is undoubtedly a complicated task. This article will focus on writing non-standard hardware device drivers, explore the hardware application programming interfaces, and use the case of Cirrus Logic EP9312 embedded platform to add device drivers.

If some programming content is not covered in this article, you can also refer to similar device driver code for reference. Another method is to retrieve historical files or send emails to the Linux kernel inquiry center.

Linux Overview

Linux is a replica of UNIX operating systems. It was first developed by Linus Torvalds in 1991 and has been continuously improved by the open source code organization through the open source code development mode. No copyright fee is required for individuals and groups using Linux.

Only the kernel is not enough. Linux is usually bundled with some Windows environments, Windows Managers, and applications running on the kernel. However, with an embedded platform, Windows environments are not essential. Unlike Microsoft's Windows operating system, Linux does not need a fixed set of application software or utilities that must be used, therefore, it can meet the customized requirements of embedded market terminal solutions.

The most basic components of the operating system include one resource manager, one scheduler, one interface between hardware and application software, one network manager, and one document system manager. The Linux operating system also includes these components and, of course, other components. This article mainly describes the interface between hardware and application software-the device driver.

Device Driver type

Device drivers can be divided into two categories: hardware device drivers and software device drivers. Hardware Device Drivers are connected to physical hardware devices, such as UART devices or IDE devices, while software device drivers are interfaces between low-level data structures, or the interface between the hardware driver and the advanced data structure. The graphics console driver is a software device driver. One LCD controller driver loads and manages the display, and the graphic console colors the characters to be displayed and obtains the input information from the keyboard. Another example of a software device driver is the document system execution-the document system driver uses a hard drive to store data, and the hard drive is directly connected to the physical hard disk.

Category of Device Drivers

Linux device drivers include characters, blocks, networks, and others. Generally, drivers are categorized based on the access method of the device. However, some devices cannot be differentiated according to this method, so they are classified as "other types ". character devices include devices that make data into data streams and can be obtained through a special file of a document system (the special files of the document system will be discussed later ). In view of the features of a character device, the device can only access data in sequence, that is, it cannot search for data forward or backward. Both the serial port and the audio device are of this type. Is the system structure of the EP9312 on Cirrus Logic. The Linux character device is marked in green.

Block devices can take care of one document system. Similar to character devices, such devices are also accessed through special files in the document system. However, the difference between Block devices and document devices is that they are randomly accessed. This means that the application can find random locations on the device. Both hard drive and CD drive are Block devices. Their internal file pointers can point to any location inside the device. The only restriction comes from the device itself. When a block device accesses a file through a special file in the document system, the application interface is the same as that of a character device, but it is different from the kernel interface. The red part is the Linux block device in the system structure on the Cirrus Logic EP9312 chip.

A network interface device can be either a hardware device or a software device. Hardware devices, such as the ethernet card and software devices, such as the low-end network protocol stack (this article regards such interfaces as software devices ). Middleware and protocol stacks are sometimes seen as software devices. A network interface device is a communication device for information packet data. It generally has a unique name and cannot be accessed through a special file in the document system. Instead, they are only open to the kernel network stack. Generally, user-level applications can access the kernel network stack, but cannot access network interface devices. The blue part in is the Linux network interface device in the system structure of Cirrus Logic EP9312.

Other device drivers include data bus drivers (USB, I2C, AMBA, etc.),/proc interfaces, and video drivers. These types of devices cannot be classified as the above three types, but they are still the device drivers connected to the Linux kernel.

Special document system files

Special files in the document system provide the feasibility of accessing hardware devices from the document system. These access points are generated in the/dev directory of the Document System Using the mknod command. Command: mknod.

Here, the name is given to the hardware device, for example,/dev/hda1 is the general name given to the hard drive. Is the type of the device driver-character (char), block, and so on. Represents the device category and the driver that matches it. Indicates one instance in the device category and only applies to the device driver. For example, a system uses two hard drives at the same time, both of which have the same serial number and use the same device driver software, however, the driver software of the device identifies the two hard drives internally Based on the secondary numbers.

It is worth noting that not all devices execute special file interfaces. As mentioned earlier in this article, network device drivers do not use this interface to access devices.

In this case, devfs is used in the device documentation system to obtain special files of the document device. Devfs is currently popular, but it is still not the default function of the kernel. If you use the devfs document system, mknod is not required to generate special files. On the contrary, the device driver software uses the direct devfs documentation system interface to generate special files when the device is idle or when the device is just initialized.

Programming instance Overview

To facilitate the demonstration of Linux Device Drivers for non-standard embedded platforms, this article describes the implementation of the device drivers for EP9312. The driver of the EP9312 IDE device is a block device, and the EP9312 touch screen is a character device. The advanced API/hardware interface, initialization sequence, and application software code in the Code are described.

 

[1] [2] [3] [4] Next page

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.