16

I want to automate a Linux build but eventually get to a point where I need to run what seems to be a very manual step: make menuconfig. This seems to synchronize configs between the OS and kernel configs?

cp git-tracked-config .config
make defconfig 
make menuconfig # <- how to automate/script this?
make V=s

Basically, how can I remove the call to make menuconfig for a build script?

As an aside, this is in reaction to a build error that seems to happen when I run without ever calling make menuconfig:

make[1]: *** No rule to make target `include/config/auto.conf', needed by `include/config/kernel.release'.  Stop.

Which seems to be there is a missing rule in a makefile perhaps because the makefile itself does NOT exist or the makefile has not been generated/morphed to contain that rule but that is a separate question.

There could be a smarter way to approach this alltogether. Are there other configs that I'm not tracking but should (e.g. oldconfig)?

Ciro Santilli OurBigBook.com
  • 18,092
  • 4
  • 117
  • 102
tarabyte
  • 4,296

3 Answers3

13

The Linux kernel build-system provide many build targets, the best way to know about it is probably to do a make help:

Configuration targets:
  config      - Update current config utilising a line-oriented program
  nconfig         - Update current config utilising a ncurses menu based program
  menuconfig      - Update current config utilising a menu based program
  xconfig     - Update current config utilising a QT based front-end
  gconfig     - Update current config utilising a GTK based front-end
  oldconfig   - Update current config utilising a provided .config as base
  localmodconfig  - Update current config disabling modules not loaded
  localyesconfig  - Update current config converting local mods to core
  silentoldconfig - Same as oldconfig, but quietly, additionally update deps
  defconfig   - New config with default from ARCH supplied defconfig
  savedefconfig   - Save current config as ./defconfig (minimal config)
  allnoconfig     - New config where all options are answered with no
  allyesconfig    - New config where all options are accepted with yes
  allmodconfig    - New config selecting modules when possible
  alldefconfig    - New config with all symbols set to default
  randconfig      - New config with random answer to all options
  listnewconfig   - List new options
  olddefconfig    - Same as silentoldconfig but sets new symbols to their default value
  kvmconfig   - Enable additional options for guest kernel support
  tinyconfig      - Configure the tiniest possible kernel

As jimmij says in the comments, the interesting parts are in the oldconfig related targets.

