一点Linux心得: 编译 modutils-2.4.27-1.src.rpm

       我目前在看宋宝华老师的《Linux设备驱动开发详解》;书中提到Linux内核编译部分,需要升级modutils 和module-init-tools.module-init-tools还好一下就编译过。而modutils就是老是出错,后来上网查了一下,发现原来是由于我电脑上安装的Linux kernel 为2.6.xx,所安装的modutils-2.4.27-1.src.rpm 是针对kernel 2.4环境的,kernel 2.4 到 kernel 2.6,某些设置已经发生改变了。我上网查了一下,还没有人发过这方面的帖子,在此,总结一下,我的安装过程。

 

首先,从www.kernel.org 网站上下载modutils-2.4.27-1.src.rpm

http://www.kernel.org/pub/linux/utils/kernel/modutils/v2.4/

然后执行,

#rpm -e --nodeps modutils (强行卸载原有的modutilsRPM包)
#rpm -ivh modutils-2.4.21-23.src.rpm (把源代码包安装到了/usr/src/redflag/目录下[我电脑系统是红旗Linux])

   1:modutils               warning: user kaos does not exist - using root
warning: group ocs does not exist - using root
########################################### [100%]
warning: user kaos does not exist - using root
warning: group ocs does not exist - using root

#cd /usr/src/redhat/SPECS (进入规范文件目录下)

到这里为止,一切都顺利!
#rpmbuild --bb modutils.spec (生成二进制的RPM包)

执行完这命令后,问题就开始了... ...

报错:

error: Legacy syntax is unsupported: copyright
error: line 5: Unknown tag: Copyright: GPL

上网查了一下资料,把modutils.spec里边的第5行

            Copyright: GPL    改成 License:GPL

OK , RPM文件开始编译了,可没有多久就报错了

In file included from obj_kallsyms.c:26:
./../include/util.h:42: warning: built-in function ‘log’ declared as non-function
obj_kallsyms.c: In function ‘obj32_kallsyms’:
obj_kallsyms.c:204: error: lvalue required as left operand of assignment
obj_kallsyms.c:279: error: lvalue required as left operand of assignment
make[1]: *** [obj_kallsyms.o] 错误 1
make[1]: Leaving directory `/usr/src/redflag/BUILD/modutils-2.4.27/obj'
make: *** [all] 错误 2

将obj_kallsyms.c文件修改如下

将204行的

  a_hdr = (struct kallsyms_header *) osec->contents =
     xmalloc(osec->header.sh_size);

改成
  osec->contents = xmalloc(osec->header.sh_size);
  a_hdr = (struct kallsyms_header *) osec->contents;

将279行的

  a_hdr = (struct kallsyms_header *) osec->contents =
    xrealloc(a_hdr, a_hdr->total_size);

改成
  osec->contents = xrealloc(a_hdr, a_hdr->total_size);
  a_hdr = (struct kallsyms_header *) osec->contents;

然后将改动压缩回../SOURCES/modutils-2.4.27.tar.gz,在压缩包里

边直接改动,是不允许保存的,所以要先解压缩,改动后,压缩回去进行覆盖,

以下都是如此做法,不再重复。然后继续。

报错:

In file included from insmod.c:79:
./../include/util.h:42: warning: built-in function ‘log’ declared as non-function
insmod.c: In function ‘add_symbols_from’:
insmod.c:278: error: lvalue required as left operand of assignment
make[1]: *** [insmod.o] 错误 1
make[1]: Leaving directory `/usr/src/redflag/BUILD/modutils-2.4.27/insmod'
make: *** [all] 错误 2
error: Bad exit status from /var/tmp/rpm-tmp.36012 (%build)

将insmod.c文件的第278行

        ((char *)s->name) += 8;

改成

     s->name = (void *)((long)(s->name)+8);

再继续编译,

 

继续报错:

In file included from genksyms.c:32:
./../include/util.h:42: warning: built-in function ‘log’ declared as non-function
genksyms.c:48: error: static declaration of ‘errors’ follows non-static declaration
./../include/util.h:43: error: previous declaration of ‘errors’ was here
make[1]: *** [genksyms.o] 错误 1
make[1]: Leaving directory `/usr/src/redflag/BUILD/modutils-2.4.27/genksyms'
make: *** [all] 错误 2
error: Bad exit status from /var/tmp/rpm-tmp.97956 (%build)

将genksyms.c第48行的语句

               static int errors;

移到文件的开头,紧跟注释后的第一行去。

继续报错:

In file included from depmod.c:44:
./../include/util.h:42: warning: built-in function ‘log’ declared as non-function
depmod.c: In function ‘addksyms’:
depmod.c:1136: error: lvalue required as left operand of assignment
make[1]: *** [depmod.o] 错误 1
make[1]: Leaving directory `/usr/src/redflag/BUILD/modutils-2.4.27/depmod'
make: *** [all] 错误 2
error: Bad exit status from /var/tmp/rpm-tmp.36319 (%build)

