Android Deep Explore sixth chapter

Source: Internet
Author: User

Linux drivers: Count the number of words

I. Steps to write a Linux driver

1. Build Linux driver skeleton (load and unload Linux drivers)

The Linux driver needs to provide two functions to handle the work of driving initialization and exit separately, specified with Module_init and module_exit macros.

The driver's header file typically includes linux/module.h,linux/init.h,linux/kernel.h,linux/fs.h,linux/miscdevice.h and asm/uaccess.h.

The difference between printf and PRINTK: printf runs in user space, PRINTK runs in kernel space

2. Registration and destruction of equipment files

Use Misc_register to create device files and use Misc_deregister to remove device files.

3. Specify driver-related information

The driver is self-describing and needs to be specified in the driver source code.

Module_author Specify author name

Module_license Specify the open source protocol used

Module_alias specifying the driver alias

Module_description description of the specified driver

View. ko file information: modinfo. ko file

4. Specifying a callback function

A driver does not necessarily specify all of the callback functions, and the callback function is registered by the relevant mechanism.

5. Writing business logic

Business logic may consist of multiple functions, multiple files, or even multiple Linux driver modules

6. Writing the makefile file

7. Install and uninstall Linux drivers

Linux drivers exist as modules, need to load Linux driver modules with Insmod or modprobe commands, uninstall Linux drivers using the Rmmod command

Install driver: insmod. ko file

Unload driver: Rmmod module name

View log information for driver output: DMESG | grep Module Name | Tail-n 2

Two. Open Source Agreement

1.GPL Protocol 2.LGPL Protocol 3.BSD protocol 4.Apache Licence2.0 Protocol 5.MIT Protocol

Android Deep Explore sixth chapter

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.