為核心增加新原始碼目錄編譯配置

2021-06-12 18:06:01 字數 2510 閱讀 3816

開始著手學習arm  linux知識了,為了自己的學習和實踐**和核心源生**實現分離和解耦,決定在核心的目錄新增乙個自己的原始碼目錄,配置並編譯進核心。

一.新增配置選項及編譯指令碼

(1)新增根目錄的配置選項

修改檔案:

arch\arm\kconfig

在「menu "system type"」之前新增專案

# study/kconfig

menu "linux kernel study & practice"

source "study/start/kconfig"

endmenu

增加這幾行可在config介面新增乙個叫linux kernel study & practice的專案

(2)新增start目錄的配置選項及編譯檔案

l建立檔案kconfig:

study/start/kconfig

內容如下:

# study/start/kconfig

menuconfig study_start

bool "kernel study start project"

help

kernel start study project

if study_start

source "study/start/hello/kconfig"

endif # study_start

這個會在新增的config專案下新增乙個二級選單,下面的

source "study/start/hello/kconfig"依賴於study_start,是我的最終學習原始碼檔案目錄。

l建立檔案makefile

study/start/makefile

內容如下

# makefile add for study

obj-$(config_study_start) += start/

這裡的巨集config_study_start由上面的study_start配置選項生成,表明子目錄」start/」下面的makefile受這個巨集依賴。

(3)新start目錄的配置選項及編譯檔案

第乙個學習專案目錄名為hello

l建立檔案\study\start\hello\kconfig

內容如下:

config hello

tristate "first android driver"

default n

help

this is the first android driver. l

建立檔案\study\start\hello\makefile

內容如下:

obj-$(config_hello) += hello.o

可見linux的原始碼目錄編譯環境配置是kconfig檔案和makefile檔案結合實現的,kconfig生成巨集和目錄依賴關係,makefile把這些巨集和依賴關係傳遞到具體的檔案,這些是隨著目錄樹由根目錄往深處層層推進的。

二.把新增的目錄加入編譯最終的鏈結

因為是新增的乙個根目錄,所以這個時候還不會被編譯器識別,還需要修改乙個檔案:

根目錄下的makefile

增加如下(黑體):

# objects we will link into vmlinux / subdirs we need to visit

drivers-y     := drivers/ sound/ firmware/

study-y   :=  study/

vmlinux-dirs        := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \

$(core-y) $(core-m) $(drivers-y) $(drivers-m) \

$(study-y) $(study-m)\

$(net-y) $(net-m) $(libs-y) $(libs-m)))

drivers-y     := $(patsubst %/, %/built-in.o, $(drivers-y))

study-y   := $(patsubst %/, %/built-in.o, $(study-y))

net-y           := $(patsubst %/, %/built-in.o, $(net-y))

vmlinux-main := $(core-y) $(libs-y) $(drivers-y) $(net-y)$(study-y)

照抄drivers目錄的配置,呵呵,這樣我的新增工程就入駐kenel的根目錄了

linux下增加新原始碼到 linux核心或 模組

root localhost home vi hello.c 內容如下 include hello.h int main root localhost home vi hello.h 內容如下 include 命令 root localhost home mkdir auto 命令 root loc...

Linux核心原始碼目錄

linux核心原始碼目錄 1 arch architecture的縮寫,意思是架構,九鼎在做移植的時候就刪掉了。其他的目錄都跟你沒有任何的關係,所以你完全可以把他們刪除。2 block 英文是塊的意思,表示是塊裝置。以塊 多個位元組組成的整體,以塊為單位來整體訪問 比如說我們的sd卡,inand n...

3 3 核心原始碼目錄結構

3.3 核心原始碼目錄結構 瀏覽核心 之前,有必要知道核心原始碼的整體分布情況,按照慣例,核心 安裝在 usr src linux目錄下,該目錄下的每乙個子目錄都代表了乙個特定的核心功能性子集,下面針對2.6.23版本進行簡單描述。1 documentation。這個目錄下面沒有核心 只有很多質量參...