linux內核學習(4)老法子---

我又回來了,上次不是說到~Documentation/kbuild/kconfig.txt中去看看嗎,顧名思義,就是配置文件。先別急,我發現這個kbuild目錄下面有個也有個00-INDEX文件,顯然,肯定又是將該目錄下文件作用的,應該先瞅瞅這個。
00-INDEX
    - this file: info on the kernel build process
kbuild.txt
    - developer information on kbuild
kconfig.txt
    - usage help for make *config
kconfig-language.txt
    - specification of Config Language, the language in Kconfig files
makefiles.txt
    - developer information for linux kernel makefiles
modules.txt
    - how to build modules and to install them
怎麼沒翻譯,呵呵,這麼短,直接看算了。先看看kbuild.txt吧。這裏得說說什麼個kbuild了,網上一搜,一堆啊!找了經典來。

關於kBuild

kBuild是一個makefile框架,用於使編寫簡單的makefiles文件來完成複雜的任務

當前kBuild設計

kBuild框架的目標

1.在所有支持的平臺具有相似的行爲

2.靈活,不會產生不需要的阻止特別方案的約束

3.Makefile能夠很容易地編寫和維護

在當前kBuild觀念中有4個概念

1.一個配置文件能夠自動包含子目錄樹

2.有目標配置文件模板作爲makefile簡化的主要機制

3.有工具和SDKs(Software Development Kit )來使模板具有靈活性

4.通過使用子makefiles來實現非遞歸makefile方法

讀了後什麼感覺,可以這樣理解什麼時kbuild,即一種另類的makefile,一種嵌套了kbuild框架語法的makefile,這樣的makefile會使內核編譯起來變得更加簡單,因此採用這樣的方案。
看看kbuild.txt裏面講了些什麼:
Output files

modules.order
--------------------------------------------------
This file records the order in which modules appear in Makefiles. This
is used by modprobe to deterministically resolve aliases that match
multiple modules.

這個文件記錄了出現在Makefiles中的順序。解決了模塊重名問題。

modules.builtin
--------------------------------------------------
This file lists all modules that are built into the kernel. This is used
by modprobe to not fail when trying to load something builtin.

這個文件列出了被編譯進built-in.o的模塊。解決加載問題。

Environment variables(環境變量)

KCPPFLAGS
--------------------------------------------------
Additional options to pass when preprocessing. The preprocessing options
will be used in all cases where kbuild does preprocessing including
building C files and assembler files.

在kbuild處理C和彙編文件前的一些附加選項。

KAFLAGS
--------------------------------------------------
Additional options to the assembler (for built-in and modules).

彙編文件的附加選項(用於build-in和模塊)。

AFLAGS_MODULE
--------------------------------------------------
Addtional module specific options to use for $(AS).

使用$(AS)的附加模塊選項。

AFLAGS_KERNEL
--------------------------------------------------
Addtional options for $(AS) when used for assembler
code for code that is compiled as built-in.

將彙編代碼編譯到build-in.o時使用$(AS)的附加選項。

KCFLAGS
--------------------------------------------------
Additional options to the C compiler (for built-in and modules).

編譯C時的附加選項(用於build-in和模塊)。

CFLAGS_KERNEL
--------------------------------------------------
Addtional options for $(CC) when used to compile
code that is compiled as built-in.

編譯進build-in.o時使用了$(CC)時的附加選項。

CFLAGS_MODULE
--------------------------------------------------
Addtional module specific options to use for $(CC).

使用$(CC)時的附加模塊選項。

LDFLAGS_MODULE
--------------------------------------------------
Additional options used for $(LD) when linking modules.

鏈接模塊時使用$(LD)的附加選項。

KBUILD_VERBOSE
--------------------------------------------------
Set the kbuild verbosity. Can be assigned same values as "V=...".
See make help for the full list.
Setting "V=..." takes precedence over KBUILD_VERBOSE.


KBUILD_EXTMOD
--------------------------------------------------
Set the directory to look for the kernel source when building external
modules.
The directory can be specified in several ways:
1) Use "M=..." on the command line
2) Environment variable KBUILD_EXTMOD
3) Environment variable SUBDIRS
The possibilities are listed in the order they take precedence.
Using "M=..." will always override the others.

尋找源代碼時所設置的目錄,按照優先順序:
1)使用“M...”在命令行中
2)使用KBUILD_EXTMOD環境變量
3)使用SUBDIRS環境變量

KBUILD_OUTPUT
--------------------------------------------------
Specify the output directory when building the kernel.
The output directory can also be specified using "O=...".
Setting "O=..." takes precedence over KBUILD_OUTPUT.

建立輸出目錄,使用“O=...”命令,也可以使用KBUILD_OUTPUT環境變量,
但優先級沒有前者高。

ARCH
--------------------------------------------------
Set ARCH to the architecture to be built.
In most cases the name of the architecture is the same as the
directory name found in the arch/ directory.
But some architectures such as x86 and sparc have aliases.
x86: i386 for 32 bit, x86_64 for 64 bit
sparc: sparc for 32 bit, sparc64 for 64 bit

