Howto build toolchain for ARM using gcc 4.0
Note: The following compilation was done on Fedora Core 4 Linux.
Download the following files from their respective web sites:
binutils-2.16.tar.bz2 wget -c ftp://ftp.gnu.org/gnu/binutils/binutils-2.16.tar.bz2
gcc-4.0.2.tar.bz2 wget -c ftp://ftp.gnu.org/gnu/gcc/gcc-4.0.2/gcc-4.0.2.tar.bz2
glibc-2.3.5.tar.gz wget -c ftp://ftp.gnu.org/gnu/glibc/glibc-2.3.5.tar.gz
glibc-linuxthreads-2.3.5.tar.gz wget -c ftp://ftp.gnu.org/gnu/glibc/glibc-linuxthreads-2.3.5.tar.gz
Place all the downloaded files inside the /usr/src directory of your system.
Create the Build Directories
[root at localhost]# cd /usr/src
[root at localhost]# mkdir build
[root at localhost]# cd build
[root at localhost]# mkdir binutils-2.16
[root at localhost]# mkdir gcc-4.0.2
[root at localhost]# mkdir glibc-2.3.5
Build binutils
[root at localhost]# cd /usr/src
[root at localhost]# tar –jxf binutils-2.16.tar.bz2
Chose the prefix for the new tool chain. This is a directory where the tool chain resides. This application report uses /opt/arm-v4 for the new tool chain. The directory is created by the installation of the tools. Go to the /usr/src/build/binutils-2.16 directory to configure and then build the binary utilities with the commands shown below.
[root at localhost]# cd /usr/src/build/binutils-2.16
[root at localhost]# ../../binutils-2.16/configure –-target=arm-linux –-prefix=/opt/armv4
[root at localhost]# make
[root at localhost]# make install
The new binary utilities can be found in /opt/armv4/bin. Add the path to the binary utilities into your current path. If you are using the bash shell,use the export command.
[root at localhost]# export PATH=/opt/armv4/bin:$PATH
Kernel Headers
Download the kernel version from Kernel.org and the patch for the same from www.muru.com using the following:
wget -c http://kernel.org/pub/linux/kernel/v2.6/linux-2.6.14.2.tar.bz2
wget -c http://www.muru.com/linux/omap/patches/patch-2.6.14-omap2.bz2
[root at localhost]# cd /usr
[root at localhost]# mkdir arm-linux
[root at localhost]# cd arm-linux
Now, extract and patch the kernel using following commands:
[root at localhost]# tar jxf linux-2.6.14.2.tar.bz2
[root at localhost]# ln -s linux-2.6.14.2 linux
[root at localhost]# bunzip2 patch-2.6.14-omap2.bz2
[root at localhost]# cd linux
[root at localhost]# patch -p1 < ../patch-2.6.14-omap2
[root at localhost]# make omap_osk_5912_defconfig
Build gcc
The gcc built here is just enough of the compiler without libraries so that the kernel or the GNU C libraries can be built. Make sure that /opt/armv4/bin is in the current path. To build gcc, the directories /opt/armv4/arm-linux/include/asm and /opt/armv4/arm-linux/include/linux must point to the corresponding kernel directories. Create the soft link from the development tools to the Innovator linux kernel with the following commands:
[root at localhost]# cd /opt/arm-v4/arm-linux
[root at localhost]# mkdir include
[root at localhost]# cd include
[root at localhost]# ln –s /usr/arm-linux/linux-2.6.14.2/include/asm-arm asm
[root at localhost]# ln –s /usr/arm-linux//linux-2.6.14.2/include/linux linux
[root at localhost]# cd /usr/src
[root at localhost]# tar –xjf gcc-4.0.2.tar.bz2
A configuration file must be modified so that the compiler is built without libc includes. Edit the /usr/src/gcc-4.0.2/gcc/config/arm/t-linux file and append
–Dinhibit_libc –D__gthr_posix_h to the line starting with TARGET_LIBGCC2_CFLAGS =.
The top of the file is shown below, after appending the flags.
# 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_h
LIBGCC2_DEBUG_CFLAGS = -g0
Go to the /usr/src/build/gcc-4.0.2 directory to configure and build the GNU C compiler with the commands below.
注意:不要在gcc-4.0.2源码目录下configure,在gcc-4.0.2源码目录下mkdir build,在build目录下configure,如下:
../configure –target=arm-linux --prefix=/opt/armv4 --disable-threads --enable-languages=c --disable-shared --disable-libmudflap --disable-libssp --disable-decimal-float --without-headers --disable-libquadmath --disable-libiberty --disable-libgomp
[root at localhost]# cd /usr/src/build/gcc-4.0.2
[root at localhost]# ../../gcc-4.0.2/configure –-target=arm-linux –-prefix=/opt/armv4 --disable-threads –-enable-languages=c
[root at localhost]# make
[root at localhost]# make install
Build glibc
Before building glibc, invoke make in the kernel directory (to create linux/include/version.h required by glibc)
[root at localhost]# cd /usr/arm-linux/linux-2.6.14.2
[root at localhost]# make
注意:如果系统的gcc版本过低,linux-2.6.14.2内核有可能编译不过,需要升级gcc版本
Make sure /opt/armv4/bin is in the current path.
[root at localhost]# cd /usr/src
[root at localhost]# tar –xzf glibc-2.3.5.tar.gz
[root at localhost]# cd glibc-2.3.5
[root at localhost]# tar –xzf ../glibc-linuxthreads-2.3.5.tar.gz
注意:把解压的linuxthreads拷贝到glibc-2.3.5目录下
Apply the attached patches (Details at the end of the document)
[root at localhost]# cd /usr/src/build/glibc-2.3.5
[root at localhost]# ../../glibc-2.3.5/configure arm-linux –-build=i686-pc-linux-gnu --prefix=/opt/armv4/arm-linux –-enable-add-ons=linuxthreads
[root at localhost]# make
[root at localhost]# make install
注意:编译glibc-2.3.5时候,当前在glibc-2.3.5目录下,configue时会出现configure: error: you must configure in a separate build错误,需要返回到上一级目录下configue,正确做法如下
glibc-2.3.5/configure –tartget=arm-linux –-build=i686-pc-linux-gnu --prefix=/opt/armv4/arm-linux –-enable-add-ons=linuxthreads
The new GNU C library can be found in /opt/armv4/arm-linux.
Build gcc With Additional Languages
Edit the /usr/src/gcc-4.0.2/gcc/config/arm/t-linux file and remove the append (Build gcc). Specifically, remove -Dinhibit_libc –D__gthr_posix_h so that the top of the file appears as follows:
# 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
LIBGCC2_DEBUG_CFLAGS = -g0
[root at localhost]# cd /usr/src/build/gcc-4.0.2
[root at localhost]# rm –rf *
[root at localhost]# ../../gcc-4.0.2/configure –-target=arm-linux –-prefix=/opt/armv4 –enable-languages=c,c++
[root at localhost]# make
[root at localhost]# make install
The complete set of GNU compilation tools can be found in /opt/armv4/bin.
Patches
The following files need to be patched to source code of glibc-2.3.5 for successful compilation of glibc:
(The required patches are attached)
1) glibc-2.3.5/include/libc-symbols.h
2) glibc-2.3.5/string/strcoll.c
3) glibc-2.3.5/include/wchar.h
4) glibc-2.3.5/wcsmbs/wcscoll.c
5) glibc-2.3.5/elf/dynamic-link.h
6) glibc-2.3.5/iconvdata/jis0208.h
7) glibc-2.3.5/sysdeps/unix/sysv/linux/arm/ioperm.c
8) glibc-2.3.5/sysdeps/arm/dl-machine.h
Note: If during compilation of glibc-2.3.5, following error occurs:
cannot find -lgcc_eh
Then remove all the occurrences of -lgcc_eh from the files: Makeconfig, configure and configure.in from the top level glibc source code directory.
*************************************************************************************************************************