Linux Kernel Configuration

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

Nasser Afshin

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.

回复
Nasser Afshin

CTO and Vice Chairman at SStaha

4 年

Note that CONFIG_IKCONFIG should be enabled in the Linux configuration.

要查看或添加评论,请登录

Vahid Gharaee的更多文章

  • GPIO on Linux user-space

    GPIO on Linux user-space

    In linux system you have the privilege to drive digital outputs/inputs from user land with no more than a simple…

    1 条评论
  • PWM on Linux user-space

    PWM on Linux user-space

    What if you need to have PWM on your Embedded linux system? of course one way is to go to the kernel level, make your…

社区洞察

其他会员也浏览了