国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
嵌入式開發(fā)實作(Linux內(nèi)核編譯及安裝) - Kemin | 本博客已經(jīng)獨立至 http...
嵌入式開發(fā)實作(Linux內(nèi)核編譯及安裝) 收藏 此文于2009-09-16被推薦到CSDN首頁
此文于2009-10-23被推薦到CSDN首頁
如何被推薦?
嵌入式開發(fā)實作(Linux內(nèi)核編譯及安裝)
部分內(nèi)容譯自《Embedded Linux kernel and driver development 》by Michael Opdenacker
劉建文(http://blog.csdn.net/keminlau
KEY:Linux 內(nèi)核編譯 內(nèi)核配置 嵌入式
內(nèi)核配置(Kernel configuration)
Makefile版本修改
為了區(qū)別基于同一源碼構(gòu)建(bulid)的不內(nèi)核鏡像,可使用變量EXTRAVERSION(定義位于makefile的頂部):
$ head -4 makefile  
VERSION = 2 
PATCHLEVEL = 6 
SUBLEVEL = 7 
EXTRAVERSION = -acme1 
$ head -4 makefile
VERSION = 2
PATCHLEVEL = 6
SUBLEVEL = 7
EXTRAVERSION = -acme1
運行“uname --r”會返回: 2.6.7--acme1
內(nèi)核配置
先定義內(nèi)核需要什么特性,并進行配置。內(nèi)核構(gòu)建系統(tǒng)(The kernel build system)遠不是簡單用來構(gòu)建整個內(nèi)核和模塊,想了解更多的高級內(nèi)核構(gòu)建選項,你可以查看 Documentation/kbuild 目錄內(nèi)的內(nèi)核文檔。
可用的配置命令和方式:
make xconfig
make menuconfig
make oldconfig
或者 手動編寫
內(nèi)核配置文件.config與內(nèi)核編譯makefile?
內(nèi)核是利用make編譯并安裝的一個C程序。而這個C程序很現(xiàn)代很復(fù)雜,僅憑單一個makefile難以完成編譯任務(wù)。假設(shè)內(nèi)核編譯只需要一個makefile,這個makefile具體也會因編譯不同功能特性的內(nèi)核而有所不同,也就是說在編譯內(nèi)核先“編譯”編譯的所需要的makefile,這個makefile是動態(tài)生成的。那么這個動態(tài)的makefile從何而來呢?答案是config命令通過讀取[內(nèi)核配置文件 ](kernel configuration file)來生成編譯內(nèi)核所需要所有文件(包括makefile);那[內(nèi)核配置文件 ]又是哪來的呢?還是make生成的,各種make的config(xconfig\menuconfig)會生成所需要的[內(nèi)核配置文件 ]。
內(nèi)核配置文件(kernel configuration file)保存為內(nèi)核源代碼的頂層目錄的.config文件。發(fā)行版的內(nèi)核配置文件通常在/boot/內(nèi)。
命令:make xconfig
qconf: 全新的基于QT的配置接口,2.6版本內(nèi)核
更易使用(切記閱讀 help -> introduction: useful options!)
具有文件瀏覽功能,更易的加載配置文件
命令:make menuconfig
老式字符界面,依然很管用。你夠自信,完全可以手寫配置文件!
命令:make oldconfig
用于升級早期發(fā)布內(nèi)核的配置文件
對一些絕對符號(obsolete symbols)發(fā)出警告
詢問新符號的配置值
何為makefile?
makefile包含用以構(gòu)建應(yīng)用程序的一組規(guī)則集(set of rules)。并且第一條[規(guī)則 ]是特殊的[規(guī)則 ],叫[默認規(guī)則 ](default rule)。一條[規(guī)則]由三部分組成:目標(target)、前提條件(prerequisites)和命令動作(command):
target: prereq1 prereq2  
[tab]commands 
target: prereq1 prereq2
[tab]commands
[目標 ]是被構(gòu)建(made)的[文件 ]或其它東西。[前提條件 ]或者叫依賴(dependents)是構(gòu)建目標的“材料”。而[命令動作 ]是利用[前提條件 ]構(gòu)建[目標 ]的shell命令。
以下是編譯C源碼的規(guī)則例子:
foo.o: foo.c foo.h  
tab]gcc -c foo.c 
 foo.o: foo.c foo.h
