已编译 LKM 的可互换性 [英] Interchangeability of compiled LKMs

查看:19
本文介绍了已编译 LKM 的可互换性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在版本 3.0.31- 的内核中使用为 3.0.8+ mod_unload ARMv5(我自己制作的内核)编译的可加载内核模块?gd5a18e0 SMP 抢占 mod_unload ARMv7 (android stock-kernel)?

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);

我正在强制使用 insmod 但随后内核崩溃了:

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

<1>[328.025360] 无法处理内核 NULL 指针取消引用虚拟地址 00000061 <1>[ 328.025695] pgd = c1be8000 <1>[328.025848] [00000061] *pgd=00000000 <0>[ 328.026184] 内部错误:哎呀:5 [#1] PREEMPT SMP <4>[ 328.026519] 模块链接在:airstream_interceptor(+)

<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(+)

我用

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.

我尝试构建一个内核模块,该模块可以在多个 android 手机(arm、armv5、armv7 等)上使用,但我想对所有手机都使用 1(如果可以的话).

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).

(编辑)

结论 #1

  1. 不可能为所有 ARM 设备编译一个版本:

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

为 ARMv5 的内核 3.0.8 编译 LKM,并在内核 3.0.39 ARMv7 上使用它

它可能(目前未经测试!)可以在最低级别(ARMv5)上编译并在更高级别(ARMv6、ARMv7)上使用

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

为 ARMv5 的内核 3.0.8 编译 LKM 并在内核 3.0.8 ARMv7 上使用它

可以互换内核版本(如果是简单的 LKM)

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

为 ARMv5 内核 3.0.8 编译 LKM 并在内核 3.0.39 ARMv5 上使用它

目前未解决的问题:

1.)

我尝试(使用 common-kernel 3.0.8 和 omap-kernel 3.0.39)为 ARMv7 构建,但结果始终是 ARMv5-LKM.

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.

我手动编辑了 .config,删除了 ARMv5 行并添加了 ARMv7 行(在 .config 中没有):

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 

但是如果我然后在内核源代码上重新运行make",文件将被自动编辑并且我的 v7-config 被删除.几个月前,我记得这没问题,我只是添加了 2 行并且它起作用了.

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.)

e.g. 和有什么区别?鉴于 LKM 构建,omap-kernel"和common-kernel"?只是另一个内核版本(例如,common-kernel 现在有 3.0.53 和 omap-kernel 3.0.39)?我想我可以忽略"特定的变体并使用通用内核进行 LKM 编译?

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?

多亏了碱度,auselen &此刻的马尔科 - 你正在帮助我摆脱困境.

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

推荐答案

不,这是不可能的.Linux 内核是架构特定,ARMv5 模块不兼容ARMv7.需要不同的头文件,它们将具有不同的指令集、寄存器映射或任意数量的重要变体.

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.

无论如何,在这种情况下,内核版本也不同,这意味着内核 API 可能会有所不同,因此即使架构相同,内核模块也很可能无法正常工作.

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.

您必须交叉编译内核模块的不同版本.如果您可以访问整个内核树,这并不太难.制造商应该已经发布了他们的内核源代码(按照 GPL).如果他们没有,他们欠你资源.

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.

如果您有兴趣阅读加载内核模块的细节,IBM 有一个很棒的解剖"系列文章.这是关于可加载的内核模块.跳转到模块加载详细信息"部分,了解内核在没有强制加载的情况下拒绝插入模块的原因.

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.

这篇关于已编译 LKM 的可互换性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