xyzLinux
Wednesday, February 22, 2006
 
FreeS/WAN: Cross-compiling for ppc & mips

FreeS/WAN: Cross-compiling for ppc & mips

Author: Matthias Gorjup
Last Update: 6th March 2003

Copyright (c) 2003 Matthias Gorjup
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the GNU Free Documentation License is included here.


This How-To describes how to cross-compile and test FreeS/WAN package for ppc platform.
It describes crosscompiling FreeS/WAN version 1.99 for kernel 2.4.17 with DTDK-0.3 Toolkit, built by Markus Haag.
Cross-compiling has been tested on Red Hat 8.0, SuSE 8.0 and SuSE8.1.

1. Installing DTDK 0.3


# cp dtdk-0.3.tar.gz /opt
# cd /opt
# tar xzvf dtdk-0.3.tar.gz
# cd dtdk-0.3/mpc860/include

Link our kernel source tree to the cross-compiler

# rm asm
# ln -s /usr/src/linux/include/asm-ppc asm
# rm linux
# ln -s /usr/src/linux/include/linux linux
# export CROSS_COMPILE=ppc-linux-
# PATH=$PATH:/opt/dtdk-0.3/mpc860/bin

2. Configuring the kernel


Download the kernel 2.4.17 from www.kernel.org and untar it into /usr/src.

# cd /usr/src/linux
# vi Makefile

Remove or comment out the line

ARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/)

and add

ARCH := ppc

Set variable CROSS_COMPILE to

CROSS_COMPILE = ppc-linux-

Now you can either test compilation of the kernel for some existing configuration (like for MBX or TQM)

# make mbx_config
# make menuconfig

or configure the kernel by your self

# make menuconfig

Make sure socket filtering is dissabled, Unix domain sockets are enabled, and IP tunneling is enabled.
It is also recomended to enable TCP syncookie support.
If you want to use tcpdump, you need to enable Packet Socket option (CONFIG_PACKET).
For more details on kernel configuration see the official FreeS/WAN documentation, chapter "Kernel
configuration"

Although FreeS/WAN compiles the kernel by it self, you should test the compilation of the
kernel just to have a good starting point for solving eventual problems with cross-compiling
the FreeS/WAN.
In that case you must do the following:

# make dep
# make zImage

You should find the new kernel image in directory /usr/src/linux/arch/ppc/boot/images.

3. gmp library


GMP (GNU MP) library is a free library for arithmetic, operating and signed integers, rational numbers,
and floating point numbers. It is needed by pluto for generation of keying material.

Download the library (at the time of writing gmp-4.1.1.tar.gz) from www.swox.com/gmp.

Make sure the path to DTDK toolkit binaries is set and that the CROSS_COMPILE, CC, AR, STRIP,
RANLIB, LD and M4 variables are set:

# export CROSS_COMPILE=ppc-linux-
# PATH=$PATH:/opt/dtdk-0.3/mpc860/bin
# CROSS=ppc-linux-
# export CC="$CROSS"gcc
# export AR="$CROSS"ar
# export STRIP="$CROSS"strip
# export RANLIB="$CROSS"ranlib
# export LD="$CROSS"ld
# export NM="$CROSS"nm

Do not set CXX and CPP variables!!

# tar xzvf gmp-4.1.1.tar.gz
# cd gmp-4.1.1

To configure the library for crosscompiling, you need to properly set the build and host. In the
documentation of the gmp library you will get more information about that but to make quick:
If you are compliling the library on a pentium 4 machine for a MPC860 processor, do following:

# ./configure --build=pentium4-pc-linux-gnu --host=powerpc-linux-gnu

