linux驅動筆記——環境搭建1

來源:互聯網
上載者:User

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分別當成一個單獨的可執行檔來看待

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.