Subject: Cross compile instructions

From: Dave Gilbert <[email-masked]>
Date: Sat, 17 Jan 1998 23:33:04 +0000 (GMT)

Hi,
 As promised here are my cross compile instructions; some of the
finer points may only apply to using an Alpha as a host but
they shouldn't cause a problem crossing from anything else.

--------------------------------------------------------------------
Cross Building ARM kernels from Alphas ([email-masked])
----------------------------------------------------------

(The techniques in this file probably also allow you to cross from other
platforms as well, reports of success and failure would be appreciated)

I'm using the EGCS compiler; its a modified version of GCC; its more uptodate
than GCC 2.7.2.3 (which won't do the job) - its not the same as GCC 2.8.0.
I'm using EGCS snapshot 971225.
It can be found on ftp.cygnus.com/egcs/snapshots
------------------------------------------------------------------------------
Then apply this fix:

The patch I have is  a small one by Richard Earnshaw (of ARM), it fixes
a problem with generating some constants on 64 bit machines.
(The patch here is hand copied!)
Its in egcs/gcc/explow.c around line 120 originally reads:

      if (GET_CODE (XEXP (x, 1)) == CONST_INT)
        return plus_constant (XEXP (x, 0), c + INTVAL (XEXP (x, 1)));

Change it to:
      if (GET_CODE (XEXP (x, 1)) == CONST_INT)
        return plus_constant (XEXP (x, 0), ((c + INTVAL (XEXP (x, 1)))
                                            & GET_MODE_MASK (mode)));

------------------------------------------------------------------------------
Binutils - before building the compiler you need a working set of binutils;
I used version 2.8.1.0.15 (anything earlier than 2.8.1.0.15 
will probably break). >> 2.8.1.0.18,2.8.1.0.19 is broken <<

Configure it with:
  ./configure arm-unknown-linuxaout --prefix=/home/arm/tools

that should build easily. Make install
In /home/arm/tools/bin you'll find some (most?) binaries with no prefix and
some starting with arm-unknown-linuxaout- - use a shell script to rename
all files to begin with arm-unknown-linuxaout- - thus my bin
directory looks like:

[gilbertd@tardis bin]$ ls
arm-unknown-linuxaout-addr2line   arm-unknown-linuxaout-objcopy
arm-unknown-linuxaout-ar          arm-unknown-linuxaout-objdump
arm-unknown-linuxaout-as          arm-unknown-linuxaout-protoize
arm-unknown-linuxaout-c++         arm-unknown-linuxaout-ranlib
arm-unknown-linuxaout-c++filt     arm-unknown-linuxaout-size
arm-unknown-linuxaout-g++         arm-unknown-linuxaout-strings
arm-unknown-linuxaout-g77         arm-unknown-linuxaout-strip
arm-unknown-linuxaout-gasp        arm-unknown-linuxaout-unprotoize
arm-unknown-linuxaout-gcc         gcov
arm-unknown-linuxaout-gprof       protoize
arm-unknown-linuxaout-ld          unprotoize
arm-unknown-linuxaout-nm

(Although some of these won't be there yet for you!)
------------------------------------------------------------------------------
Put /home/arm/tools/bin in your path and

Now configure EGCS with:
  ./configure --target=arm-unknown-linuxaout --prefix=/home/arm/tools --with-gnu
-ld --host=alpha-local-linux-gnu

Next you need to create /home/arm/tools/arm-unknown-linuxaout/include and
populate it with the include directory off an ARM Linux system; all stdio.h
etc is needed and make symlinks from include/linux and include/asm and include/scsi
etc. to whereever your ARM Linux kernel source is, in the same way that you
would when building a kenel native. Also float.h is needed to build some of the
stuff (objc only I think??)

do 
make LANGUAGES="C"
make install LANGUAGES="C"

(I had some problems here - but I can't remember what - tell me if you hit
any - I think they were from me not having copied the includes in yet).

One reported problem is that if you don't have a _G_config.h in your
include directory it fails building an st-dummy.c - hmm. As far as I can
tell it is the install of GCC which creates it - try doing a make install
and then doing it again ? You should find even if this fails that the
build has finished in the egcs/gcc directory - and that that can be installed.

IF you are really lucky it will let you build for other languages as well.

------------------------------------------------------------------------------
Now time for the kernel....
Edit linux/include/asm-arm/a.out.h, add a 
#include <linux/types.h> near the top
(NOTE this is actually wrong but works - trying to find safe soloution for this!)
and change all the types in the struct exec to
__u32
(from unsigned and unsigned long).

Edit the Makefile to set ARCH = arm
edit the CROSS_COMPILE= line to:

CROSS_COMPILE   = /home/arm/tools/bin/arm-unknown-linuxaout-

Edit arch/arm/Makefile, type make xconfig, set it up as you want and then
type:

make and then make Image
(make zImage not done yet).

-------------------------------------------------------------------------------
In egcs-971225 you'l get an error building gcc/cse.c (multiple defaults in a
case statement at line 751 and 755; 751 is a macro, 755 is a default: followed
by a break;  Remove the default: break from cse.c
-------------------------------------------------------------------------------
There is an erm...disagreement... between the Linux kernel and the newer C
compilers about an alignment issue - add -mshort-load-bytes to the CFLAGS
below.
(This probably also stops the use of the fancy new halfword instructions
which don't work on StrongARM RiscPCs)

[This is a temporary hack - a proper fix will arrive later - 11/01/98]
---------------------------------------------

Change arch/arm/makefile so that the  section is updated to:

ifeq ($(PROCESSOR),armo)
CFLAGS_PROC += -mapcs-26 -D__arm2__ -mshort-load-bytes
TEXTADDR   = 0x02080000
ZTEXTADDR  = 0x01800000
ZRELADDR   = 0x02080000
HEAD    := arch/arm/kernel/head.o
endif

ifeq ($(PROCESSOR),armv)
CFLAGS_PROC += -mapcs-32 -D__arm6__ -mshort-load-bytes
TEXTADDR   = 0xC0008000
ZTEXTADDR  = 0x00008000
ZRELADDR   = 0x00008000 
HEAD    := arch/arm/kernel/head32.o
endif

you might also like to add -mcpu-strongarm if you have one (untested!)

-------------------------------------------------------------------------------
To build Linux on a non-linux sysytem (e.g. DEC UNIX) you need gmake,gfind and
bash and you need to edit the top level makefile to use them instead of the
standard system utilities.

Another problem is genksyms; you need this to be able to add version
information to the kernel for modules - and you need that to be able to
load the floating point emulator module.  You can get this in the
Linux modutils package (available from 
ftp://ftp.kernel.org/pub/linux/kernel/v2.1/modutils-2.1.55.tar.gz)
I'm told that this works nicely.

 --------------------------------------------------------------------
/ Dr. David Alan Gilbert      | Running Linux on Alpha & ARM         \ 
\   gro.gilbert @ treblig.org | ------- Happy in hex -------         /
 \____________________________|___ http://www.treblig.demon.co.uk __/

unsubscribe: body of `unsubscribe linux-arm' to [email-masked]