Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you non-interactively turn on features in a Linux kernel .config file?

I have a situation where our software needs to work with several different Linux kernel distributions / kernel trees. (including Android forks)

In trying to automate our build process, I am finding that some of the defconfig files for particular builds we need to support do not include the kernel modules we depend on.

For example, let's imagine I need an option called XXX in my .config. For some dependencies, I can do something like this:

sed -i 's/# CONFIG_XXX is not set/CONFIG_XXX=m/' .config

For others, it's not so easy since the dependency may span multiple lines of .config statements.

Is there a more supported way to do this non-interactively, or am I stuck writing a more complex search-and-replace script?

like image 544
mpontillo Avatar asked Sep 21 '11 18:09

mpontillo


People also ask

What is .config file in Linux kernel?

The Linux kernel configuration is usually found in the kernel source in the file: /usr/src/linux/. config . It is not recommended to edit this file directly but to use one of these configuration options: make config - starts a character based questions and answer session.

How do I enable kernel configuration options?

To configure the kernel, change to /usr/src/linux and enter the command make config. Choose the features you want supported by the kernel. Usually, There are two or three options: y, n, or m. m means that this device will not be compiled directly into the kernel, but loaded as a module.

Where are kernel configs stored?

How are Android's kernel configs stored? The kernel configs are stored in the kernel/configs repo. Kernel configuration settings that must be present for Android to function are located in the base config fragment, android-base. config .


1 Answers

To do a series of simple flipping of a single config while updating any and all config dependencies:

Single Option approach

./scripts/config --set-val CONFIG_OPTION y
./scripts/config --enable CONFIG_BRIDGE
./scripts/config --enable CONFIG_MODULES
./scripts/config --disable CONFIG_X25
./scripts/config --module CONFIG_NFT
make oldconfig
(updates dependencies; may prompt with new dependencies, but old deps silently goes away)

Multiple-File Merge approach

If you have several small snippets of .config-* files that you want to selectively merge into the main .config file, execute:

# Merge IP fragment CONFIG_ settings into the main .config file
./scripts/kconfig/merge_config.sh .config .config-fragment
# Merge  Notebook HW-specific CONFIG_ settings into main .config file
./scripts/kconfig/merge_config.sh .config .config-notebook-toshiba

# Auto-add/auto-remove CONFIG_ dependencies
make oldconfig

References

  • https://www.kernel.org/doc/html/latest/kbuild/kconfig.html#nconfig-mode
  • https://stackoverflow.com/questions/27090431/linux-kconfig-command-line-interface/70728869#70728869
like image 51
John Greene Avatar answered Oct 03 '22 01:10

John Greene