linux高版本模块在低版本运行,Re: 关于Linux下高版本内核编译低版本内核的问题...

下面是FC5下编译2.4.20的例子,FC5有bug,中文命名文件会没有反映,建议用稳定的FC4,FC5内核貌似2.6.15还是18忘了。

1.准备2.4.20的源代码

$tar jxf linux-2.4.20.tar.bz2

$mv linux-2.4.20 linux

$cd linux

$make mrproper

$make config

$make dep

上面这些步骤都能顺利

通过

$make bzImage

一会就出现了如下的 错误

/usr/linux-2.4.20/include/linux/smp.h:29: error: conflicting types for "smp_send_reschedule"

/usr/linux-2.4.20/include/asm/smp.h:42: error: previous declaration of "smp_send_reschedule" was here In file included from /usr/linux-2.4.20/include/linux/unistd.h:9,from init/main.c:17:

/usr/linux-2.4.20/include/asm/unistd.h:375: warning: conflicting types for built-in function "_exit"

这是因为FC5下的GCC版本太新(gcc4.1)

建议使用 gcc 2.95或者gcc3.2进行编译(Dave Thompson)

在网上寻找了一会,发现其实FC5下可以安装一个pachage,就可以使用gcc3.2,同时不会影响当前的gcc4.1。

于是就在

ftp://rpmfind.net/linux/fedora/core/5/i386/os/Fedora/RPMS/compat-gcc-32-3.2.3-55.fc5.i386.rpm

里下载了一个

该包的大致描述为:The compatibility GNU Compiler Collection Fedora Core 5 for i386,马上进行安装

$rpm -ivh compat-gcc-32-3.2.3-55.fc5.i386.rpm

安装完成后在/usr/bin下多了一个gcc32

于是马上修改Makefile,把里面的CC修改为 gcc32,接着

$make bzImage

经过漫长的等待(不长,也就15分钟左右),结果等来的却是:

{standard input}: Assembler

messages:

{standard input}:936: Error: suffix or operands invalid for `mov"

{standard input}:937: Error: suffix or operands invalid for `mov"

{standard input}:1031: Error: suffix or operands invalid for `mov"

{standard input}:1032: Error: suffix or operands invalid for `mov"

{standard input}:1083: Error: suffix or operands invalid for `mov"

{standard input}:1084: Error: suffix or operands invalid for `mov"

{standard input}:1086: Error: suffix or operands invalid for `mov"

{standard input}:1098: Error: suffix or operands invalid for `mov"

结论:是FC5下的binutils的一个bug,

下载相应的补丁

http://www.kernel.org/pub/linux/devel/binutils/linux-2.6-seg-5.patch

在待编译的内核源码(本例为linux-2.4.20/)的根目录下进行patch操作:

$patch -p1

patching file arch/i386/kernel/process.c

Hunk #1 succeeded at 693 with fuzz 1 (offset 96 lines).

patching file arch/i386/kernel/vm86.c

Hunk #1 FAILED at 294.

1 out of 1 hunk FAILED -- saving

rejects to file arch/i386/kernel/vm86.c.rej

patching file arch/x86_64/kernel/process.c

Hunk #1 succeeded at 458 with fuzz

2 (offset 67 lines).

Hunk #2 succeeded at 443 with fuzz 2 (offset -14 lines).

Hunk #3 FAILED at 458.

Hunk #4 FAILED at 479.

2 out of 4 hunks FAILED -- saving rejects to file arch/x86_64/kernel/process.c.rej

patching file include/asm-

i386/system.h

Hunk #1 succeeded at 84 (offset 3 lines).

Hunk #2 FAILED at 96.

1 out of 2 hunks FAILED -- saving rejects to

file include/asm-i386/system.h.rej

$make bzImage

又是漫长的等待,出现如下错误

{standard input}: Assembler messages:

{standard input}:936: Error: suffix or operands invalid for `mov"

{standard input}:937: Error: suffix or operands invalid for `mov"

{standard input}:1031: Error: suffix or operands invalid for `mov"

{standard input}:1032: Error: suffix or operands invalid for `mov"

make[1]: *** [process.o] 错误 1

make[1]: Leaving directory `/usr/src/linux/arch/i386/kernel"

make: *** [_dir_arch/i386/kernel] 错误 2

是as的问题,再编辑

arch/i386/kernel/process.c

在579行,将

asm volatile("movl %%" #seg ",%0":"=m" (*(int *)&(value)))

改成

asm volatile("mov %%" #seg ",%0":"=m" (value))

执行

$make bzImage

一切正常

$make modules

$make modules_install

出现了如下的信息

cd /lib/modules/2.4.20; \

mkdir -p pcmcia; \

find kernel -path "*/pcmcia/*" -name "*.o" | xargs -i -r ln -sf ../{} pcmcia

if [ -r System.map ]; then /sbin/depmod -ae -F System.map 2.4.20; fi

Version requires old depmod, but couldn"t run /sbin/depmod.old: No such file or directory

make: *** [_modinst_post] 错误 2

那就创建一个depmod.old的链接

$ln -s /sbin/depmod /sbin/depmod.old

$make modules_install

$mkinitrd -f -v /boot/initrd-2.4.20.img 2.4.20

一切正常,修改相应的

lino或者 grub,重新启动。

如果你不是用FC5,再遇到错误贴出来我给你看。。。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要生成不同版本Linux 内核通用的 .ko 模块,可以按照以下步骤进行: 1. 安装内核源代码和编译工具链 在 Linux 系统中,可以通过包管理器安装内核源代码和编译工具链。例如,在 Ubuntu 系统中,可以使用以下命令来安装: ``` sudo apt-get install linux-source build-essential ``` 2. 解压内核源代码 在安装完内核源代码后,需要解压到本地,解压后会生成一个源代码目录。可以使用以下命令来解压: ``` tar xvf linux-source-版本号.tar.xz ``` 3. 进入内核源代码目录,并编译模块 进入解压后的内核源代码目录,使用以下命令进行编译: ``` make modules ``` 编译完成后,会在内核源代码目录的 /lib/modules/版本号 目录下生成 .ko 模块文件。 4. 使用生成的 .ko 模块 生成的 .ko 模块可以在不同版本Linux 内核中使用。如果要使用该模块,需要将该模块文件放到系统的 /lib/modules/版本号/kernel/drivers 目录下,并执行以下命令更新模块依赖关系: ``` depmod -a ``` 然后,可以通过 modprobe 命令加载该模块: ``` modprobe 模块名 ``` 加载成功后,可以通过 lsmod 命令查看已加载的模块信息: ``` lsmod ``` 如果要卸载该模块,可以使用以下命令: ``` rmmod 模块名 ``` 卸载成功后,可以通过 lsmod 命令查看已加载的模块信息,确认该模块已被卸载。 总之,要生成通用的 .ko 模块,需要在相同的内核版本下进行编译,然后将生成的模块文件放到不同版本内核中使用。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值