build kernel module - Linux

Gary avatar
By Gary
at 2014-04-02T19:54

Table of Contents

在進行android embedded system開發時
遇到了kernel module編譯的小問題, 還請各位指教, 謝謝!

Q1 :
假如我只想要單build kernel module ,
我需要完整的kernel source tree嗎?
還是只需要kernel source 的 header file package?

A1 :
有些部落格提到是下載整個kernel source tree,
然後還要把這個kernel source tree給build過一次 ...
可是我從國外網站查到的答案如下,
簡單來說就是不需要kernel source tree, 只需要kernel headers
請問各位是如何處理的呢 @@?

ref - http://ppt.cc/Tl91
In order to build a kernel module, we need the kernel headers
(or kernel source) that match the binary image.
The headers provide vital definitions that are needed
in order to compile the source code for the module.

The compressed source code is about 110MBytes in size.
This is the full source for the kernel including all of the headers.
Strictly speaking, we just need the headers, but you might want to
explore the kernel, other kernel modules, ARM-specific support code,
or the PERF subsystem. It’s all there.


ref - http://ppt.cc/Fuy8
To be frank you do not need a new full source tree in order to
just compile or build module against the running kernel
i.e an exploded source tree is not required to build kernel driver or module.
Please note that to work with this hack you just need the Linux kernel
headers
and not the full kernel source tree.

也就是說
通常下載的 kernel source code 會在 /usr/src/linux-xxx
/lib/modules/3.6.11+/build 這邊的build 會 ln 到 上面的位址
如果沒有 就手動建立link
ln -s /usr/src/linux /lib/modules/3.6.11+/build

note.
上面那個build你可以連到 kernel source header only
或 kernel full source


================================================================================

Q2.
一般我們build一個c程式, 在link 其他 library 時有兩種case:
a. standard c library , 這不需要特別指定路徑,
gcc 會去 /usr/include 找header ,
去 /usr/lib 找 libc.a libc.so
b. 3rd party library, 這就要指定
header file 及 library binary(*.a / *.so) 的位置

然而在build kernel module的時候,
怎沒看到需要去指定library的動作呢 ?
我的意思是, 自訂的 kernel module 中會include 到
platform.h init.h 之類非standard c 的 部份 ,
這些部份在build kernel module的時候是如何處理的?

文長請多包含 謝謝!

--
Tags: Linux

All Comments

Daniel avatar
By Daniel
at 2014-04-03T00:42
1.這要看你的module 是否能夠 out of tree compile
2.kernel_src 變數指定

找不到HP ML110 G5 centos的RAID驅動...

Christine avatar
By Christine
at 2014-04-01T16:37
公司server是HP ML110 G5原本是用外接的RAID卡,可是故障了,所以想用主機板做RAID 已經進BIOS改RAID,也建起RAID,但在centos安裝時看不到硬碟,應該是沒驅動, 但上網找都找不到驅動...(官網有放Red Hat5的驅動,但安裝時讓他讀取都失敗) 第一次打給HP他 ...

Cent OS網路問題

Faithe avatar
By Faithe
at 2014-03-31T22:36
各位大大好 小弟剛接觸CentOS不久,但遇到以下問題不知如何解,所以上來一問 首先是開機時遇到以下問題 http://ppt.cc/31dR 另外下圖是網路設定的圖 http://ppt.cc/COw4 我參考網路上好幾篇文章的處理方式 例如更改以下檔案或是刪掉後再reboot /etc/udev ...

如何讓電腦架設可讓外界使用的SSH連線

Isla avatar
By Isla
at 2014-03-31T22:11
各位大大好 我是centos新手,我的實驗室有一台電腦供我使用 因為資料都在這台電腦,所以回家後就無法取得這些資料 請問要如何設定讓我可以從家中SSH到學校這台電腦呢? 架設FTP? 請問要收尋的關鍵字和資料有哪些?? PS這台電腦是固定IP,如果不是固定IP也可以嗎? (抱歉問了很新手的問頭) ...

RedHat次版本的差異性

Ophelia avatar
By Ophelia
at 2014-03-31T19:58
哈囉 各位板友大家好, 最近有需要選擇使用的OS版本, 因為想了解一下redhat版本的差異, 拜了一個小時的咕狗大神, 感覺還是沒有解惑到, 所以來這邊跟板友討教一下了。 主要是次版號的部分,如5.5、5.6、5.7, 這個次版號是以什麼為依據來做提升的呢? 像redhat5.x、redhat6.x, 知 ...

git 列出某的版本號之後所有異動過的檔案

Elizabeth avatar
By Elizabeth
at 2014-03-31T17:33
不好意思又在linux板發問git的問題了 請問是否有方式一次列出 在這個branch(或是某個版本號之後) 所有曾經異動過的檔案 而不是需要從commit的紀錄一筆一筆的去看 或是把兩個前後兩個版本都倒出來 再用比對檔案的軟體去比對 - ...