Configuration of the Nuttx
The NUTTX configuration system is made up of kconfig, makefile, and configuration tools.
The makefile of the kernel is divided into 5 components:
makefile top makefile
Config & nbsp; the current configuration document of the kernel, which becomes part of the fixed-layer Makefile at compile time
arch/$ (arch)/makefile architecture-related Makefile
s/makefile.* general rules for some Makefile
Kbuild Makefile About 500 documents in the , directories, compiled based on the macro definitions and other compilation rules passed down from the upper makefile, The source code is compiled into a module or a makefile document programmed into the kernel
to read the contents of the. config document and is generally responsible for the build kernel and modules. Arch Makefile provides additional information about the architecture. The Makefile document in the S directory contains any definitions and rules needed to build the kernel based on the Kbuild Makefile. (where the. config content is the result of the Kconfig document configuration at Make Menuconfig. )
In Nuttx, the Makefile directory tree is as follows:
' |<--. config | | | <--. config | | <--tools/config.mk |<--makefile.unix-| makefile-| | | <--. config | | <--make.defs-|<--tools/config.mk | | <--arch/arm/src/armv7-m/toolchain.defs | | <--makefile.win-(slightly)
The Makefile, Make.defs, and MAKE.DEP under subdirectories are not included by include, but are invoked when the make command in the Makefile file is executed.
The main Kconfig file for Nuttx is nuttx/kconfig. The primary Kconfig file invokes the Kconfig file of the Kconfig file and the application directory of each level subdirectory to form a tree-like relationship. The menu is organized in a tree-like structure, with submenus under the main menu, submenus and submenu or configuration options. Each option can have dependencies that determine whether it is displayed. The subkey is displayed only if the parent of the dependent item is selected.
Attention:
The Nuttx/.config is a preset. config file. Copy from nuttx/config/< board >/< target configuration >/defconfig
Nuttx/make.defs: Copied from nuttx/config/< board >/< target configuration >/make.defs.
Execute the Make Menuconfig command in the NUTTX directory, read the preset. config file, bring up the configuration interface based on the text menu , exit the Configuration interface, select <Yes> Save, and generate a new. config file in the Nuttx directory.
For example, I have written mytest.c files, which do not care about mytest.c content. If you want to compile the mytest.c into the kernel, you need to follow the steps below.
1) put test.c in any directory, this directory only requires the existence of kconfig and makefile, such as the source code root directory/arch/arm/directory.
2) Add in the kconfig of this directory
Config my_test
BOOL "My Test"
3) Add in Makefile
obj-$ (config_my_test) + = MYTEST.O
4) in. CONFIG, you can add config_my_test = y to select.
Or, when you execute make menuconfig, find the option to display the name my test, using a space to select it.
All in all, if you need to add a feature to the system kernel, first define a configuration item that corresponds to this feature and add it to a specific kconfig file. Then in makefile, define which files the configuration item needs to compile. Finally, you can use make menuconfig or directly modify. config to enable this configuration item.
Add:
The syntax for Defconfig is as follows:
# STM32 Peripheral Support
# CONFIG_STM32_ADC1 is not set
# CONFIG_STM32_SPI1 is not set
Config_stm32_usart1=y
# Config_stm32_usart2 is not set
Add the driver to increase the GPIO. First you need to modify the kconfig.
Configuration Order
The basic configuration order is bottom-up:
- Choosing a Build environment
- Select processor
- Select the Board Card
- Select the supported Peripherals
- Configuring device drivers
- Configure Application Options
This is quite the right direction for creating a new configuration, but it is not appropriate to modify an existing configuration.
When you execute make menuconfig, there are some important configuration options to keep in mind, such as remembering the choice of the application's entry address when configuring NUTTX.
Because the all target is the default target, executing the parameterless make command compiles the all target, first attempting to compile the context target, where config.h is generated based on the. config file, and many C files contain config.h to obtain the user configuration. Note The 2 directory soft links, which are used below:
$ (ARCH_SRC)/board:
Link the Nuttx/configs/shenzhou/src directory to the Nuttx/arch/arm/src/board directory.
$ (ARCH_SRC)/chip:
Link the Nuttx/arch/arm/src/stm32 directory to the Nuttx/arch/arm/src/chip directory.
However, because the make context was executed once while installing buildroot, and do clean does not delete the files generated by the context target, this step did nothing.
Kconfig syntax
1. Basic composition
The basic composition consists of five species, Menu/endmenu,menuconfig,config,choice/endchoice,source. Each of these is described in detail below:
(1) Menu/endmenu
Menu function, can be understood as a directory, menu can be part of the configuration items included in a menu, which facilitates the configuration of the classification display. Menu and Endmenu are a set of instructions that must appear at the same time. The sections that are included in menu and Endmenu are the configuration items in subdirectories.
For example, 24 rows (possibly different) in Init/kconfig are shown as:
Menu "General Setup"
In this way, a table of contents is generated, and the feature is that an arrow appears on the right, and the first row in 1. When the confirmation key is clicked, it will enter the menu item, 2.
Figure 1
Figure 2
(2) Menuconfig
Menuconfig a bit like the menu, but the difference is that the menu is more than a config, the menu is configurable, the second line in 2, the front is more than the menu type a box, through the space can modify the selection of this configuration item. And from a format point of view, there is a difference. The format is 1131 lines in Init/kconfig:
Menuconfig MODULES
BOOL "Enable loadable module Support" config
If MODULES
Xx
endif
In other words, the configuration items are located in the IF and endif. Part of this is what is displayed in the Modules subdirectory. If module is selected, the contents of the IF and endif can be displayed. If there is no definition, you can only enter an empty directory.
(3) Config
Config is the most basic unit that makes up the kconfig, which defines the details of the configuration item. The defined format references the 8th line in the Arch/arm/kconfig.
Config ARM
bool
Default Y
Select Xxxxxxxxxx
Help
???????????
The config needs to define the name, which is the same as menuconfig. This name is used not only in the cropping kernel, but also in the interdependencies among the configuration items.
There are 5 types of config, namely bool (y/n), TriState (y/m/n), String (string), Hex (hexadecimal), Integer (integer). In particular, the bool and Tristate,bool can only be selected and not selected, and the tristate may also be configured as modules (m), which is particularly useful for driver development. the bool type can only be checked or unchecked, shown 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_ in. CONFIG Module=m configuration, if the choice of built-in, is directly compiled into the kernel effect, will be in. CONFIG to generate a config_hello_module=y configuration. Hex hexadecimal type is displayed as ().
Value types of variables in Kconfig
There are 5 kinds of variable value types in Kconfig. Among the most common are tristate and bool, which correspond to the make Meuconfig configuration Interface < > and [] options.
(1) tristate: Y, N, M desirable.
(2) bool (variant of tristate): Y, N
(3) String: Value is a string, such as: Config_cmdline = "root =/dev/hdal ro init =/bin/bash console =ttysac0"
(4) Hex (variant of String): The value is hexadecimal data, such as: Config_vectors_base =0xffff0000.
(5) Int (which is a variant of string): Values are decimal data, such as: config_split_ptlock_cpus=4096
The other syntax is as follows:
1) Prompt: Hint, the name displayed in make Menuconfig is generally omitted. The following two are written in the same way.
A. BOOL "Networking support"
B. bool
Prompt "Networking support"
2) Default: Defaults
A configuration item can have more than one default value, but only the first defined value is valid.
3) depends on/requires: dependencies
If the dependent configuration item is not selected, then the current item cannot be selected.
4) Select: Reverse Dependency
If the current item is selected, the option after select is also selected.
5) Range: Range for hex and integer
Range A b indicates that the current value is not less than A, not greater than B
6) Comment: Notes
(4) Choice/endchoice
Choice function, choose one more, a bit like the radio control in MFC. Refer to Line No. 205 of Arch/arm/kconfig.
Choice
Prompt "ARM system type"
Default Arch_versatile
???????
Config arch_s3c2410
BOOL "Samsung s3c2410, s3c2412, s3c2413, s3c2440, s3c2442, s3c2443"
Select Generic_gpio
Select Arch_has_cpufreq
Select HAVE_CLK
???????
Endchoice
Results displayed 3, after entering this item, display the result 4.
Figure 3
Figure 4
Visible, choice a bit similar to the menu, is selected in the Sub-window, but the difference is that the child window can only select one item. The name of the current selection is displayed after prompt.
(5) Source
Source simply copies the other Kconfig file directly to the current location. But it also has a clear role to play in the system. From the start position, arch/arm/kconfig the entire system as a configuration type.
Five Configuration analysis
When we enter the root directory of the Linux source code, enter make Menuconfig. Assume that the root directory already exists. config, which is generated automatically if it does not exist. At this point, 5 is displayed on the command line.
Obviously, when you execute make menuconfig, the scripts/kconfig/mconf Arch/arm/kconfig is automatically invoked to start the configuration of the system, then Arch/arm/kconfig is the starting point for the configuration. This file uses the source directive to invoke the Kconfig file in the other directory to complete the overall configuration. Thus, Arch/arm/kconfig can be understood as the main function, and the source directive is somewhat similar to include. You can parse the Kconfig file according to the syntax above.
Configuration and compilation of NUTTX