By Sam (zhufeng) sam_code@hotmail.com
Sam needs to check the USB mouse code in 2.6 kernel. By the way, let's talk about the relationship between makefile and kconfig files in the kernel and how they can be used together.
Background:
Background 1: kconfig introduction:
In# Make menuconfigThe displayed menu list is composed of kconfig of each layer.
The underlying kconfig is stored in ~ /ARCH/i386/kconfig. With this header, it uses source layer by layer to add keconfig to various directories to be added.
For example:Source "Drivers/kconfig"
Then ~ Add/Drivers/kconfig to the menu list.
Background Knowledge 2: Syntax of kconfig:
Config hid
Tristate "generic hid support"
Depends on input
Default y
--- Help ---
A human interface device (HID) is a type of computer device that interacts directly with and takes input from humans. the term "hid" most commonly used to refer to the USB-HID specification, but other devices (such as, but not strictly limited to, Bluetooth) are designed using hid specification (this involves certain keyboards, mice, tablets, etc ). this option compiles into kernel the generic hid Layer Code (parser, usages, etc .), which can then be used by transport-specific hid implementation (like USB or Bluetooth ).
For docs and specs, see http://www.usb.org/developers/hidpage/
If unsure, say y
Explanation:
Config hid: Indicates that this entry corresponds to the CONFIG-HID. CONFIG-HID is used in makefile.
Tristate "generic hid support"The content in the quotation marks is displayed in the menu list. Tristate indicates that this item is in three states.
Depends on input: Dependent on input. If no input is selected, this option is not displayed in menu list.
Default y: Selected by default.
Background Knowledge 3: built-in.o
Vmlinux is the kernel that is not compressed after the Linux source code is compiled. vmlinux is composed of arch/i386/kernel/head. O and arch/i386/kernel/init_task.o and the built-in.o links under each related subdirectory.
Background 4: Kernel makefile
The makefile System in the kernel and how to compile it, in fact, Sam has always been a bit knowledgeable.
The makefile in the kernel directory is calledUnderlying makefile.
After the kernel is successfully configured using a command similar to # Make menuconfig. ConfigFile.
In other words, when make menuconfig, makefile starts from ~ /ARCH/i386/kconfig read kconfig. Generate the. config file.
For example, in drivers/HID/kconfig:
Config hid
Tristate "generic hid support"
If you select y, it will be reflected in. config:
Config_hid = y
Then in ~ /Drivers/makefile:
OBJ-$ (config_hid) + = hid/
Indicates that if config_hid is Y, add the hid directory to the directory to be compiled.
Go to the/driver/hid directory and you will see:
Hid-objs: = hid-core.o hid-input.o
It indicates that these two. O files will be compiled.
OBJ-$ (config_hid) + = hid. o
Indicates that if config_hid is Y, hid. O will be compiled. And built-in.
If it is = M., hid. O is compiled, but finally made into modules (KO)
BACKGROUND 5: kbuild make:
The makefile of the Linux kernel is different from the makefile we usually write. It consists of five parts:
1. makefile: top-level makefile.
2. config: The Kernel configuration file.
3. Arch/XXX/makefile: makefile of the specific architecture.
4. scripts/makefile. XXX: general rules.
5. kbuild makefile: there are about hundreds of such files in the entire kernel.
# Make menuconfig: generate the Kernel configuration file:. config.
Top-level makefileRead. Config.
Top-level makefileBy Parsing. ConfigTo determine which directories are accessed recursivelyKbuild makefile.
In this process,Kbuild makefilePress. ConfigAdd the file list one by one for the final compilation.
The simplest kbuild makefile is as follows:
OBJ-y + = Foo. o
Indicates that kbuild has a target file named Foo. O in this directory. Foo. O will be compiled from the foo. C or Foo. s file. And it will be included in built-in.
All the target files compiled into the kernel are in the $ (obj-y) list. These lists depend on Kernel configurations. Kbuild compiles all $ (obj-y) files. Then, call "$ (LD)-R" to merge them into a build-in.o file. Later, the build-in.o will be connected to vmlinux by its parent makefile.
If Foo. O is to be compiled into a module, it will use obj-M. The format is as follows:
OBJ-M + = Foo. o
Example 1:
In ~ /Driver/HID/hid-core.c, there are the following statements, that is, the kernel insmod interface hid_init.
Module_init (hid_init );
That is to say, when this module is buildin or used as module insmod, the kernel will automatically call hid_init.
Then view ~ /Driver/HID/makefile, found
Hid-objs: = hid-core.o hid-input.o
Indicates that the hid-core.o is generated as long as the hid directory is added.
I had to see how the directory on the previous layer would enter the hid directory:
OBJ-$ (config_hid) + = hid/
Indicates that the hid directory is added as long as config_hid = y and M.
But what did the user do? Is the hid directory added for compilation? See ~ /Drivers/HID/kconfig
Config hid
Tristate "generic hid support"
In this case, the hid-core.o is compiled as long as this item is selected in make menuconfig.
Example 2:
Sam wants to study USB keyboard & mouse driver. When making menuconfig, select:
Config usb_hid
Tristate "USB Human Interface Device (full hid) support"
Then, view the makefile. If config_usb_hid is selected, USB _ hid.o is compiled.
But ~ The/Drivers/HID/usbhid directory does not contain usbhid. C. How is usbhid. O generated?
There is a. usbhid. O. CMD file in the drivers/HID/usbhid directory.