Linux驅動Invalid module format錯誤解決

來源:互聯網
上載者:User

 

1.編譯錯誤(其實這個問題和 Makefile有很大關係)

2.Invalid module format 錯誤

3.insmod: error inserting ./hello.ko: -1 File exists

開發環境

核心版本:2.6.22(我下載的最新版本)

gcc:gcc (GCC) 4.1.2

Makefile

gcc -D__KERNEL__ -DMODULE -DLINUX -I /usr/local/src/linux2.4/include -c -o hello.o hello.c

上面這種寫法適合 2.4 版本的核心,在2.6下用這種寫法很可能導致許多編譯錯誤,即使編譯通過也會產生 Invalid module format 錯誤。

2.6下正確的 Makefie 如下:

# Makefile2.6ifneq ($(KERNELRELEASE),)#kbuild syntax. dependency relationshsip of files and target modules are listed here.mymodule-objs := hello.oobj-m := hello.o elsePWD := $(shell pwd)KVER ?= $(shell uname -r)KDIR := /lib/modules/$(KVER)/buildall:$(MAKE) -C $(KDIR) M=$(PWD)clean:rm -rf .*.cmd *.o *.mod.c *.ko .tmp_versionsendif

使用上面的 Makefie 同時也解決了 Invalid module format 錯誤

insmod: error inserting ./hello.ko: -1 File exists 錯誤解決

第一次insmod ./hello.ko 沒有輸出表示你的模組被正常載入了,後來的錯誤是你重複載入這個模組導致的

用命令 lsmod | grep hello 看看是不是有這個模組?

用命令 tail /var/log/messages

有 hello,world

module程式正常執行。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.