the Linux system maps each driver into a single file. These files are called device files or drive files and are saved in the/ dev directory.
Since most Linux drivers have their corresponding device files, exchanging data with the Linux driver becomes the exchange of data with the device files.
To write a Linux driver:
Step 1 : Build a linux driver skeleton (load and unload Linux drivers).
Step 2 : Register and unregister the device files.
Step 3 : Specify driver-related information.
Step 4 : Specify the callback function.
Step 5 : Write the business logic.
Step 6 : Write the Makefile file.
Step 7 : Compile the Linux driver.
Step 8 : Install and uninstall Linux drivers. ( the first 5 steps in step 8 above are about how to write a Linux driver, after 3 The Linux driver to work properly. )
InAndroidin the systemLinuxThe main users of the drive areAPKprogram. Therefore,Linuxwhen the driver is finished , it must be usedAPKprogram to be tested to illustrateLinuxThe driver can be used normally. Since the previous sectionAndroiduse on virtual machinesCthe executable program written by the language tests theLinuxDrive, so it's easy to think about the useANDROIDNDKto testLinuxDrive, due toAndroid NDKalso useC + +to write a program, so you can take advantage of the previous section'sClanguage code, of course, plus someANDROIDNDKunique code. When usingANDROIDNDKTestLinuxThere are two things to do before driving. (becauseLinuxThe drive module does not follow theAndroidthe system starts and loads, so you must performbuild.shscript File InstallationWord CountDrive. Cannot start using default modeAndroidemulator, and to use our own compiledLinuxKernel bootAndroidsimulation. )
Android Deep Exploration (Vol. 1) HAL and Driver Development chapter Sixth