linux驱动笔记——环境搭建1

1, 安装 Module-Init-Tools

Module-Init-Tools 的内容

安装的程序:depmod, insmod, insmod.static, lsmod (链接到 insmod), modinfo, modprobe (链接到 insmod), rmmod (链接到 insmod)

简要描述

depmod

创建一个可加载内核模块的依赖关系文件,modprobe 用它来自动加载模块。

insmod

向正在运行的内核加载模块

insmod.static

insmod 的静态编译版本

lsmod

显示当前已加载的内核模块信息

modinfo

检查与内核模块相关联的目标文件,并打印出所有能得到的信息。

modprobe

利用 depmod 创建的依赖关系文件来自动加载相关的模块

rmmod

从当前运行的内核中卸载模块

 

2,需要升级modutils

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

static去掉,

继续报错:

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了

3,终于可以使用 /sbin/insmod 和 /sbin/rmmod 向内核加载卸载驱动了 

[root@localhost simple]# ll /sbin/insmod /sbin/rmmod
-rwxr-xr-x 1 root root 4924 2007-09-05 /sbin/insmod
-rwxr-xr-x 1 root root 8264 2007-09-05 /sbin/rmmod

把insmod和rmmod分别当成一个单独的可执行文件来看待


 

你可能感兴趣的:(linux,function,struct,File,header)