arm9tdmi交叉编译环境搭建笔记

内核编译和嵌入式产品的设计与开发
回复
头像
jeffwei
帖子: 1344
注册时间: 2007-05-12 22:48

arm9tdmi交叉编译环境搭建笔记

#1

帖子 jeffwei » 2008-10-19 13:12

和大家一起分享,希望对大家有帮助
我的平台是ubuntu 8.04 2.6.26.3 x86_64

代码: 全选

sudo  apt-get install fakeroot
sudo apt-get install build-essential autoconf automake1.9 cvs subversion kernel-package libncurses5-dev
sudo apt-get install bison flex
cd $home                                      :到用户根目录
mkdir downloads                               :建立下载包的文件夹
mkdir crosstool                               :建立安装目录,我把安装目录改成了$home/crosstool,原来是/opt/crosstool
sudo mv /usr/bin/gcc /usr/bin/gcc-4.2.4
sudo ln -s /usr/bin/gcc-3.4 /usr/bin/gcc      :这两步是把默认gcc换成3.4,不然出错,这两个版本ubuntu8.04默认安装了
wget http://kegel.com/crosstool/crosstool-0.43.tar.gz
tar -xzvf crosstool-0.43.tar.gz
做些修改工作
------------------------------------------------------------------------
arm9tdmi.dat 改TARGET,如TARGET=arm-linux,最后得到的就是arm-linux-gcc
-----------------------------
KERNELCONFIG=`pwd`/arm.config
TARGET=arm-linux
GCC_EXTRA_CONFIG="--with-cpu=arm9tdmi --enable-cxx-flags=-mcpu=arm9tdmi"
TARGET_CFLAGS="-O"
-----------------------------------------------------------------------
-----------------------------------------------------------------------
gcc-4.1.0-glibc-2.3.2.dat :下面这些包就是自动要下载的,默认不改
-----------------------------
BINUTILS_DIR=binutils-2.16.1
GCC_CORE_DIR=gcc-3.3.6
GCC_DIR=gcc-4.1.0
GLIBC_DIR=glibc-2.3.2
LINUX_DIR=linux-2.6.15.4
LINUX_SANITIZED_HEADER_DIR=linux-libc-headers-2.6.12.0
GLIBCTHREADS_FILENAME=glibc-linuxthreads-2.3.2
GDB_DIR=gdb-6.5
------------------------------------------------------------------------
------------------------------------------------------------------------
demo-arm9tdmi.sh  我修改了安装目录的 RESULT_TOP=$HOME/crosstool
-----------------------------------------------------------
#!/bin/sh
# This script has one line for each known working toolchain
# for this architecture.  Uncomment the one you want.
# Generated by generate-demo.pl from buildlogs/all.dats.txt

set -ex
TARBALLS_DIR=$HOME/downloads
RESULT_TOP=$HOME/crosstool
export TARBALLS_DIR RESULT_TOP
GCC_LANGUAGES="c,c++"
export GCC_LANGUAGES

# Really, you should do the mkdir before running this,
# and chown /opt/crosstool to yourself so you don't need to run as root.
mkdir -p $RESULT_TOP

#eval `cat arm9tdmi.dat gcc-3.2.3-glibc-2.2.5.dat` sh all.sh --notest
#eval `cat arm9tdmi.dat gcc-3.2.3-glibc-2.3.2.dat` sh all.sh --notest
#eval `cat arm9tdmi.dat gcc-3.2.3-glibc-2.3.2-tls.dat` sh all.sh --notest
#eval `cat arm9tdmi.dat gcc-3.3.6-glibc-2.2.5.dat` sh all.sh --notest
#eval `cat arm9tdmi.dat gcc-3.3.6-glibc-2.3.2.dat` sh all.sh --notest
#eval `cat arm9tdmi.dat gcc-3.3.6-glibc-2.3.2-tls.dat` sh all.sh --notest
#eval `cat arm9tdmi.dat gcc-3.4.5-glibc-2.2.5.dat` sh all.sh --notest
#eval `cat arm9tdmi.dat gcc-3.4.5-glibc-2.3.2.dat` sh all.sh --notest
#eval `cat arm9tdmi.dat gcc-3.4.5-glibc-2.3.2-tls.dat` sh all.sh --notest
#eval `cat arm9tdmi.dat gcc-3.4.5-glibc-2.3.5.dat` sh all.sh --notest
#eval `cat arm9tdmi.dat gcc-3.4.5-glibc-2.3.5-tls.dat` sh all.sh --notest
#eval `cat arm9tdmi.dat gcc-3.4.5-glibc-2.3.6.dat` sh all.sh --notest
#eval `cat arm9tdmi.dat gcc-3.4.5-glibc-2.3.6-tls.dat` sh all.sh --notest
#eval `cat arm9tdmi.dat gcc-4.0.2-glibc-2.3.2.dat` sh all.sh --notest
#eval `cat arm9tdmi.dat gcc-4.0.2-glibc-2.3.2-tls.dat` sh all.sh --notest
#eval `cat arm9tdmi.dat gcc-4.0.2-glibc-2.3.5.dat` sh all.sh --notest
#eval `cat arm9tdmi.dat gcc-4.0.2-glibc-2.3.5-tls.dat` sh all.sh --notest
#eval `cat arm9tdmi.dat gcc-4.0.2-glibc-2.3.6.dat` sh all.sh --notest
#eval `cat arm9tdmi.dat gcc-4.0.2-glibc-2.3.6-tls.dat` sh all.sh --notest
#eval `cat arm9tdmi.dat gcc-4.1.0-glibc-2.3.2.dat` sh all.sh --notest
eval `cat arm9tdmi.dat gcc-4.1.0-glibc-2.3.2-tls.dat` sh all.sh --notest

echo Done.
--------------------------------------------------------------------------
cd $home/crosstool-0.43
./demo-arm9tdmi.sh
慢慢等待,最后看到下面内容就成功了
+ echo testhello: C compiler can in fact build a trivial program.
testhello: C compiler can in fact build a trivial program.
+ test '' = 1
+ test '' = 1
+ test '' = 1
+ test 1 = ''
+ echo Done.
Done.
-----------------------------------------------------------------------------
测试一下交叉编译工具

写一个简单的c程序test.c:
----------------------------
#include <stdio.h>
int main()
{
printf("hello,world!\n");
return 0;
}
----------------------------

PATH=/home/wei/crosstool/gcc-4.1.0-glibc-2.3.2/arm-linux/bin
arm-linux-gcc -o test test.c
PATH=/usr/bin
file test
显示下面内容说明成功
test: ELF 32-bit LSB executable, ARM, version 1, for GNU/Linux 2.4.18, dynamically linked (uses shared libs), not stripped
----------------------------------------------------------------------------------------------------------------------
改回gcc4.2.4版
sudo rm /usr/bin/gcc
sudo mv /usr/bin/gcc-4.2.4 /usr/bin/gcc


回复