It is not difficult to develop the driver of a Linux system.

Source: Internet
Author: User
It is not difficult to develop a driver for a Linux system-general Linux technology-Linux programming and kernel information. For more information, see the following. I have recently read the multi-kernel programming and driver development tutorials and also referred to some Development Board examples. To sum up, it is not as high as you think. To develop drivers, you must have a certain understanding of the kernel.

The drivers mentioned below are designed for specific devices and work in dynamic module loading mode. The driver framework is layered. Some drivers are not drivers for specific devices, such as the ext2 file system or the TCP/IP protocol. These drivers can be called soft drivers, works on drivers of other specific devices. Because we are doing embedded development, we only need to write the device driver at the lowest layer.

Device Drivers are generally divided into character devices and Block devices. The difference is that the block device has a buffer, and the character device does not have a buffer. However, in the drivers directory of linux source code, there are not only block and char directories, but also various other devices, this is because some developers use a more intuitive feature classification for convenience. For example, the sound directory stores various audio drivers at a glance.

Since it is a device driver, let's first look at how the device describes in linux. Store all devices supported by the system in the/dev directory. The device can also be a device node. if you add a new device to the system, you must create a node under/dev. A device driver can usually drive several devices, which are differentiated by the primary device number and secondary device number. All devices with the same primary device number use one driver. The sub-device number indicates how the driver separates the entries of different devices. In some cases, the Operation Type of the device can be distinguished based on the level and level of the sub-device number. For example, the relationship between hda0-hda4 and hdb0-hdb4, hda represents the first hard disk, hdb represents the second hard disk, because everyone is a hard disk, so this with the same driver, therefore, the primary device numbers of had and hdb are the same. The serial numbers after Hda represent the partition information on the hard disk. In order to effectively distinguish these partitions, the sub-device settings are classified. The four-byte high bits represent different hard disks, the four lower digits represent the partition index.

After learning about the device description, let's look at the software environment. Development of drivers in linux has nothing to do with the release version you are using, no matter whether you use redhat or mandrake. What really affects you is the version of your current kernel. If you plan to use the 2.4.x Kernel on the target board, but linux on your host uses the 2.6.x system, your development will be troublesome. Where is the problem? You can see it later. Therefore, we recommend that you use the same kernel version for the host and target system.

During driver development, because kernel references are used, you do not need to link to the library files during program compilation. Therefore, the lib path is useless to us. However, to reference various data structures and interfaces provided by the kernel, you must set the include path for the corresponding version, usually in/usr/include. There are many header files under/usr/include. What we really need is the/usr/include/linux directory and/usr/include/asm directory.

There are two functions and three data structures in the driver design. Init_module and cleanup_module functions. The File_operations, inode, and file data structures are defined in linux/fs. h. Other operations such as memory, I/o, timer, interrupt, and DMA wait are all upgraded.
Related Article

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.