Projects - Cross Compiler
It's the first important step for the development of Embedded System to make a well used cross compiler, this will tell you what's the structure of making cross compiler and how to make it with cross-2.95.3 for ARM as an example.
The structure for making cross compiler is:
binutils ---> Host ---> binutils (ld, as, etc.) source gcc
Linux Kernel glibc
source source
|___+___|
|
|
gcc ---> Host ---> BootStrap ---> glibc
source gcc Compiler |
| |
+----------------------------------+---> Host ---> Full
gcc Compiler
If you want to do following this document, the first important thing you should know is the host compiling environment for doing all of the following things.
I would like to have everything well organized, therefore, the first to be prepared is the structure of the files and directories:
/arm ----- tars ------------ SourceDir
| |
| |
| |--- BuildDir
| |
| +--- compressed source files (.gz)
|
+--- armtools
where
These are files I need to compile cross-2.95.3 with the version and the address to download.
Remember to put all these files to /arm/tars/ direcory.
#ls /arm/tars/ BuildDir/ SourceDir/ binutils-2.11.tar.gz gcc-2.95.3.tar.gz gcc-2.95.3.patch gcc-com.patch glibc-2.2.3.tar.gz glibc-linuxthreads-2.2.3.tar.gz linux-2.4.18.tar.gz patch-2.4.18-rmk7.gz
The exactly steps for this example.
#cd /arm/tars/SourceDir/ #tar xvfz /arm/tars/linux-2.4.18.tar.gz #cd linux #zcat /arm/tars/patch-2.4.18-rmk7.gz | patch -p1
#make ARCH=arm menuconfig
#mkdir -p /arm/armtools/arm-linux/include/linux #mkdir -p /arm/armtools/arm-linux/include/asm #cp -dR include/linux/* /arm/armtools/arm-linux/include/linux/ #cp -dR include/asm-arm/* /arm/armtools/arm-linux/include/asm/
#cd /arm/armtools/arm-linux/include/asm/ #ln -sf arch-integator arch #ln -sf proc-armv proc
Compiling and installing binutils.
#cd /arm/tars/SourceDir/ #tar xvfz /arm/tars/binutils-2.11.tar.gz #cd /arm/tars/BuildDir/ #mkdir binutils #cd binutils #/arm/tars/SourceDir/binutils-2.11/configure --target=arm-linux --prefix=/arm/armtools #make all install
Compiling and installing c compiler for arm. Or you can directly download and use the gcc-core packages to omitting this step.
#cd /arm/tars/SourceDir #tar xvfz /arm/tars/gcc-2.95.3.tar.gz
#cd /arm/tars/SourceDir/gcc-2.95.3/ #patch -p1 < /arm/tars/gcc-2.95.3.patch #patch -p1 < /arm/tars/gcc-com.patch
#cd /arm/tars/SourceDir/gcc-2.95.3/gcc/config/arm/ #mv t-linux t-linux-orig #sed 's/TARGET_LIBGCC2_CFLAGS =/TARGET_LIBGCC2_CFLAGS = -D__gthr_posix_h -Dinhibit_libc/' < t-linux-orig > t-linux-core #cp t-linux-core t-linux
#export PATH=$PATH:/arm/armtools/bin
#cd /arm/tars/BuildDir/ #mkdir gcc-core #cd gcc-core #/arm/tars/SourceDir/gcc-2.95.3/configure --target=arm-linux --prefix=/arm/armtools --enable-languages=c --with-local-prefix=/arm/armtools/arm-linux --without-headers --with-newlib --disable-shared #make all-gcc #make install-gcc
Compiling and installing glibc.
#cd /arm/tars/SourceDir/ #tar xvfz /arm/tars/glibc-2.2.3.tar.gz #cd glibc-2.2.3/ #tar xvfz /arm/tars/glibc-linuxthreads-2.2.3.tar.gz #cd /arm/tars/BuildDir #mkdir glibc #cd glibc/ #CC=arm-linux-gcc /arm/tars/SourceDir/glibc-2.2.3/configure --host=arm-linux --prefix=/arm/armtools/arm-linux --enable-add-ons --with-headers=/arm/armtools/arm-linux/include #make
Before you run make install you must change a file in /arm/tars/SourceDir/glibc-2.2.3/manual directory named stdio.texi, or you will get an error. The solution is to substitute the word @ref{, , , with @ref{Top, , , at the 3268 and 3269 line. Then
#make install
Using the original t-linux file to do this.
#cd /arm/tars/BuildDir #mkdir gcc #cd gcc/ #cp /arm/tars/SourceDir/gcc-2.95.3/gcc/config/arm/t-linux-orig /arm/tars/SourceDir/gcc-2.95.3/gcc/config/arm/t-linux #/arm/tars/SourceDir/gcc-2.95.3/configure --target=arm-linux --prefix=/arm/armtools --enable-languages=c,c++ --with-local-prefix=/arm/armtools/arm-linux #make all install
Testing the cross-compiler just made.
/* * helloworld.c */ #include <stdio.h> int main(void) { printf("Hello, World!\n"); return 0; }
Then4
#arm-linux-gcc -o helloword helloworld.c #file helloworld helloworld: ELF 32-bit LSB executable, ARM, version 1 (ARM), dynamically linked (uses shared libs), not stripped
If you get some errors while doing something, just make yourself lucky because you can learn more than others. :)
1. Choose the appropriate kernel options according to your requirements. After this step you can just check whether you have include/linux/version.h and include/linux/autoconf.h generated which are for compiling glibc.
2. This step is necessary for compiling glibc, or else you will have some errors while compiling glibc.
3. If you donot do this modify you will get some errors.
4. Make sure that /arm/armtools/bin is in your PATH.