I can use the following command to create a Linux kernel .config file based on a specified architecture default for a custom ARM-based board:
AR
It also generate include/generated/autoconf.h.
This header file is included by C source file. On the other hand, .config is for Makefile system.
Build system generate two files, and keep them consistent.
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 only specify 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.
When .config file is being generated, kernel build system goes through all Kconfig files (from all subdirs), checking all options in those Kconfig files:
defconfig, build system puts that option into .config with value chosen in defconfigdefconfig, build system puts that option into .config using its default value, specified in corresponding KconfigCheck scripts/kconfig/Makefile and scripts/kconfig/conf.c files to see how it's actually done.
From "Kbuild: the Linux Kernel Build System" by Javier Martinez:
Defining Configuration Symbols:
KconfigFilesConfiguration symbols are defined in files known as
Kconfigfiles. EachKconfigfile can describe an arbitrary number of symbols and can also include (source) otherKconfigfiles. 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 oneKconfigthat includes theKconfigfiles of its subdirectories. On top of the kernel source code directory, there is aKconfigfile 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 rootKconfigand recursively read theKconfigfiles located in each subdirectory to build their menus. Which subdirectory to visit also is defined in eachKconfigfile and also depends on the config symbol values chosen by the user.Storing Symbol Values:
.configFileAll 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 asmenuconfigorxconfig. These read theKconfigfiles to create the menus and update the config symbols' values using the values defined in the.configfile. Additionally, these tools update the.configfile with the new options you chose and also can generate one if it didn't exist before.Because the
.configfile 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.
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