Sixth chapter
Linux drives work and access is one of the highlights of Linux, and the Linux system maps each driver into a single file. These files, called device files or drive files, are stored in the/dev directory, and since most Linux drivers have their corresponding device files, exchanging data with Linux drives becomes a data exchange with the device files. Describes how to test Linux drivers in a variety of ways on multiple platforms. The given example is the number of statistical words, but the key to implement the algorithm is the Linux
Driven.
(a), the steps to write a Linux driver
1. Build Linux driver skeleton (load and unload Linux drivers)
In the Linux driver, you need to provide two functions to handle the operation of the driver initialization and exit separately. The two functions are specified with Module_init and module_exit macros, respectively.
2. Registering and unregistering device files
Deleting a device file is typically done in the 1th step of the function that handles the Linux exit. You can create and remove device files using the Misc_register and Misc_deregister functions, respectively.
3. Specify driver-related information
You can get the driver's author name, open source protocol, alias, driver description and other information through the Modinfo command.
4. Specifying a callback function
A driver does not necessarily specify all of the callback functions. The callback function is registered through 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
To write a new Linux driver, you must have a makefile file.
7. Compiling Linux Drivers
Linux drivers can be compiled directly into the kernel or can be compiled separately as modules
8. Install and uninstall Linux drivers
If the Linux driver is compiled into the kernel, the driver will automatically load as soon as Linux uses the kernel. If the Linux driver is present in a separate module, you need to load the Linux driver module with the Insmod or modprobe command and uninstall the Linux driver module using the RMMOD command
9. The first 5 steps in step 8 above are about how to write a Linux driver, and after 3 steps can make the Linux driver work properly
(ii) First Linux driver: Count the number of words
The complete code for the Java Section (Wordcountndktestmain.java):
Import android.app.Activity;
Import Android.os.Bundle;
Import Android.view.View;
Import Android.widget.EditText;
Import Android.widget.TextView;
Import Android.widget.Toast;
public class Wordcountndktestmain extends Activity
{
Private TextView Tvwordcount;
Private EditText etstring;
@Override
public void OnCreate (Bundle savedinstancestate)
{
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
Tvwordcount = (TextView) Findviewbyid (R.id.textview_wordcount);
etstring = (EditText) Findviewbyid (R.id.edittext_str ...
(iii), the driver is compiled into the Linux kernel for testing
The dynamic load driver module does not automatically mount with the Android system booting, so the Android system must be loaded with the Insmod or modprobe command every time the Linux driver module is booted. The Word_count driver can be added to the Linux kernel source tree using the following steps.
1. Put the word_count.c file into the Linux kernel source code
Place the word_count.c file in the <linux kernel directory >/drivers/char directory
2. Modify the Kconfig file
Open the/root/kernel/goldfish/drivers/char/kconfig file, locate Endmenu, and add the following code in front of Endmenu:
Config Word_count
BOOL "Word_count Driver"
Help
3. Modify the Makefile file
Open the/root/kernel/goldfish/drivers/char/makefile file.
4. Set the. config file
The. config file can be configured manually or through the make Menuconfig command in the menu.
5. Compiling the Linux kernel
Enter the/root/kernel/goldfish directory and execute the following command to compile the Linux kernel.
# make
6. Create a new Kconfig file
Create a Kconfig file in the Word_count directory and enter the following:
Config Word_count
TriState "Word_count Driver"
Default Y
Help
This is a word count driver. It can get a word count from/dev/wordcount
(iv) Development of Linux drivers in eclipse
1. Building C Project
Click the File > New > Other menu item in Eclipse to open the New dialog box and select the C project item (optional C + + project item)
2. Establish C source code file link
Click the "new" > "Soruce Folder" menu item in the Word_count_eclipse Project context menu to open the "New Soruce folder" dialog box and enter "src" in the "folder name" text box
3. Setting the Include path
Click the "Properties" menu item in the Word_count_eclipse project's context menu (or select Word_count_eclipse, press Alt+enter) to open the Project Properties dialog box. Select the "C + + General" > "Paths and Symbols" item, select the "GNU C" entry on the right "includes" page, and click on the "Add" button on the right to add the following two paths,/root/kernel/goldfish/ Include
/root/kernel/goldfish/arch/arm/include
4. Compiling Linux Drivers
Add a program to the project and remove the check boxes before the system's two established entries. where argument directly fill in the path of the script file can be
http://www.cnblogs.com/xxyue/
Android Drive Development Reading note six