簡體   English   中英

如何針對新Source編譯內核模塊

[英]How to compile a kernel module against a new Source

我正在嘗試編譯Hello World模塊。 我的系統中有一個新的Ubuntu沒有任何編譯內核。

我的內核是:

2.6.32-34泛型

我給了以下Makefile並得到了錯誤:

obj-m += hello-1.o
all:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

# make
make -C /lib/modules/2.6.32-34-generic/build M=/home/james/Desktop/hello modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.32-34-generic'
make[2]: *** No rule to make target `/home/james/Desktop/hello/hello-1.c', needed by `/home/james/Desktop/hello/hello-1.o'.  Stop.
make[1]: *** [_module_/home/james/Desktop/hello] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-2.6.32-34-generic'
make: *** [all] Error 2

我的/lib/modules/2.6.32-34-generic的內容是

total 3864
lrwxrwxrwx  1 root root     40 2011-11-05 15:55 build -> /usr/src/linux-headers-2.6.32-34-generic
drwxr-xr-x  2 root root   4096 2011-11-05 15:49 initrd
drwxr-xr-x 10 root root   4096 2011-11-05 15:49 kernel
.......................................................
.......................................................

文件夾/usr/src/linux-headers-2.6.32-34-generic存在。

由於它沒有工作,我從Ubuntu下載了linux-headers-2.6.32-34-generic源代碼並編譯並將我的Makefile更改為:

obj-m += hello-1.o
all:
    make -C /usr/src/linux-2.6.32/ M=$(PWD) modules

clean:
    make -C /usr/src/linux-2.6.32/ M=$(PWD) clean

#make
make -C /usr/src/linux-2.6.32/ M=/home/james/Desktop/hello modules
make[1]: Entering directory `/usr/src/linux-2.6.32'

  ERROR: Kernel configuration is invalid.
         include/linux/autoconf.h or include/config/auto.conf are missing.
         Run 'make oldconfig && make prepare' on kernel src to fix it.


  WARNING: Symbol version dump /usr/src/linux-2.6.32/Module.symvers
           is missing; modules will have no dependencies and modversions.

make[2]: *** No rule to make target `/home/james/Desktop/hello/hello-1.c', needed by `/home/james/Desktop/hello/hello-1.o'.  Stop.
make[1]: *** [_module_/home/james/Desktop/hello] Error 2
make[1]: Leaving directory `/usr/src/linux-2.6.32'
make: *** [all] Error 2

有人可以幫我解決這個問題.http://packages.ubuntu.com/lucid-updates/devel/linux-headers-2.6.32-34-generic

我有一些一般性問題要問。

在全新安裝之后,編譯內核的最佳方法是什么。 在我編譯內核並構建了一個模塊后,它可以更早地完美運行。 但在這種情況下我無法知道該怎么做

錯誤:

ERROR: Kernel configuration is invalid.
         include/linux/autoconf.h or include/config/auto.conf are missing.
         Run 'make oldconfig && make prepare' on kernel src to fix it.


  WARNING: Symbol version dump /usr/src/linux-2.6.32/Module.symvers
           is missing; modules will have no dependencies and modversions.

原因很簡單,因為您的內核源代碼是新下載的,之前是未編譯過的。

這就是你應該如何編譯任何內核模塊。

下載內核源代碼后,必須准備好向其添加任何模塊。

將舊內核的“config-xxxx”文件從/ boot /目錄復制到新的內核源目錄中,並將其重命名為“.config”。

然后執行“make oldconfig”,它將.config的備份轉換為.config.old,並根據新的內核源重新生成一個新的.config。 只需為所有默認設置(很多設置)輸入“ENTER”。

接下來是做一個“make”(並等待一段時間) - 它將生成一個新的內核文件“vmlinux”,以及模塊編譯過程讀取的許多其他文件。

現在,您可以轉到內核模塊源代碼所在的目錄,並基於以下Makefile:

obj-m += hello-1.o

default: modules

modules:

    make -C /kernel_source/ M=$(PWD) modules

clean:
    make -C /kernel_source/ M=$(PWD) clean

與Makefile一起是你的頭文件和源文件,它們是hello-1.c。

只需“make”即可成功生成內核模塊。

你需要在Fedora上安裝一些類似'kernel-devel'的軟件包(抱歉我不是Ubuntu用戶),它提供了頭文件和.config來編譯你的內核模塊。

make [2]: *沒有規則來制作目標/home/james/Desktop/hello/hello-1.c', needed by /home/james/Desktop/hello/hello-1.o'。 停止

您在第一次編譯中遇到此錯誤,因為/ home / james / Desktop / hello /目錄中缺少hello-1.c文件。

  1. 檢查/ home / james / Desktop / hello /目錄中是否存在hello-1.c。
  2. 你需要在你的內核中有modules_enabled。 您需要編譯一個新的內核來執行此操作。 以下文章解釋了如何很好地構建內核。 在內核構建配置中啟用模塊。

    http://kernelnewbies.org/FAQ/KernelCompilation

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM