GNU交叉工具鏈(arm-linux-gcc 3.4.4)

來源:互聯網
上載者:User

來源: ChinaUnix部落格  日期: 2006.08.28 00:33

 

GNU交叉工具鏈(arm-linux-gcc 3.4.4)
Modified by litroncn (
litroncn@163.com
)
Based on sunhe (msunhe@gmail.com)

1 Linux下工作使用者及環境
1.1軟體環境
Linux ubuntu 6.06 LTS
Kernel version 2.6.15-23-686
gcc version 4.0.3 (Ubuntu 4.0.3-1ubuntu5)
GNU Make 3.81
msgfmt (GNU gettext-tools) 0.14.5
makeinfo (GNU texinfo) 4.8
GNU M4 1.4.4
flex 2.5.31
GNU Awk 3.1.5
perl, v5.8.7
GNU sed version 4.1.4
gettext (GNU gettext-runtime) 0.14.5
autoconf (GNU Autoconf) 2.59
automake (GNU automake) 1.4-p6
1.2 編譯相關配置
1. 添加工作使用者(在root使用者下)
root@ubuntu:~# useradd -G root -g root -d/home/arm arm
root@ubuntu:~# mkdir -p /home/arm
root@ubuntu:~# chown -R arm /home/arm
root@ubuntu:~# chmod -R 775 /home/arm
2. 建立工作目錄(用arm使用者登陸)
arm@ubuntu:~$ mkdir dev_home
arm@ubuntu:~$ cd dev_home
arm@ubuntu:~/dev_home$ mkdir btools kernel 
3. 登陸時啟動環境變數(用root使用者登陸)
root@ubuntu:~# vi ~/.bashrc
在.bashrc最後加上
export PATH=/usr/local/arm/3.4.4/bin:$PATH
arm@ubuntu:~/dev_home$

重新登陸arm使用者,環境變數生效
arm@ubuntu:~$ su arm

2. 設定環境變數,準備源碼及相關補丁
2.1 設定環境變數
arm@ubuntu:~$ vi ~/.bashrc
export PREFIX=/usr/local/arm/3.4.4
export TARGET=arm-linux
export SYSROOT=${PREFIX}/sysroot
export ARCH=arm
export CROSS_COMPILE=${TARGET}-
export PATH=${PREFIX}/bin:$PATH
export SRC=/home/arm/dev_home/btools/tchain3.4.4
注意: 如果你已經安裝過arm-linux-gcc,並且已經加入了環境變數中,將其從環境中去掉保證root使用者和arm使用者環境中沒有arm-linux-gcc

2.2 準備源碼包

2.2.1 binutils
名稱:binutils-2.16.tar.gz
tar.gz

http://ftp.gnu.org/gnu/binutils/binutils-2.16.tar.gz

2.2.2 gcc
名稱: gcc-3.4.4.tar.bz2

http://ftp.gnu.org/gnu/gcc/gcc-3.4.4/gcc-3.4.4.tar.bz2

2.2.3 glibc
名稱:   glibc-2.3.5.tar.gz
           glibc-linuxthreads-2.3.5.tar.gz
:  
http://ftp.gnu.org/gnu/glibc/glibc-2.3.5.tar.gz
                  
http://ftp.gnu.org/gnu/glibc/glibc-linuxthreads-2.3.5.tar.gz

2.2.4 linux kernel
名稱:   linux-2.6.14.1.tar.bz2

http://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.14.1.tar.bz2

2.2.5 gdb
名稱: gdb-6.4.tar.gz

http://ftp.gnu.org/pub/gnu/gdb/gdb-6.4.tar.gz

2.3 準備補丁
2.3.1 ioperm.c.diff
作用: 打修正ioperm()函數

http://frank.harvard.edu/~coldwell/toolchain/ioperm.c.diff
2.3.2 flow.c.diff
作用: 修改gcc一處bug

http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/flow.c.diff?cvsroot=gcc&only_with_tag=csl-arm-branch&r1=1.563.4.2&r2=1.563.4.3

2.3.3 t-linux.diff
作用: 該補丁用於產生crti.o和crtn.o檔案.

http://frank.harvard.edu/~coldwell/toolchain/t-linux.diff

2.4 編譯GNU binutils

