What does make oldconfig do exactly in the Linux kernel makefile?
It reads the existing .config
file that was used for an old kernel and prompts the user for options in the current kernel source that are not found in the file. This is useful when taking an existing configuration and moving it to a new kernel.
What exactly does Linux kernel's `make defconfig` do?
Motivation
The .config
file is not simply copied from your defconfig
file. The motivation for storing defconfig
in such a format is next: in defconfig
we can specify only options with non-default values (i.e. options we changed for our board). This way we can keep it small and clear. Every new kernel version brings a bunch of new options, and this way we don't need to update our defconfig
file each time the kernel releases. Also, it should be mentioned that kernel build system keeps very specific order of options in defconfig
file, so it's better to avoid modifying it by hand. Instead you should use make savedefconfig
rule.
Simplified explanation
When .config
file is being generated, kernel build system goes through all Kconfig
files (from all subdirs), checking all options in those Kconfig
files:
- if option is mentioned in
defconfig
, build system puts that option into.config
with value chosen indefconfig
- if option isn't mentioned in
defconfig
, build system puts that option into.config
using its default value, specified in correspondingKconfig
Check scripts/kconfig/Makefile and scripts/kconfig/conf.c files to see how it's actually done.
More precise and detailed explanation
From "Kbuild: the Linux Kernel Build System" by Javier Martinez:
Defining Configuration Symbols:
Kconfig
FilesConfiguration symbols are defined in files known as
Kconfig
files. EachKconfig
file can describe an arbitrary number of symbols and can also include (source) otherKconfig
files. Compilation targets that construct configuration menus of kernel compile options, such asmake menuconfig
, read these files to build the tree-like structure. Every directory in the kernel has oneKconfig
that includes theKconfig
files of its subdirectories. On top of the kernel source code directory, there is aKconfig
file that is the root of the options tree. Themenuconfig
(scripts/kconfig/mconf
),gconfig
(scripts/kconfig/gconf
) and other compile targets invoke programs that start at this rootKconfig
and recursively read theKconfig
files located in each subdirectory to build their menus. Which subdirectory to visit also is defined in eachKconfig
file and also depends on the config symbol values chosen by the user.Storing Symbol Values:
.config
FileAll config symbol values are saved in a special file called
.config
. Every time you want to change a kernel compile configuration, you execute a make target, such asmenuconfig
orxconfig
. These read theKconfig
files to create the menus and update the config symbols' values using the values defined in the.config
file. Additionally, these tools update the.config
file with the new options you chose and also can generate one if it didn't exist before.Because the
.config
file is plain text, you also can change it without needing any specialized tool. It is very convenient for saving and restoring previous kernel compilation configurations as well.
Useful commands
You can use simpler syntax for make defconfig
, like:
$ make ARCH=arm your_board_defconfig
See the full list of available defconfigs with:
$ make ARCH=arm help | grep defconfig
If you need to do reverse action (i.e. create a neat small defconfig
from extensive .config
), you can use savedefconfig
rule:
$ make ARCH=arm savedefconfig
Also, as 0andriy mentioned, you can use diffconfig
script to see changes from one .config
to another one:
$ scripts/diffconfig .config_old .config_new
Definition of target in Linux kernel's Makefile
The kernel build system makes heavy use of GNU Make features. In the top-level Makefile, the rule for the menuconfig
target is this one:
%config: outputmakefile scripts_basic FORCE
$(Q)$(MAKE) $(build)=scripts/kconfig $@
That runs a sub-make for the target in "scripts/kconfig/Makefile". In "scripts/kconfig/Makefile", the rule for the menuconfig
target is slightly obscured:
define config_rule
PHONY += $(1)
$(1): $(obj)/$($(1)-prog)
$(Q)$$< $(silent) $(Kconfig)
PHONY += build_$(1)
build_$(1): $(obj)/$($(1)-prog)
endef
$(foreach c, config menuconfig nconfig gconfig xconfig, $(eval $(call config_rule,$(c))))
make oldconfig overwriting value in .config
Usually kernel config options are dependent on other config options. So even if you disable one config option, as its enabled by some other config option it will fall back to its original value after you do make oldconfig
In case of CONFIG_TRACEPOINTS
it depends on or set by several other flags TRACING [=y] || BLK_DEV_IO_TRACE [=y] && TRACING_SUPPORT [=y] && FTRACE [=y] && SYSFS [=y] && BLOCK [=y]
Try setting one by one of them to =n
along with CONFIG_TRACEPOINTS=n
and see if its persistent after doing make oldconfig
. For me setting CONFIG_FTRACE=n
worked
How to find dependency. Run make menuconfig
. Press /
to search the config option and see the Selected by
. Those are the config flags who are also setting your config option. See their current value next to them. For e.g. above you can see that TRACING_SUPPORT
is set to y
make kernel prompting for config options even when .config is present
If used, ARCH
parameter to make
is needed not only when building the kernel, but also when configuring it:
make ARCH=x86_64 menuconfig
BTW, you have already used the parameter for other configuration step:
make ARCH=x86_64 x86_64_defconfig
Related Topics
How to Call Accept() for One Socket from Several Threads Simultaneously
Bash Pass Variable as Argument with Quotes
What Are Good Linux/Unix Books for an Advancing User
Differencebetween Ld_Library_Path and -L at Link Time
How to Query X11 Display Resolution
Expect - Interrupt Program - Ctrl+C
How to Ignore Some Differences in Diff Command
Monitoring File and Directory Access on Linux
Rsync Over Ssh Preserve Ownership Only for Www-Data Owned Files
Shell Script, Saving the Command Value to a Variable
Split Files Using Tar, Gz, Zip, or Bzip2
How to File Split at a Line Number
What Is a Way to Read Man Pages in Vim Without Using Temporary Files