Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to compile a single driver file in linux

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 to compile a single driver file in linux, 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 linux article on how to compile a single driver file. Let's take a look at it.

1. First of all, you have to have all the source code, which is necessary.

For example, I download to the directory / home/lany/workspace/linux-sunxi

If it is a cross-compilation, execute first:

Export ARCH=arm

Export CROSS_COMPILE=arm-linux-gnueabihf-

two。 Go to this directory and create a configuration file. Cubieboard can use sun4i_defconfig as a configuration.

Cd / home/lany/workspace/linux-sunxi

Make sun4i_defconfig

After generating the .config of the default configuration, you can open the configuration item of the driver you want in the .config (you can edit the .config directly or use the make menuconfig image interface to configure it). Here, I use the sun4i_gpio driver as a list:

Vi. / .config

/ GPIO # Press / key to enter GPIO enter (that is, search for the word GPIO)

Change the line of GPIO configuration you found to CONFIG_SUN4I_GPIO_UGLY=m

Then save and exit.

# Note: if you are compiling other drivers that are slightly more complex, such as several drivers in gpu, they have dependencies. It is recommended to use make menuconfig to configure them.

3. After saving, ask him to prepare:

Make prepare

Make scripts

4. Now let's go to the source directory of the driver to be compiled, such as sun4i-gpio.c in the drivers/misc directory:

Cd / home/lany/workspace/linux-sunxi/drivers/misc/

Make-C / home/lany/workspace/linux-sunxi/ M = `pwd` modules

#-C is followed by the directory of the kernel source code you downloaded, M = `pwd`, which means that the module directory to be compiled is specified as the current directory

First check to see if the compiled version of the driver is the same as your system, if it is not the same, it cannot be used:

Modinfo / home/lany/workspace/linux-sunxi/drivers/misc/sun4i-gpio.ko

Output:

Filename: / home/lany/workspace/linux-sunxi/drivers/misc/sun4i-gpio.ko

License: GPL

Author: Tom Cubie

Description: a simple sun4i_gpio driver

Depends:

Vermagic: 3.0.57 + mod_unload modversions ARMv7

You can see that the version is 3.0.57 + mod_unload modversions ARMv7, and my system version is 3.0.57. If not, you need to recompile the source code checkout to the branch of your corresponding version, or compile directly and completely, and replace the system kernel uImage with a new one (but then your other drivers will have to be replaced)

If there are other characters between 3.0.57 + and mod_unload, you should check to see if other drivers in your system have the same character, which cannot be used if it doesn't match.

5. If there is no problem, copy sun4i-gpio.ko directly to / lib/modules/ (your kernel version) / kernel/drivers/misc/ (that is, where the driver should be, not all drivers).

Then insmod / lib/modules/ (your kernel version) / kernel/drivers/misc/sun4i-gpio.ko

If there is no error, then congratulations, has been loaded successfully, you can use the command: lsmod view. If there is an error, enter the command: dmesg | tail to view the detailed error information. Then go to google (it is usually difficult to solve, in this case, you'd better change the kernel and all the drivers)

If you report this mistake:

Sun4i_gpio_init script_parser_fetch "gpio_para"gpio_used" error

[607.040000] sun4i_gpio_init script_parser_fetch "gpio_para"gpio_used" error

Insmod: error inserting 'sun4i-gpio.ko':-1 Interrupted system call

Copy the code

That is, you did not set the gpio_para configuration in script.bin. After setting it, insmod will OK.

6. If the driver test works properly and you need it every time you boot the system, you can add it to the boot self-loading module:

Depmod-a

Vi / etc/modules

Save exit, note: for some dependent drivers, you need to pay attention to the order.

This is the end of the article on "how to compile a single driver file in linux". Thank you for reading! I believe you all have a certain understanding of "how to compile a single driver file in linux". 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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report