Personally, I would recommend you to go for silentoldconfig (if nothing changed in the .config file or olddefconfig if you updated your .config file with a new kernel.

perror
  • 3,239
  • 7
  • 33
  • 45
3

merge_config.sh config fragments

$ cd linux
$ git checkout v4.9
$ make x86_64_defconfig
$ grep -E 'CONFIG_(DEBUG_INFO|GDB_SCRIPTS)[= ]' .config
# CONFIG_DEBUG_INFO is not set
$ # GDB_SCRIPTS depends on CONFIG_DEBUG_INFO in lib/Kconfig.debug.
$ cat <<EOF >.config-fragment
> CONFIG_DEBUG_INFO=y
> CONFIG_GDB_SCRIPTS=y
> EOF
$ # Order is important here. Must be first base config, then fragment.
$ ./scripts/kconfig/merge_config.sh .config .config-fragment
$ grep -E 'CONFIG_(DEBUG_INFO|GDB_SCRIPTS)[= ]' .config
CONFIG_DEBUG_INFO=y
CONFIG_GDB_SCRIPTS=y

Process substitution does not work unfortunately:

./scripts/kconfig/merge_config.sh arch/x86/configs/x86_64_defconfig \
    <( printf 'CONFIG_DEBUG_INFO=y\nCONFIG_GDB_SCRIPTS=y\n' ) 

because of: https://unix.stackexchange.com/a/164109/32558

merge_config.sh is a simple front-end for the make alldefconfig target.

When cross compiling, ARCH must be exported when you run merge_config.sh, e.g.:

export ARCH=arm64
export CROSS_COMPILE=aarch64-linux-gnu-
make defconfig
./scripts/kconfig/merge_config.sh .config .config-fragment

The merged output file can be specified explicitly with the KCONFIG_CONFIG environment variable; otherwise it just overwrites .config:

KCONFIG_CONFIG=some/path/.config ./scripts/kconfig/merge_config.sh .config .config-fragment

Buildroot automates it with BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES: https://stackoverflow.com/questions/1414968/how-do-i-configure-the-linux-kernel-within-buildroot

Related: https://stackoverflow.com/questions/7505164/how-do-you-non-interactively-turn-on-features-in-a-linux-kernel-config-file

Ciro Santilli OurBigBook.com
  • 18,092
  • 4
  • 117
  • 102
  • 1
    thanks for help in comments on this question https://stackoverflow.com/questions/4943857/linux-kernel-live-debugging-how-its-done-and-what-tools-are-used/44226360#44226360 also can u please let me know which flag in makefile I have to add like config_XYZ=y to disable linux kernel tcp stack since I like to give a try to Userspace TCP stack that I downloaded – user786 Jun 01 '21 at 11:04
  • @user786 not sure about this. grep the Kconfig files to see if any interesting options show up. You can also try to search inside make menuconfig with /. – Ciro Santilli OurBigBook.com Jun 01 '21 at 11:09
  • I plan to write in makefile the debug flags=y. Please confirm is this also correct way that I plan – user786 Jun 01 '21 at 12:20
  • @user786 which makefile? Linux kernel or your own? By debug flags do you mean a standard kernel config, or something else? For standard kernel configs, no need to patch makefiles. For non standard, then you might need to hack kernel source I suppose. – Ciro Santilli OurBigBook.com Jun 01 '21 at 12:43
  • There is file with name Makefile which inside in the kernel downloaded source folder. For example when I downloaded linux-5.12.6 its inside that folder – user786 Jun 01 '21 at 12:59
  • File downloaded with linux source code from kernel.org that I plan to compile and install with make command.. – user786 Jun 01 '21 at 14:32
  • @user786 OK, and what do you mean by "I plan to write in makefile the debug flags=y" more precisely? CONFIG_DEBUG_INFO=y or something else? – Ciro Santilli OurBigBook.com Jun 01 '21 at 14:34
  • I mean where should I type CONFIG_DEBUG_INFO=y – user786 Jun 01 '21 at 17:24
  • @user786 see the code given in this answer. – Ciro Santilli OurBigBook.com Jun 01 '21 at 17:42
  • I have successfully compiled the kernel with debug flags from your above link answer. thank u very much for this. now I want to debug Ethernet driver from realTek thats my nic card driver. Now I want to debug realTek r8169 Ethernet driver same way as the link answer which u gave. I know there is function rtl_rx in r8169_main.c file which called from NAPI poll handler. and inside that rtl_rx function napi_gro_receive(&tp->napi, skb); called and napi_gro_receive I beleive forward the packet up the kernel stack. – user786 Jun 03 '21 at 11:38
  • So are there any chances I can run and debug compiled kernel using qemu and check the kernel tcp stack 's functions call-stack -- since there will be only kernel running in Qemu but can I see the packet going way up the kernel stack following the driver 's rtl_rx napi_gro_receive function call – user786 Jun 03 '21 at 11:38
  • @user786 great! Is there any specific reason why https://stackoverflow.com/questions/4943857/linux-kernel-live-debugging-how-its-done-and-what-tools-are-used/42316607#42316607 won't work? – Ciro Santilli OurBigBook.com Jun 03 '21 at 12:02
  • I just like to ask since it wont be ubanu os. There is no userspace, just compiled kernel with debug flags so how to test the kernel tcp stack. How do I find the ip so I can send packets from some other system to check target compiled running kernel in qemu. Can I specify in qemu t)which ethernet device to use as hardware ?so Realtek Ethernet driver can be debugged. Other wise r8169 pci network driver will not be used and not running. – user786 Jun 03 '21 at 12:15
  • @user786 in general you just the only/easiest solution is to just setup userspace as well and run your content. My preferred way is with a Buildroot userland as shown at: https://github.com/cirosantilli/linux-kernel-module-cheat – Ciro Santilli OurBigBook.com Jun 03 '21 at 13:54
0

I had this same issue since I wanted to upgrade my CentOS kernel and needed to do it on several machines. Assume here my new CentOS kernel tree is in /linux-5.1 (I'm logged into the root account)

  1. cd /linux-5.1
  2. run make menuconfig and make your changes and save them to .config
  3. copy the /linux-5.1/.config file to your development server
  4. Now for your next machine to upgrade you'll copy .config file from your development server to /linux-5.1/.config on the new machine.

Hope this helps someone in the same predicament.

GAD3R
  • 66,769