7

I'm writing a script that has to automatically change a number of Linux kernel configuration options based on an input file.
The easiest way to do this would of course be to edit the .config file directly, but this is discouraged and may cause issues.
I can't seem to find a way to do this "the right way" though.

"make help" doesn't show a way to change single options, nor does ./scripts/kconfig/conf --help. This file on kernel.org doesn't seem to have a way either.
Even Gentoo's Genkernel manually changes the .config file.

So, basically:
Is there a safe way to change kernel configuration options programmatically, complete with dependency tracking, etc.?
Can Kconfig be run manually to achieve this?

2

What I do is first:

make defconfig

Then append settings changes to .config followed by:

make olddefconfig

This should "fix up" any inconsistencies introduced in the configuration. YMMV since it may not fix them in the way you expect.

  • Thanks for your reply! I've considered doing that, but like you said, YMMV. If there's 2 conflicting options, there's no telling which one it'll fix. – SharkWipf Nov 23 '16 at 23:09
  • @SharkWipf Well in any case I would expect the result to be deterministic. So if the result is not what you want, just add another statement turning off the thing that conflicts and repeat this process until it works. – DepressedDaniel Nov 23 '16 at 23:14
  • True, but it might mess with other options in ways I can't check, and as I eventually want to put this script up on github I'd like it to be as stable and reliable as possible. Generally this script will be used to modify existing, user-made kernel configs, rather than generating new ones, so it is hard to get it working reliably this way. – SharkWipf Nov 23 '16 at 23:21
  • @SharkWipf Well, it sounds like what you're trying to achieve requires an AI of sorts ;) The conventional solution is to provide a default that works and let people customize if they dare. – DepressedDaniel Nov 23 '16 at 23:25
  • if I want to do it completely manually, yeah. But I was hoping there'd be some way I could use Kconfig to simulate "ticking a box" in menuconfig, because it sounds like that should be a thing. Basically what I want to do is allow users to copy kernel requirements from the Gentoo wiki, resolve that to the right configuration values where possible (easy enough), and then update the config accordingly (after a user review of course). So there are no "defaults" in this case. – SharkWipf Nov 24 '16 at 0:04
0

I would go for a patch of the .config file. The steps you have to take to prepare it are

cp .config .config.bck
make menuconfig # Here change all that you need to fit your needs
diff -u .config.bck .config > myconfig.$(kern_vers).patch

Then, in your script add this line

patch .config myconfig.$(kern_vers).patch

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.