Interchangeability of compiled LKMs

萝らか妹 提交于 2019-12-22 10:17:30

问题


Is it possible, to use a Loadable Kernel Module, compiled for 3.0.8+ mod_unload ARMv5 (my self-make'd kernel) in a kernel with version 3.0.31-gd5a18e0 SMP preempt mod_unload ARMv7 (android stock-kernel)?

The module itself contains nearly nothing, just

// Defining __KERNEL__ and MODULE allows us to access kernel-level code not usually available to userspace programs.
#undef __KERNEL__
#define __KERNEL__

#undef MODULE
#define MODULE

// Linux Kernel/LKM headers: module.h is needed by all modules and kernel.h is needed for KERN_INFO.
#include <linux/module.h>    // included for all kernel modules
#include <linux/kernel.h>    // included for KERN_INFO
#include <linux/init.h>        // included for __init and __exit macros

MODULE_AUTHOR("martin");
MODULE_LICENSE("GPL");

static int __init hello_init(void)
{
    //printk(KERN_INFO "Hello world!\n");
    return 0;    // Non-zero return means that the module couldn't be loaded.
}

static void __exit hello_cleanup(void)
{
    //printk(KERN_INFO "Cleaning up module.\n");
}

module_init(hello_init);
module_exit(hello_cleanup);

I'm forcing the insmod but then the kernel-crashes:

<1>[ 328.025360] Unable to handle kernel NULL pointer dereference at virtual address 00000061 <1>[ 328.025695] pgd = c1be8000 <1>[ 328.025848] [00000061] *pgd=00000000 <0>[ 328.026184] Internal error: Oops: 5 [#1] PREEMPT SMP <4>[ 328.026519] Modules linked in: airstream_interceptor(+)

I use

CROSS_COMPILE=/home/adminuser/WORKING_DIRECTORY/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi-
KDIR    ?= /home/adminuser/WORKING_DIRECTORY/android-3.0
ARCH=arm

for both building the kernel and now building module. But the system on it should be inserted uses it's own factory kernel.

I try to build a kernel modul which can be used on several android-phones (arm,armv5,armv7 and so on) but I want to use 1 for all (if this is possible in any way).

(edit)

CONCLUSION #1

  1. it should not be possible to compile one version for all ARM-devices:

    compile LKM for kernel 3.0.8 for ARMv5 and use it on a kernel 3.0.39 ARMv7

  2. it may (untested at the moment!) be possible, to compile on the lowest level (ARMv5) and use it in higher levels (ARMv6, ARMv7)

    compile LKM for kernel 3.0.8 for ARMv5 and use it on a kernel 3.0.8 ARMv7

  3. it may be possible to interchange the kernel-versions (maybe if simple LKM)

    compile LKM for kernel 3.0.8 for ARMv5 and use it on a kernel 3.0.39 ARMv5

Open questions at the moment:

1.)

I tried (with common-kernel 3.0.8 and omap-kernel 3.0.39) to build for ARMv7 but the result is always a ARMv5-LKM.

I manually edited the .config, removed the ARMv5-line and added the ARMv7-line (which was nowhere in the .config):

#CONFIG_CPU_32v5=y # I added the #
CONFIG_CPU_V7=y # didn't exist 
CONFIG_CPU_32v7=y # didn't exist 

but if I then re-run "make" on the kernel-source, the file get's automatically edited and my v7-config where removed. Some months ago, I remember this was no problem, I just added the 2 lines and it worked.

Is this a thing of the kernel-source or the used toolchain?

2.)

What is the difference between e.g. the "omap-kernel" and the "common-kernel" in view of the LKM-building? Just an other kernel-version (e.g. common-kernel has now 3.0.53 and omap-kernel 3.0.39)? I think I can "ignore" the specific variants and use the common-kernel for LKM-compiling?

Many thanks to alkalinity, auselen & Marko at the moment - you're helping me out of the mud.


回答1:


No, this isn't possible. The Linux kernel is architecture-specific, and ARMv5 modules are not compatible with ARMv7. There are different header files needed, which will have different instruction sets, or register mappings, or any number of important variants.

In any event, the kernel versions are different in this case too, which means that the kernel API can vary, and therefore the kernel module will not work in all likelihood, even if the architecture were the same.

You'll have to cross-compile separate versions of your kernel module. This isn't too difficult if you have access to the whole kernel tree. The manufacturer should have released their kernel sources (as per the GPL). If they have not, they owe you sources.

If you're interested in reading up on the specifics of loading kernel modules, IBM has a great "anatomy" series of articles. Here's on on loadable kernel modules. Jump to the section on "module loading details" to understand why the kernel rejects insertion of your module in the absence of the force-load.




回答2:


You can't use the same binary driver with different versions of Linux.

Linux does not have a binary kernel interface, nor does it have a stable kernel interface. (source)



来源:https://stackoverflow.com/questions/14241174/interchangeability-of-compiled-lkms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!