Sharing and Discussion on the essence of Linux kernel cultivation (5) -- kernel map: kconfig and makefile

Source: Internet
Author: User

Recommended blog posts:Linux Kernel "problem Gate"-learning issues and experience highlights

Recommended download:Methodology of essence edition of "Cultivation of Linux kernel"

 

Makefile is not make love

I used to spend four years in school and didn't learn anything. Every day, I skip classes, surf the Internet, play games, and go to bed. When I graduated from college, I was told that makefile was completely unknown, but when I talked about make love, I came here. Now I still feel ashamed to think about it.

To put it bluntly, kconfig and makefile are the two most dependent files when we browse kernel code. Basically, each directory in the Linux kernel contains a kconfig file and a MAKEFILE file. For a person who wants to see a glimmer of dawn in the Linux kernel's Wang Yang code, the importance of putting them on the list is not much.

When we go to Hong Kong and pass through customs, there will always be free maps and various guides. With them in our hands, we will not be confused to walk in unfamiliar streets like flies. Even when traveling in the Mainland, you will always find a map first. Of course, you just need to buy a map and you won't get it. Different places have different characteristics, however, some features are services, and some features are requests.

Kconfig and makefile are the maps in the Linux Kernel maze. The map guides us to know a city, while kconfig and makefile allow us to understand the structure under a kernel directory. Every time we browse the kernel to find our own code segment, we should first look at the two files in the directory.

Use kconfig and makefile to find the target code

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

For example, we plan to study the implementation of the USB flash drive. Because the USB flash drive is a storage device, we should first go to the drivers/USB/storage/directory. But there are a lot of files in this directory, So what files do we need to pay attention? In this case, it is necessary to read the kconfig and makefile files first.

For the kconfig file, we can see the following options.

34 config usb_storage_datafab
35 bool "datafab compact flash reader support (experimental )"
36 depends on usb_storage & experimental
37 help
38 support for certain datafab compactflash readers.
39 datafab has a web page at

Obviously, this option has nothing to do with our purpose. First, it specifically targets datafab products. Secondly, although compactflash Reader is a flash device, it is obviously not a USB flash disk. Because the code in the drivers/USB/storage directory is for USB mass storage devices, rather than for a specific device. USB flash drives are only one type of USB mass storage devices. For example:

101 config usb_storage_sddr55
102 bool "SanDisk SDDR-55 smartmedia support (experimental )"
103 depends on usb_storage & experimental
104 help
105 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 related to the SanDisk product and is intended for sm. It is also not a USB flash drive, so we do not need to pay attention to it.

In fact, it is easy to determine that only the config_usb_storage option is what we really need to pay attention.

9 config usb_storage
10 tristate "USB Mass Storage support"
11 depends on USB & SCSI
12 --- help ---
13 say y here if you want to connect USB mass storage devices to your
14 computer's USB port. This is the driver you need for USB
15 floppy drives, USB hard disks, USB tape drives, usb cd-ROMs,
16 USB flash devices, and memory sticks, along
17 similar devices. This driver may also be used for some cameras
18 and card readers.
19
20 This option depends on 'scsi 'support being enabled, but you
21 probably also need 'scsi Device Support: SCSI disk support'
22 (blk_dev_sd) for most USB storage devices.
23
24 to compile this driver as a module, choose m here:
25 module will be called USB-storage.

Next, read the MAKEFILE file.

0 #
1 # makefile for the USB mass storage device drivers.
2 #
3 #15 Aug 2000, Christoph Hellwig
4 # rewritten to use lists instead of IF-statements.
5 #
6
7 extra_cflags: =-idrivers/SCSI
8
9 obj-$ (config_usb_storage) + = usb-storage.o
10
11 USB-storage-obj-$ (config_usb_storage_debug) + = Debug. o
12 USB-storage-obj-$ (config_usb_storage_usbat) + = shuttle_usbat.o
13 USB-storage-obj-$ (config_usb_storage_sddr09) + = sddr09.o
14 USB-storage-obj-$ (config_usb_storage_sddr55) + = sddr55.o
15 USB-storage-obj-$ (config_usb_storage_freecom) + = freecom. o
16 USB-storage-obj-$ (config_usb_storage_dpcm) + = DPCM. o
17 USB-storage-obj-$ (config_usb_storage_isd200) + = isd200.o
18 USB-storage-obj-$ (config_usb_storage_datafab) + = datafab. o
19 USB-storage-obj-$ (config_usb_storage_jumpshot) + = jumpshot. o
20 USB-storage-obj-$ (config_usb_storage_alauda) + = Alauda. o
21 USB-storage-obj-$ (config_usb_storage_onetouch) + = onetouch. o
22 USB-storage-obj-$ (config_usb_storage_karma) + = karma. o
23
24 USB-storage-objs: = scsiglue. O protocol. O transport. o usb. O/
25 initializers. o $ (USB-storage-obj-y)
26
27 ifneq ($ (config_usb_libusual ),)
28 obj-$ (config_usb) + = libusual. o
29 endif

Based on the analysis of the kconfig file, we have determined that we only need to pay attention to the config_usb_storage option. Search for config_usb_storage in the makefile file. From row 9th, we learned that the module corresponding to this option is USB-storage.

Because we do not need to pay attention to other options in the kconfig file, the 11 ~ Ignore 22 rows. Row 24th means that we only need to pay attention to scsiglue. C, Protocol. C, transport. C, USB. C, initializers. C, and Their. h header files with the same name.

Kconfig and makefile help us locate the target, just as we need to carry a map to a strange place. When we learn the Linux kernel, remember to seek help from 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.