Linux driver compilation and running

Source: Internet
Author: User
Linux driver compilation and running-Linux general technology-Linux programming and kernel information. The following is a detailed description. I read the source code of the buttons two days ago and learned how to compile the driver framework into the kernel today. The Makefile will not be written. It uses the makefile in the book (is it generic? It seems that any driver can be compiled using it ).

The compiled file is key_test.ko.

I. Manual Loading Test

1. insmod./key_test.ko load the driver module to the kernel.

2. Run cat/proc/modules | grep key_test to check the address of the key_test module in the kernel. If no filter is added, all loaded modules are displayed.

3. lsmod: display the module. The module names are displayed, followed by the main device number and secondary device number.

4. rmmod key_test uninstalls the module from the kernel.

Ii. Dynamic Loading

1. Put the key_test.c source code under/drives/char/of the kernel source code, because this is a compaction-type driver, which is compiled to zImage.

2. In this case, the key_test option is not displayed when we make menuconfig to compile the kernel. We can only write this option into the menu. There is a Kconfig file under/drives/char/in the kernel source code to open

(1) Add several lines to vi Kconfig:
Config ConFig_key_test
Bool "key test" // switch the previous bool to tristate to support modular compilation.

In the above sentence, the key test option will appear in make menuconfig under the drive/char sub-menu, and the TAB key is in front of bool.

------ Help ---------- this sentence appears under the menu options
This key test help. This is your driver description that will appear in help.

(2) Add the following sentence to the Makefile file in the/drivers/char directory:
Obj-$ (CONFIG_key_test) + = key_test.o
The above sentence is to compile key_test into the kernel during Make.

(3) make menuconfig select the key_test Option

(4) make zImage
Generate the zImage file and restart and load the new kernel.

3. lsmod will be able to see key_test, but it is not available yet. There is no interface, that is, there is no

4. mknod/dev/key_test c 121 0. This is the master device number defined in the source code that can be called by the common program after the device is created under/dev, 0 indicates the next device number.

5. cat/dev/key_test is equivalent to the open device, or write a program to directly call functions such as open and write.

Fd = ("/dev/key_test", ORW );
Related Article

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.