In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of how android compiles kernel drivers in the way of modules, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe you will gain something after reading this android article on how to compile kernel drivers in a modular way. Let's take a look.
9.5.2.1 Kernel and compiler paths
This section describes the kernel path, compiler path
As shown in the figure below, the author's android source code is in the "/ home/imx6/iTOP-iMX6_android4.4.2" directory, and the kernel source code is in the "kernel_imx" directory.
Go to the "kernel_imx" directory and view the script file in "build_android_kernel.sh", as shown in the following figure.
As shown in the figure above, we can get some information that when compiling the kernel module later, we need to set the compilation target platform to arm, "export ARCH=arm"; the path of the compiler is "$(pwd) /.. / prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/bin/arm-eabi-".
9.5.2.2 Makefile Fil
The author creates a new "imx_driver_modules" directory under the "/ home/imx6" directory and places the compiled drivers and Makefile files in this directory.
Makefile script file:
Obj-m + = iTOP-iMX6_driver_hello.o
KDIR = / home/imx6/iTOP-iMX6_android4.4.2/kernel_imx
PWD? = $(shell pwd)
All:
Make-C $(KDIR) masking $(PWD) modules ARCH=arm
CROSS_COMPILE=$ (KDIR) /.. / prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/bin/arm-eabi-
Clean:
Rm-rf modules.order * .o workqueue.o Module.symvers * .mod.c * .ko
In the script:
First line
Bj-m + = iTOP-iMX6_driver_hello.o means that the compiled source file is iTOP-iMX6_driver_hello.c, and if the name of the source file changes, it needs to be modified to the corresponding one.
The second line: the KDIR parameter points to the corresponding kernel source directory. The author's kernel source code is in the / home/imx6/iTOP-iMX6_android4.4.2/kernel_imx directory, and users need to change it according to their own specific conditions.
The third line: PWD? = $(shell pwd) means that the path of the current directory is assigned to the PWD variable, that is, / home/imx6/imx_driver_modules
Line 5: where make-C $(KDIR) MIMO $(PWD) modules indicates that the files in the current directory are compiled into modules and the path to the kernel source code is established
Where ARCH=arm indicates that the target CPU category is set to arm, that is, the compiled dependent kernel and driver module target CPU is ARM
Where CROSS_COMPILE=$ (KDIR) /.. / prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/bin/arm-eabi-, means to set the compiler path, and $(KDIR) is / home/imx6/iTOP-iMX6_android4.4.2/kernel_imx, so the complete path here is "/ home/imx6/iTOP-iMX6_android4.4.2/kernel_imx/../prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/bin/arm-eabi-" It just points to the path of the author's kernel compiler.
9.5.2.3 simple driver source code
The name of the driver file is iTOP-iMX6_driver_hello.c, and the source code is as follows:
# include
# include
MODULE_LICENSE ("Dual BSD/GPL")
MODULE_AUTHOR ("iTOPEET_dz")
Static int hello_init (void)
{
Printk (KERN_EMERG "Hello World enter!\ n")
Return 0
}
Static void hello_exit (void)
{
Printk (KERN_EMERG "Hello world exit!\ n")
}
Module_init (hello_init)
Module_exit (hello_exit)
The driver source code has only basic entry and exit functions. Print "Hello Worldenter!" when loading and uninstalling, respectively. And "Hello world exit!"
9.5.2.4 Module compilation
Copy the source code to the Ubuntu system as shown in the figure below.
Using the command "make", as shown in the following figure, you can see that the "iTOP-iMX6_driver_hello.ko" file is generated.
Using the command "make clean", you can delete intermediate files, as shown in the following figure.
9.5.2.5 FAQs in module compilation
In the process of compiling the driver as a module, the novice may have the following problems.
1. The kernel source code is not compiled or the kernel source code path is not set correctly.
If the kernel source code is not compiled, the module will prompt for errors such as missing libraries; if the path is not set correctly, the kernel will not be found.
two。 The source code and Makefile files are written under Windows and then copied to Ubuntu, resulting in transcoding errors due to different editors.
This kind of error is easy to solve. After Make is compiled, the system will prompt Makefile or a specific line of the driver file to have a problem. Use the vim editor to open and check, you can find some garbled, use the vim editor to correct it and then compile it.
9.5.2.6 Module loading and unloading
The author here uses the minimum linux system to test the loading and unloading of the module, which is described in Chapter 13 of the user manual. Before compiling the module, the kernel source code must be compiled and passed, the author here is in the minimum system to load the module, then the kernel source code must also be compiled into the qt kernel (the minimum system uses the qt kernel), otherwise it cannot be loaded.
As shown in the following figure, copy the ko file to the u disk, start the development board, insert the U disk into the development board (the usb interface near the network port), create a new folder with the command "mkdir / mnt/udisk", mount the drive letter with the command "mount / dev/sda1/mnt/udisk/", and copy the driver module to the development board with the command "cp-r / mnt/udisk/iTOP-iMX6_driver_hello.ko. /".
Then use the command "insmod iTOP-iMX6_driver_hello.ko" to load the driver module, as shown in the following figure, print out "Hello World enter!", indicating that the module driver loaded successfully.
Then use the command "rmmod iTOP-iMX6_driver_hello" to uninstall the module, as shown in the following figure, and find that there is no directory "/ lib/modules", so we follow the prompts to create a new directory.
As shown in the following figure, using the command "mkdir / lib/modules" to create a new directory, and again using the command "rmmodiTOP-iMX6_driver_hello" to uninstall the driver module, you are still prompted that there is no "3.0.35-g0e09bb1-dirty" path.
As shown in the following figure, use the command "mkdir / lib/modules/3.0.35-g0e09bb1-dirty" to create a new directory, uninstall the driver module again with the command "rmmod iTOP-iMX6_driver_hello", and find the print message "Hello worldexit!". The module is uninstalled successfully.
As long as you re-burn the write system, these new directories only need to be established once.
This is the end of the article on "how android compiles kernel drivers as modules". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how android compiles kernel drivers in a modular way". If you want to learn more, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.