Developing an Android driver that can count words (2)

Publisher:温暖的拥抱Latest update time:2024-10-21 Source: cnblogs Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

5. Specify driver-related information

Although it is not necessary to specify this information, a complete Linux driver will specify this driver-related information. Generally, the following information needs to be specified for a Linux driver.

1. Module author: specified using the MODULE_AUTHOR macro.

2. Module description: specified using the MODULE_DESCRIPTION macro.

3. Module alias: specified using the MODULE_ALIAS macro.

4. Open source agreement: use MODULE_LICENSE macro to specify.

In addition to this information, the Linux driver module itself also contains some information. Readers can execute the following command to view the information of word_count.ko.

# modinfo word_count.ko

After executing the above command, the information shown in Figure 6-6 will be output. Depends indicates the dependencies of the current driver module. Word_count does not depend on anything, so this item is empty. Vermagic indicates the Linux kernel version under which the current Linux driver module is compiled.

Now use the following code to specify the above 4 types of information. Generally, these codes are placed at the end of the word_count.c file.

MODULE_AUTHOR("lining");

MODULE_DESCRIPTION("statistics of wordcount.");

MODULE_ALIAS("word count module.");

MODULE_LICENSE("GPL");

Now use the method in the previous section to recompile the word_count.c file. Then execute the modinfo command, and the information shown in Figure 6-7 will be displayed. As can be seen from Figure 6-7, the information set by the above code is included in the word_count.ko file.

6. Open Source Agreement

Although many individual developers or small companies do not consider the restrictions of open source agreements, larger companies may be at risk of being sued if they violate open source agreements. Therefore, companies with a certain scale and influence must pay attention to the open source agreements used by these software when using open source software.

In order to reduce the difficulty of publishing Linux drivers and the size of the installation package, many Linux drivers are open source. In the Linux driver source code, the MODULE_LICENSE macro is used to specify the open source agreement. For example, the word_count driver uses the GPL agreement. So what agreement should we adopt when writing Linux' drivers? There are many open source agreements at present. Readers can go to the following page to view all open source agreements.

http://www.opensource.org/licenses/alphabetical

The following is an introduction to the basics of the five most commonly used open source protocols. For details of these five open source protocols and other open source protocols, please refer to the relevant pages of the Open Source Initiative organization.

GPL License

Programmers who like to delve into technology should like the GPL agreement very much. This is because the GPL agreement forces software that uses the open source agreement to be open source. For example, the Linux kernel uses the GPL agreement. The starting point of GPL is free/open source. But unlike other open source agreements (such as BSD, Apache Licence), the GPL agreement is more thorough in open source. Not only does it require software that uses the GPL agreement to be open source/free, but it also requires its derivative code to be open source/free. For example, software A uses the GPL agreement, and software B uses software A, so software B must also be free/open source. And its software B must also use the GPL agreement. Software C uses software B, so software C must also be open source/free, and of course, software C must also use the GPL agreement. This is the so-called "contagiousness." This is also the reason why there are many Linux distributions and other software that use the GPL agreement that are open source.

Since the GPL agreement strictly requires that software products using the GPL agreement must use the GPL agreement and must be open source/free. For commercial software or departments that have confidentiality requirements for code, it is not suitable to use the GPL agreement to release software or reference libraries based on the GPL agreement. In order to meet the needs of commercial companies and confidentiality, the LGPL agreement emerged on the basis of the GPL agreement.

LGPL

LGPL is an open source protocol designed mainly for class libraries. Unlike GPL, which requires that any software that uses/modifies/derives from GPL class libraries must adopt the GPL protocol. LGPL allows commercial software to use LGPL class libraries through class library references (links) without the need to open source the commercial software code. This allows open source code using the LGPL protocol to be referenced, published, and sold by commercial software as a class library.

However, if you modify or derive the LGPL-licensed code, all modified code, additional code involved in the modified part, and derived code must use the LGPL protocol. Therefore, the LGPL-licensed open source code is very suitable for being referenced by commercial software as a third-party class library, but it is not suitable for commercial software that wants to use the LGPL-licensed code as a basis for secondary development through modification and derivation.

BSD License

The BSD open source protocol is a protocol that gives users great freedom. Basically, users can "do whatever they want", they can freely use and modify the source code, and they can also release the modified code as open source or proprietary software. However, the premise of "doing whatever you want" is that when you release the code using the BSD protocol, or when you use the BSD protocol code as the basis for secondary development of your own products, you need to meet the following three conditions.

1. If the redistributed product contains source code, the source code must contain the BSD license in the original code.

2. If you are only releasing a binary library/software, you need to include the BSD license in the original code in the library/software documentation and copyright statement.

3. You may not use the name of the author/institution of the open source code or the name of the original product for marketing purposes.

The BSD protocol encourages code sharing, but it is necessary to respect the copyright of the source code author. BSD allows users to modify and republish code, and also allows the use or development of commercial software on BSD code for release and sale, so it is a very friendly protocol for commercial integration. Many companies and enterprises prefer the BSD protocol when choosing open source products, because they can fully control these third-party codes and can modify or redevelop them when necessary.

Apache License 2.0

Apache Licence is a license adopted by the famous non-profit open source organization Apache. This license is similar to BSD, and also encourages code sharing and respects the copyright of the original author. It also allows code modification and re-release (as open source or commercial software). The conditions that need to be met are also similar to BSD.

1. You need to give the user of the code an Apache License

2. If you modify the code, you need to indicate it in the modified file.

3. The extended code (modified and derived code from the source code) must include the original code's agreement, trademark, patent statement and other instructions required to be included by the original author.

