?? 如何為嵌入式開發建立交叉編譯環境 wimax寬帶無線網絡技術論壇 - www_wimax_org_cn.htm
字號:
<TABLE cellSpacing=0 cellPadding=5 width="100%"
bgColor=#eeeeee border=1>
<TBODY>
<TR>
<TD><PRE><CODE class=section>
<FONT face="Lucida Console">$export PRJROOT=/home/liang/embedded
$export TARGET=arm-linux
$export PREFIX=$PRJROOT/tools
$export TARGET_PREFIX=$PREFIX/$TARGET
$export PATH=$PREFIX/bin:$PATH
</FONT></CODE></PRE></TD></TR></TBODY></TABLE><BR>
<P>如果你不慣用環境變量的,你可以直接用絕對或相對路徑。我如果不用環境變量,一般都用絕對路徑,相對路徑有時會失敗。環境變量也可以定義在.bashrc文件中,這樣當你logout或換了控制臺時,就不用老是export這些變量了。</P>
<P>體系結構和你的TAEGET變量的對應如下表</P><BR><IMG height=332 alt=""
src="" width=580 border=0> <BR>
<P>你可以在通過glibc下的config.sub腳本來知道,你的TARGET變量是否被支持,例如:</P><BR>
<TABLE cellSpacing=0 cellPadding=5 width="100%"
bgColor=#eeeeee border=1>
<TBODY>
<TR>
<TD><PRE><CODE class=section>
<FONT face="Lucida Console">$./config.sub arm-linux
arm-unknown-linux-gnu
</FONT></CODE></PRE></TD></TR></TBODY></TABLE><BR>
<P>在我的環境中,config.sub 在 glibc-2.2.3/scripts 目錄下。</P>
<P>網上還有一些 HOWTO 可以參考,ARM 體系結構的《The GNU Toolchain for ARM
Target HOWTO》,PowerPC 體系結構的《Linux for PowerPC Embedded
Systems HOWTO》等。對TARGET的選取可能有幫助。</P>
<P>4. 建立編譯目錄</P>
<P>為了把源碼和編譯時生成的文件分開,一般的編譯工作不在的源碼目錄中,要另建一個目錄來專門用于編譯。用以下的命令來建立編譯你下載的binutils、gcc和glibc的源代碼的目錄。</P><BR>
<TABLE cellSpacing=0 cellPadding=5 width="100%"
bgColor=#eeeeee border=1>
<TBODY>
<TR>
<TD><PRE><CODE class=section>
<FONT face="Lucida Console">$cd $PRJROOT/build-tools
$mkdir build-binutils build-boot-gcc build-gcc build-glibc gcc-patch
</FONT></CODE></PRE></TD></TR></TBODY></TABLE><BR>
<P>build-binutils-編譯binutils的目錄<BR>build-boot-gcc-編譯gcc
啟動部分的目錄<BR>build-glibc-編譯glibc的目錄<BR>build-gcc-編譯gcc
全部的目錄<BR>gcc-patch-放gcc的補丁的目錄</P>
<P>gcc-2.95.3 的補丁有
gcc-2.95.3-2.patch、gcc-2.95.3-no-fixinc.patch
和gcc-2.95.3-returntype-fix.patch,可以從 <A
href="http://www.linuxfromscratch.org/"><FONT
color=#5c81a7><A href="http://www.linuxfromscratch.org/"
target=_blank>http://www.linuxfromscratch.org/</A></FONT></A>
下載到這些補丁。</P>
<P>再將你下載的 binutils-2.10.1、gcc-2.95.3、glibc-2.2.3 和
glibc-linuxthreads-2.2.3 的源代碼放入 build-tools 目錄中</P>
<P>看一下你的 build-tools 目錄,有以下內容:</P><BR>
<TABLE cellSpacing=0 cellPadding=5 width="100%"
bgColor=#eeeeee border=1>
<TBODY>
<TR>
<TD><PRE><CODE class=section>
<FONT face="Lucida Console">$ls
binutils-2.10.1.tar.bz2 build-gcc gcc-patch
build-binutls build-glibc glibc-2.2.3.tar.gz
build-boot-gcc gcc-2.95.3.tar.gz glibc-linuxthreads-2.2.3.tar.gz
</FONT></CODE></PRE></TD></TR></TBODY></TABLE><BR><BR>
<TABLE cellSpacing=0 cellPadding=0 width="100%"
border=0>
<TBODY>
<TR>
<TD><FONT face="Lucida Console"><IMG height=1
alt="" src="" width="100%"><BR><IMG height=6
alt="" src="" width=8
border=0></FONT></TD></TR></TBODY></TABLE>
<TABLE class=no-print cellSpacing=0 cellPadding=0
align=right>
<TBODY>
<TR align=right>
<TD><FONT face="Lucida Console"><IMG height=4
alt="" src="" width="100%"><BR></FONT>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD vAlign=center><FONT
face="Lucida Console"><IMG height=16 alt=""
src="" width=16 border=0><BR></FONT></TD>
<TD vAlign=top align=right><A class=fbox
href="http://www-128.ibm.com/developerworks/cn/linux/l-embcmpl/#main"><B><FONT
color=#996699>回頁首</FONT></B></A></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR><BR>
<P><A name=N1011E><SPAN class=atitle><FONT face=Arial
size=4>建立內核頭文件</FONT></SPAN></A></P>
<P>把你從 <A
href="http://www-128.ibm.com/developerworks/cn/linux/l-embcmpl/www.kernel.org"><FONT
color=#5c81a7>www.kernel.org</FONT></A> 下載的內核源代碼放入
$PRJROOT /kernel 目錄</P>
<P>進入你的 kernel 目錄:</P><BR>
<TABLE cellSpacing=0 cellPadding=5 width="100%"
bgColor=#eeeeee border=1>
<TBODY>
<TR>
<TD><PRE><CODE class=section>
<FONT face="Lucida Console">$cd $PRJROOT /kernel
</FONT></CODE></PRE></TD></TR></TBODY></TABLE><BR>
<P>解開內核源代碼</P><BR>
<TABLE cellSpacing=0 cellPadding=5 width="100%"
bgColor=#eeeeee border=1>
<TBODY>
<TR>
<TD><PRE><CODE class=section>
<FONT face="Lucida Console">$tar -xzvf linux-2.4.21.tar.gz
</FONT></CODE></PRE></TD></TR></TBODY></TABLE><BR>
<P>或</P><BR>
<TABLE cellSpacing=0 cellPadding=5 width="100%"
bgColor=#eeeeee border=1>
<TBODY>
<TR>
<TD><PRE><CODE class=section>
<FONT face="Lucida Console">$tar -xjvf linux-2.4.21.tar.bz2
</FONT></CODE></PRE></TD></TR></TBODY></TABLE><BR>
<P>小于 2.4.19 的內核版本解開會生成一個 linux 目錄,沒帶版本號,就將其改名。</P><BR>
<TABLE cellSpacing=0 cellPadding=5 width="100%"
bgColor=#eeeeee border=1>
<TBODY>
<TR>
<TD><PRE><CODE class=section>
<FONT face="Lucida Console">$mv linux linux-2.4.x
</FONT></CODE></PRE></TD></TR></TBODY></TABLE><BR>
<P>給 Linux 內核打上你的補丁</P><BR>
<TABLE cellSpacing=0 cellPadding=5 width="100%"
bgColor=#eeeeee border=1>
<TBODY>
<TR>
<TD><PRE><CODE class=section>
<FONT face="Lucida Console">$cd linux-2.4.21
$patch -p1 < ../patch-2.4.21-rmk2
</FONT></CODE></PRE></TD></TR></TBODY></TABLE><BR>
<P>編譯內核生成頭文件</P>
<P>$make ARCH=arm CROSS_COMPILE=arm-linux-
menuconfig</P>
<P>你也可以用 config 和 xconfig 來代替
menuconfig,但這樣用可能會沒有設置某些配置文件選項和沒有生成下面編譯所需的頭文件。推薦大家用 make
menuconfig,這也是內核開發人員用的最多的配置方法。配置完退出并保存,檢查一下的內核目錄中的
include/linux/version.h 和 include/linux/autoconf.h
文件是不是生成了,這是編譯 glibc 是要用到的,version.h 和 autoconf.h
文件的存在,也說明了你生成了正確的頭文件。</P>
<P>還要建立幾個正確的鏈接</P><BR>
<TABLE cellSpacing=0 cellPadding=5 width="100%"
bgColor=#eeeeee border=1>
<TBODY>
<TR>
<TD><PRE><CODE class=section>
<FONT face="Lucida Console">$cd include
$ln -s asm-arm asm
$cd asm
$ln -s arch-epxa arch
$ln -s proc-armv proc
</FONT></CODE></PRE></TD></TR></TBODY></TABLE><BR>
<P>接下來為你的交叉編譯環境建立你的內核頭文件的鏈接</P><BR>
<TABLE cellSpacing=0 cellPadding=5 width="100%"
bgColor=#eeeeee border=1>
<TBODY>
<TR>
<TD><PRE><CODE class=section>
<FONT face="Lucida Console">$mkdir -p $TARGET_PREFIX/include
$ln -s $PRJROOT/kernel/linux-2.4.21/include/linux $TARGET_PREFIX/include/linux
$in -s $PRJROOT/kernel/linux-2.4.21/include/asm-arm $TARGET_PREFIX/include/asm
</FONT></CODE></PRE></TD></TR></TBODY></TABLE><BR>
<P>也可以把 Linux 內核頭文件拷貝過來用</P><BR>
<TABLE cellSpacing=0 cellPadding=5 width="100%"
bgColor=#eeeeee border=1>
<TBODY>
<TR>
<TD><PRE><CODE class=section>
<FONT face="Lucida Console">$mkdir -p $TARGET_PREFIX/include
$cp -r $PRJROOT/kernel/linux-2.4.21/include/linux $TARGET_PREFIX/include
$cp -r $PRJROOT/kernel/linux-2.4.21/include/asm-arm $TARGET_PREFIX/include
</FONT></CODE></PRE></TD></TR></TBODY></TABLE><BR><BR>
<TABLE cellSpacing=0 cellPadding=0 width="100%"
border=0>
<TBODY>
<TR>
<TD><FONT face="Lucida Console"><IMG height=1
alt="" src="" width="100%"><BR><IMG height=6
alt="" src="" width=8
border=0></FONT></TD></TR></TBODY></TABLE>
<TABLE class=no-print cellSpacing=0 cellPadding=0
align=right>
<TBODY>
<TR align=right>
<TD><FONT face="Lucida Console"><IMG height=4
alt="" src="" width="100%"><BR></FONT>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD vAlign=center><FONT
face="Lucida Console"><IMG height=16 alt=""
src="" width=16 border=0><BR></FONT></TD>
<TD vAlign=top align=right><A class=fbox
href="http://www-128.ibm.com/developerworks/cn/linux/l-embcmpl/#main"><B><FONT
color=#996699>回頁首</FONT></B></A></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR><BR>
<P><A name=N10194><SPAN class=atitle><FONT face=Arial
size=4>建立二進制工具(binutils)</FONT></SPAN></A></P>
<P>binutils是一些二進制工具的集合,其中包含了我們常用到的as和ld。</P>
<P>首先,我們解壓我們下載的binutils源文件。</P><BR>
<TABLE cellSpacing=0 cellPadding=5 width="100%"
bgColor=#eeeeee border=1>
<TBODY>
<TR>
<TD><PRE><CODE class=section>
<FONT face="Lucida Console">$cd $PRJROOT/build-tools
$tar -xvjf binutils-2.10.1.tar.bz2
</FONT></CODE></PRE></TD></TR></TBODY></TABLE><BR>
<P>然后進入build-binutils目錄配置和編譯binutils。</P><BR>
<TABLE cellSpacing=0 cellPadding=5 width="100%"
bgColor=#eeeeee border=1>
<TBODY>
<TR>
<TD><PRE><CODE class=section>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -