Relationship Between. config, kconfig, and makefile

Source: Internet
Author: User

After writing a driver, we need to compile it as a module or directly compile it.

When you enter the kernel, You need to modify the relevant files, the most important of which is kconfig and makefile.

It mainly analyzes the relationship between the three, and then briefly talks about its syntax.

When we execute make (or make menuconfig, etc.) in the kernel source code directory

Command) The command is actually compiled based on makefile. I am at mini2440

On the Development Board, a key-controlled LED light driver is compiled. The file name is buttons_leds_z.

Hao. C is a character driver. Therefore, the makefile part in the/driver/Char/directory is the most

Add a row later

OBJ-$ (config_buttons_leds_zhao) + =

Buttons_leds_zhao.o

As follows:

OBJ-y + = mem. O random. O tty_io.o n_tty.o tty_ioctl.o

Tty_ldisc.o tty_buffer.o tty_port.o

OBJ-$ (config_bfin_jtag_comm) + = bfin_jtag_comm.o

OBJ-$ (config_console_translations) + = lelemap. o

Consolemap_deftbl.o

OBJ-$ (config_hw_console) + = vt. O defkeymap. o

OBJ-$ (config_audit) + = tty_audit.o

OBJ-$ (config_buttons_leds_zhao) + =

Buttons_leds_zhao.o

In the first line, Y in obj-y indicates that the object is compiled into the kernel, while obj-$ (config_legac

In y_ptys), config_legacy_ptys indicates a variable, similar to C

The variables in the language are represented by $ (). Generally, three values Y, M, and N. Y can be used for representation.

Compile the data into the kernel, while M indicates that the data is compiled in the module mode, and N indicates that the data is not compiled into the kernel.

Core. OBJ-y + = The. O suffix file after the equal sign is named

The. c file is compiled.

The value of the above config_legacy_ptys variable is set through the. config file.

.. The configuration content is as follows:

# Character Devices
#
Config_vt = y

Config_console_translations = y

Config_vt_console = y

Config_hw_console = y


# Config_vt_hw_lele_binding is not set


# Config_devkmem is not set

Config_mini2440_hello_module = m

Config_buttons_leds_zhao = m

Config_leds_mini2440 = m

Config_mini2440_buttons = m

Config_mini2440_buzzer = y

Config_mini2440_adc = y

# Config_serial_nonstandard is not set

From the above lines, we can see that all the variables in makefile are in. config.

Assigned. When we enter the make command in the source code directory, all of them are from. config by default.

.

Therefore, before entering make, use LS-a to check whether the file exists. For

For projects that only contain a few files, it is not difficult to manually write. config and makefile.

But if it is a project containing hundreds of files, it is quite difficult

Difficult. You can use Autoconf to automatically generate. config and automake.

Makefile. It seems that the problem is solved, but in fact, this approach lacks some flexibility.

And cannot meet on-demand customization requirements. If you want to add or delete a driver

Find the corresponding items in the. config file and modify them. Very inconvenient. Therefore

Kconfig.

When we input make menuconfig in the kernel source code directory, the following content appears:

. Config-Linux kernel v2.6.32.2 Configuration
── ─ ── ─
┌ ── ─
│ Arrow keys navigate the menu. <enter> selects submenus --->. Highlighted letters are │
│ Hotkeys. pressing <Y> includes, <n> excludes, <m> modularizes features. Press <ESC> │
│ To exit, <?> For help, </> for search. Legend: [*] built-in [] excluded <m> module │
│ <> Module capable │
│ ┌ ── ─ ── ─ ── │
│ General setup ---> │
│ [*] Enable loadable module support ---> │
│-*-Enable the block layer ---> │
│ System type ---> │
│ Bus support ---> │
│ Kernel features ---> │
│ Boot options ---> │
│ CPU power management ---> │
│ Floating point emulation ---> │
│ Userspace binary formats ---> │
│ Power management options ---> │
│ [*] Networking support ---> │
│ Device drivers ---> │
│ File systems ---> │
│ └ ── ─ ┴ (+) ── ─ ┘ │
├ ── ─ ── ─ Accept
│ <SELECT> <exit> └ ── ─ ── ─ Accept

It is configured by reading the kconfig file in the kernel source code directory.

The contents of kconfig in the/Drivers/Char/directory are as follows:

Config devkmem
Bool "/dev/kmem Virtual Device Support"
Default y
Help
Say y here if you want to support the/dev/kmem device.
/Dev/kmem device is rarely used, but can be used for certain
Kind of kernel debugging operations.
When in doubt, say "N ".

Config mini2440_hello_module
Tristate "mini2440 module sample"
Depends on mach_mini2440
Default m if mach_mini2440
Help
Mini2440 module sample.

Config buttons_leds_zhao
Tristate "mini2440 button and LEDs sample"
Depends on mach_mini2440
Default m if mach_mini2440
Help
Mini2440 button and LEDs module sample.

The syntax format is described as follows:

The Config keyword is the entry to a new configuration option, followed by the option mini2440_h.

Ello_module omitted config. Complete Expression: config_mini2440

_ Hello_module, that is, when we set this option to Y, it will automatically

Config_mini2440_hello_module = m of. config is rewritten

Config_mini2440_hello_module = y.

Next, there are two main types of menu properties: Tristate and Boolean. Tristate table

Show three states: compiled into the kernel (Y), compiled into a module (M), not compiled (n ). Boolean master

If there are two types of Y or ndepend, the default dependency default compilation option M indicates

The file indicates that the file is compiled as a module. The help is the help information. When we select

The Help menu is not required. Compilation options

Up to thousands. For average people, it is very difficult to find out every option.

Multiple options are default.

In general, the relationship between the three is as follows: when we enter

When you select an item in the menu that appears in makemenuconfig, it automatically follows

The value of the. config item. If no selection is made, a row is inserted in. config.

Annotations. Similar to # config_serial_nonstandard is not set, when

When we input make, the variables in makefile are compiled according to the MAKEFILE file.

The value is assigned by. config. Only add the option in kconfig.

The menu is displayed. Even if y or M is selected, the file is not compiled. You also need

Only corresponding lines can be added to the MAKEFILE file for compilation. A simple illustration is as follows:

Kconfig ------->. config ----------> 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.