here you go son..


#The whole idea of building a cross-compiler is that you be able to 
build an executable sitting on a host system that can run on your target 
system when they are disparate.

In my case i am doing so , sitting on my cozy X86 based (Athlon with 
lots of RAM and HDD) with debian-linux and trying to build a 
cross-compiler for ARM, in my specific case a strong-arm SA1110.

Why the hell do we need a cross-compiler in the first place ??
That is because my friend, you cant even imagine trying to compile a 
program sitting on your embedded system ! .. For example you are given a 
board lets say an assabet or a lart or any 
microprocessor/micro-controller board which has less resources than the 
hair on a bald's scalp. Therefore you build your programs sitting on the 
host and just hoist them on to your target board using some known 
methods like J-tag or angelboot etc. etc.

   The first program that you would wish to compile is of-course the 
kernel itself. Of course you get pre-compiled kernels for these boards, 
but i am sure you are brave enough to venture into building your own 
customized super-light-ning fast Kernel hands on. Well if you aren't in 
a mood for getting your hands dirty, you can chicken out right away,.. 
or read on...

Well, first of all, since we are starting this for the first time, and 
we don't want to screw up a lot of things we will build the whole damn 
thing in our own home directory. Once you get through, you can always 
repeat the same in your all-powerful superuser mode.

I shall explain, exactly how i did it, the pitfalls i encountered and 
their corrections.

Now you got to get some things from the net before we begin to brew.


1) Binutils : These are a set of programs that enable to compile your 
compiler. The set
                   includes these programs: `addr2line', `ar', 
`c++filt', `demangle', `gas',
                  `gprof', `ld', `nlmconv', `nm', `objcopy', `objdump', 
`ranlib', `readelf',
                  `size', `strings', `strip', and 'windres'.
                  Get the latest stable version mine was @ this time of 
writing   2.10.1

2)GCC :   This is a free compiler collection for C, C++, Fortran, 
Objective C and other
              languages. You can easily download it from www.gnu.org. 
Get the latest
              stable version. In my case it was GCC-2.95.1

3)Linux-Kernel : get the latest stable one from kernel.org mine was 2.4.1

4)Linux-kernel-patches : This, you got to search for your target platform.
                                      I got mine from arm-linux site







HERE WE Go

login as a user into your linuxbox . Now you have to decide on 3 things


1.source directories
2.build directory
3.installation directory

source directory is where you un-compress all the tar-zip files you 
downloaded. This includes the linux-2.4.1-tar.gz, 
binutils-2.10.*-tar.gz, gcc-*.*.tar.gz and ofcourse all the patches. 
Mine was in /usr/home/kishan/src.

Now comes the build directory. This is the directory where you store 
information as to how to compile your souces. That is the information as 
to what goes into your installation after compilation. My build 
directories are

/home/kishan/build/binutils
/home/kishan/build/gcc
/home/kishan/build/glibc

If you want to play safe and check everything works fine before making 
an actual installation then you might want to choose a installation 
directory. I played safe and the directory i choose was 
/home/kishan/arm-linux. Note that making your installation directory a 
subdirectory of either your build or src directories may cause a lot of 
problems and is not supported. So is the vice-versa. Therefore do not 
make any of these directories a subdirectory of the other.

And so...

mkdir build src build/gcc build/binutils build/glibc
cd src
tar -xzvf binutils;
tar -xzvf gcc
tar -xzvf linux
tar -xzvf glibc
cd ..
cd build/binutils
/home/kishan/src/binutils/configure --prefix=/home/user/arm-linux 
--target=arm-linux
make
make install

This should go on without any problems. You will have new tools 
installed in your arm-linux directory. These are all the tools that you 
require for compiling the gcc . Now before making head-on with the gcc 
we need to create an air of ambiance to that gcc compilation goes 
smoothly. The first step for this is to get the links in your src/linux 
proper so that gcc finds the proper headers for your port. This is done 
by applying the patches to the kernel and running the config once, which 
will in turn set all the links for us.

  cd ~/source/
  patch -p0 < patch-2.4.0-rmk2
  patch -p0 < patch-2.4.0-rmk2-np2

