Linux Kernel Configuration
There are about 30 million lines of code in Linux kernel because it caries support for too many architectures and devices, but every compile for a specific piece of HW roughly involves 2-3 million lines of the Kernel source. so how do you compile the kernel? mostly for embedded devices the steps are 1- pull the source 2- checkout to the branch you want 3- update the PATH with the path of your tool-chain (gcc) and set the ARCH and CROSS_COMPILE variables with proper values 4- do a "make distclean" 5- apply one of defconfigs 6- do a "make menuconfig" (if needed) 7- do a "make -jX" (X is the number of hyper-threads of your machine) 8- go for a cup of tee! 9- your image is in arch/<machine arch>/boot/ and your dtb will be in the same path and in directory dtc/ . I just mentioned the steps of cross compilation of the linux kernel very very briefly! I don't want to go in there right now, maybe another talk!
The compiled kernel is a file named "Image" and usually it is compressed and come by the name of "zImage" or "vmlinuz" the boot will decompress it in the memory in a specific address (arch dependent) and will jump to it then ......machine is ready. So if we go a little back, how is it, that in every build, just 2-3 million of that 30 million lines of code gets compiled? the answer is "kernel configuration" which is a bunch of pre-definitions for different features, devices, architectures and so on. These definitions could be ON or OFF for instance: "CONFIG_OF = y" is one of those. all of them starts with the word CONFIG and they being "y" or not defined or sometimes a value, will lead to a piece of code gets compiled or not! if you want more data in this regards, google the "kbuild method". anyhow, all the configurations from all sub-folders gather around in a single file in the kernel tree named ".config" then the build starts.
Lets say, you have a working machine and you want to know whether a specific config is set or not. where is it? well in x86: (/boot/config-<kernel version>..) embedded: /proc/config.xz (it should be unzipped). Now, what if you have just a "zImage" ! How can you extract the kernel configurations? Simply go to the kernel source (github of Mr. Torvalds for example) inside the directory "scripts" there is a script named "extract-ikconfig" give your zImage to it and BAMMMM ... there is your zImage configurations! there are all sorts of beautiful script in that "scripts" directory which you would find amazing. Happy coding
An example: ./extract-ikconfig zImage | grep -i config_of
CTO and Vice Chairman at SStaha
4 年Furthermore, if CONFIG_IKCONFIG=m then you should look in the appropriate kernel module (configs.ko) for the Linux kernel configuration info.
CTO and Vice Chairman at SStaha
4 年Note that CONFIG_IKCONFIG should be enabled in the Linux configuration.