将depmod.c的第1136行

               ((char *)ksym->name) += 8;

改成
                ksym->name = (void *)((long)(ksym->name)+8);

继续... ...

Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1
Requires: /bin/sh libc.so.6 libc.so.6(GLIBC_2.0) libc.so.6(GLIBC_2.1) libc.so.6(GLIBC_2.1.3) libc.so.6(GLIBC_2.3)
Checking for unpackaged file(s): /usr/lib/rpm/check-files /var/tmp/modutils-root
warning: Installed (but unpackaged) file(s) found:
   /sbin/kallsyms.static
   /sbin/ksyms.static
   /sbin/lsmod.static
   /sbin/modprobe.static
   /sbin/rmmod.static
Wrote: /usr/src/redflag/RPMS/i386/modutils-2.4.27-1.i386.rpm
Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.85202
+ umask 022
+ cd /usr/src/redflag/BUILD
+ cd modutils-2.4.27
+ rm -rf /var/tmp/modutils-root
+ exit 0

OK,终于编过去了,好累!!!



#cd ../RPMS/i386 (转入刚生成的二进制的RPM包所在位置)

#rpm -ivh modutils*.rpm

Preparing...                ########################################### [100%]
        file /usr/share/man/man2/delete_module.2.gz from install of modutils-2.4.27-1 conflicts with file from package man-pages-2.21-4
        file /usr/share/man/man2/init_module.2.gz from install of modutils-2.4.27-1 conflicts with file from package man-pages-2.21-4
        file /sbin/depmod from install of modutils-2.4.27-1 conflicts with file from package module-init-tools-3.2-0.pre9.2.2.2
        file /sbin/insmod from install of modutils-2.4.27-1 conflicts with file from package module-init-tools-3.2-0.pre9.2.2.2
        file /sbin/insmod.static from install of modutils-2.4.27-1 conflicts with file from package module-init-tools-3.2-0.pre9.2.2.2
        file /sbin/lsmod from install of modutils-2.4.27-1 conflicts with file from package module-init-tools-3.2-0.pre9.2.2.2
        file /sbin/modinfo from install of modutils-2.4.27-1 conflicts with file from package module-init-tools-3.2-0.pre9.2.2.2
        file /sbin/modprobe from install of modutils-2.4.27-1 conflicts with file from package module-init-tools-3.2-0.pre9.2.2.2
        file /sbin/rmmod from install of modutils-2.4.27-1 conflicts with file from package module-init-tools-3.2-0.pre9.2.2.2
        file /usr/share/man/man8/depmod.8.gz from install of modutils-2.4.27-1 conflicts with file from package module-init-tools-3.2-0.pre9.2.2.2
        file /usr/share/man/man8/insmod.8.gz from install of modutils-2.4.27-1 conflicts with file from package module-init-tools-3.2-0.pre9.2.2.2
        file /usr/share/man/man8/lsmod.8.gz from install of modutils-2.4.27-1 conflicts with file from package module-init-tools-3.2-0.pre9.2.2.2
        file /usr/share/man/man8/modinfo.8.gz from install of modutils-2.4.27-1 conflicts with file from package module-init-tools-3.2-0.pre9.2.2.2
        file /usr/share/man/man8/modprobe.8.gz from install of modutils-2.4.27-1 conflicts with file from package module-init-tools-3.2-0.pre9.2.2.2
        file /usr/share/man/man8/rmmod.8.gz from install of modutils-2.4.27-1 conflicts with file from package module-init-tools-3.2-0.pre9.2.2.2

安装之前生成的RPM,从上边提示来看,我电脑上已有的设置跟RPM包有一些冲突,可能是因为电脑本身的内核版本就很高,跟modultils-2.4有不一致的地方。不知道对后面编译内核有没有影响,这个放到后面再说吧。本来想找 modultils-2.6,哪知连www,kernel.org网站都找不着,之好用 所看到最新的modultils-2.4.27了

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值