Creating kernel modules for different versions of Linux

I am new to writing kernel modules, so I run into a few non-technical issues.

Since creating the kernel module for a specific version of the kernel (say, 3.0.0-10, 10 is the patch number) requires the same kernel headers, so it looks right to set the kernel headers and begin development there. But kernel headers for a fixed version of the kernel are not available. Since I have a guest kernel vmlinuz-3.0.0-10 running on the machine, and after loading the kernel headers this says it was not found.

  • Another approach is to get the source for this particular kernel, but again, the problem in the same source is not available for the fixed kernel (it does not need to get the sources linux-kernel-3.0.0-10 or even linux-kernel-3.0. 0 and 10th patch). In some situations, you can get the source of the running kernel, but not always possible.

  • the other is to create a kernel other than a working kernel, and put the embedded kernel in the machine. But this requires creating modules of this kernel that require a lot of time and space.

So, the intention to ask for this is to find out what the preferences of the kernel driver developers are. Are there other alternatives?

Is it possible to compile the kernel module in one version and run in another version (although it will give an error, but is there any workaround for this?)

+6
source share
3 answers

Thus, creating a new kernel is not a good option, as it will require:

  • core building
  • building modules and firmware
  • building headers Moving all of the above items in the appropriate place (if your car is not the one on which you plan to develop the module)

So, if you have kernel headers to start the system, you do not need to download the source code for any version of the kernel and when using the module

make -C /lib/modules/kernel-headers-xyz/build M=`pwd` modules 

and your module will be ready.

If there are better answers, I will not hesitate to agree with them.

+6
source

I know this for a long time since this question was asked. I am new to kernel development. I also encountered the same error. But now I can load my module into another kernel with which I created it. Below is the solution:

  • download kernel-devel associated with the image you are using. It should have the version as close as possible.
  • Make sure the functions you use in the module are mapped to the header files you have in kernel-devel.
  • modify the include / generated / utsrelease.h file for the value UTS_RELEASE. change it to the kernel image version running on your HW.
  • Compile the module using this kernel tree.
  • Now you can insert your module inside the kernel.

Note. This can lead to some undesirable events occurring, as mentioned above Shahbaz. But if you do it just for experimentation, I think it’s good. :)

+2
source

There is a way to create a module on one core and insert it into another. This disables a specific configuration. I am not telling you exactly which configuration, because it is ABSOLUTELY DANGEROUS. The reason is that there may be changes between the kernels that can lead to the behavior of your module in different ways, often leading to complete freezing.

What you have to do is build a module against an already built kernel (or at least a tuned one). If you have a fixed kernel, the best thing you can do is build this kernel and boot your OS with it.

I know this takes a long time. I have done this many times, and I know how boring it can get, but once you do it right, it makes your life a lot easier. Compiling a kernel takes about 2 hours or so, but you can parallelize it if you have a multi-core processor. In addition, you can always let him compile before leaving the office (or if at home, before going to bed) and let him work at night.

In short, I highly recommend that you create a kernel that interests you.

-3
source

Source: https://habr.com/ru/post/917239/


All Articles