"Summarize" the relationship of Makefile, Kconfig,. config in the embedded Linux kernel and add boot Hello World "turn"

Source: Internet
Author: User

This article was reproduced from: http://blog.csdn.net/fengyuwuzu0519/article/details/73772109

To understand the structure of the kernel, let's implement the following simple example.

First, increase the kernel boot Hello World

Task:

The kernel starts by loading the Hello driver and prints out Hello World

Steps:

(1) Create a new Hello folder in the drivers directory and implement the corresponding hello.c, Makefile, Kconfig

(2) Modify the makefile, Kconfig of the previous level (Linux-3.4.2/drivers)

(3) Make Menuconfig configuration

(4) Compile, burn write, run

Realize:

(1) Implement driver hello.c

The simplest driver

[CPP]View PlainCopy print?
  1. #include <linux/module.h>
  2. #include <linux/kernel.h>
  3. #include <linux/init.h>
  4. #include <linux/delay.h>
  5. static int first_drv_init (void)
  6. {
  7. PRINTK ("------------------Hello World!--------------------");
  8. return 0;
  9. }
  10. static void First_drv_exit (void)
  11. {
  12. PRINTK ("------------------exit Hello World!--------------------");
  13. }
  14. Module_init (First_drv_init);
  15. Module_exit (First_drv_exit);
  16. Module_license ("GPL");

(2) Realizing Hello/makefile

[CPP]View PlainCopyprint?
    1. # LED Core
    2. obj-$ (Config_hello) + = hello.o

Note that the Config_hello here is defined in. config, and if the configuration is compiled into the kernel, then the config_hello=y is present in the. config and the hello.o is compiled into the kernel.

(3) Realizing Hello/kconfig

[CPP]View PlainCopyprint?
    1. Config HELLO
    2. TriState "Hello World for Fengyuwuzu"
    3. Help
    4. Hello for Fengyuwuzu

Config Hello determines the name of Config_hello.

Hello World for Fengyuwuzu: determines the GUI name at make Menuconfig

(4) Modify Drivers/makefile, add:

[CPP]View PlainCopyprint?
    1. Obj-y + = myled/

(5) Modify Drivers/kconfig, add:

[CPP]View PlainCopyprint?
    1. SOURCE "Drivers/myled/kconfig"

(6) Make menuconfig configure the appropriate entry into the kernel




(7) Make Uimage

(8) Burn write new kernel boot

See "------------------Hello World!--------------------" is printed, and the corresponding driver is loaded.

Ii. relationship of Makefile, Kconfig,. config in the Linux kernel

(1) The role of the three

Simply put: Kconfig is the menu, makefile is the practice,. config is the dish you ordered.

Makefile: A text-form file that compiles a method of the source file.

Kconfig: A text form of the file, the kernel configuration menu.

. config: The configuration on which the compilation is based.

(2) The grammar of the three

1, Makefile

Goal definition: The target definition is used to define what is to be compiled as a module and which to compile the link into the kernel.

Direct compilation:

Obj-y + = hello.o

Indicates to be compiled by hello.c or Hello.s file hello.o and linked into the kernel

A more common practice is to determine how files are compiled based on the config_ variable of the. config file:

Conditional compilation:

obj-$ (Config_hello) + = hello.o

Obj-m indicates that the file is to be compiled as a module.

Objects other than y,m are not compiled in obj-x form.

2, Kconfig

Type definition:

Each config menu item must have a type definition: bool Boolean type, TriState tri-State (built-in, module, remove), string string, hex 16 binary, Integer integer.
For example:
Config Hello_module
BOOL "Hello Test module"
The bool type can only be selected or unchecked and displayed as [];

TriState types of menu items are compiled into kernel module options, shown as < >, if you choose to compile into a kernel module, you will generate a config_hello_module=m configuration in. CONFIG, if the choice of built-in, is directly compiled into the kernel effect, A config_hello_module=y configuration is generated in. CONFIG. Hex hexadecimal type is displayed as ().

Directory hierarchy iterations
There is a similar statement in Kconfig: source "Drivers/usb/kconfig"
Used to include (or nest) new kconfig files so that each directory can manage its own configuration so that it is not necessary to write those configurations in the same file for easy modification and management.

To configure dependencies between options:
Depend on: An option relies on another option to generate
Select: Reverse dependency, when selected, selects the item defined after the Select
Requie
Default value: Default (Defaults y/n/m equivalent)
Input hint: prompt
Helpful Information: Help

3,. config

The kernel compiles the reference file.

How to modify:

(1) Make Menuconfig

(2) Make Xxx_defconfig

(3) Direct modification

! Note If you modify directly, it does not necessarily take effect, because some configurations may have dependencies, make will be based on dependencies, the rules are checked, not recommended directly in the. config to modify.

"Summarize" the relationship of Makefile, Kconfig,. config in the embedded Linux kernel and add boot Hello World "turn"

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.