Process Analysis of Two loading methods for Linux drivers

Source: Internet
Author: User

I. Brief Introduction to concepts

In Linux, you can load the driver in two ways: Static Loading and dynamic loading.

Static Loading is to directly compile the driver into the kernel, which can be called directly after the system is started. The disadvantage of static loading is that it is troublesome to debug. You need to re-compile and download the kernel each time you modify a local file, which is less efficient. If a large number of drivers are used for static loading, the kernel capacity will be large and storage space will be wasted.

Dynamic Loading utilizes the module feature of Linux. After the system is started, you can use the insmod command to add a module (. ko), use the rmmod command to uninstall the module when it is not needed. This dynamic loading method is used to facilitate debugging of the driver. At the same time, the kernel can be tailored to the functional requirements of the product, remove unnecessary drivers, greatly reducing the storage capacity of the kernel.

On a desktop, the dynamic loading mode is generally used. In embedded products, you can use the Dynamic Loading Mode for debugging. After successful debugging, You can compile it into the kernel.

Ii. instance analysis

The following uses the loading of the audio driver in Linux as an example to analyze the loading process of the two methods.

1. Static Loading

1) decompress the kernel and modify the hardware architecture and compiler;

Decompress the internal compressed file linux-2.6.8.1-zzm.tar.bz2 to the/home/sxy/directory, the command is, extract the kernel source code directory file linux-2.6.8.1-zzm, enter the directory, edit Makefile file, change ARCH to arm, change CROSS_CPMPILE to arm-linux, as shown in:


Save and exit.

2) configure the kernel;

In the kernel source code tree directory, enter the make menuconfig command to enter the Kernel Configuration interface, enter the "Load an Alternate Configuration File" option, Load the Configuration File kernel_2410.cfg, and save and exit, as shown in the process:




Enter the make menuconfig command again and edit the sound option,Compile it into the kernel (*), As shown in the result, save the configuration and exit.

3) Compile the kernel;

Enter the make zImage command in the source code tree directory. After compilation, you can generate a zImage file in the/arch/arm/boot/directory.

4) download the kernel

Download the kernel image file zImage to the development board. When the serial port terminal displays the following information, the driver is loaded successfully.

2. Dynamic Loading

1) decompress the kernel. The process is the same as that during static compilation;

2) configure the kernel. The previous process is the same as during static compilation. Run the make menuconfig command again. When the sound option is configured,Compile it into a module (M)The result is shown in. Save the configuration and exit;

In this way, the audio card driver is compiled into a module, and you can dynamically choose whether to load it to the kernel.

3) download the kernel

Download the kernel image file zImage to the Development Board to verify whether the sound card can be driven as follows:

Note: first, mount the/home/directory under the virtual machine to the/tmp/directory on the Development Board, and thenSuccessivelyLoad soundcore. ko and s3c2410-oss.ko modules, and finally through the lsmod command to check whether to load the sound card driver, the results show that the load is successful, so that you can program in the application space, audio recording and other operations.

PS: ① When the make menuconfig command is used, option * Indicates Y, which indicates compiling the driver into the kernel; M indicates compiling the driver into a module; null indicates N, which indicates not compiling;

② There are many things that must be matched between the kernel file and the module, such as the compiler version, source code version, and configuration during compilation. Therefore, when the Kernel File is modified, for example, if you modify the driver's compilation options (Y, M, and N), you must re-compile and download the kernel. Otherwise, an error occurs.

Iii. Problems Encountered

Problem:The following error occurs during dynamic loading:

Error: The device registration and logout symbols are unknown.

Solution:Search for dependencies and view the definitions of several symbols. We found that the above functions are defined in the soundcore. c file and the symbols are exported. Take register_sound_dsp as an example, as shown in:

So you should first load soundcore. ko, and then load the s3c2410-oss.ko.

Note: dependencies are defined in the Kconfig and Makefile files. You can also find the cause of the problem.

Saturday, June 21, 2014

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.