New kernel driver code directories and subdirectories

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/Sophisticated_/article/details/88253749

Suppose we want to add drivers in the kernel source directory for the ARM architecture as a test driver directory tree of
Here Insert Picture Description
increased directories and subdirectories in the kernel, we need to create the corresponding new directory Kconfigand Makefilefile, while the new directory parent directory Kconfig and also need to modify the Makefile to Makefile and the new files can be referenced Kconfig

In the new test directory should contain the following Kconfigfiles:

# 
# TEST driver configuration
#
menu "TEST Driver "
comment " TEST Driver"

config CONFIG_TEST
	bool "TEST support "

config CONFIG_TEST_USER
	tristate "TEST user-space interface"
	depends on CONFIG_TEST

endmenu

Because TEST driver for the kernel is a new feature, so you first need to create a menu TEST Driver; then display "TEST support", waits for the user to select; next determine whether the user has selected TEST Driver, if it is (CONFIG_TEST = y), further shows the functions: support a user interface with the CPU functions; as a user interface function may be compiled into the kernel module, the query statements used herein tristate

To make this Kconfig file to work, you need to modify arch / arm / Kconfig file, add the following

source "drivers/test/Kconfig"

Script source means that references the new file Kconfig

In the new test directory should contain the following Makefilefiles:

# drivers/test/Makefile
#
# Makefile for the TEST.
#

obj-$(CONFIG_TEST) += test.o test_queue.o test_client.o
obj-$(CONFIG_TEST_USER) += test_ioctl.o
obj-$(CONFIG_PROC_FS) += test_proc.o

obj-$(CONFIG_TEST_CPU) += cpu/

The script builds a list based on the value obj- * configuration variables. Since test directory contains a subdirectory cpu, when CONFIG_TEST_CPU = y, need to be added to the directory list cpu

cpu test directory contains the following subdirectories also need the Makefile

# drivers/test/test/Makefile
#
# Makefile for the TEST CPU
#

obj-$(CONFIG_TEST_CPU) += cpu.o

In order to make the entire test catalog can be compiled to a command role, Makefile file test directory parent directories also need to add the following script

obj-$(CONFIG_TEST) += test/

Obj added in drivers / Makefile in - $ (CONFIG_TEST) + = test /, so that the user can during the test directory compiled kernel

The new test directory tree adds Kconfig and after the Makefile is as follows:
Here Insert Picture Description

Guess you like

Origin blog.csdn.net/Sophisticated_/article/details/88253749