Linux kernel (1)-Kernel map: Kconfig and Makefile

Source: Internet
Author: User

Makefile not make Love

Once in school, mixed for four years, did not learn anything, every day is skipping classes, surfing the internet, playing games, sleeping. When I graduated, I was told that I had no idea of makefile, but I felt a sense of embarrassment when I said make love.

It's no exaggeration to say that kconfig and makefile are the two files we rely on when we browse the kernel code. Basically, there is a kconfig file and a makefile file underneath each directory in the Linux kernel. For a person who wants to see a glimmer of light in the code of the Linux kernel, it is not too important to put them in a position of importance.

We go to Hong Kong, through customs, there will always be free maps and a variety of guide to take, with them in their hands we are not without a head flies like wandering in the unfamiliar streets. Even when traveling in the mainland generally will always be the first to find a map, of course, this is to buy, take is not get, different places have different characteristics, but some features are services, and some features is to obtain.

Kconfig and Makefile are maps of the Linux kernel maze. Maps lead us to know a city, while Kconfig and makefile let us understand the structure under a kernel directory. Every time we browse kernel to find the piece of code that belongs to us, we should look at the two files in the directory first.

Use Kconfig and makefile to find the target code

Just like using maps to find a destination, we need to use kconfig and makefile to find the target code to be researched.

For example, we intend to study the implementation of USB drive, because the USB stick is a storage device, so we should go into the drivers/usb/storage/directory first. But there are a lot of files in this directory, so what are the files that we need to focus on? It is then necessary to read the Kconfig and makefile files first.

For kconfig files, we can see the following options.

Usb_storage_datafab Config
+ bool "Datafab Compact Flash Reader Support (experimental)"
Depends on Usb_storage && experimental
Panax Notoginseng Help
Certain datafab CompactFlash readers.
Datafab have a Web page at <http://www.datafabusa.com/;

Obviously, this option is not related to our purpose. First it is specifically for Datafab company's products, and second, although CompactFlash reader is a flash device, but obviously not a U disk. Because the code in the Drivers/usb/storage directory is for a device such as the USB mass storage, not for a particular device. The USB flash drive is just one of the mass storage devices. Another example:

101 Config Usb_storage_sddr55
102 bool "SanDisk SDDR-55 SmartMedia Support (experimental)"
103 depends on Usb_storage && experimental
104 Help
Say Y here to include additional code to support the Sandisk SDDR-55
106 SmartMedia Reader in the USB Mass Storage driver.

Obviously this option is about SanDisk products, and for the SM card, also not a U disk, so we do not need to pay attention to.

In fact, it's easy to be sure that only the option config_usb_storage is what we really need to focus on.

9 Config Usb_storage
Ten tristate "USB Mass Storage Support"
Depends on USB && SCSI
---help---
Say Y want to connect USB mass storage devices to your
Computer ' s USB port. The driver need for USB
Floppy drives, USB hard disks, USB tape drives, USB CD-ROMs,
USB Flash devices, and memory sticks, along with
Similar devices. This driver may also is used for some cameras
and card readers.
19
This option depends the ' SCSI ' support being enabled
Probably also need ' SCSI device SUPPORT:SCSI disk support '
(BLK_DEV_SD) for most USB storage devices.
23
Compile this driver as a module, choose M here:the
Module would be called Usb-storage.

Next read the makefile file.

0 #
1 # Makefile for the USB Mass Storage device drivers.
2 #
3 # Christoph Hellwig
4 # Rewritten to use lists instead of if-statements.
3 E
6
7 Extra_cflags: =-IDRIVERS/SCSI
8
9 obj-$ (config_usb_storage) + = USB-STORAGE.O
10
usb-storage-obj-$ (config_usb_storage_debug) + = DEBUG.O
usb-storage-obj-$ (config_usb_storage_usbat) + = SHUTTLE_USBAT.O
usb-storage-obj-$ (config_usb_storage_sddr09) + = SDDR09.O
usb-storage-obj-$ (config_usb_storage_sddr55) + = SDDR55.O
usb-storage-obj-$ (config_usb_storage_freecom) + = FREECOM.O
usb-storage-obj-$ (CONFIG_USB_STORAGE_DPCM) + = DPCM.O
usb-storage-obj-$ (config_usb_storage_isd200) + = ISD200.O
usb-storage-obj-$ (config_usb_storage_datafab) + = DATAFAB.O
usb-storage-obj-$ (config_usb_storage_jumpshot) + = JUMPSHOT.O
usb-storage-obj-$ (Config_usb_storage_alauda) + = ALAUDA.O
usb-storage-obj-$ (config_usb_storage_onetouch) + = ONETOUCH.O
usb-storage-obj-$ (config_usb_storage_karma) + = KARMA.O
23
USB-STORAGE-OBJS: = SCSIGLUE.O protocol.o transport.o usb.o/
INITIALIZERS.O $ (usb-storage-obj-y)
26
Ifneq ($ (config_usb_libusual),)
obj-$ (CONFIG_USB) + = LIBUSUAL.O
endif

In the previous analysis of the Kconfig file, we determined that we only had to pay attention to the config_usb_storage option. Find Config_usb_storage in the makefile file, from line 9th that the module for this option is usb-storage.

Because the other options in the Kconfig file do not need to be noticed, the makefile 11~22 line can be ignored. Line 24th means that we only need to focus on scsiglue.c, PROTOCOL.C, transport.c, USB.C, INITIALIZERS.C, and their same name. h header files.

Kconfig and Makefile are good at helping us navigate to the goals we want to focus on, as we go to a strange place to carry maps, and when we learn about the Linux kernel, we also want to ask for help from Kconfig and makefile.

Linux kernel (1)-Kernel map: Kconfig and Makefile

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.