設置機器目錄。

CROSS_COMPILE
--------------------------------------------------
Specify an optional fixed part of the binutils filename.
CROSS_COMPILE can be a part of the filename or the full path.

CROSS_COMPILE is also used for ccache in some setups.

CF
--------------------------------------------------
Additional options for sparse.
CF is often used on the command-line like this:

    make CF=-Wbitwise C=2

INSTALL_PATH
--------------------------------------------------
INSTALL_PATH specifies where to place the updated kernel and system map
images. Default is /boot, but you can set it to other values.

設置安裝目錄。

INSTALLKERNEL
--------------------------------------------------
Install script called when using "make install".
The default name is "installkernel".

The script will be called with the following arguments:
    $1 - kernel version
    $2 - kernel image file
    $3 - kernel map file
    $4 - default install path (use root directory if blank)

The implementation of "make install" is architecture specific
and it may differ from the above.

INSTALLKERNEL is provided to enable the possibility to
specify a custom installer when cross compiling a kernel.

設置安裝內核時的腳本文件:
$1 - 內核版本
$2 - 內核映像
$3 - 內核符號表文件
$4 - 默認安裝目錄

MODLIB
--------------------------------------------------
Specify where to install modules.
The default value is:

     $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE)

The value can be overridden in which case the default value is ignored.

設置模塊安裝目錄。

INSTALL_MOD_PATH
--------------------------------------------------
INSTALL_MOD_PATH specifies a prefix to MODLIB for module directory
relocations required by build roots.  This is not defined in the
makefile but the argument can be passed to make if needed.

MODLIB的前綴,用於模塊安裝的目錄,makefile沒有定義,如果需要可以通過make定義。

INSTALL_MOD_STRIP
--------------------------------------------------
INSTALL_MOD_STRIP, if defined, will cause modules to be
stripped after they are installed.  If INSTALL_MOD_STRIP is '1', then
the default option --strip-debug will be used.  Otherwise,
INSTALL_MOD_STRIP will used as the options to the strip command.

如果變量定義了爲1,那麼默認選項“--strip-debug”就會使用。

INSTALL_FW_PATH
--------------------------------------------------
INSTALL_FW_PATH specifies where to install the firmware blobs.
The default value is:

    $(INSTALL_MOD_PATH)/lib/firmware

The value can be overridden in which case the default value is ignored.

特指用來安裝firmware模塊的路徑。

INSTALL_HDR_PATH
--------------------------------------------------
INSTALL_HDR_PATH specifies where to install user space headers when
executing "make headers_*".
The default value is:

    $(objtree)/usr

$(objtree) is the directory where output files are saved.
The output directory is often set using "O=..." on the commandline.

The value can be overridden in which case the default value is ignored.

這個路徑用來特指安裝用戶空間時的,使用“O=...”命令即可設置輸出目錄。

KBUILD_MODPOST_WARN
--------------------------------------------------
KBUILD_MODPOST_WARN can be set to avoid errors in case of undefined
symbols in the final module linking stage. It changes such errors
into warnings.

這個變量將在鏈接階段避免沒有定義的符號發生錯誤,它可以將error變成warning。

KBUILD_MODPOST_NOFINAL
--------------------------------------------------
KBUILD_MODPOST_NOFINAL can be set to skip the final link of modules.
This is solely useful to speed up test compiles.

這個變量用來跳過鏈接模塊,加速編譯。

KBUILD_EXTRA_SYMBOLS
--------------------------------------------------
For modules that use symbols from other modules.
See more details in modules.txt.

使用另外的模塊的符號,更多信息看“modules.txt”文件。

ALLSOURCE_ARCHS
--------------------------------------------------
For tags/TAGS/cscope targets, you can specify more than one arch
to be included in the databases, separated by blank space. E.g.:

    $ make ALLSOURCE_ARCHS="x86 mips arm" tags

To get all available archs you can also specify all. E.g.:

    $ make ALLSOURCE_ARCHS=all tags

看完了沒,好像時kbuild的一些輸出文件信息。什麼時候會出現呢?內核配置完後,還是在編譯階段產生的,還是...不曉得。其實如果你在頂級目錄下試試“make menuconfig”,即按照菜單方式配置內核,也就是README裏面:
"make menuconfig"  Text based color menus, radiolists & dialogs.
                       有顏色的文本菜單,按鈕列表和對話框
呵 呵,記起來了吧,然後編輯後保存一下,在目錄中使用“ls -a”,會發現有幾個陌生人,有個文件“.config”,顯然就是配置後生成的,看看“cat .config | more”,發現沒有,變量名前面都會有CONFIG_,就是配置的意思,和上面kbuild.txt文件裏面變量比較一下,說明這些輸出文件不是內核配 置完後的,排除了一個,呵呵!萬事開頭難啊!
那麼這些到底怎麼來的,有什麼用,估計現在沒法知道啊!還得繼續分析着走。。。linux內核學習(4)老法子--- - 小魚 - ringk--linuxer

發佈了74 篇原創文章 · 獲贊 0 · 訪問量 12萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章