This article goes from WebEx to:http://www.topeetboard.com
Hello everyone, this chapter will show you how to implement a module-loaded kernel driver under Linux. We use the buzzer inside the kernel.
Drive as an example to explain.
1) First open the kernel source code, as shown in:
2) Use the command "CD drivers/char/" to enter the directory where the buzzer driver is located, as shown in:
3) Then use the command "vi Kconfig" To open the kernel configuration file in the current directory, as shown in:
4) Then findthe location where "config buzzer_ctl" is located, as shown in:
5) then change the "bool" Enable buzzer config "" line to "tristate" Enable buzzer config ""as shown in:
6) then save and exit as shown in:
7) then go back to the root directory of the kernel source, as shown in:
8) then enter the command "makemenuconfig" To configure the kernel as shown in:
9) Select " Device Drivers ", "Character Devices", "Enable buzzer config"as shown in:
Then change the "*" on the left of" Enable buzzer config " to "M", as shown in:
11) then save and exit the configuration interface, such as:
then use the command " vi arch/arm/mach-exynos/mach-itop4412.c" to open the mach-itop4412.c, As shown in the following:
then find the " struct platform_device s3c_device_buzzer_ctl " line, as shown in:
Change the " #ifdef config_buzzer_ctl"in front of this line to "#if defined (config_buzzer_ctl) | |
Defined (config_buzzer_ctl_module) "as shown in:
then find the " &s3c_device_buzzer_ctl" line, as shown in:
Change the " #ifdef config_buzzer_ctl"in front of this line to "#if defined (config_buzzer_ctl) | |
Defined (config_buzzer_ctl_module) "as shown in:
then save and exit, and return to the root directory of the Linux kernel source code as shown in:
then enter the command "make" to start compiling the kernel as shown in:
After compiling, theimage file "zimage" is generatedin the kernel's " arch/arm/boot" Directory, as shown in:
Thedriver module " Itop4412_buzzer.ko" of the buzzer is generatedin the " drivers/char" Directory of the kernel, as shown in:
21) Next we burn write the generated zimage onto the development Board and then the Development Board boots into the Android system.
22) then pass the driver module of the buzzer to the "/data" Directory of the Development Board via ADB , as shown in:
23) Then the serial port input command "cd/data", into the Development Board "/data" directory, as shown in:
and then enter the "ls" command to see The buzzer driver module passed through the adb " Itop4412_buzzer.ko ", such as
As shown:
25) Then in the serial Port input command " insmod Itop4412_buzzer.ko ", load the buzzer driver, as shown in:
by the driver that can see the buzzer is loaded into the kernel, and then enter the command "cd/dev" as shown in:
by the above picture, you can see the node that generated the " buzzer_ctl" buzzer, we need to enter " chmod 777 buzzer_ctl"
command to modify the permissions under buzzer_ctl , as shown in:
then we can use the android 's own buzzer applet to control the buzzer, so that the module to load the driver is completed.
Above our drive is placed in the kernel source directory down the implementation of the compilation into the driver module, many times we are getting a driver source code,
Do not need to put him into the kernel source, but directly to compile him into a driver module, the following we are to implement the method, we still use the buzzer
As an example to explain the driver.
1) because the core of the Development Board with the default is to compile the buzzer directly into the kernel, so we have to repeat the front step "1" to the Step "",
After completing these steps, burn the generated image "zimage" to the Development Board.
2) Then create the folder "module"with the command mkdir in the directory of the virtual machine , as shown in:
3) Then use the command CD to enter the established "module" folder, as shown in:
4) The buzzer inside the copy kernel is driven to the module folder, as shown in:
5) then Create the file "Makefile" in the module folder, as shown in:
6) Then Enter the following information in the "Makefile" file:
Obj-m + = ITOP4412_BUZZER.O
Kdir: =/home/broswer/itop4412_kernel_3.0
PWD = $ (shell pwd)
All
Make-c $ (Kdir) m=$ (PWD) modules
Clean
RM-RF *.O
One of the "kdir: =/home/broswer/itop4412_kernel_3.0" is the designated directory of our kernel source code, I here the kernel source
is placed under the " /home/broswer/" directory, you need to modify this place according to your own storage location
7) then save and exit Makefile, enter "make" command in terminal, compile buzzer driver, as shown in:
8) After compiling, you can look under the "module" folder generated " Itop4412_buzzer.ko", as shown in:
9) You can thenTest Our compiled buzzer driver by referring to the previous step "a".
[Embedded Development Board]itop-4412 in a modular way to compile the driver