Android Deep Exploration (Volume I) sixth chapter

Source: Internet
Author: User

The Linux system maps each driver into a single file. These files, called device files or drive files, are stored in the/dev project. This design concept makes interacting with Linux drivers as easy as interacting with ordinary files.

Since most Linux drivers have their corresponding device files, exchanging data with Linux drives becomes

Device File Exchange data. For example, to send a print command to a Linux printer driver, you can open the device file directly using the C function open, so that the liver function OC TL sends a print command to the drive's device file.

Steps to write Linux drivers

First step: Build Linu Drive skeleton load and unload Linux drivers)

Any type of order has a basic structure, for example, rumors need to have an entry function Ma. Inux Driving Path

The order is no exception. The Linux kernel requires a load driver to start the load during the loading process.

For example, set up a file allocation memory address, and so on. When the Nux system exits, the Inux driver needs to be uninstalled,

The resources that are consumed by Linux drivers are required during uninstallation

Step two: Register and unregister the device files

Create and remove device files using the misc GI mis dere ter function, respectively.

Step three: Develop something related to the drive

MOD ule_a uthormodule CE SE MOD ULE LI MODUL DES ript IO macros can specify driver-related information.

Fourth step: Specify the callback function

A driver does not have to specify all the trap functions. The callback function is registered through the relevant mechanism

Fifth step: Writing business logic

The core part of the Linux drive. There is no point in having a Linux driver with a skeleton and a callback function. Any full Li Nux driver will do some work related to its function.

Sixth step: Writing the Makefile file

Seventh step: Compiling Linux drivers

Eighth Step: Install and uninstall Linux drivers

Write a count of the number of words driven

    1. command to create a directory that holds inux drivers
    2. Create a drive source code file
    3. Write a Makefile file
    4. Writing skeleton parts of Linux drivers, initialization and exit functions for Linux drivers
    5. Install Linux driver Insmod Word count.k
    6. See if Word_count is installed successfully
    7. Uninstalling the Li nux driver
    8. View log information for Linux driven output

Android Deep Exploration (Volume I) sixth chapter

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.