重新以arm使用者登陸,讓新設定得環境變數起作用
arm@ubuntu:~/dev_home/btools/tchain3.4.4$ tree -L 1
.
|-- BUILD
|-- binutils-2.16
|-- binutils-2.16.tar.gz
|-- flow.c.diff
|-- gcc-3.4.4
|-- gcc-3.4.4.tar.bz2
|-- gdb-6.4.tar.gz
|-- glibc-2.3.5
|-- glibc-2.3.5.tar.gz
|-- glibc-linuxthreads-2.3.5.tar.gz
|-- ioperm.c.diff
|-- linux-2.6.14.1.tar.bz2
`-- t-linux.diff
arm@ubuntu:~$ su arm
arm@ubuntu:~$ cd ${SRC}
arm@ubuntu:~/dev_home/btools/tchain3.4.4$ tar zxvf binutils-2.16.tar.gz
arm@ubuntu:~/dev_home/btools/tchain3.4.4$ mkdir -p BUILD/binutils-2.16
arm@ubuntu:~/dev_home/btools/tchain3.4.4$ cd BUILD/binutils-2.16
arm@ubuntu:~/dev_home/btools/tchain3.4.4/BUILD/binutils-2.16$ ../../binutils-2.16/configure --prefix=${PREFIX} --target=${TARGET} --with-sysroot=${SYSROOT}
arm@ubuntu:~/dev_home/btools/tchain3.4.4/BUILD/binutils-2.16$ make
arm@ubuntu:~/dev_home/btools/tchain3.4.4/BUILD/binutils-2.16$ su root
root@ubuntu:/home/arm/dev_home/btools/tchain3.4.4/BUILD/binutils-2.16#make install
root@ubuntu:/home/arm/dev_home/btools/tchain3.4.4/BUILD/binutils-2.16# exit
arm@ubuntu:~/dev_home/btools/tchain3.4.4/BUILD/binutils-2.16$

2.5 準備核心標頭檔
2.5.1 使用當前平台的gcc編譯核心標頭檔
arm@ubuntu:~/dev_home/btools/tchain3.4.4/BUILD/binutils-2.16$ cd ${KERNEL}
arm@ubuntu:~/dev_home/kernel$
arm@ubuntu:~/dev_home/kernel$ tar jxvf ../btools/tchain3.4.4/linux-2.6.14.1.tar.bz2
arm@ubuntu:~/dev_home/kernel$ cd linux-2.6.14.1/
arm@ubuntu:~/dev_home/kernel/linux-2.6.14.1$ cp arch/arm/configs/smdk2410_defconfig  .config
本人是用的CPU是S3C2410,選擇了一個設定檔smdk2410_defconfig,你可以根據你的需要選擇
arm@ubuntu:~/dev_home/kernel/linux-2.6.14.1$ make ARCH=arm menuconfig
   System Type  --->   
            ARM system type (Samsung S3C2410)  --->                              
                         S3C24XX Implementations  --->   
                                   [ ] Simtec Electronics ANUBIS                                         
                                   [ ] Simtec Electronics BAST (EB2410ITX)                               
                                   [ ] IPAQ H1940                                                        
                                   [ ] Acer N30                                                          
                                   

  • SMDK2410/A9M2410                                                  
                                       [ ] SMDK2440                                                          
                                       [ ] Thorcom VR1000                                                    
                                       [ ] HP iPAQ rx3715                                                    
                                       [ ] NexVision OTOM Board                                              
                                       [ ] NexVision NEXCODER 2440 Light Board                                       
                             --- S3C2410 Boot                                                         
                             --- S3C2410 Setup                                                        
                             [ ] S3C2410 DMA support                                                  
                             (0) S3C2410 UART to use for low-level messages                           
                             --- Processor Type                                                       
                             --- Processor Features                                                                           
  • Support Thumb user binaries                                          
                             [ ] Disable I-Cache                                                      
                             [ ] Disable D-Cache                                                      
                             [ ]   Force write through D-cache                                        
    退出時            
    Do you wish to save your new kernel configuration?        
                                     No  >       
    選擇Yes
    arm@ubuntu:~/dev_home/kernel/linux-2.6.14.1$ make

    2.5.2 複製核心標頭檔 
    arm@ubuntu:~/dev_home/kernel/linux-2.6.14.1$ su root
    root@ubuntu:/home/arm/dev_home/kernel/linux-2.6.14.1# mkdir -p ${SYSROOT}/usr/include 
    root@ubuntu:/home/arm/dev_home/kernel/linux-2.6.14.1# cp -a include/linux ${SYSROOT}/usr/include/linux
    root@ubuntu:/home/arm/dev_home/kernel/linux-2.6.14.1# cp -a include/asm-arm ${SYSROOT}/usr/include/asm
    root@ubuntu:/home/arm/dev_home/kernel/linux-2.6.14.1# cp -a include/asm-generic ${SYSROOT}/usr/include/asm-generic
    root@ubuntu:/home/arm/dev_home/kernel/linux-2.6.14.1# exit
    arm@ubuntu:~/dev_home/kernel/linux-2.6.14.1$

    2.6 編譯glibc標頭檔
    arm@ubuntu:~/dev_home/kernel/linux-2.6.14.1$ cd ${SRC}
    arm@ubuntu:~/dev_home/btools/tchain3.4.4$ tar zxvf glibc-2.3.5.tar.gz
    arm@ubuntu:~/dev_home/btools/tchain3.4.4$ patch -d glibc-2.3.5 -p1 
    arm@ubuntu:~/dev_home/btools/tchain3.4.4$ cd glibc-2.3.5
    arm@ubuntu:~/dev_home/btools/tchain3.4.4/glibc-2.3.5$ tar zxvf  ../glibc-linuxthreads-2.3.5.tar.gz
    arm@ubuntu:~/dev_home/btools/tchain3.4.4/glibc-2.3.5$ cd ..
    arm@ubuntu:~/dev_home/btools/tchain3.4.4$ mkdir -p BUILD/glibc-2.3.5-headers
    arm@ubuntu:~/dev_home/btools/tchain3.4.4$ cd BUILD/glibc-2.3.5-headers/
    arm@ubuntu:~/dev_home/btools/tchain3.4.4/BUILD/glibc-2.3.5-headers$ ../../glibc-2.3.5/configure --prefix=/usr --host=${TARGET} --enable-add-ons=linuxthreads --with-headers=${SYSROOT}/usr/include
    arm@ubuntu:~/dev_home/btools/tchain3.4.4/BUILD/glibc-2.3.5-headers$ su root
    root@ubuntu:/home/arm/dev_home/btools/tchain3.4.4/BUILD/glibc-2.3.5-headers# make cross-compiling=yes install_root=${SYSROOT} install-headers
    root@ubuntu:/home/arm/dev_home/btools/tchain3.4.4/BUILD/glibc-2.3.5-headers# touch  ${SYSROOT}/usr/include/gnu/stubs.h
    root@ubuntu:/home/arm/dev_home/btools/tchain3.4.4/BUILD/glibc-2.3.5-headers# 
    touch ${SYSROOT}/usr/include/bits/stdio_lim.h
    root@ubuntu:/home/arm/dev_home/btools/tchain3.4.4/BUILD/glibc-2.3.5-headers# exit
    arm@ubuntu:~/dev_home/btools/tchain3.4.4/BUILD/glibc-2.3.5-headers$

    2.7 編譯gcc 第一階段
    arm@ubuntu:~/dev_home/btools/tchain3.4.4/BUILD/glibc-2.3.5-headers$ cd ${SRC}
    arm@ubuntu:~/dev_home/btools/tchain3.4.4$ tar jxvf gcc-3.4.4.tar.bz2
    arm@ubuntu:~/dev_home/btools/tchain3.4.4$ patch -d gcc-3.4.4 -p1 
    arm@ubuntu:~/dev_home/btools/tchain3.4.4$ patch -d gcc-3.4.4 -p1 
    arm@ubuntu:~/dev_home/btools/tchain3.4.4$ mkdir -p BUILD/gcc-3.4.4-stage1
    arm@ubuntu:~/dev_home/btools/tchain3.4.4$ cd BUILD/gcc-3.4.4-stage1/
    arm@ubuntu:~/dev_home/btools/tchain3.4.4/BUILD/gcc-3.4.4-stage1$ ../../gcc-3.4.4/configure --prefix=${PREFIX} --target=${TARGET} --enable-languages=c --with-sysroot=${SYSROOT}
    注意:   不能加上--disable-shared
    arm@ubuntu:~/dev_home/btools/tchain3.4.4/BUILD/gcc-3.4.4-stage1$ make all-gcc
    arm@ubuntu:~/dev_home/btools/tchain3.4.4/BUILD/gcc-3.4.4-stage1$ su root
    root@ubuntu:/home/arm/dev_home/btools/tchain3.4.4/BUILD/gcc-3.4.4-stage1# make install-gcc
    root@ubuntu:/home/arm/dev_home/btools/tchain3.4.4/BUILD/gcc-3.4.4-stage1# exit
    arm@ubuntu:~/dev_home/btools/tchain3.4.4/BUILD/gcc-3.4.4-stage1$

    2.8 編譯完整的glibc
    arm@ubuntu:~/dev_home/btools/tchain3.4.4/BUILD/gcc-3.4.4-stage1$ cd ${SRC}
    arm@ubuntu:~/dev_home/btools/tchain3.4.4$ mkdir -p BUILD/glibc-2.3.5
    arm@ubuntu:~/dev_home/btools/tchain3.4.4$ cd BUILD/glibc-2.3.5
    arm@ubuntu:~/dev_home/btools/tchain3.4.4/BUILD/glibc-2.3.5$ BUILD_CC=gcc CC=${CROSS_COMPILE}gcc AR=${CROSS_COMPILE}ar RANLIB=${CROSS_COMPILE}ranlib AS=${CROSS_COMPILE}as LD=${CROSS_COMPILE}ld ../../glibc-2.3.5/configure --prefix=/usr --build=i386-ubuntu-linux --host=arm-unknown-linux-gnu --target=arm-unknown-linux-gnu --without-__thread --enable-add-ons=linuxthreads --with-headers=${SYSROOT}/usr/include
    說明:
    --prefix:                                  指定安裝路徑。
    --target:                               指定目標平台。
    --host:                                    指定當前平台。
    --build:                                   指定編譯平台。
    --with-sysroot:                        用於指定編譯所需要的標頭檔,及連結庫。
    --enable-add-ons:                   加入其它的庫,如線程庫等。
    --enable-languages:                 指定gcc所支援的語言。
    arm@ubuntu:~/dev_home/btools/tchain3.4.4/BUILD/glibc-2.3.5$ make
    arm@ubuntu:~/dev_home/btools/tchain3.4.4/BUILD/glibc-2.3.5$ su root
    root@ubuntu:/home/arm/dev_home/btools/tchain3.4.4/BUILD/glibc-2.3.5# make install_root=${SYSROOT} install
    root@ubuntu:/home/arm/dev_home/btools/tchain3.4.4/BUILD/glibc-2.3.5# exit
    arm@ubuntu:~/dev_home/btools/tchain3.4.4/BUILD/glibc-2.3.5$

    2.9 編譯完整的gcc
    arm@ubuntu:~/dev_home/btools/tchain3.4.4/BUILD/glibc-2.3.5$ cd ${SRC}
    arm@ubuntu:~/dev_home/btools/tchain3.4.4$ mkdir -p BUILD/gcc-3.4.4
    arm@ubuntu:~/dev_home/btools/tchain3.4.4$ cd BUILD/gcc-3.4.4
    arm@ubuntu:~/dev_home/btools/tchain3.4.4/BUILD/gcc-3.4.4$../../gcc-3.4.4/configure --prefix=${PREFIX} --target=${TARGET} --with-sysroot=${SYSROOT} --disable-nls --enable-threads=posix --enable-symvers=gnu --enable-__cxa_atexit --with-softfloat-support=internal --enable-languages=c,c++ --enable-shared --enable-c99 --enable-long-long
    arm@ubuntu:~/dev_home/btools/tchain3.4.4/BUILD/gcc-3.4.4$ make
    arm@ubuntu:~/dev_home/btools/tchain3.4.4/BUILD/gcc-3.4.4$ su root
    root@ubuntu:/home/arm/dev_home/btools/tchain3.4.4/BUILD/gcc-3.4.4# make install
    root@ubuntu:/home/arm/dev_home/btools/tchain3.4.4/BUILD/gcc-3.4.4# exit
    arm@ubuntu:~/dev_home/btools/tchain3.4.4/BUILD/gcc-3.4.4$
    arm@ubuntu:~/dev_home/btools/tchain3.4.4/BUILD/gcc-3.4.4$ arm-linux-gcc -v
    Reading specs from /usr/local/arm/3.4.4/lib/gcc/arm-linux/3.4.4/specsConfigured with: ../../gcc-3.4.4/configure --prefix=/usr/local/arm/3.4.4 --target=arm-linux --with-sysroot=/usr/local/arm/3.4.4/sysroot --disable-nls --enable-threads=posix --enable-symvers=gnu --enable-__cxa_atexit --with-softfloat-support=internal --enable-languages=c,c++ --enable-shared --enable-c99 --enable-long-long
    Thread model: posix
    gcc version 3.4.4
    arm@ubuntu:/usr/local/arm/3.4.4$ tree -L 1
    .
    |-- arm-linux
    |-- bin
    |-- include
    |-- info
    |-- lib
    |-- libexec
    |-- man
    |-- share
    `-- sysroot
    arm@ubuntu:/usr/local/arm/3.4.4$ du -sh
    193M    .
    arm@ubuntu:/usr/local/arm/3.4.4/bin$ ls
    arm-linux-addr2line  arm-linux-c++filt  arm-linux-gcc-3.4.4  arm-linux-nm       arm-linux-readelf
    arm-linux-ar         arm-linux-cpp      arm-linux-gccbug     arm-linux-objcopy  arm-linux-size
    arm-linux-as         arm-linux-g++      arm-linux-gcov       arm-linux-objdump  arm-linux-strings
    arm-linux-c++        arm-linux-gcc      arm-linux-ld         arm-linux-ranlib   arm-linux-strip

    2.10 測試gcc,g++
    arm@ubuntu:~$ vi hello_c.c
    #include
    #include
    int main()
    {
            printf("Hello,World~/n");
            return 0;
    }
    arm@ubuntu:~$ vi hello_cpp.cpp
    #include
    using std::cout;
    using std::endl;
    int main()
    {
      cout
      return 0;
    }
    arm@ubuntu:~$ arm-linux-gcc hello_c.c -o hello_c
    arm@ubuntu:~$ arm-linux-g++ -o hello_cpp hello_cpp.cpp
    arm@ubuntu:~$ tree -L 1
    .
    |-- dev_home
    |-- hello_c
    |-- hello_c.c
    |-- hello_cpp
    `-- hello_cpp.cpp

    1 directory, 4 files
    arm@ubuntu:~$ file hello_c
    hello_c: ELF 32-bit LSB executable, ARM, version 1 (ARM), for GNU/Linux 2.0.0, dynamically linked (uses shared libs), for GNU/Linux 2.0.0, not stripped
    arm@ubuntu:~$ file hello_cpp
    hello_cpp: ELF 32-bit LSB executable, ARM, version 1 (ARM), for GNU/Linux 2.0.0, dynamically linked (uses shared libs), for GNU/Linux 2.0.0, not stripped

    2.11 編譯主機上啟動並執行gdb
    arm@ubuntu:~/dev_home/btools/tchain3.4.4$ tar zxvf gdb-6.4.tar.gz
    arm@ubuntu:~/dev_home/btools/tchain3.4.4$ mkdir -p BUILD/gdb-6.4-host
    arm@ubuntu:~/dev_home/btools/tchain3.4.4$ cd  BUILD/gdb-6.4-host
    arm@ubuntu:~/dev_home/btools/tchain3.4.4/BUILD/gdb-6.4-host$ export CC=gcc
    arm@ubuntu:~/dev_home/btools/tchain3.4.4/BUILD/gdb-6.4-host$ ../../gdb-6.4/configure --target=arm-linux
    arm@ubuntu:~/dev_home/btools/tchain3.4.4/BUILD/gdb-6.4-host$ make
    arm@ubuntu:~/dev_home/btools/tchain3.4.4/BUILD/gdb-6.4-host$ file gdb/gdb
    gdb/gdb: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.2.0, dynamically linked (uses shared libs), for GNU/Linux 2.2.0, not stripped

    2.12建立目標平台上啟動並執行gdbserver
    arm@ubuntu:~/dev_home/btools/tchain3.4.4/BUILD/gdb-6.4-host$ mkdir -p ../gdbserver-6.4
    arm@ubuntu:~/dev_home/btools/tchain3.4.4/BUILD/gdb-6.4-host$ cd ../gdbserver-6.4
    arm@ubuntu:~/dev_home/btools/tchain3.4.4/BUILD/gdbserver-6.4$ export CC=/usr/local/arm/3.4.4/bin/arm-linux-gcc
    arm@ubuntu:~/dev_home/btools/tchain3.4.4/BUILD/gdbserver-6.4$ ../../gdb-6.4/gdb/gdbserver/configure  --host=arm-linux
    arm@ubuntu:~/dev_home/btools/tchain3.4.4/BUILD/gdbserver-6.4$ make
    arm@ubuntu:~/dev_home/btools/tchain3.4.4/BUILD/gdbserver-6.4$ file gdbserver 
    gdbserver: ELF 32-bit LSB executable, ARM, version 1 (ARM), for GNU/Linux 2.0.0, dynamically linked (uses shared libs), for GNU/Linux 2.0.0, not stripped

    3 GNU交叉工具鏈的下載
    工具鏈的官方:
    http://www.arm.linux.org.uk/
    可以從該網站下載2.95.3, 3.0以及3.2工具鏈
    ftp://ftp.arm.linux.org.uk/pub/armlinux/toolchain/cross-2.95.3.tar.bz2
    ftp://ftp.arm.linux.org.uk/pub/armlinux/toolchain/cross-3.0.tar.bz2

    ftp://ftp.handhelds.org/projects/toolchain/arm-linux-gcc-3.3.2.tar.bz2
    ftp://ftp.handhelds.org/projects/toolchain/arm-linux-gcc-3.4.1.tar.bz2
    http://ftp.snapgear.org/pub/snapgear/tools/arm-linux/gcc-3.4.4.tar.bz2

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.