These patches can be got from the netwinder site (for arm ports) .
Now run the config once so that the sym-links are made

cd ~/source/linux
make menuconfig   /*just save and exit */
make dep

Now for the GCC .

Untar-unzip the GCC-2.95.1.tar.gz into the src directory.

/home/kishan/source/tar -xzvf gcc-2.95.1.tar.gz

include the arm-linux path

go to your build directory. Ie /build/gcc and configure the gcc somewhat 
like this. Note that the options that you give to the gcc should be 
customized for your requirement. But the general rule is , if you enable 
the "static" option the number of hurdles that you may encounter will be 
less. So here goes

cd /home/kishan/build/gcc
~/src/gcc/configure --prefix=~/arm-linux  --target=arm-linux 
--enable-static --with-gnu-as --with-gnu-ld --with-cpu=strongarm110 
--with-headers=~/src/linux/include  --with-libs=~/arm-linux/libs

make

you may encounter a couple of errors here. If they look like

./libgcc2.c:41: stdlib.h: no such file or directory
./libgcc2.c:42: unistd.h no such file or directory
make[3]: *** [libgcc2.a] error 1

then.. you need to apply the Dinihibit Hack.. so what you do is this
go to the source directory of gcc and get into gcc/config/arm and edit 
the t-linux file

cd ~/source/gcc-2.95.2/gcc/config/arm
vi t-linux

edit the line that looks like
TARGET_LIBGCC2_CFLAGS = -fomit-frame-pointer -fPIC

to

TARGET_LIBGCC2_CFLAGS = -fomit-frame-pointer -fPIC -Dinihibit_libc 
-D__gthr_posix_h

now, you could go back to the build directory and reconfigure. But with 
an additional option of --disable-threads

cd /home/kishan/build/gcc
~/src/gcc/configure --prefix=~/arm-linux  --target=arm-linux 
--enable-static --with-gnu-as --with-gnu-ld --with-cpu=strongarm110 
--with-headers=~/src/linux/include  --with-libs=~/arm-linux/libs 
--disable-threads

make

you will notice a couple errors .. hmm.. now we are in a little hot 
tomato soup. Make it baby-corn if you want to.  Here is how we succeed 
in compilation of the gcc

make clean
make LANGUAGES="c"
/* you will get errors here .. so dont fret */
cd libiberty
make LANGUAGES="c"                       /*this will result in no errors*/
make install
cd ..
cd gcc
make LANGUAGES="c"                       /*this should also not result 
in errors */
make install

There we are we have all the tools installed to compile our kernel.
Now we go to the source directory of the kernel and just compile it, its 
that simple

cd ~/source/linux
make zImage

it will take a while before it compiles. so why don't we go out for a 
cuppa. What say ?

Àîϼ wrote:

> Hi,
>         I'm new to arm linux, can anyone tell me how to crosscompile a arm-linux 
>kernel 2.4?
>         I tried to change CROSSCOMPILE=arm-linux- in the top Makefile, but I don't 
>have the proper binutils, where can I get it ?
> 
> Best Regards,
> Xia Li
> 
> 
> 
> ===============================================
> ΪÄã¶ø½¨£¬ÎªÄã¶øÉ裬ÈÃÄã´«µÝÕæÐÄÕæÒâ 
> 
>     ---- 163.netºØ¿¨Õ¾£¨http://ecard.163.net£©;
> 
> 163µç×ÓÓʾÖȫзîÏ×£¬¾«²ÊÎÞÏ޵ĵç×Ӻؿ¨Õ¾¡£
> ===============================================
> 
> 
> 
> _______________________________________________
> http://lists.arm.linux.org.uk/mailman/listinfo/linux-arm
> Please visit the above address for information on this list.



_______________________________________________
http://lists.arm.linux.org.uk/mailman/listinfo/linux-arm
Please visit the above address for information on this list.

Reply via email to