Labels

Friday, 9 January 2015

How to cross compile open ssl for ARM platform

Gather the Sources


Now that we have a workspace created and we are currently in the src directory we can begin bringing down the sources and extracting them.

openssl

$ wget ftp://ftp.openssl.org/source/openssl-1.0.1e.tar.gz
$ tar -pxzf openssl-1.0.1e.tar.gz
 
$ wget http://www.linuxfromscratch.org/patches/downloads/openssl/openssl-1.0.1e-fix_parallel_build-1.patch
 
$ wget http://www.linuxfromscratch.org/patches/downloads/openssl/openssl-1.0.1e-fix_pod_syntax-1.patch
 

Build Environment


To make things a little smoother let's setup some environment variables:

$ export INSTALLDIR=~/workbench/gcc-4.8.2/arm
$ export PATH=$INSTALLDIR/bin:$PATH
$ export TARGETMACH=arm-none-linux-gnueabi
$ export BUILDMACH=i686-pc-linux-gnu
$ export CROSS=arm-none-linux-gnueabi
$ export CC=${CROSS}-gcc
$ export LD=${CROSS}-ld
$ export AS=${CROSS}-as
$ export AR=${CROSS}-ar
 
NOTE: Depending on whether you are using a cross-compiler built from my other wikis you might need to change INSTALLDIR to point to your cross-compiler.

Build OpenSSL


$ cd openssl-1.0.1e/
$ patch -Np1 -i ../openssl-1.0.1e-fix_parallel_build-1.patch
$ patch -Np1 -i ../openssl-1.0.1e-fix_pod_syntax-1.patch
$ ./Configure -DOPENSSL_NO_HEARTBEATS --openssldir=/home/<your user>/workbench/openssl/final shared os/compiler:arm-none-linux-gnueabi-
$ make
$ make install
$ cd ../../final/lib/
$ $AR -x libcrypto.a
$ $CC -shared *.o -o libcrypto.so
$ rm *.o
$ $AR -x libssl.a
$ $CC -shared *.o -o libssl.so
$ rm *.o

Output


cd into the final directory and output its contents:
$ cd ../
$ ls
You should have the following directories and file:
  • bin
  • certs
  • include
  • lib
  • man
  • misc
  • private
  • openssl.cnf

Make sure the binaries are for ARM:
$ cd bin/
$ file openssl
bash: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.16, not stripped
If you see something similar to above you're good to go ;-)

Lastly, move the contents of these directories, or the directories themselves if they do not already exist, to your custom Linux file system or dev board. Read on to build OpenSSL 1.0.1g.


OpenSSL 1.0.1g


Create a Workspace


I recommend creating a workspace under your /home/<your user>/ directory that is dedicated to this build. In a new terminal:
$ export OPENSSL_SRC=~/workbench/openssl-1.0.1g/src
$ mkdir -pv ~/workbench/openssl-1.0.1g
$ mkdir $OPENSSL_SRC
$ cd $OPENSSL_SRC

Gather the Sources


Now that we have a workspace created and we are currently in the src directory we can begin bringing down the sources and extracting them.

openssl-1.0.1g

$ wget ftp://ftp.openssl.org/source/openssl-1.0.1g.tar.gz
$ tar -pxzf openssl-1.0.1g.tar.gz
 
$ wget http://www.linuxfromscratch.org/patches/downloads/openssl/openssl-1.0.1g-fix_parallel_build-1.patch
 
$ wget http://www.linuxfromscratch.org/patches/downloads/openssl/openssl-1.0.1g-fix_pod_syntax-1.patch

Build Environment


To make things a little smoother let's setup some environment variables:
$ export INSTALLDIR=~/workbench/gcc-4.8.2/arm
$ export PATH=$INSTALLDIR/bin:$PATH
$ export TARGETMACH=arm-none-linux-gnueabi
$ export BUILDMACH=i686-pc-linux-gnu
$ export CROSS=arm-none-linux-gnueabi
$ export CC=${CROSS}-gcc
$ export LD=${CROSS}-ld
$ export AS=${CROSS}-as
$ export AR=${CROSS}-ar
 
NOTE: Depending on whether you are using a cross-compiler built from my other wikis you might need to change INSTALLDIR to point to your cross-compiler.

Build OpenSSL 1.0.1g


$ cd openssl-1.0.1g/
$ patch -Np1 -i ../openssl-1.0.1g-fix_parallel_build-1.patch
$ patch -Np1 -i ../openssl-1.0.1g-fix_pod_syntax-1.patch
$ ./Configure --openssldir=/home/<your user>/workbench/openssl-1.0.1g/final shared os/compiler:arm-none-linux-gnueabi-
$ make
$ make install
$ cd ../../final/lib/
$ $AR -x libcrypto.a
$ $CC -shared *.o -o libcrypto.so
$ rm *.o
$ $AR -x libssl.a
$ $CC -shared *.o -o libssl.so
$ rm *.o

Output


cd into the final directory and output its contents:
$ cd ../
$ ls
You should have the following directories and file:
  • bin
  • certs
  • include
  • lib
  • man
  • misc
  • private
  • openssl.cnf

Make sure the binaries are for ARM:


$ cd bin/
$ file openssl
bash: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.16, not stripped

If you see something similar to above you're good to go ;-)

No comments:

Post a Comment