Linux Drive Learning Note 02--Application example: New driver code directories and subdirectories in the kernel

Source: Internet
Author: User
Tags parent directory

Here is a comprehensive example, assuming we want to add the following to the ARM architecture in the kernel source code drivers Directory
Tree Catalog for test driver:
| --test
| --CPU
| --CPU.C
| --TEST.C
| --TEST_CLIENT.C
| --TEST_IOCTL.C
| --TEST_PROC.C
| --TEST_QUEUE.C
To add directories and subdirectories to the kernel, we need to create Makefile and Kconfig files for the corresponding additions, and the new
The Kconfig and Makefile in the parent directory of the add-in directory also need to be modified so that the new Kconfig and Makefile can be referenced.
In the new test directory, the following Kconfig files should be included:

1 #2 # TEST Driver Configuration3 #4Menu"TEST Driver"5Comment"TEST Driver"6 Config config_test7     BOOL "TEST Support"8 config Config_test_user9TriState"TEST User-space Interface"Ten depends on Config_test OneEndmenu

Because test driver is a new feature for the kernel, a menu test driver needs to be created first. Then, the "Test support" is displayed, waiting for the user to select, and then the user is determined whether the test Driver is selected, if Yes (config_test=y),

Further display sub-function: User interface and CPU function support, because the user interface function can be compiled into kernel module, so the query statement here uses TriState. To make this Kconfig work, modify the Arch/arm/kconfig file to add:
SOURCE "Drivers/test/kconfig"

The source in the script means referencing the new Kconfig file.

In the new test directory, the following Makefile files should be included:

 1  # Drivers/test/makefile  2  #  3  # Makefile for   the TEST.  4  5  obj-$ (config_test) += TEST.O test_queue.o test_client.o  6  obj-$ (config_test_user) += TEST_IOCTL.O  7  obj-$ (config_proc_fs) += TEST_PROC.O  Span style= "color: #008080;" >8  obj-$ (config_test_cpu) + = cpu/

The script builds the obj-* list based on the value of the configuration variable. Because the test directory contains a subdirectory CPU, when config_test_cpu=y, the CPU directory needs to be added to the list.
The CPU subdirectories in the test directory should also contain the following Makefile:

1 # drivers/test/test/Makefile2#3 for the test CPU 4 # 5 obj-$ (config_test_cpu) + = CPU.O

In order for the entire test directory to be compiled commands, the Makefile in the test directory parent Directory also needs to be added as follows
Script:

Obj-$ (config_test) + = test/

Adding obj-$ (config_test) + = test/in Drivers/makefile allows the user to compile the kernel
Access to the test directory.
After adding Kconfig and Makefile, the new test tree directory is:
| --test
| --CPU
| --CPU.C
| --Makefile
| --TEST.C
| --TEST_CLIENT.C
| --TEST_IOCTL.C
| --TEST_PROC.C
| --TEST_QUEUE.C
| --Makefile
| --Kconfig

Go back to the main Linux source directory, execute the Make Menuconfig command, go to the device drivers option, see the newly added options,

You can see that test driver is already in the Menuconfig, and it's not surprising that the configuration options we've added are already available. (According to the original book slightly modified the drivers in the Kconfig, and finally added the source Drivers/test/kconfig,

The newly added content will appear under the device Drivers option, plus the set CPU freq option is added.

Linux Drive Learning Note 02--Application example: New driver code directories and subdirectories in the kernel

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.