|
HOWTO build arm-linux toolchain for ARM/XSCALE
----------------------------------------------
These instructions document how to build an arm-linux tool chain
that contains both little-endian and big-endian target libraries.
# 注意,你必须有一个至少是配置好的linux kernel.
1. Packages used:
binutils-2.14.tar.gz
gcc-3.3.2.tar.gz
glibc-2.2.5.tar.gz
glibc-linuxthreads-2.2.5.tar.gz
2. binutils-2.14
tar xvzf binutils-2.14.tar.gz
cd binutils-2.14
mkdir xscale_linux_be
cd xscale_linux_be
../configure --target=armbe-linux --prefix=/opt/xscale_linux_be --with-lib-path=/opt/xscale_linux_be/armbe-linux/lib --program-prefix=xscale_linux_be-
make
make install
chmod 777 /opt/xscale_linux_be
3. gcc-3.3.2 -- bootstrap gcc
tar xvzf gcc-3.3.2.tar.gz
cd gcc-3.3.2
cp $(ATTACHED t-linux file) gcc/config/arm/
# 替换Makefile.in文件中对GCC_FOR_TARGET的定义,增加-mbig-endian选项
perl -pi -e 's/GCC_FOR_TARGET = \$\(STAGE_CC_WRAPPER\) \$\$r\/gcc\/xgcc /GCC_FOR_TARGET = \$\(STAGE_CC_WRAPPER\) \$\$r\/gcc\/xgcc -mbig-endian /g' Makefile.in
cd gcc
# 替换Makefile.in文件中对GCC_FOR_TARGET的定义,增加-mbig-endian选项
perl -pi -e 's/GCC_FOR_TARGET = \$\(STAGE_CC_WRAPPER\) \.\/xgcc /GCC_FOR_TARGET = \$\(STAGE_CC_WRAPPER\) \.\/xgcc -mbig-endian /g' Makefile.in
cd config/arm
# 以下三条perl命令将t-arm-elf文件中的三个宏定义的注释符“#”去掉
perl -pi -e 's/^# MULTILIB_OPTIONS[ ]*\+= mlittle-endian\/mbig-endian/MULTILIB_OPTIONS += mlittle-endian\/mbig-endian/' t-arm-elf
perl -pi -e 's/^# MULTILIB_DIRNAMES[ ]*\+= le be/MULTILIB_DIRNAMES += le be/' t-arm-elf
perl -pi -e 's/^# MULTILIB_MATCHES[ ]*\+= mbig-endian=mbe mlittle-endian=ml/MULTILIB_MATCHES += mbig-endian=mbe mlittle-endian=ml/' t-arm-elf
#当前目录处于gcc-3.3.2/gcc/config/arm
cd ../../..
#回到gcc-3.3.2目录
export PATH=/opt/xscale_linux_be/bin:$PATH
mkdir xscale_linux_be
cd xscale_linux_be
#以下配置GCC,注意--with-headers需要指定你的snapgear uclinux kernel 的头文件位置。
../configure --program-prefix=xscale_linux_be- --prefix=/opt/xscale_linux_be --target=armbe-linux --disable-shared --disable-threads --with-headers=$(WHEREYOURSRCBEING)/snapgear/linux-2.4.x/include --with-gnu-as --with-gnu-ld --enable-multilib --enable-languages=c
perl -pi -e 's/^program_transform_cross_name = s,\^,\$\(target_alias\)-,/program_transform_cross_name = s,\^,xscale_linux_be-,/g' gcc/Makefile
# make的时候可能会出现gcc/Makefile 673行出错[缺少分割符],在gcc/Makefile673行,677行起始处增加TAB就可以了。
# 这个问题到是由什么引起的?照理说自动生成的Makefile不应该有问题
# 另外,make的时候同样会碰到xgcc no input file的错误,问题同样出在673,677行,在行末尾的"\"符号之后多了一个空格,删除这#
# 个空格,就可以了。
make
make install
4. glibc-2.2.5 (big-endian)
tar xvzf glibc-2.2.5.tar.gz
cd glibc-2.2.5
tar xvzf ../glibc-linuxthreads-2.2.5.tar.gz
# 增加arm target
perl -pi -e 's/i386/arm*)\n\tlibc_cv_gcc_unwind_find_fde=yes\n\tarch_minimum_kernel=2.0.10\n\t;;\n i386/' sysdeps/unix/sysv/linux/configure
# 注释掉此行
perl -pi -e 's/weak_alias \(__old_sys_nerr/\/\/ $&/' sysdeps/unix/sysv/linux/arm/errlist.c
# 注释掉此行
perl -pi -e 's/weak_alias \(__old_sys_nerr/\/\/ $&/' sysdeps/unix/sysv/linux/errlist.c
cd sysdeps/arm
patch -p0 < ../../Patch.armbe-strlen-fix
# 当前我们在glibc-2.2.5/sysdeps/arm目录下
cd ../..
# 切换到glibc-2.2.5目录
vi linuxthreads/sysdeps/pthread/pthread.h
- change line 163, "__thread" -> "__thr"
- change line 591, "__thread" -> "__thr"
vi linuxthreads/internals.h
- change line 555, "__thread" -> "__thr"
vi linuxthreads/sysdeps/unix/sysv/linux/bits/sigthread.h
- change line 36, "__thread" -> "__thr"
# 以下两行改变函数声明
vi stdio-common/sprintf.c
- line 30, change to "sprintf(char *s, const char *format, ...)"
vi stdio-common/sscanf.c
- line 30, change to "sscanf(const char *s, const char *format, ...)"
# 就是把134行的a1删掉,clobber list是指内联汇编的修饰列表
vi sysdeps/unix/sysv/linux/arm/sysdep.h
- line 134, remove "a1" from clobber list
# 主要是内联汇编没有换行符,有很多
vi sysdeps/arm/dl-machine.h
- add '\n\' to end of all macro asm lines (there is a _lot_ of them)
vi config.make.in
- change "slibdir=@libc_cv_slibdir@" to "slibdir=@libdir@"
vi sysdeps/unix/sysv/linux/arm/ioperm.c
- add include file <linux/input.h> to avoid compile error of BUS_ISA not defined.
mkdir xscale_linux_be
cd xscale_linux_be
export CC="xscale_linux_be-gcc -mbig-endian -finline-limit=10000"
export AR="xscale_linux_be-ar"
export RANLIB="xscale_linux_be-ranlib"
export LD="xscale-linux_be-ld -mbig-endian"
../configure armbe-linux --target=armbe-linux --prefix=/opt/xscale_linux_be/armbe-linux --build=i686-pc-linux-gnu --with-headers=$(WHEREYOURSRCBEING)/snapgear/linux-2.4.x/include --with-headers=/opt/xscale_linux_be/armbe-linux/sys-include --enable-add-ons=linuxthreads --enable-shared
make
make install
6. gcc-3.3.2 (c++, etc) full version
tar xvzf gcc-3.3.2.tar.gz
cd gcc-3.3.2
cp $(ATTACHED t-linux file) gcc/config/arm/
vi gcc/config/arm/t-linux
- remove all "-Dinhibit_libc" occruances
# 替换Makefile.in文件中对GCC_FOR_TARGET的定义,增加-mbig-endian选项
perl -pi -e 's/GCC_FOR_TARGET = \$\(STAGE_CC_WRAPPER\) \$\$r\/gcc\/xgcc /GCC_FOR_TARGET = \$\(STAGE_CC_WRAPPER\) \$\$r\/gcc\/xgcc -mbig-endian /g' Makefile.in
cd gcc
# 替换Makefile.in文件中对GCC_FOR_TARGET的定义,增加-mbig-endian选项
perl -pi -e 's/GCC_FOR_TARGET = \$\(STAGE_CC_WRAPPER\) \.\/xgcc /GCC_FOR_TARGET = \$\(STAGE_CC_WRAPPER\) \.\/xgcc -mbig-endian /g' Makefile.in
cd config/arm
# 以下三条perl命令将t-arm-elf文件中的三个宏定义的注释符“#”去掉
perl -pi -e 's/^# MULTILIB_OPTIONS[ ]*\+= mlittle-endian\/mbig-endian/MULTILIB_OPTIONS += mlittle-endian\/mbig-endian/' t-arm-elf
perl -pi -e 's/^# MULTILIB_DIRNAMES[ ]*\+= le be/MULTILIB_DIRNAMES += le be/' t-arm-elf
perl -pi -e 's/^# MULTILIB_MATCHES[ ]*\+= mbig-endian=mbe mlittle-endian=ml/MULTILIB_MATCHES += mbig-endian=mbe mlittle-endian=ml/' t-arm-elf
export PATH=/opt/xscale_linux_be/bin:$PATH
mkdir xscale_linux_be
cd xscale_linux_be
../configure --program-prefix=xscale_linux_be- --prefix=/opt/xscale_linux_be --target=armbe-linux --enable-multilib --with-headers=/opt/xscale_linux_be/armbe-linux/include --enable-languages=c,c++
perl -pi -e 's/int namelen/unsigned int namelen/' ../libjava/java/net/natInetAddress.cc
[ For big-endian ]
perl -pi -e 's/^CC_FOR_TARGET = \$\$r\/gcc\/xgcc/CC_FOR_TARGET = \$\$r\/gcc\/xgcc -mbig-endian /' Makefile
perl -pi -e 's/\$\$r\/gcc\/ -nostdinc\+\+ /\$\$r\/gcc\/ -nostdinc++ -mbig-endian /' Makefile
cd gcc
perl -pi -e 's/libstdc\+\+ /libstdc\+\+ -mbig-endian /' Makefile
make LDFLAGS="-mbig-endian"
make install
7. gdb-5.1.1
bzip2 -cd gdb-5.1.1.tar.bz2 | tar xvf -
cd gdb-5.1.1
mkdir xscale_linux_be
cd xscale_linux_be
../configure --prefix=/opt/xscale_linux_be --program-prefix=xscale_linux_be- --target=armbe-linux
make
make install
8. cd /
tar cvzf /opt/xscale_linux_be-toolchain-20040511.tar.gz /opt/xscale_linux_be
------------------------------------------------------------------------------
APPENDIX A -- modified t-linux for gcc-3.3.2
------------------------------------------------------------------------------
# Just for these, we omit the frame pointer since it makes such a big
# difference. It is then pointless adding debugging.
TARGET_LIBGCC2_CFLAGS = -fomit-frame-pointer -fPIC -Dinhibit_libc -D__gthr_posix
LIBGCC2_DEBUG_CFLAGS = -g0
# Don't build enquire
ENQUIRE=
LIB1ASMSRC = arm/lib1funcs.asm
LIB1ASMFUNCS = _udivsi3 _divsi3 _umodsi3 _modsi3 _dvmd_lnx
# MULTILIB_OPTIONS = mhard-float/msoft-float
# MULTILIB_DIRNAMES = hard-float soft-float
MULTILIB_OPTIONS = mlittle-endian/mbig-endian
MULTILIB_DIRNAMES = le be
# If you want to build both APCS variants as multilib options this is how
# to do it.
# MULTILIB_OPTIONS += mapcs-32/mapcs-26
# MULTILIB_DIRNAMES += apcs-32 apcs-26
EXTRA_MULTILIB_PARTS = crtbegin.o crtbeginS.o crtend.o crtendS.o crti.o crtn.o
LIBGCC = stmp-multilib
INSTALL_LIBGCC = install-multilib
T_CFLAGS = -Dinhibit_libc -D__gthr_posix_h
# Assemble startup files.
$(T)crti.o: $(srcdir)/config/arm/crti.asm $(GCC_PASSES)
$(GCC_FOR_TARGET) $(GCC_CFLAGS) $(MULTILIB_CFLAGS) $(INCLUDES) \
-c -o $(T)crti.o -x assembler-with-cpp $(srcdir)/config/arm/crti.asm
$(T)crtn.o: $(srcdir)/config/arm/crtn.asm $(GCC_PASSES)
$(GCC_FOR_TARGET) $(GCC_CFLAGS) $(MULTILIB_CFLAGS) $(INCLUDES) \
-c -o $(T)crtn.o -x assembler-with-cpp $(srcdir)/config/arm/crtn.asm
------------------------------------------------------------------------------
------------------------------------------------------------------------------
APPENDIX B -- Patch.armbe-strlen-fix for glibc-2.2.5
------------------------------------------------------------------------------
--- strlen.S.orig 2003-06-30 14:55:04.000000000 +0200
+++ strlen.S 2003-06-30 14:58:16.000000000 +0200
@@ -53,11 +53,20 @@
ldrne r2, [r1], $4 @ and we continue to the next word
bne Laligned @
Llastword: @ drop through to here once we find a
+#ifdef __ARMEB__
+ tst r2, $0xff000000 @ word that has a zero byte in it
+ addne r0, r0, $1 @
+ tstne r2, $0x00ff0000 @ and add up to 3 bytes on to it
+ addne r0, r0, $1 @
+ tstne r2, $0x0000ff00 @ (if first three all non-zero, 4th
+ addne r0, r0, $1 @ must be zero)
+#else
tst r2, $0x000000ff @ word that has a zero byte in it
addne r0, r0, $1 @
tstne r2, $0x0000ff00 @ and add up to 3 bytes on to it
addne r0, r0, $1 @
tstne r2, $0x00ff0000 @ (if first three all non-zero, 4th
addne r0, r0, $1 @ must be zero)
+#endif
RETINSTR(mov,pc,lr)
END(strlen)
------------------------------------------------------------------------------ |
|