One
1. Implement kernel driver module
The directory structure of the driver Freg is as follows:
~/android-2.3_r1/kernel/goldfish
----drivers
----Freg
----Freg.h
----FREG.C
----Kconfig
----Makefile
Freg.h and Freg.c refer to the Linux character device driver http://blog.csdn.net/jltxgcy/article/details/29184391.
Kconfig as follows:
Config fregtristate "Fake Register Driver" Default nhelpthis is the Freg Driver for Android system.
Before compiling the driver Freg, we can set these compilation options by executing the make Memuconfig command so that you can specify how the driver Freg is compiled. The driver Freg can be compiled in three different ways. The first is built directly into the kernel, and the second is compiled into kernel modules, and the third Way is not compiled into the kernel.
This file defines the compiler options for the driver Freg.
TriState defines the pop-up interface for make Menuconfig and configures the name of the Freg compilation option.
Default n means that it is not compiled into the kernel.
Makefile as follows:
obj-$ (config_freg) + = FREG.O
where $ (config_freg) is a variable whose value is related to the compiler option for the driver Freg. If you choose to build the driver Freg into the kernel, the value of the variable $ (config_freg) is Y, and if you choose to compile the driver Freg in a modular way, the value of the variable $ (config_freg) is m; if the variable $ (config_freg) If the value is neither Y nor M, then the driver Freg will not be compiled.
2. Modify Kernel Kconfig
Open Arch/arm/kconfig, and find the following two lines of content:
Menu "Device Drivers" ... endmenu
Add the following line between the two lines to include the Kconfig file that the driver Freg.
Menu "Device Drivers" source "drivers/freg/kconfig" ... Endmenu
3. Modify Kernel Makefile File
In Drivers/makefile, add the following line:
obj-$ (config_freg) + = freg/
4. Compiling kernel driver module
First, execute the three-sentence command:
Export Android_product_out=~/android-2.3_r1/out/target/product/generic With this statement emulator not to join the three IMG file Export PATH = $PATH: ~/android-2.3_r1/out/host/linux-x86/bin/ emulator command Location Export path= $PATH: ~/android-2.3_r1/prebuilt/ Linux-x86/toolchain/arm-eabi-4.4.3/bin using when compiling the kernel
Then execute:
The following interface pops up:
Enable Loadable module support in front of the [], you can press Y (will show *) or n (nothing displayed), y means the kernel supports dynamic loading module, n means the kernel does not support dynamic loading module.
If y is pressed, then enter enable Loadable module Support, in the Sub-option "Module unloading", in the same vein, press Y, which means that dynamic unload module is supported.
Only press Y, in the first configuration page that pops up to select "Device Drivers" item, and then continue using the up and DOWN ARROW keys to select "Fake Register Driver" item in the second configuration screen, press Y or M key, You can see that the characters of the square brackets in front of the AO option become "*" or "M" symbols, respectively, that either compile the driver Freg into the kernel or compile it as a module.
Final execution:
The compiled kernel image files are zimage saved in the Arch/arm/boot directory.
Two
1. Develop C executable program to verify the Android hardware driver
~/android-2.3_r1/kernel/goldfish
----External
----Freg
----FREG.C
----ANDROID.MK
FREG.C refer to the Linux character device driver http://blog.csdn.net/jltxgcy/article/details/29184391.
Android.mk
Local_path: = $ (call My-dir) include $ (clear_vars) Local_module_tags: = Optionallocal_module: = freglocal_src_files: = $ ( Call All-subdir-c-files) include $ (build_executable)
Include $ (build_executable), which indicates that an executable application module is currently being compiled.
2. Compile C executable file
First execute the following command:
Once the compilation is successful, you can see a freg file in the Out/target/product/gerneric/system/bin directory.
Then pack:
The Android system image file System.img is generated under the Out/target/product/gerneri directory.
3, start the simulator, verify the correctness.
then adb shell.
Description our driver compiles correctly.