4. If the re-released product contains a Notice file, the Apache Licence must be included in the Notice file. You can add your own license in the Notice, but it cannot be expressed as an Apache Licence.

Apache Licence is also a commercial application-friendly license. Users can also modify the code to meet their needs when necessary and publish/sell it as open source or commercial products.

MIT Protocol

MIT is a loosely restricted license like BSD. The author only wants to retain copyright without any other restrictions. In other words, you must include the original license statement in your distribution, whether you release it in binary or source code.

7. Register and unregister device files

This section will create a device file for the word_count driver. The name of the device file is wordcount and it is located in the /dev directory. Device files are different from ordinary files. They cannot be created using IO functions. Instead, they need to be created using the misc_register function and deregistered (removed) using the misc_deregister function. The definitions of these two functions are as follows:

extern int misc_register(struct miscdevice * misc);
extern int misc_deregister(struct miscdevice*misc);

Generally, it is necessary to create a device file when initializing the Linux driver and delete the device file when uninstalling the Linux driver. In addition, the device file also requires a structure (miscdevice) to describe the information related to it. There is an important member variable fops in the miscdevice structure, which is used to describe the function pointer of the device file in various triggerable events. The data type of this member variable is also a structure file_operations.

In this section, you need to modify the word_count_init and word_count_exit functions of the word_count.c file and define some macros and variables. The modified code is as follows:

// Define the device file name
#define DEVICE_NAME "wordcount"
//Describes the callback function pointer corresponding to the event triggered by the device file
// owner: which driver modules the device event callback function is applied to, THIS_MODULE means it is applied to the current driver module
static struct file_operations dev_fops =
{ .owner = THIS_MODULE};
//Describe the information of the device file
// minor: minor device number MISC_DYNAMIC_MINOR,: dynamically generated minor device number name: device file name
//fops: file_operations structure variable pointer
static struct miscdevice misc =
{ .minor = MISC_DYNAMIC_MINOR, .name = DEVICE_NAME,.fops = &dev_fops };
// Initialize the Linux driver
static int word_count_init(void)
{
int ret;
// Create device file
ret = misc_register(&misc);
// Output log information
printk("word_count_init_successn");
return ret;
}
// Uninstall the Linux driver
static void word_count_exit(void)
{
// Unregister (remove) device file
misc_deregister(&misc);
// Output log information
printk("word_init_exit_successn");
}

There are a few things to note when writing the above code:

[1] [2]
Reference address:Developing an Android driver that can count words (2)

Previous article:Developing an Android driver that can count words (3)
Next article:Developing an Android driver that can count words (1)

Recommended ReadingLatest update time:2024-11-15 07:31

Huawei: Hongmeng smartphones will not be launched for now unless the US stops supplying Android
According to US technology media CNET, although Huawei has been vigorously promoting the power of its Harmony operating system, the company said it hopes to maintain the Android ecosystem and therefore has no plans to launch a Harmony phone, unless the United States imposes a ban to prevent Huawei from accessing key A
[Mobile phone portable]
Huawei: Hongmeng smartphones will not be launched for now unless the US stops supplying Android
Google Android 12L already supports long screenshots in WebView
      The Android 12 system natively supports the long screenshot function. This function is different from the screenshots developed by many OEM manufacturers. It is not implemented by stitching multiple pictures, but is based on View, that is, recognizing the structure of the view, with better performance and effect
[Mobile phone portable]
Research on high power LED street lighting driver
1 The significance and value of LED drive circuit research LED has become the focus of attention in the lighting field due to its many advantages such as energy saving and environmental protection, long life, high photoelectric efficiency, and short startup time. It has developed rapidly in recent years. Due to the un
[Power Management]
Research on high power LED street lighting driver
Android phones collect 20 times more user data than comparable iPhones
       Sina Digital News reported on the morning of March 31 that a study conducted by a computer science professor at Trinity College Dublin in Ireland found that Android phones collect 20 times more user data than similar iPhones.   According to Doug Leith, a researcher and the college's chair of computer systems, b
[Mobile phone portable]
74HC595 MCU C51 driver (source code)
#include "reg52.h" #define uchar unsigned char sbit HC595_CS=P1^0; //STcp ////Latch clock-----74HC595 12#  sbit HC595_CLK=P1^1; //SHcp ////Shift clock-----74HC595 11#  sbit HC595_DAT=P1^2; //Ds ////Data---------74HC595 14#  //Delay subroutine void mDelay(float Delay) { fly i;     for(;Delay 0;Dela
[Microcontroller]
Industry technical tips: Teach you how to correctly choose LED driver power supply
Although the stability of LED lights has reached a relatively good level recently , some products have problems with light decay and color drift, mainly due to unreasonable heat dissipation design. Relatively speaking, the problem of LED light drive power supply is much more serious, which is the main reason for dead
[Power Management]
LYTSwitch-0 LED Bulb and T8 Tube Driver Review
The LYTSwitch-0 product family is designed specifically for low-cost LED bulb and T8 tube applications. LYTSwitch-0 devices integrate a 700 V power MOSFET, oscillator, on/off control scheme, EMI reduction and multiple control functions (including cycle-by-cycle current limit and thermal shutdown circuitry) on a single
[Power Management]
LYTSwitch-0 LED Bulb and T8 Tube Driver Review
Five key points to simplify LED driver design
  The future world is believed to be the world of LEDs. With its development, its necessary supporting LED drivers are also inevitable. Therefore, how to solve the problems that may be encountered in the design of LED drivers is an issue that all major design manufacturers face. This article analyzes five problems enc
[Power Management]
Five key points to simplify LED driver design
Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号