( you shouldn't use powerpc860 for --host because it causes a malfunction of the library!!)

# make

Now add the library to the DTDK toolkit (more precise: to the target file system):

# cp libgmp.la /opt/dtdk-0.3/mpc860/dev_fs/lib
# cp gmp.h /opt/dtdk-0.3/mpc860/dev_fs/include
# cd .libs
# cp libgmp.a libgmp.lai /opt/dtdk-0.3/mpc860/dev_fs/lib

4. pcap library

compile for PPC
This library represents an interface for user-level packet capture. It is needed by tcpdump.
If you are not going to use tcpdump on your target, you don't need it.
Download the latest library (at the time of writing libpcap-0.7.1) from www.tcpdump.org.

Make sure following variables are set:

# CROSS=ppc-linux-
# export CC="$CROSS"gcc
# export CXX="$CROSS"g++
# export CPP="$CROSS"g++
# export AR="$CROSS"ar
# export STRIP="$CROSS"strip
# export RANLIB="$CROSS"ranlib
# export CFLAGS=-O2
# export CXXFLAGS=-O2
# export LD="$CROSS"ld
# export NM="$CROSS"nm

# tar xzvf libpcap-0.7.1.tar.gz
# cd libpcap-0.7.1

To configure the library for crosscompiling, you need to properly set host and target. Documentation
of pcap library is rather poor, so browsing through files configure and configure.in will help.

# vi configure

Edit line 1728:
< ac_cv_linux_vers="unknown"> ac_cv_linux_vers=2

# ./configure --with-pcap=linux --host=i686-pc-linux-gnu --target=powerpc-linux-gnu

# vi Makefile

Edit line 100
<> $(AR) rc $@ $(OBJ)

# make

Now add the library to the DTDK toolkit (more precise - to the target file system):

# cp libpcap.a /opt/dtdk-0.3/mpc860/dev_fs/lib
# cp pcap.h /opt/dtdk-0.3/mpc860/dev_fs/include
# cd net
# cp bpf.h /opt/dtdk-0.3/mpc860/dev_fs/include/net

compile for mips
$./configure --host=i686-pc-linux-gnu --with-pcap=linux --target=mipsel-linux-uclibc

5. Cross-compiling


# cp freeswan-1.99.tar.gz /usr/src
# cd /usr/src
# tar xzvf freeswan-1.99.tar.gz
# cd freeswan-1.99

Set variables for cross-compiling tools:

# CROSS=ppc-linux-
# export CC="$CROSS"gcc
# export CXX="$CROSS"g++
# export CPP="$CROSS"g++
# export AR="$CROSS"ar
# export STRIP="$CROSS"strip
# export RANLIB="$CROSS"ranlib
# export CFLAGS=-O2
# export CXXFLAGS=-O2
# export LD="$CROSS"ld
# export NM="$CROSS"nm

Now you need to change several Makefiles:

# vi Makefile

Edit the line 162
<> ARCH := ppc

# vi Makefile.inc

DESTDIR=/home/gorjup/target_ppc (where "make install" will put the results)

# vi libdes/Makefile

Comment out the line 46:
< make="make"> #MAKE=make -f Makefile

In line 57 comment out AS:
< as="as"> #AS=as

In line 123 set variable CC to ppc-linux-gcc:
< $(MAKE) CC=gcc CFLAGS="-O3 -fomit-frame-pointer $(OPTS) $(CFLAG)" all > $(MAKE) CC=ppc-linux-gcc CFLAGS="-O3 -fomit-frame-pointer $(OPTS) $(CFLAG)" all

In line 180 replace ar with AR:
<> $(AR) cr $(DLIB) $(OBJ)

Replace lines 181-183
< -if test -s /bin/ranlib; then /bin/ranlib $(DLIB); \ <>
with line
> $(RANLIB) $(DLIB); \

# vi lib/Makefile

In line 40 include the "include" directory of the DTDK toolkit:
< cflags="-I."> CFLAGS=-I/opt/dtdk-0.3/mpc860/dev_fs/include -I. $(USERCOMPILE)

In line 76 replace ar with AR:
<> $(AR) $(ARFLAGS) $(LIB) $(OBJS)

Replace lines 93-96 with one line:
< cc="'$(CC)'" cflag="'$(CFLAGS)'" testing="''" cc="'$(CC)'" cflag="'$(CFLAGS)'"> $(MAKE) CC='$(CC)' CFLAG='$(CFLAGS)' libdes.a ; \

# vi lib/Makefile.kernel

In line 36 include the "include" directory of the DTDK toolkit:
<> EXTRA_CFLAGS += -I/opt/dtdk-0.3/mpc860/dev_fs/include -I. $(KLIPSCOMPILE)

# vi utils/Makefile

In line 38 include the "lib" directory of the DTDK toolkit:
< cflags="-I../lib"> CFLAGS= -I/opt/dtdk-0.3/mpc860/dev_fs/include -I../lib $(USERCOMPILE)

In line 56 include the path to gmp library:
< $(CC) $(CFLAGS) rsasigkey.o $(LIB) -lgmp -o $@ > $(CC) $(CFLAGS) rsasigkey.o $(LIB) /opt/dtdk-0.3/mpc860/dev_fs/lib/libgmp.a -o $@

# vi klips/net/ipsec/Makefile

Replace lines 94-98 with one line:
< ( cd libdes && \ < cc="'$(CC)'" cflag="'$(CFLAGS)'" testing="''" cc="'$(CC)'" cflag="'$(CFLAGS)'"> cd libdes; $(MAKE) CC='$(CC)' CFLAG='$(CFLAGS)' libdes.a ;

# vi klips/utils/Makefile

Edit lines 22 and 23
< cc="gcc" cflags="$(USERCOMPILE)"> CC=ppc-linux-gcc
> CFLAGS=-I/opt/dtdk-0.3/mpc860/dev_fs/include $(USERCOMPILE) -I../net/ipsec -I../../lib

# vi pluto/Makefile

Edit Line 40
< hdrdirs =" -I.."> HDRDIRS = -I/opt/dtdk-0.3/mpc860/dev_fs/include -I.. -I$(KLIPSD) $(FREESWANINCLS)

Edit line 87
< libspluto =" -lgmp"> LIBSPLUTO = -L/opt/dtdk-0.3/mpc860/dev_fs/lib/ -lresolv # -lefence

Edit line 91
< libsadns =" -lresolv"> LIBSADNS = -lresolv /opt/dtdk-0.3/mpc860/dev_fs/lib/libgmp.a # -lefence

Edit line 175
< $(CC) -o $(BINNAMEPLUTO) $(LDFLAGS) $(OBJSPLUTO) $(LIBSPLUTO) > $(CC) -o $(BINNAMEPLUTO) $(LDFLAGS) $(OBJSPLUTO) /opt/dtdk-0.3/mpc860/dev_fs/lib/libgmp.a

# vi zlib/Makefile

Edit line 48
< $(CC) -D__ASSEMBLY__ -DNO_UNDERLINE -traditional -c $< -o $*.o > $(CC) -D__ASSEMBLY__ -I/opt/dtdk-0.3/mpc860/dev_fs/include -DNO_UNDERLINE -traditional -c $< -o $*.o

# vi testing/utils/uml_netjig/Makefile

Edit lines 26-27
< pcaph="-I/usr/include/pcap" pcaplib="-lpcap"> PCAPH=-I/opt/dtdk-0.3/mpc860/dev_fs/include
> PCAPLIB=/opt/dtdk-0.3/mpc860/dev_fs/lib/libpcap.a

Now you can start cross-compiling FreeS/WAN:

# make menugo

Check the configuration settings - make sure everything for ipsec is selected.

# make install
# cd /usr/src/linux
# make modules
# make INSTALL_MOD_PATH=/opt/dtdk/mpc860/dev_fs/lib/modules/2.4.17 modules_install

At the end you will get report about errors although no errors acutally appeared during the compilation process.
This is because cross-compiling FreeS/WAN isn't supported in the Makefile, so some of its checks may not be correct for a
cross-compiling environment, and it might be returning false positives.
Check by scrolling back the shell window that really no error appeared during the cross-compilation process.
If you don't see any errors, cross-compilation succeeded.
It could also be that you will get some errors during compilation of testing /utils/uml_netjig/, but the compilation would not be stopped.
Well, this is probably not important to you, since this directory only contains some testing tools.

6. Utilities, needed for FreeS/WAN

FreeS/WAN needs all kinds of utilities, needed by scripts, included in the package.
Here is a list of some:
- cat, gawk (with awk as a symbolic link to gawk), egrep, expr, hostname, id, md5sum, netstat, paste, printf, ps, sed, sort, test, tr

For starting and stopping FreeS/WAN, you only need cat, expr, gawk, sed, test and tr.
Others you would need if you want to have other features supported like "ipsec look", "ipsec verify" ...

7. Installing and testing

Move to the DESTDIR:

# cd /home/gorjup/target_ppc

Copy everything to your target filesystem:

# cp -r * /opt/dtdk/mpc860/dev_fs

On the target file system you must create a /var/run/, /var/lock/ and /var/log/ directories.
Also, you must enable random(4) generator on the target:

# mknod /dev/random c 1 8
# mknod /dev/urandom c 1 9


Now you can test FreeS/WAN the same way as on a desktop PC.


Powered by Blogger