【轉】搭建帶軟浮點交叉編譯工具鏈

  使用crosstool-ng爲s3c6410製作交叉編譯工具鏈

來自:http://www.usr.cc/thread-51735-1-1.html

 

 

-
前言
    以前都是用別人做好的工具鏈,現在想自己做個工具鏈。先是看看CLFS的文檔,對交叉編譯工具鏈的編譯過程有個基本瞭解,然後下載codesource cs2008q3的源代碼包,根據其提供的編譯腳本,花了一天時間終於編譯出了一個工具鏈,再將cs2008q3的編譯過程寫成多個shell腳本文件,這樣編譯工具鏈的時間會小於1小時。似乎,我這麼做太麻煩了,有沒有智能一點的方法呢,當然有,crosstool-ng就是其中的一個!    很多人可能聽說過crosstool,但可能不知道crosstool-ng。crosstool-ng對Dan Kegel的crosstool進行了重寫,支持最新的gcc、glibc等。我就利用這個工具成功製作了用於armv6的工具鏈。


環境
主機硬件: 奔騰雙核T4400(2.2G Hz) 2.5G內存
操作系統: Scientific Linux 6.0 x86版
主要軟件: GCC 4.4.4 Binutils 2.20


製作過程
  • 下載所需的軟件包
    爲了節省時間,最好先將要用到的軟件包下載到本地。
    crosstool-ng( http://my.chinaunix.net/link.php?url=http://ymorin.is-a-geek.org/projects/crosstool )
    根據需要下載特定版本的gcc、binutils、glibc、glibc-ports、gmp、mpfr、ppl等
  • 安裝crosstool-ng
    crosstool-ng的安裝比較簡單,指定安裝目前即可:
    • ./configure --prefix=/opt/ct-ng
    • #安裝目錄可以根據需要自行設置
    • make
    • make install

  • 製作工具鏈
    crosstool-ng的配置與內核配置類似,輸入以下命令即可:
    • /opt/ct-ng/bin/ct-ng menuconfig

    配置完成後,進入編譯安裝即可:
    • /opt/ct-ng/bin/ct-ng build


補充說明:
  • 關於浮點就hard/soft兩個選項,要想使用softfp需要改一下lib/ct-ng-版本號/scripts下的functions文件,將如下一行:
  • [ "${CT_ARCH_FLOAT_SW}" ] && { CT_ARCH_FLOAT_CFLAG="-msoft-float"; CT_ARCH_WITH_FLOAT="--with-float=soft"; }

改成:
  • [ "${CT_ARCH_FLOAT_SW}" ] && { CT_ARCH_FLOAT_CFLAG="-mfloat-abi=softfp"; CT_ARCH_WITH_FLOAT="--with-float=softfp"; }

    在配置浮點時選中soft浮點並指定fpu即可。
  • 針對s3c6410的主要配置:
    Architecture level: armv6zk
    Emit assembly for CPU: arm1176jzf-s
    Tune for CPU: arm1176jzf-s
    Use specific FPU: vfp
    Floating point: software
    運行工具鏈的gcc會得到類似的輸出:
    • $ arm-none-linux-gnueabi-gcc -v
    • Using built-in specs.
    • COLLECT_GCC=arm-none-linux-gnueabi-gcc
    • COLLECT_LTO_WRAPPER=/opt/armv6toolchain/libexec/gcc/arm-none-linux-gnueabi/4.5.2/lto-wrapper
    • Target: arm-none-linux-gnueabi
    • Configured with: /home/hale/ct-build/build/src/gcc-4.5.2/configure --build=i686-build_pc-linux-gnu --host=i686-build_pc-linux-gnu --target=arm-none-linux-gnueabi --prefix=/opt/armv6toolchain --with-sysroot=/opt/armv6toolchain/arm-none-linux-gnueabi/sysroot --enable-languages=c,c++ --disable-multilib --with-arch=armv6zk --with-cpu=arm1176jzf-s --with-tune=arm1176jzf-s --with-fpu=vfp --with-float=softfp --with-pkgversion='ct-ng armv6 toolchain' --enable-__cxa_atexit --disable-libmudflap --disable-libgomp --disable-libssp --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --with-gmp=/home/hale/ct-build/build/arm-none-linux-gnueabi/build/static --with-mpfr=/home/hale/ct-build/build/arm-none-linux-gnueabi/build/static --with-mpc=/home/hale/ct-build/build/arm-none-linux-gnueabi/build/static --with-ppl=/home/hale/ct-build/build/arm-none-linux-gnueabi/build/static --with-cloog=/home/hale/ct-build/build/arm-none-linux-gnueabi/build/static --with-libelf=/home/hale/ct-build/build/arm-none-linux-gnueabi/build/static --enable-threads=posix --enable-target-optspace --with-local-prefix=/opt/armv6toolchain/arm-none-linux-gnueabi/sysroot --disable-nls --enable-symvers=gnu --enable-c99 --enable-long-long
    • Thread model: posix
    • gcc version 4.5.2 (ct-ng armv6 toolchain)

    爲什麼這裏浮點選軟浮點(其實最後應用的是softfp,並不是soft),上面已經解釋過了
  • 編譯過程可能會出現:error: forced unwind support is required的錯誤,選中C庫選項的Force unwind support即可。
  • 如果用生成的工具鏈靜態編譯helloworld,用qemu-arm來運行出現uncaught target signal 11 (Segmentation fault) ,可能是C-library -> Minimum supported kernel version的設置有問題。我開始設爲2.6.28,結果就出現了這個錯誤,後來改成2.6.20就沒這個問題了。
  • 編譯時間大概40多分鐘左右,這個與硬件有關,就不多說了。

二 用crosstool-NG-1.9.3構建ARM工具鏈

來自:http://busybox.is-programmer.com/posts/24549.html

在成功重裝了兩次系統之後之前的移植工作終於還是被我弄丟了,無奈只好一切重頭再來了。
    首先下載u-boot源碼,下載地址爲ftp://ftp.denx.de/pub/u-boot/,這次將要移植的版本爲2010-12。
    製作交叉工具鏈(Cross-Tool),還是使用crosstool-NG來製作編譯工具,下載地址:http://ymorin.is-a-geek.org/download/crosstool-ng/ 。版本爲1.9.3,這個工具的使用方法可以在文檔或是http://ymorin.is-a-geek.org/projects/crosstool中找到,由於之前在弄crosstool的時候遇到一些問題,所以這次也把它的安裝過程和使用方法記錄下來。
    Features of This Tool

  • kernel-like menuconfig configuration interface
    • widespread, well-known interface
    • easy, yet powerful configuration
  • growing number of supported architectures
  • support for alternative components in the toolchain
    • uClibc-glibc- oreglibc-based toolchain supportedright now!
    • others easy to implement
  • different target OS supported
    • Linux
    • bare metal
  • patch repository for those versions needing patching
    • patches for many versions of the toolchain components
    • support for custom (understand local) patch repository
  • different threading models
    • NPTL
    • linuxthreads
  • support for both soft- and hard-float toolchains
  • debug facilities
    • native and cross gdb, gdbserver
    • debugging libraries: dmalloc, duma
    • restart a build at any step
  • sample configurations repository usable as starting point for your own toolchain

    安裝crosstool-NG
    配置安裝路徑./configure --prefix=/opt/programs/crosstool-ng-1.9.3,會提示缺少必要的工具,安裝就行了。
    sudo yum install lzma,接下來make, make install,可以檢查以下是否安裝成功
        PREFIX='/opt/programs/crosstool-ng-1.9.3'
        BINDIR='/opt/programs/crosstool-ng-1.9.3/bin'
        LIBDIR='/opt/programs/crosstool-ng-1.9.3/lib/ct-ng-1.9.3'
        DOCDIR='/opt/programs/crosstool-ng-1.9.3/share/doc/ct-ng-1.9.3'
        MANDIR='/opt/programs/crosstool-ng-1.9.3/share/man'
    然後測試,將其添加到PATH環境變量中,運行ct-ng help, ct-ng menuconfig, ct-ng build。
    使用ct-ng製作工具鏈
    ct-ng list-samples,列出已經通過實踐檢驗的示例配置腳本。
    這裏使用arm-unknown-linux-uclibcgnueabi的配置方案預先配置一下,然後再調整。
    Options:


 

  • OS:linux-2.6.33.7
  • uClibc-0.9.30.2
  • linuxthread

    調整完成之後可以在工作目錄下查看配置結果.config文件,然後確認無誤就可以build了,哦,對了,如果不能正常下載需要的tar文件時最好自己手動下載,然後再build,build時會出現錯誤提示'Don't set LD_LIBRARY_PATH. It screws up the build.',按照提示unset LD_LIBRARY_PATH,這時程序自動創建了目錄結構,接下來先停下來,手動下載所需要的安裝文件,需要在配置時選擇forbid download:

    當所有的安裝文件都下載、解壓、patch之後,還差一個uClibc的配置文件'[ERROR]    You did not provide a uClibc config file!',我們默認的配置文件在.config中的定義是"CT_LIBC_UCLIBC_CONFIG_FILE="${CT_LIB_DIR}/samples/${CT_TARGET}/${CT_LIBC}-${CT_LIBC_VERSION}.config",但是經過修改之後的CT_TARGET已經不存在了,所以直接把‘uClibc-0.9.30.2.config‘文件複製出來,放到剛纔的工作目錄的target下,然後再修改.config中的CT_LIBC_UCLIBC_CONFIG_FILE內容。

    雖然一切都準備好了,但是在編譯器生成的最後階段(Installing final compiler)還是出問題了,所以只好把gcc的版本換成4.3.2再試一次,不過這次沒有手動下載所需的安裝文件,直接通過爲wget設置代理來自動通過ct-ng下載。爲wget設置代理也很簡單,直接編輯/etc/wgetrc文件,加上這兩行:

http_proxy = http://58.248.245.225:80/

use_proxy = on

就行了,build的時候還是死掉了,原因是.../scripts/functions文件中的代碼

# OK, just look if we have them...
_aria2c=$(CT_Which aria2c)
_wget=$(CT_Which wget)
#_curl=$(CT_Which curl)
  
  
# Wrapper function to call one of, in order of preference:
#   aria2
#   curl
#   wget
# Usage: CT_DoGetFile
CT_DoGetFile() {
#CT_DoLog EXTRA "1 ${_aria2c}"
#CT_DoLog EXTRA "2 ${_curl}"
#CT_DoLog EXTRA "3 ${_wget}"
    if  [ -n"${_aria2c}"-a ${CT_DOWNLOAD_MAX_CHUNKS} -gt 1 ];then
        CT_DoGetFileAria2"$1"
    elif[ -n"${_curl}"]; then
        CT_DoGetFileCurl"$1"
    elif[ -n"${_wget}"]; then
        CT_DoGetFileWget"$1"
    else
        CT_Abort"Could find neither wget nor curl"
    fi

}

實際上CT_DoGetFile函數調用的是CT_DoGetFileCurl而非剛纔設置的wget,把上面的那個_curl=$(CT_Which curl)註釋掉就行了。

程序腳本中安裝文件的下載地址有時不可用,需要修改以下。

下載完成之後重新開始安裝,最後成功!

.config的文件內容如下:

 

# Automatically generated make config: don't edit
# crosstool-NG version: 1.9.3
# Fri Feb 18 19:16:42 2011
#
# CT_BACKEND is not set
CT_MODULES=y
  
#
# Paths and misc options
#
  
#
# crosstool-NG behavior
#
# CT_OBSOLETE is not set
CT_EXPERIMENTAL=y
# CT_DEBUG_CT is not set
  
#
# Paths
#
CT_LOCAL_TARBALLS_DIR="${HOME}/src"
CT_SAVE_TARBALLS=y
CT_WORK_DIR="${CT_TOP_DIR}/targets"
CT_PREFIX_DIR="${HOME}/x-tool-2/${CT_TARGET}"
CT_INSTALL_DIR="${CT_PREFIX_DIR}"
CT_REMOVE_DOCS=y
CT_INSTALL_DIR_RO=y
CT_STRIP_ALL_TOOLCHAIN_EXECUTABLES=y
  
#
# Downloading
#
# CT_FORBID_DOWNLOAD is not set
# CT_FORCE_DOWNLOAD is not set
CT_USE_MIRROR=y
# CT_PREFER_MIRROR is not set
CT_CONNECT_TIMEOUT=10
CT_DOWNLOAD_MAX_CHUNKS=1
# CT_ONLY_DOWNLOAD is not set
  
#
# Extracting
#
# CT_FORCE_EXTRACT is not set
CT_OVERIDE_CONFIG_GUESS_SUB=y
# CT_ONLY_EXTRACT is not set
CT_PATCH_BUNDLED=y
# CT_PATCH_LOCAL is not set
# CT_PATCH_BUNDLED_LOCAL is not set
# CT_PATCH_LOCAL_BUNDLED is not set
# CT_PATCH_BUNDLED_FALLBACK_LOCAL is not set
# CT_PATCH_LOCAL_FALLBACK_BUNDLED is not set
# CT_PATCH_NONE is not set
CT_PATCH_ORDER="bundled"
# CT_PATCH_SINGLE is not set
# CT_PATCH_USE_LOCAL is not set
  
#
# Build behavior
#
CT_PARALLEL_JOBS=1
CT_LOAD=0
CT_USE_PIPES=y
# CT_CONFIG_SHELL_SH is not set
# CT_CONFIG_SHELL_ASH is not set
CT_CONFIG_SHELL_BASH=y
# CT_CONFIG_SHELL_CUSTOM is not set
CT_CONFIG_SHELL="bash"
  
#
# Logging
#
# CT_LOG_ERROR is not set
# CT_LOG_WARN is not set
# CT_LOG_INFO is not set
CT_LOG_EXTRA=y
# CT_LOG_ALL is not set
# CT_LOG_DEBUG is not set
CT_LOG_LEVEL_MAX="EXTRA"
# CT_LOG_SEE_TOOLS_WARN is not set
CT_LOG_PROGRESS_BAR=y
CT_LOG_TO_FILE=y
CT_LOG_FILE_COMPRESS=y
  
#
# Target options
#
CT_ARCH="arm"
CT_ARCH_SUPPORTS_BOTH_MMU=y
CT_ARCH_SUPPORTS_BOTH_ENDIAN=y
CT_ARCH_SUPPORTS_32=y
# CT_ARCH_SUPPORTS_64 is not set
CT_ARCH_SUPPORT_ARCH=y
# CT_ARCH_SUPPORT_ABI is not set
CT_ARCH_SUPPORT_CPU=y
CT_ARCH_SUPPORT_TUNE=y
CT_ARCH_SUPPORT_FPU=y
CT_ARCH_DEFAULT_HAS_MMU=y
# CT_ARCH_DEFAULT_BE is not set
CT_ARCH_DEFAULT_LE=y
CT_ARCH_DEFAULT_32=y
# CT_ARCH_DEFAULT_64 is not set
CT_ARCH_ARCH="armv4t"
CT_ARCH_CPU=""
CT_ARCH_TUNE=""
CT_ARCH_FPU=""
# CT_ARCH_BE is not set
CT_ARCH_LE=y
CT_ARCH_32=y
# CT_ARCH_64 is not set
CT_ARCH_BITNESS=32
# CT_ARCH_FLOAT_HW is not set
CT_ARCH_FLOAT_SW=y
CT_TARGET_CFLAGS=""
CT_TARGET_LDFLAGS=""
  
#
# General target options
#
CT_ARCH_arm=y
# CT_ARCH_x86 is not set
# CT_ARCH_sh is not set
# CT_ARCH_avr32 is not set
# CT_ARCH_ia64 is not set
# CT_ARCH_mips is not set
# CT_ARCH_powerpc is not set
# CT_ARCH_s390 is not set
# CT_ARCH_m68k is not set
# CT_ARCH_alpha is not set
# CT_ARCH_blackfin is not set
CT_ARCH_arm_AVAILABLE=y
CT_ARCH_x86_AVAILABLE=y
CT_ARCH_sh_AVAILABLE=y
CT_ARCH_avr32_AVAILABLE=y
CT_ARCH_ia64_AVAILABLE=y
CT_ARCH_mips_AVAILABLE=y
CT_ARCH_powerpc_AVAILABLE=y
CT_ARCH_s390_AVAILABLE=y
CT_ARCH_m68k_AVAILABLE=y
CT_ARCH_alpha_AVAILABLE=y
CT_ARCH_blackfin_AVAILABLE=y
CT_ARCH_USE_MMU=y
  
#
# arm other options
#
CT_ARCH_ARM_MODE="arm"
CT_ARCH_ARM_MODE_ARM=y
# CT_ARCH_ARM_MODE_THUMB is not set
# CT_ARCH_ARM_INTERWORKING is not set
CT_ARCH_ARM_EABI=y
  
#
# Target optimisations
#
  
#
# Toolchain options
#
  
#
# General toolchain options
#
CT_USE_SYSROOT=y
CT_SYSROOT_DIR_PREFIX=""
  
#
# Tuple completion and aliasing
#
CT_TARGET_VENDOR="cool"
CT_TARGET_ALIAS_SED_EXPR=""
CT_TARGET_ALIAS="arm-cool-uClibc"
  
#
# Toolchain type
#
# CT_NATIVE is not set
CT_CROSS=y
# CT_CROSS_NATIVE is not set
# CT_CANADIAN is not set
CT_TOOLCHAIN_TYPE="cross"
  
#
# Build system
#
CT_BUILD=""
CT_BUILD_PREFIX=""
CT_BUILD_SUFFIX=""
  
#
# Operating System
#
# CT_BARE_METAL is not set
# CT_MINGW32 is not set
CT_KERNEL_SUPPORTS_SHARED_LIBS=y
CT_KERNEL="linux"
CT_KERNEL_VERSION="2.6.33.7"
# CT_KERNEL_mingw32 is not set
# CT_KERNEL_bare_metal is not set
CT_KERNEL_linux=y
CT_KERNEL_mingw32_AVAILABLE=y
CT_KERNEL_bare_metal_AVAILABLE=y
CT_KERNEL_linux_AVAILABLE=y
CT_KERNEL_LINUX_INSTALL=y
# CT_KERNEL_V_2_6_36 is not set
# CT_KERNEL_V_2_6_35_8 is not set
# CT_KERNEL_V_2_6_34_7 is not set
CT_KERNEL_V_2_6_33_7=y
# CT_KERNEL_V_2_6_32_25 is not set
# CT_KERNEL_V_2_6_31_14 is not set
# CT_KERNEL_V_2_6_27_55 is not set
# CT_KERNEL_LINUX_CUSTOM is not set
CT_KERNEL_LINUX_VERBOSITY_0=y
# CT_KERNEL_LINUX_VERBOSITY_1 is not set
# CT_KERNEL_LINUX_VERBOSITY_2 is not set
CT_KERNEL_LINUX_VERBOSE_LEVEL=0
CT_KERNEL_LINUX_INSTALL_CHECK=y
# CT_KERNEL_LINUX_USE_CUSTOM_HEADERS is not set
  
#
# Common kernel options
#
CT_SHARED_LIBS=y
  
#
# Binary utilities
#
CT_ARCH_BINFMT_ELF=y
# CT_ARCH_BINFMT_FLAT is not set
# CT_ARCH_BINFMT_FDPIC is not set
  
#
# GNU binutils
#
# CT_BINUTILS_V_2_20_1 is not set
# CT_BINUTILS_V_2_20 is not set
CT_BINUTILS_V_2_19_1=y
# CT_BINUTILS_V_2_19 is not set
# CT_BINUTILS_V_2_18 is not set
# CT_BINUTILS_V_2_17 is not set
# CT_BINUTILS_V_2_16_1 is not set
CT_BINUTILS_VERSION="2.19.1"
CT_BINUTILS_EXTRA_CONFIG=""
CT_BINUTILS_FOR_TARGET=y
CT_BINUTILS_FOR_TARGET_IBERTY=y
CT_BINUTILS_FOR_TARGET_BFD=y
  
#
# C compiler
#
CT_CC="gcc"
CT_CC_VERSION="4.3.2"
CT_CC_gcc=y
# CT_CC_V_4_5_1 is not set
# CT_CC_V_4_5_0 is not set
# CT_CC_V_4_4_5 is not set
# CT_CC_V_4_4_4 is not set
# CT_CC_V_4_4_3 is not set
# CT_CC_V_4_4_2 is not set
# CT_CC_V_4_4_1 is not set
# CT_CC_V_4_4_0 is not set
# CT_CC_V_4_3_5 is not set
# CT_CC_V_4_3_4 is not set
# CT_CC_V_4_3_3 is not set
CT_CC_V_4_3_2=y
# CT_CC_V_4_3_1 is not set
# CT_CC_V_4_2_4 is not set
# CT_CC_V_4_2_3 is not set
# CT_CC_V_4_2_2 is not set
# CT_CC_V_4_2_1 is not set
# CT_CC_V_4_2_0 is not set
# CT_CC_V_4_1_2 is not set
# CT_CC_V_4_0_4 is not set
# CT_CC_V_3_4_6 is not set
CT_CC_GCC_4_2_or_later=y
CT_CC_GCC_4_3_or_later=y
# CT_CC_GCC_4_4_or_later is not set
# CT_CC_GCC_4_5_or_later is not set
# CT_CC_GCC_HAS_GRAPHITE is not set
# CT_CC_GCC_HAS_LTO is not set
CT_CC_GCC_USE_GMP_MPFR=y
# CT_CC_GCC_USE_PPL_CLOOG is not set
# CT_CC_GCC_USE_MPC is not set
# CT_CC_GCC_USE_LIBELF is not set
CT_CC_PKGVERSION="crosstool-NG-${CT_VERSION}"
CT_CC_BUGURL=""
CT_CC_ENABLE_CXX_FLAGS=""
CT_CC_CORE_EXTRA_CONFIG=""
CT_CC_EXTRA_CONFIG=""
CT_CC_SUPPORT_CXX=y
CT_CC_SUPPORT_FORTRAN=y
CT_CC_SUPPORT_JAVA=y
CT_CC_SUPPORT_ADA=y
CT_CC_SUPPORT_OBJC=y
CT_CC_SUPPORT_OBJCXX=y
  
#
# Additional supported languages:
#
CT_CC_LANG_CXX=y
# CT_CC_LANG_FORTRAN is not set
# CT_CC_LANG_JAVA is not set
# CT_CC_LANG_ADA is not set
# CT_CC_LANG_OBJC is not set
# CT_CC_LANG_OBJCXX is not set
CT_CC_LANG_OTHERS=""
  
#
# gcc other options
#
CT_CC_GCC_ENABLE_TARGET_OPTSPACE=y
# CT_CC_GCC_LIBMUDFLAP is not set
# CT_CC_GCC_LIBGOMP is not set
# CT_CC_GCC_LIBSSP is not set
  
#
# Misc. obscure options.
#
CT_CC_CXA_ATEXIT=y
# CT_CC_GCC_DISABLE_PCH is not set
CT_CC_GCC_SJLJ_EXCEPTIONS=m
CT_CC_GCC_LDBL_128=m
  
#
# C-library
#
CT_LIBC="uClibc"
CT_LIBC_VERSION="0.9.30.2"
# CT_LIBC_mingw is not set
# CT_LIBC_glibc is not set
# CT_LIBC_newlib is not set
CT_LIBC_uClibc=y
# CT_LIBC_none is not set
# CT_LIBC_eglibc is not set
CT_LIBC_mingw_AVAILABLE=y
CT_LIBC_glibc_AVAILABLE=y
CT_LIBC_newlib_AVAILABLE=y
CT_LIBC_uClibc_AVAILABLE=y
# CT_LIBC_UCLIBC_V_0_9_31 is not set
# CT_LIBC_UCLIBC_V_0_9_30_3 is not set
CT_LIBC_UCLIBC_V_0_9_30_2=y
# CT_LIBC_V_0_9_30_1 is not set
# CT_LIBC_V_0_9_30 is not set
# CT_LIBC_V_0_9_29 is not set
# CT_LIBC_V_0_9_28_3 is not set
# CT_LIBC_V_snapshot is not set
# CT_LIBC_V_specific_date is not set
CT_LIBC_UCLIBC_0_9_30_or_later=y
CT_LIBC_UCLIBC_PARALLEL=y
CT_LIBC_UCLIBC_VERBOSITY_0=y
# CT_LIBC_UCLIBC_VERBOSITY_1 is not set
# CT_LIBC_UCLIBC_VERBOSITY_2 is not set
CT_LIBC_UCLIBC_VERBOSITY=""
CT_LIBC_UCLIBC_DEBUG_LEVEL_0=y
# CT_LIBC_UCLIBC_DEBUG_LEVEL_1 is not set
# CT_LIBC_UCLIBC_DEBUG_LEVEL_2 is not set
CT_LIBC_UCLIBC_DEBUG_LEVEL=0
CT_LIBC_UCLIBC_CONFIG_FILE="${HOME}/scratch/toolchain-build/${CT_LIBC}-${CT_LIBC_VERSION}.config"
CT_LIBC_none_AVAILABLE=y
CT_LIBC_eglibc_AVAILABLE=y
CT_LIBC_SUPPORT_THREADS_ANY=y
# CT_LIBC_SUPPORT_NPTL is not set
CT_LIBC_SUPPORT_LINUXTHREADS=y
# CT_LIBC_SUPPORT_WIN32THREADS is not set
CT_THREADS="linuxthreads"
  
#
# Common C library options
#
# CT_THREADS_NPTL is not set
CT_THREADS_LINUXTHREADS=y
# CT_THREADS_WIN32THREADS is not set
# CT_THREADS_NONE is not set
CT_LIBC_XLDD=y
  
#
# uClibc other options
#
CT_LIBC_UCLIBC_LNXTHRD_OLD=y
# CT_LIBC_UCLIBC_LNXTHRD_NEW is not set
CT_LIBC_UCLIBC_LNXTHRD="old"
# CT_LIBC_UCLIBC_LOCALES is not set
# CT_LIBC_UCLIBC_WCHAR is not set
  
#
# Debug facilities
#
CT_DEBUG_ltrace=y
CT_LTRACE_V_0_5_3=y
# CT_LTRACE_V_0_5_2 is not set
# CT_LTRACE_V_0_5 is not set
# CT_LTRACE_V_0_4 is not set
CT_LTRACE_VERSION="0.5.3"
CT_LTRACE_0_5_3_or_later=y
CT_DEBUG_gdb=y
CT_GDB_CROSS=y
# CT_GDB_CROSS_STATIC is not set
# CT_GDB_NATIVE is not set
CT_GDB_GDBSERVER=y
CT_GDB_GDBSERVER_STATIC=y
# CT_GDB_V_7_2 is not set
# CT_GDB_V_7_1 is not set
# CT_GDB_V_7_0_1 is not set
# CT_GDB_V_7_0 is not set
CT_GDB_V_6_8=y
CT_GDB_VERSION="6.8"
CT_DEBUG_duma=y
CT_DUMA_A=y
CT_DUMA_SO=y
CT_DUMA_V_2_5_15=y
# CT_DUMA_V_2_5_14 is not set
# CT_DUMA_V_2_5_12 is not set
# CT_DUMA_V_2_5_8 is not set
# CT_DUMA_V_2_5_1 is not set
CT_DUMA_VERSION="2_5_15"
CT_DEBUG_dmalloc=y
CT_DMALLOC_V_5_5_2=y
CT_DMALLOC_VERSION="5.5.2"
CT_DEBUG_strace=y
# CT_STRACE_V_4_5_20 is not set
CT_STRACE_V_4_5_19=y
# CT_STRACE_V_4_5_18 is not set
# CT_STRACE_V_4_5_17 is not set
# CT_STRACE_V_4_5_16 is not set
# CT_STRACE_V_4_5_15 is not set
CT_STRACE_VERSION="4.5.19"
  
#
# Companion libraries
#
CT_COMPLIBS_NEEDED=y
CT_GMP_NEEDED=y
CT_MPFR_NEEDED=y
# CT_PPL_NEEDED is not set
# CT_CLOOG_NEEDED is not set
# CT_MPC_NEEDED is not set
# CT_LIBELF_NEEDED is not set
CT_COMPLIBS=y
# CT_WRAPPER_NEEDED is not set
CT_GMP=y
CT_MPFR=y
CT_LIBELF_TARGET=y
# CT_GMP_V_5_0_1 is not set
CT_GMP_V_4_3_2=y
# CT_GMP_V_4_3_1 is not set
# CT_GMP_V_4_3_0 is not set
# CT_GMP_V_4_2_4 is not set
# CT_GMP_V_4_2_2 is not set
CT_GMP_VERSION="4.3.2"
# CT_MPFR_V_3_0_0 is not set
CT_MPFR_V_2_4_2=y
# CT_MPFR_V_2_4_1 is not set
# CT_MPFR_V_2_4_0 is not set
# CT_MPFR_V_2_3_2 is not set
# CT_MPFR_V_2_3_1 is not set
CT_MPFR_VERSION="2.4.2"
  
#
# libelf version needed to build for target
#
CT_LIBELF_V_0_8_13=y
# CT_LIBELF_V_0_8_12 is not set
CT_LIBELF_VERSION="0.8.13"
  
#
# Companion libraries common options
#
CT_COMPLIBS_BACKUP=y
# CT_COMPLIBS_CHECK is not set
# CT_COMPLIBS_SHARED is not set
  
#
# Companion tools
#
  
#
# READ HELP before you say 'Y' below !!!
#
# CT_COMP_TOOLS is not set
  
#
# Test suite
#
# CT_TEST_SUITE is not set
# CT_TEST_SUITE_GCC is not set

參考鏈接:

http://forum.samdroid.net/wiki/showwiki/How+to+build+cross+toolchains+for+ARM+crosstool-NG?s=3be360ee3bb8458456aadf55f3229e12&do=comments

http://ymorin.is-a-geek.org/projects/crosstool

三 用crosstool-ng在ubuntu下構建交叉編譯環境

來自:http://home.eeworld.com.cn/my/space.php?uid=67366&do=blog&id=43600

這個整的比較鬱悶,公司的電腦太菜了,虛擬機一開,電腦連QQ都不敢開。編譯一次耗費大量時間,在虛擬機下,還容易出問題。搞了幾天,後來在家裏的電腦上,28分鐘就弄好了。下面記錄流程:
1.下載工具crosstool-ng 最新版本是1.93。主機環境爲ubuntu 10.04.開始我以爲編譯過程與主機上的GCC版本和GDB版本以及BINUTILS版本有關。後來發現沒有關係。
2.切換到root用戶下,安裝相關工具。爲了省事,以下所有操作都在root用戶下。
apt-get install bison flex texinfo automake libtool cvs patch
apt-get install libncurses5* 這裏怕安裝不全,直接用*
apt-get install aria2 curl gcj g++ subversion  cvsd gawk有幾個軟件系統中原本就有。
apt-get install glibc*.我編譯到native gdb的時候出現了錯誤,我懷疑是這個地方有問題。當然有可能是其它原因,保險起見,還是安裝這個東東,反正裝好後,重新編譯成功了,至於是不是這個原因,不去追究了。
下載:

binutils-2.19.1.tar.bz2

dmalloc-5.5.2.tgz

duma_2_5_15.tar.gz

expat-2.0.1.tar.gz

gcc-4.3.2.tar.bz2

gdb-6.8.tar.bz2

glibc-2.9.tar.bz2

glibc-ports-2.9.tar.bz2

gmp-4.3.2.tar.bz2

libelf-0.8.13.tar.gz

linux-2.6.33.7.tar.bz2 //源碼自己下載,一般只要是33.7版本以下都可以。我用的是26.32.17,補丁也下載下來。不過我覺得最好用26.32.25的版本,因爲在ct-ng menuconfig的時候,發現上面多了一句話。Long-term 什麼的。

mpfr-2.4.2.tar.bz2

ncurses-5.7.tar.gz

Sstrip.c

strace-4.5.19.tar.bz2

一定要全部下載好,要不然以後的編譯過程中,速度很慢還存在潛在的危險,說不定哪個包自動下載不下來,編譯錯誤,那連原因也找不到

3.cd  /usr/bin
mv mawk mawk.bak
ln -s gawk mawk
4.cd /home
mkdir crosstool-ng
cd crosstool-ng
mkdir src
將上面下載的源碼包全部複製到 src目錄下。
解壓crosstool-ng-1.9.3到當前目錄下。
cd crosstool-ng-1.9.3
./configure --prefix=/opt/crosstool-ng 後面的參數是安裝目錄,不用自己建立,她自動會建立。
會有兩個No,沒關係。繼續。
make
make install
make clean

$ echo "PATH=$PATH:/opt/crosstool-ng/bin" >> ~/.bashrc  #  爲後面調用ct-ng命令增加環境變量

$ source ~/.bashrc下班了,明天繼續寫。

5.接下來

cd /home/crosstool-ng

mkdir  crosstool-ng-1.9.3_build  //編譯時的輸出目錄

cd crosstool-ng-1.9.3_build/

cp /opt/crosstool-ng/lib/ct-ng-1.9.3/samples/arm-unknown-linux-gnueabi/crosstool.config .config

如果足夠牛逼的話,直接編寫這個配置文件。對於我而言,還是老老實實運行圖形化配置工具。

 ct-ng menuconfig    //一定要在上面建立的crosstool-ng-1.9.3_build目錄下運行。

改寫下面的路徑,按照上面的定義,最後的結果如下

Paths and misc options  --->

  (/home/crosstool-ng/src) Local tarballs directory           保存源碼包路徑

  (/opt/crosstool-ng/${CT_TARGET}) Prefix directory  交叉編譯器的安裝路徑

 Target options  --->

          *** Target optimisations ***

           (armv4t) Architecture level

           (arm9tdmi) Emit assembly for CPU   

           (arm920t) Tune for CPU

C compiler --->

*** Additional supported languages:***

[*] C++

[ ] Fortran

[ ] Java

取消下面兩個語言的選擇。這個應該取消選擇,否則容易出錯。

Paths and misc options  --->

   *** Build behavior ***

  (4) Number of parallel jobs  如果是雙核的話,不是在虛擬機下運行的,就填4.在虛擬機下,開2就行了,開4也沒用。弄不好整死機了。

保存退出

6.如果你選擇配置界面裏面的LINUX版本整好爲你下載的版本,例如2.6.32.25。則不需要執行以下操作。

否則,請修改內核,默認的內核版本爲2.6.33.7。

vi .config

修改CT_KERNEL=“linux"我下載的內核源碼

      CT_KERNEL_VERSION=2.6.32.17

     CT_KERNEL_V_2_6_32_17=y

    CT_LIBC_GLIBC_MIN_KERNEL=2.6.32.17

保存退出。

7.ct-ng build.4 bulid後面有個點,不要忘了。意思爲4線程編譯。一切正確配置的話。我的家裏的電腦爲酷睿雙核E7200,金士頓8002G內存。所耗費時間爲28分多種,編譯成功。

8. $echo "PATH=$PATH:/opt/crosstool-ng/arm-unknown-linux-gnueabi/bin" >> ~/.bashrc。             //root家目錄下的.bashrc

source ~/.bashrc 立即生效

9.arm-unknown-linux-gnueabi -v 會看到出來一大堆的東西。最後一行是

gcc version 4.3.2 (crosstool-NG-1.9.3-unknown)

10.其中arm-unknown-linux-gnueabi。中的UNKNOWN可以改爲你想要的任何文字,這個步驟在上面的圖形配置裏面,不過沒有什麼意義,就不寫了。

用crosstool-ng建立Linux 交叉編譯環境

來自:http://blog.chinaunix.net/space.php?uid=20543672&do=blog&id=94369

用crosstool-ng建立Linux交叉編譯環境(以S3C2440(armv4t)爲例)

    最近準備針對Linux內核和驅動做實驗,但是當我用從前的製作的gcc-4.1.1編譯最新的Linux內核的時候發現因爲編譯器太舊了無法編譯,所以決定在做一個新的可以使用的。早就知道crosstool-ng這個工具了,但是去年使用了以後發現編譯出的庫文件不對(我要編譯armv4的,結果編譯出了v5的),所以只留下了記錄,沒有寫文檔。這次編譯成功了,經過編譯u-boot、Linux kernel、busybox,並製作了根文件系統做測試,都沒有問題,這才決定寫一份文檔放到博客來。好的,閒話不多說,現在就是見證製作過程的時刻。

    首先可以去crosstool-ng的主頁瞭解一下這個工具,從那裏我們可以知道他是根據crosstool寫的。

    本文檔的重點參考資料:用crosstool-ng建立arm-linux交叉工具鏈

一、下載crosstool-ng,併爲使用安裝必要的軟件。
   crosstool-ng的下載地址是:http://blog.chinaunix.net/link.php?url=http://ymorin.is-a-geek.org/download/crosstool-ng/
   值得注意的是,下載裏最新的crosstool-ng以後,記得在到http://blog.chinaunix.net/link.php?url=http://ymorin.is-a-geek.org/download/crosstool-ng/01-fixes/看看有沒有相應的補丁,有得話一起下載下來。

   我這次使用的是1.6.1。
   使用crosstool-ng必須安裝一些開發用的軟件,在ubuntu下必須安裝(使用apt):
libncurses5-dev
bison
flex
texinfo
automake
libtool
patch
gcj
cvs
cvsd
gawk根據

用crosstool-ng建立arm-linux交叉工具鏈的介紹,最好手動安裝一下termcap

二、解壓、打補丁(如果有)並建立工作目錄。
   crosstool-ng和crosstool不同的地方之一就是:她並不是一下載下來就可以使用了,必須先配置安裝。
   將下載下來的crosstool-ng-X.Y.Z.tar.bz2解壓到你爲她準備的工作目錄(這裏假設爲${CROSSTOOLNG}),並建立安裝和編譯目錄。

mkdir crosstool-ng-1.6.1_build    #這次編譯新交叉編譯器的工作目錄
mkdir crosstool-ng-1.6.1_install  #crosstool-ng的安裝目錄
cd crosstool-ng-1.6.1             #進入解壓後的crosstool-ng目錄

patch -p1 <  <補丁文件>           #給crosstool-ng打補丁(如果有)

./configure--prefix=${CROSSTOOLNG}/crosstool-ng-1.6.1_install

                                   #配置crosstool-ng
make                               #編譯crosstool-ng

make install                       #安裝crosstool-ng
三、配置本次編譯的交叉編譯工具鏈
   接下來就是配置你要編譯的交叉編譯工具鏈了,在crosstool-ng已很多已經做好的默認配置(位於crosstool-ng-X.Y.Z/samples目錄下),你只要針對其進行修改就好了。對於編譯器組件部分的版本最好不要修改,因爲那個配搭應該是經過測試後的最高本版了,但內核版本可以修改

cd ${CROSSTOOLNG}/crosstool-ng-1.6.1_build/  

#進入編譯新交叉編譯器的工作目錄
cp ../crosstool-ng-1.6.1/samples/arm-unknown-linux-gnueabi /* ./

#拷貝默認配置文件到工作目錄

mv crosstool.config  .config

#修改文件名

../crosstool-ng-1.6.1_install/bin/ct-ng menuconfig

進入menuconfig,開始修改配置

下面我只說說針對armv4t需要修改的地方,別的構架等有了板子測試再說:
1、已下載好的源碼包路徑和交叉編譯器的安裝路徑。
Paths and misc options  --->
  (${HOME}/development/crosstool-ng/src) Local tarballs directory   保存源碼包路徑
  (${HOME}/development/x-tools/${CT_TARGET}) Prefix directory  交叉編譯器的安裝路徑
這兩個請依據你的實際情況來修改。

2、修改交叉編譯器針對的構架
 Target options  --->
           *** Target optimisations ***
           (armv4t) Architecture level
           (arm9tdmi) Emit assembly for CPU   
           (arm920t) Tune for CPU

以上這幾個參數是如何得出的可以參考gcc的man手冊,你可以在你下載的gcc-4.3.2.tar.bz2解壓後找到,她的位置是gcc-4.3.2/gcc/doc/gcc.1。打開方式:

man ./gcc.1


你可以在其中找到:
ARM Options
......
-mcpu=name   (Emit assembly for CPU)
           This specifies the name of the target ARM processor. GCC usesthis
           name to determine what kind of instructions it can emit when gener‐
           ating assembly code. Permissible names are: arm2, arm250, arm3,
           arm6, arm60, arm600, arm610, arm620, arm7, arm7m, arm7d, arm7dm,
           arm7di, arm7dmi, arm70, arm700, arm700i, arm710, arm710c, arm7100,
           arm7500, arm7500fe, arm7tdmi, arm7tdmi-s, arm8, strongarm, stron‐
           garm110, strongarm1100, arm8, arm810, arm9, arm9e, arm920, arm920t,
           arm922t, arm946e-s, arm966e-s, arm968e-s, arm926ej-s, arm940t,
           arm9tdmi, arm10tdmi, arm1020t, arm1026ej-s, arm10e, arm1020e,
           arm1022e, arm1136j-s, arm1136jf-s, mpcore, mpcorenovfp,
           arm1156t2-s, arm1176jz-s, arm1176jzf-s, cortex-a8, cortex-r4, cor‐
           tex-m3, xscale, iwmmxt, ep9312.

       -mtune=name  
(Tune for CPU)
           This option is very similar to the -mcpu= option, except that
           instead of specifying the actual target processor type,and hence
           restricting which instructions can be used, it specifies that GCC
           should tune the performance of the code as if the target were of
           the type specified in this option, but still choosing the instruc‐
           tions that it will generate based on the cpu specified by a-mcpu=
           option. For some ARM implementations better performance can be
           obtained by using this option.

       -march=name 
(Architecture level)
           This specifies the name of the target ARM architecture. GCC uses
           this name to determine what kind of instructions it can emit when
           generating assembly code. This option can be used in conjunction
           with or instead of the -mcpu= option. Permissible names are:
           armv2, armv2a, armv3, armv3m, armv4,armv4t, armv5, armv5t,
           armv5te, armv6, armv6j, armv6t2, armv6z, armv6zk, armv7, armv7-a,
           armv7-r, armv7-m, iwmmxt, ep9312.

......

3、關閉JAVA編譯器,避免錯誤。
  我這裏用ubuntu 9.10編譯JAVA編譯器的時候會出錯,也許是host的gcj的問題,反正我不用JAVA,所以就直接關閉了。如果有兄弟知道如何修正記得通知一聲!!
C compiler  --->
      *** Additional supported languages: *** 
      [N] Java 

error log:
INFO ]  =================================================================
[INFO ]  Installing final compiler
[EXTRA]    Configuring final compiler
[EXTRA]    Building final compiler
[ERROR]    jar: internal error:
[ERROR]    make[4]: *** [libgcj-4.3.2.jar] Error 1
[ERROR]    make[3]: *** [all-recursive] Error 1
[ERROR]    make[2]: *** [all-target-libjava] Error 2
[ERROR]    make[1]: *** [all] Error 2
[ERROR]    Build failed in step 'Installing final compiler'
[ERROR]    Error happened in '/home/tekkaman/development/research/crosstool-ng/crosstool-ng-1.6.1_install/lib/ct-ng-1.6.1/scripts/functions' in function 'CT_DoExecLog' (line unknown, sorry)
[ERROR]          called from '/home/tekkaman/development/research/crosstool-ng/crosstool-ng-1.6.1_install/lib/ct-ng-1.6.1/scripts/build/cc/gcc.sh' at line # 350 in function 'do_cc'
[ERROR]          called from '/home/tekkaman/development/research/crosstool-ng/crosstool-ng-1.6.1_install/lib/ct-ng-1.6.1/scripts/crosstool-NG.sh' at line # 562 in function 'main'
[ERROR]    Look at '/home/tekkaman/development/x-tools/arm-tekkaman-linux-gnueabi/build.log' for more info on this error.
[ERROR]  (elapsed: 67:10.67)
[67:11] / make: *** [build] 錯誤 2

4、根據參考資料,禁止內核頭文件檢測(只起到節約時間的作用(不到1S的時間),不推薦禁用)
Operating System  --->

 [N]     Check installed headers

5、增加編譯時的並行進程數,以增加運行效率,加快編譯。
Paths and misc options  --->
   *** Build behavior *** 
   (4) Number of parallel jobs 
   這個數值不宜過大,應該爲CPU數量的兩倍。由於我的CPU是雙核的,所以我填了4.

6、一些個性化的修改(可以不修改)
Toolchain options  --->
       *** Tuple completion and aliasing ***  
       (tekkaman) Tuple's vendor string 
這樣產生的編譯器前綴就是:arm-tekkaman-linux-gnueabi-

C compiler  --->
       (crosstool-NG-${CT_VERSION}-tekkaman) gcc ID string 

配置好以後保存。

最後,內核源碼的版本號修改,請直接修改crosstool-ng-1.6.1_build目錄下的.config文件,不止一處,有關的都要修改。
有:

CT_KERNEL_VERSION=
CT_KERNEL_V_2_6_??_?=y
CT_LIBC_GLIBC_MIN_KERNEL=


如果再次../crosstool-ng-1.6.1_install/bin/ct-ng menuconfig,這個修改又會復原,必須再次手工修改。
你也可以選擇修改crosstool-ng-X.Y.Z_build/config/kernel/linux.in等文件,只是比較麻煩,但這可以徹底解決,實現在界面中增加內核版本。

四、爲加快速度,根據配置自行下載相應的軟件包。(選做)
   雖然crosstool-ng發現找不到軟件包的時候會自動下載,但是比較慢。根據這次的配置情況(查看“.config”文件),我預先下載了以下的軟件包:
binutils-2.19.1.tar.bz2
glibc-2.9.tar.gz         
dmalloc-5.5.2.tgz       
glibc-ports-2.9.tar.bz2  
mpfr-2.4.2.tar.bz2
duma_2_5_15.tar.gz      
gmp-4.3.1.tar.bz2        
ncurses-5.7.tar.gz
ecj-latest.jar      
libelf-0.8.12.tar.gz     
sstrip.c
gcc-4.3.2.tar.bz2       
linux-2.6.33.1.tar.bz2  
strace-4.5.19.tar.bz2
gdb-6.8.tar.bz2        
ltrace_0.5.3.orig.tar.gz

下載完之後,記得將這些軟件包放在配置時指定的文件夾

 

五、開始編譯。
../crosstool-ng-1.6.1_install/bin/ct-ng  build

六、編譯好後的交叉編譯器。
編譯器位於:${你配置時確定的路徑}/x-tools/arm-tekkaman-linux-gnueabi/bin
庫文件位於:${你配置時確定的路徑}/x-tools/arm-tekkaman-linux-gnueabi/arm-tekkaman-linux-gnueabi/lib


 

 開了兩個終端,一個終端用tail -f build.log監測,另外一個進行安裝

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章