How to reverse lookup linux kernel config option in menuconfig - linux

If I find an option in .config that I would like to enable or disable. Is there a quick way to find it in menuconfig menu?
i.e. I don't want CONFIG_STRICT_DEVMEM to be set. I had to guess where I can find it in the make menuconfig sub-menu. Is there a programmatic way or a faster way to find the sub-menu, rather than "guess"?

If I remember correctly, you can just hit
/DEVMEMEnter
and you'll be taken there? Look for the 'search'/'find' option. If my memory serves me well, it will even tell you about required dependencies

You can use the key / while in menuconfig to research a particular string. This will give you a list of matching configuration option and their path.
You can also use a gui instead of the ncurse menuconfig by typing make xconfig.
Another way to do the lookup would be to use the find command like that:
find /path/to/kernel/sources -name Kconfig -exec grep -Hn config_pattern {} \;

.config is a text file. As such, the easiest way to directly modify an option is to simply place y, m, or n as required. make oldconfig can subsequently be used if this leaves the configuration in an inconsistent state.

Related

How to create a consistent .config file to compile Linux kernel?

To compile Linux kernel, I created a default .config file using make defconfig. Since I didn't want to browse thousands of options through a menu-driven interface (make menuconfig), I set CONFIG_KALLSYMS=n manually, and then triggered the build (make -j8). I noticed the build system overwrote my changes and set CONFIG_KALLSYMS=y again. I suspect there might be other options present in the configuration which rely on CONFIG_KALLSYMS. How can I create a consistent .config file without using any menu-driven interface?
It might be burdensome to browse thousands of options through a menu-driven interface (make menuconfig). When you only want to change a couple of options and don't remember where they are in the menu hierarchy, you can use search to find any specific option. Just press / (slash) and type the full or partial name of the option. The result of the search will show where the options are located in the menu hierarchy, and what are the dependencies. Save and exit after you are done with the changes, and you should have a consistent .config file.
After you create a .config using make defconfig, to change just a few config options after that "make menuconfig" is the best way to do this. It also tells you about the dependencies and doesn't allow you to make a change unless the dependencies are met.

Linux Kernel configs official documentation

When compiling a linux kernel, one of the first step is to generate the .config file which in my case I'm getting from the currently installed kernel. So it generates this files with a lot of KEY=VALUES like:
CONFIG_64BIT=y
CONFIG_X86_64=y
CONFIG_X86=y
CONFIG_INSTRUCTION_DECODER=y
CONFIG_OUTPUT_FORMAT="elf64-x86-64"
CONFIG_ARCH_DEFCONFIG="arch/x86/configs/x86_64_defconfig"
CONFIG_STACKTRACE_SUPPORT=y
# etc...
I can just copy/paste one of those keys in google and I'll probably find (in some random site) a detailed explanation for what it is used for. So my question is, is there an official place where I can rely to know about those configs? I searched on kernel.org/doc and didn't found so I decided to ask here. Thanks in advance.
The documentation can be access through the make menuconfig, each entry is documented (a paragraph describes the option).
But you can only see the options that are available to your architecture, and also if you disable a feature it may hide some related option.
If you want to see all options, the best thing it is to open the Kconfig files.
You can go here: https://github.com/torvalds/linux/ and search for Kconfig files (There are at this moment 1021 Kconfig files)
But clearly if you do not know where to search, for example if you are looking for CONFIG_INSTRUCTION_DECODER, from the kernel source tree run: grep INSTRUCTION_DECODER $(find -name Kconfig)
But INSTRUCTION_DECODER is not really a good example since there is no associated help section with that option...

how to let cg_annotate include a dictionary?

I've tried to use cg_annotate to include a dictionary by use --include flag. However, no matter what I typed after --include=, it always shows the manual (indicating that my path is wrong).
for example, I typed ".util" after --include= but it shows the manual:
the sceenview
The official manual says:
-I --include= [default: none] Adds a directory to the list in which to search for files. Multiple -I/--include options can be given to add multiple directories.
There is no 'dictionnary' of directories stored somewhere, you always have
to give the list of directories each time you launch cg_annotate.
So, in your case, the mandatory argument cachegrind-out-file is not provided in your command. This causes cg_annotate to stop and show its usage.
You might possibly use kcachegrind (and --tool=callgrind), as kcachegrind has some support for specifying source directories (if ever that is needed, as normally kcachegrind+callgrind will find automatically the source files).
To add some directories in kcachegrind, you can use the menu entry Settings->Configure Kcachegrind and add directories in the Annotations tab.

How to specify customized emacs configuration file rather than "~/.emacs"?

I just want emacs to load another file as the configuration file, and ignore the default file ("~/.emacs").
Note that I don't want to change the original "~/.emacs" file.
I've tried to change "$HOME" env variable, but it doesn't work.
(Platform is Linux.)
emacs --no-init-file --load=some-other-config.el
Or with short options:
emacs -q -l some-other-config.el
From the Emacs manual, section 48.4:
Emacs looks for your init file using the filenames ‘~/.emacs’, ‘~/.emacs.el’, or ‘~/.emacs.d/init.el’ you can choose to use any one of these three names […].
If you really want to use another file, you should consider patching Emacs and making a custom build. It looks like lisp/startup.el:1009 is a good place to start.
As far as I can see, the only option is to use -u to indicate another user's init file.
As #Benjamin quoted, there are three filenames you can choose. As normally, we choose ~/.emacs.d/init.el to be loaded. That's because, we can simply add more configuration files in this directory and add them all under version control(Git). Be sure ~/.emacs and ~/.emacs.el removed before u choose to use the ~/.emacs.d/init.el.

How do you search for all the files that contain a particular string?

Let's say you're working on a big project with multiple files, directories, and subdirectories. In one of these directories/subdirectories/files, you've defined a method, but now you want to know exactly which files in your entire project have been calling your method. How do you do this?
You mentioned grep so I'll throw this solution out there. A more robust solution would be to implement a version control system as Fibbe suggested.
find . -exec grep 'method_name' {} \; -print 2> /dev/null
The idea is, for each file that is found in the current directory and sub-directories, a grep for 'method_name' is executed on that file. The 2> /dev/null is nice if you don't want to get warned about all of the directories and files you don't have access to.
The most common way to do this is by using your editor. For example emacs can do this if you create a tag index with etags.
Source: http://www.gnu.org/software/emacs/emacs-lisp-intro/html_node/etags.html
The you just types M-. and type the name of the function you want to visit and emacs will take you there.
I don't know what system or which editor you are using but most editors has a simular function.
If you don't use emacs an other good way to keep track of functions, and get a lots of other good features, is to use a versions control system. Like git, it provides really fast search.
If you don't use a version control system you may want to look at a program that is designed just for searching. Like OpenGrok.

Resources