[tab]gcc -c foo.c
注意格式,冒號前是[目標 ],后是[前提條件 ];[命令 ]在第二行,并且開始于一個tab字符。
編譯內(nèi)核
編譯和安裝內(nèi)核
編譯步驟:
$ cd /usr/src/linux2.6 
$ make 
$ cd /usr/src/linux2.6
$ make 
安裝步驟 (logged as root!)
$ make install  
$ make modules_install 
$ make install
$ make modules_install
以下的步驟在2.6版本不再使用:
$ make depends  
$ make modules (done by make) 
$ make depends
$ make modules (done by make)
提升編譯速度
多花一些時間在內(nèi)核配置上,并且只編譯那些你硬件需要的模塊。這樣可以把編譯時間縮短為原來的1/30,并且節(jié)省數(shù)百MB的空間。另外,你還可以并行編譯多個文件:
$ make -j <number>
make 可以并行執(zhí)行多個目標(target)(KEMIN:前提是目標規(guī)則間沒有交叉依賴項,這個怎么做到的?)
$ make -j 4
即便是在單處理器的工作站上也會很快,讀寫文件的時間被節(jié)省下來了。多線程讓CPU保持忙碌。
number大于4不見得有效了,因為上下文切換過多反而降低的工作的速度。
make -j <4*number_of_processors>
內(nèi)核編譯tips
查看完整的 (gcc, ld)命令行: $ make V=1
清理所有的生成文件 (to create patches...): $ make mrproper
部分編譯:$ make M=drivers/usb/serial
單獨模塊編譯:$ make drivers/usb/serial/visor.ko
別處編譯(假設(shè)源碼在CDROM):
$ cd /mnt/cdrom/linux-2.6.17.11
$ make O=~/linux/linux-2.6.17.11
最終生成的文件
vmlinux 原始內(nèi)核鏡像,非壓縮的
arch/<arch>/boot/zImage zlib壓縮的內(nèi)核鏡像(Default image on arm)
arch/<arch>/boot/bzImage bzip2壓縮的內(nèi)核鏡像。通常很小,足夠放入一張軟盤(Default image on i386)
安裝的文件
/boot/vmlinuz-<version> 內(nèi)核鏡像;
/boot/System.map-<version> 保存有內(nèi)核的符號地址(symbol addresses);
/boot/initrd-<version>.img Initial RAM disk:保存有你需要在引導(dǎo)時掛接最終根文件系統(tǒng)的模塊。安裝命令“make install”為替你運行“mkinitrd ”生成initrd;
/etc/grub.conf or /etc/lilo.conf
bootloader的配置文件:“make install”會為你的新內(nèi)核更新相應(yīng)的bootloader的配置文件。如果你使用的是LILO,它會在生成配置文件后,執(zhí)行/sbin/lilo,讓LILO的配置生效。
/lib/modules/<version>/ Kernel modules + extras
build/
為本<version>的內(nèi)核添加模塊所需的所有東西: .config file (build/.config), module symbol information (build/module.symVers), kernel headers (build/include/)
kernel/
內(nèi)核模塊文件 .ko (Kernel Object),目錄結(jié)構(gòu)與源代碼目標一一對應(yīng)。
modules.alias
模塊別名記錄(用于insmod和modprobe),例如:
alias sound--service--?-0 snd_mixer_oss
modules.dep
模塊依賴記錄(用于insmod和modprobe)
modules.symbols
標識某符號是屬于哪個模塊的。
這個目錄的所有文件都是文本文件,可以直接查看。
小結(jié)編譯及安裝步驟:
編輯Makefile版本信息
定義內(nèi)核特性,生成配置文件.config,用于編譯:make xconfig
編譯內(nèi)核:make
安裝內(nèi)核:make install
安裝模塊:make modules_install
交叉編譯內(nèi)核
Makefile修改
通常通過修改已有的makefile獲得
你必須修改目標平臺,假設(shè)目標平臺是ARM,修改以下:
ARCH ?= arm  
CROSS_COMPILE ?= arm-linux- 
ARCH ?= arm
CROSS_COMPILE ?= arm-linux-
或運行帶參數(shù)的make:
$ cd /usr/scr/linuxXX  
$ make ARCH=arm CROSS_COMPILE=arm-linux- 
$ cd /usr/scr/linuxXX
$ make ARCH=arm CROSS_COMPILE=arm-linux- 
內(nèi)核配置文件
配置過程和本地配置一樣; 可以把生成的配置文件(.config)分享給其他人,比如像:
$  
$ cp .config arch/<arch>/config/acme_defconfig 
$
$ cp .config arch/<arch>/config/acme_defconfig 
這樣其他同樣開發(fā)ACME系統(tǒng)的開發(fā)人員可以通過以下命令編譯出同樣的內(nèi)核:
$ make acme_defconfig  

