使用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-  or eglibc-based toolchain supported right 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_MIRROR_BASE_URL= "http://ymorin.is-a-geek.org/mirrors/"
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,
           arm9tdmiarm10tdmi, 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= optionexcept 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,armv4tarmv5, 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监测,另外一个进行安装

Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