TipsAndTricks/QuickAndDirtyKernelConfig

= How to Quickly Set Some Options in the Kernel =
== The Real Way == 
The best in depth explanation/tutorial for working with the kernel in Yocto is located here: https://www.yoctoproject.org/training/kernel-lab. It has a pdf, and supporting layers/metadata to allow you to follow along. There is also a kernel development manual located at http://www.yoctoproject.org/docs/latest/kernel-dev/kernel-dev.html.
If you are going to do a lot with the kernel or are planning to ship it in a product/project, I'd strongly recommend going through the lab and reading the kernel manual.
== The Quick and Dirty Way == 
But, sometimes, you really just want to be able to set an option. How can you do this?
=== Menuconfig ===
 bitbake linux-yocto -c menuconfig 
This will put you into the standard ncurses menuconfig screen and you can select options as normal and then rebuild your kernel with:
 bitbake linux-yocto 
This will modify the .config file that linux-yocto uses
 tmp/work/<machine>-common-poky-linux/linux-yocto/<version>/linux-<machine>-common-standard-build/.config 
in the version I am working off of it looks like this for a machine=intel-corei7-64 and a linux-yocto near the time of Morty's (YP 2.2) release.
 tmp/work/corei7-64-intel-common-poky-linux/linux-yocto/4.8+gitAUTOINC+552a83790b_67813e7efa-r0/linux-corei7-64-intel-common-standard-build/.config
The good news is that that was pretty easy. The bad news, is that 
* if I remove tmp, as I tend to do, then my .config will go away.
* if I want to share my additions with someone else, I need to give them a whole .config file and tell them to read the above referenced lab for how to use it.
=== Just the Configs I want, nothing more ===
Suppose I know that I just want to set 
 CONFIG_DMA_API_DEBUG=y
and nothing else. What can I do then? With the standard settings, we get:
 
 $grep CONFIG_DMA_API tmp/work/.../.config
 # CONFIG_DMA_API_DEBUG is not set
 
So, the Quick & Dirty approach is to add the following to the end of my conf/local.conf file:
 
 FILESEXTRAPATHS_prepend_pn-linux-yocto := "/my/absolute/path/build/conf:"
 SRC_URI_append_pn-linux-yocto = " file://myKernelConfigs.cfg "
The file myKernelConfigs.cfg is in my conf directory. I could have put it anywhere I wanted, even into a separate git repo in ~/kernelconfigsrepo, for example. myKernelConfigs.cfg contains the kernel configs I want to set. Let's suppose I want to turn on CONFIG_DMA_API_DEBUG.
So the file myKernelConfigs.cfg would have:
 
 # yes, comments are ok
 CONFIG_DMA_API_DEBUG=y
If I delete the tmp folder and rerun bitbake linux-yocto I can then see the following:
 
 $grep CONFIG_DMA_API tmp/work/.../.config
 CONFIG_DMA_API_DEBUG=y
The CONFIG_DMA_API_DEBUG got turned on as we hoped, yay!
=== Something Can Go Wrong... ===
This part is a silly example of how to tell what went wrong when you set config options. Let's suppose that I decide I also want to turn on the feature CONFIG_DMA_API_COW. I'm pretty certain that this is in my kernel so I'll just add it to the file myKernelConfigs.cfg:
 
 # yes, comments are ok 
 CONFIG_DMA_API_DEBUG=y
 # I'm pretty sure this is in my kernel
 CONFIG_DMA_API_COW=y
We can rm tmp and rerun bitbake linux-yocto . Sadly the grep of our config does not show a CONFIG_DMA_API_COW setting. Where did it go?
 
 $grep CONFIG_DMA_API tmp/work/.../.config
 CONFIG_DMA_API_DEBUG=y
It turns out that the CONFIG_DMA_API_COW option is not in the linux-yocto kernel. Big surprise! (This could also have been a typo, or an old config whose name got changed...).
Config options that can't be applied for some reason appear in the file mismatch.cfg &/or invalid.cfg. These are in tmp/work-shared/<machine>/kernel-source/.kernel-meta/ .
This is a useful place to look when you set something and it doesn't seem to be taking effect. For instance:
 
 $grep -rH DMA_API_COW tmp/work-shared/intel-corei7-64/kernel-source/.kernel-meta/
 tmp/work-shared/intel-corei7-64/kernel-source/.kernel-meta/cfg/.config:CONFIG_DMA_API_COW=y
 tmp/work-shared/intel-corei7-64/kernel-source/.kernel-meta/cfg/mismatch.cfg:CONFIG_DMA_API_COW
 tmp/work-shared/intel-corei7-64/kernel-source/.kernel-meta/cfg/invalid.cfg:CONFIG_DMA_API_COW
 tmp/work-shared/intel-corei7-64/kernel-source/.kernel-meta/cfg/mismatch-all.txt:Config: CONFIG_DMA_API_COW
 tmp/work-shared/intel-corei7-64/kernel-source/.kernel-meta/cfg/mismatch-all.txt:Requested value: CONFIG_DMA_API_COW=y
 tmp/work-shared/intel-corei7-64/kernel-source/.kernel-meta/cfg/merge_config_build.log:Value requested for CONFIG_DMA_API_COW not in final .config
 tmp/work-shared/intel-corei7-64/kernel-source/.kernel-meta/cfg/merge_config_build.log:Requested value: CONFIG_DMA_API_COW=y
 tmp/work-shared/intel-corei7-64/kernel-source/.kernel-meta/configs/standard/intel/myKernelConfigs.cfg:CONFIG_DMA_API_COW=y 
This tells us that the value CONFIG_DMA_API_COW is not in the final .config and is in the invalid.cfg file. Good to know!