The sixth chapter of Android Deep Exploration is about the first Linux driver: counting the number of words. 1. To write a Linux driver: Step 1th: Build a Linux driver skeleton (load and unload Linux drivers), which are specified with Module_init and module_exit macros, and step 2nd: Register and unregister device files using MISC_ respectively Register and Misc_deresiger functions to create and remove device files; 3rd step: Specify driver-related information through Module_author, Module_license, Module_alias, Module_ Description and other macros can specify driver-related information; 4th: Specify the callback function, a driver does not have to specify all the callback functions, the return function will be registered through the relevant mechanism; Step 5th: Write the business logic; step 6th: Write the Makefile file Step 7th: Compile the Linux driver; step 8th: Install and uninstall Linux drivers. 2. Test Linux drive: Test Linux drivers with Ubuntu Linux, test Linux drivers using the Android NDK, and use Java code to directly manipulate the device files for Linux drivers, Test the Linux driver by running an executable program on the S3C6410 board and compiling the driver into the kernel for testing. 3. Developing Linux drivers in Eclipse: 1th step: Build C Project, 2nd step: Establish C source code file link, 3rd step: set include path; 4th step: Compile Linux driver. 4. Test Linux driver in Eclipse: 1th step: Import test_word_count.c file, 2nd step: Set include path, 3rd step: Set Target, 4th step: Build Project, 5th step: Run test program.
By studying the sixth chapter, I know that the Linux system maps every driver into a single file. These files are called device files or drive files and are saved in the/dev directory. This design concept makes interacting with Linux drivers as easy as interacting with ordinary files. Of course, it's easier than accessing the Linux API. Since most Linux drivers have their corresponding device files, exchanging data with the Linux driver becomes the exchange of data with the device files. The most important step in writing a Linux driver is to write a callback function, otherwise data that interacts with the device file will not be processed. You can test Linux drivers directly using Ubuntu Linux, and there are many drivers that can be installed directly on Android, Linux and other embedded systems once they are compiled again with the appropriate Linux kernel. Of course, Linux drivers can also be tested on Android simulators, boards, and even mobile phones. To develop Linux drivers faster, you can also consider using the Eclipse integrated development environment.
"Android Deep Exploration" sixth chapter experience