knave wrote:
All I want to do is to be able to view/read all of the source files (.h.c.S) that went into compiling the kernel. I don't want all the source files in the kernel directory, just the ones that went into building the kernel against my config file.
I assume that different config files use different source files when compiling... Due to the different options selected.
The task you have set yourself to just read just what "went into compiling the kernel" does not seem like a simple matter to me.
The first thing worth noting is that if you want the kernel source files, you will most easily see the kernel source from an unpacked kernel source tarball. It's possible to chase up the source from various git repositories, but as I hope to show in the following, it may not be so practical.
Looking just at the statistics of the task, it's not small. If you take a config file for the kernel, which is usually available on a working system in /boot, the number of configured elements is considerable. For example on this machine I'm writing on:
Code:
[[email protected] /boot]$ wc -l config-5.19.0-1-amd64
10516 config-5.19.0-1-amd64
With one configuration per line, there are 10,516 configuration elements that the kernel has to negotiate to be compiled. Not all the elements are set, so one can take out all those config variables that are not set by removing the configs that are commented out in that config file, config-5.19.0-1-amd64, which is shown by lines that begin with #, for example:
Code:
[[email protected] /boot]$ sed '/#/d' config-5.19.0-1-amd64 > /home/flop/configsSet
wc -l /home/flop/configsSet
6854 /home/flop/configsSet
This kernel has compiled for 6854 config elements that were set in the initial configuration specification.
Next comes the task of finding the header and other code files for those 6854 configured elements. The most straight forward way would be to look at the source of the kernel, in this example, kernel 5.19.0-1-amd64. The source is available in the relevant kernel tarball which can be downloaded from kernel.org.
The relevant code for each config needs to be found. Take for example the configuration for the ethernet device which is usually compiled into standard kernels: CONFIG_ETHERNET=y. With the kernel source tarball unpacked, one might navigate to the include files and search for etheret related code:
Code:
[[email protected] ~/src/linux-5.19.0/include/linux]$ ls | grep -i eth
etherdevice.h
ethtool.h
ethtool_netlink.h
if_ether.h
mv643xx_eth.h
pxa168_eth.h
rethook.h
sh_eth.h
It looks like there's a few relevant files with "etherdevice.h" looking most promising. Reading the file itself, one comes across a reference to another configuration which it refers to: CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS. A look back at the original config file: config-5.19.0-1-amd64, shows this configuration to also be compiled into the kernel, so that will likely have to be followed up to be read to get a fuller picture of what the software is doing.
But wait, there's more.
It's another file of code relevant to ethernet in another directory of the kernel source.
After discovering and reading all the ethernet code, there's still over 6000 other configurations to follow up. There will some overlap to mollify the task, but not having done it all myself I can't say by how much.
The kernel source unpacked takes up about 1.4 gig. The documentation is about 62 meg. There's heaps of driver code which is compiled into kernels when only a few drivers are generally needed for any particular machine. As for finding all code and documentation relevant to ethernet, including the driver code for the particular relevant NICs, I shall leave that as an exercise for the reader.
The point is, it's complicated. Doubtless someone very familiar with any particular configuration element could direct one efficiently to the relevant source code, but for the ordinary interested punter on the hunt, it may well be quite a different matter.
knave asked:
Am I missing something obvious here?
Maybe.
That all said, it should be noted that when configuring a kernel and setting a config such as CONFIG_ETHERNET=y, that there will be a file that references all the files that are necessary to enable the ethernet capabilities, and that file would potentially be the one to start with in a search for what is involved. As for finding it, again, I'll leave that to the interested reader.