⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 如何为嵌入式开发建立交叉编译环境 wimax宽带无线网络技术论坛 - www_wimax_org_cn.htm

📁 再做嵌入式开发的时候
💻 HTM
📖 第 1 页 / 共 5 页
字号:
                        <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 &lt; ../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 + -