$ make acme_defconfig
建立交叉編譯環(huán)境(Cross--compiling setup)
假設(shè)你有ARM的交叉編譯工具(cross--compiling toolchain)在 in /usr/local/arm/3.3.2/, 你得把它輸出到PATH:
$ export PATH=/usr/local/arm/3.3.2/bin:$PATH 
$ export PATH=/usr/local/arm/3.3.2/bin:$PATH 
注意查看內(nèi)核文檔(在Documentation/Changes)有關(guān)最低工具版本要求。
編譯并安裝內(nèi)核
1. $ make //如果你修改了Makefile
或者
1'. $ make ARCH=arm CROSS_COMPILE=arm-linux-
2. 拷貝 arch/<platform>/boot/zImage 到目標系統(tǒng)
$ make modules_install
3. 拷貝 /lib/modules/<version> 到目標系統(tǒng)
你可以通過 arch/<arch>/boot/install.sh 自定義安裝,讓”make install“自動代勞。
何為交叉編譯工具鏈(cross--compiling toolchain)?
有如任何其它開發(fā)活動一般,嵌入式開發(fā)的第一步是建立(setting up)用于構(gòu)建嵌入式Linux內(nèi)核(當然包括驅(qū)動程序)及應(yīng)用程序的工具鏈(toolchains )。不過,嵌入式開發(fā)需要是跨平臺工具鏈??缙脚_是什么意思呢?一般開發(fā)活動是在本地編譯,使用是本地的工具鏈;而由于嵌入式的軟硬資源(內(nèi)存不足、沒有本地編譯器或操作系統(tǒng)都沒有)限制等沒法進行本地開發(fā)。需要在Linux-x86 主機(HOST)開發(fā),使用主機的編譯器生成目標(TARGET)平臺代碼,這個過程叫交叉編譯。
我們常常說的編譯器有廣義和狹義之分。狹義的編譯器只完軟件編譯(或者叫軟件構(gòu)建)的第一步;廣義的編譯器包括了軟件編譯(或者叫軟件構(gòu)建)所需要代碼庫(比如libc)和其它構(gòu)建工具(比如匯編器和連接器)。無論是什么編譯器都需要支持的代碼庫和各種構(gòu)建工具,交叉編譯也不例外。一整套廣義的編譯器稱為交叉編譯工具鏈。
何為工具鏈?
In software, a toolchain is the set of computer programs (tools) that are used to create a product (typically another computer program or system of programs). The tools may be used in a chain, so that the output of each tool becomes the input for the next, but the term is used widely to refer to any set of linked development tools.
A simple software development toolchain consists of a text editor for editing source code, a compiler and linker to transform the source code into an executable program, libraries to provide interfaces to the operating system, and a debugger.
The GNU toolchain is a blanket term for a collection of programming tools produced by the GNU Project. These tools form a toolchain (suite of tools used in a serial manner) used for developing applications and operating systems.
Projects included in the GNU toolchain are:
* GNU make: Automation tool for compilation and build;
* GNU Compiler Collection (GCC): Suite of compilers for several programming languages;
* GNU Binutils: Suite of tools including linker, assembler and other tools;
* GNU Bison: Parser generator
* GNU m4: m4 macro processor
* GNU Debugger (GDB): Code debugging tool;
* GNU build system (autotools):
o Autoconf
o Autoheader
o Automake
o Libtool
參考
http://www.developingprogrammers.com/index.php/2006/01/05/autotools-tutorial/

本文來自CSDN博客,轉(zhuǎn)載請標明出處:http://blog.csdn.net/keminlau/archive/2009/09/15/4556157.aspx
本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
linux設(shè)備驅(qū)動歸納總結(jié)(一):內(nèi)核的相關(guān)基礎(chǔ)概念
Linux內(nèi)核編譯詳解
2.4內(nèi)核(arm版)Makefile分析
menuconfig過程詳解
【z】make config解惑
編譯 Linux2.6 內(nèi)核總結(jié) - build-kernel - AC郎拿度
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服