Show must go on !

Hi šŸ™‚

I have recently started working on a new project on Linux Kernel Backports, namely to provide the backporting facility for configuring the kernel with localmodconfig option. Throughout this project I will be guided by Luis Rodriguez and Steven Rostedt.

If the project sounds a bit ambiguous, let me provide you some background:

First of all, what is backporting ?

In Linux Kernel most bugs are encountered in time by users and that is why older kernel versions are more stable and recommended for usage in industry.Ā  However, sometimes functionalities from newer kernels are needed. Backporting is a method of providing newer features to older kernels. Given that API’s change in time, the idea behind backports is to define a generic function for a particular functionality that behaves differently for different kernel versions. For example,


Fig 1. Backports patch example (source)

The image provides a useful example of backports patch: the declaration and usage of the structure net_device_ops is available in kernel versions greater or equal to 2.06-26 but the USB device operations should be defined for older kernels so the patch also adds the implementation for the older API. The same functionality is provided by running different code according to version.

If you find the subject interesting you can check out this paper and this conference speech for a more detailed insight.

Next, what is localmodconfig ?

localmodconfig is an option for make tool used to create a configuration (ie. a .config) file based on the loaded modules of the target system. For example, if you want to build a configuration for the current machine you should call:

make localmodconfig

in the root of the kernel tree. This will access the lsmod tool to get loaded modules, will check dependencies and finally find all CONFIG_* options that need to be set for the current machine. The trick works even if the target machine is not the one we work on:

target$ lsmod > /tmp/mylsmod
target$ scp /tmp/mylsmod host:/tmp

host$ make LSMOD=/tmp/mylsmod localmodconfig

The LSMOD enviromental variable holds the path to a file with the output of lsmod on the target machine. The .config generated suits the target machine.

The implementation uses the script for the tree scripts/kconfig/ This script parses recursively Kconfig and Makefile files starting with the ones from the root of the tree and builds a few internal data structures to define the dependencies between symbols. It then uses the lsmod file (or generates a lsmod file using the lsmod tool from the current machine) to find which modules are needed and, based on the internal structures, determines the CONFIG_* options that need to be set in order to have all the modules available.

A few useful data structures are:

@kconfigs -> array of Kconfig file names

@makefiles -> array of Makefile names

$config -> specific configuration (CONFIG_*)

%depends -> hashtable with key=configuration and value=string of dependencies for that configuration

%objects -> hashtable with key=makefile target and value=array of required targets for the key-target to be compiled

There are many useful variables, I just listed the most important ones. All of them are mapped on the kconfig and Makefile structure explained in Documentation. I recommend Documentation/kbuild/kconfig-language.txt and Documentation/kbuild/makefiles.txt as excellent readings in the subject. Some Perl knowledge would be useful too.

Now what’s the project exactly ?

The project is to provide backports functionality for localmodconfig, namely creating a configuration with localmodconfig should return not only the drivers available in the current distribution, but also the backported ones. The project shifts a bit from what I have done so far: if until now I have written kernel code for driver development, now I will work on the kernel build system itself. Level up ! šŸ˜‰

The great part about this project is that is requires some research beforehand. There is no definite solution for the problem, only approach ideas. The goal is to optimize as much as possible the kernel configuration, thus the final kernel image.

Wish me good luck šŸ™‚ !


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s