To cross compile openSHH for ARM (in my case a mini2440) I did following:

Install arm cross compiler - (eg. what is arm-linux-gcc and how to install this in ubuntu)

Download:

  • Zlib
  • OpenSSL
  • OpenSSH

Build Zlib:

cd zlib-1.2.7
CC=arm-linux-gnueabi-gcc
./configure --prefix=$HOME/zlibArm
make 
make install

Build OpenSSL:

export cross=arm-linux-gnueabi-
cd openssl-1.0.1c
./Configure dist --prefix=$HOME/opensslArm
make CC="${cross}gcc" AR="${cross}ar r" RANLIB="${cross}ranlib"
make install

Build OpenSSH:

./configure --host=arm-linux --with-libs --with-zlib=$HOME/zlibArm --with-ssl-dir=$HOME/opensslArm --disable-etc-default-login CC=gcc-arm-linux-gnueabi-gcc AR=gcc-arm-linux-gnueabi-ar
make

More info at http://code.google.com/p/openssh4mini2440/wiki/HowTo, download source and read "build.sh"


The board used is Mini6410. The requirement of OpenSSH includes zlib and OpenSSL. I prepare

  • zlib 1.2.8
  • OpenSSL 1.0.1e
  • OpenSSH 6.4p1

My toolchain is built by crosstool-NG 1.15.2. The toolchain configuration below is modified from arm-unknown-linux-gnueabi.

Arch:         armv6
CPU:          arm1176jzf-s
FPU:          vfp
Linux kernel: 2.6.38.8
binutils:     2.19.1a
gcc:          4.6.3
glibc:        2.11
gmp:          4.3.2
mpfr:         3.0.1
ppl:          0.11.2
cloog:        0.15.11
mpc:          0.9

Next I define three environment variables, HOST, ROOTFS and SYSROOT. HOST is arm-unknown-linux-gnueabi. ROOTFS is the root filesystem obviously. SYSROOT is the directory as the root directory for headers and libraries in the toolchain.

You might add CFLAGS and LD_LIBRARY_PATH pointing to your root filesystem so that the cross compiler can find what you have installed. However, I prefer not to set these variables. The alternative is installing those libraries in both SYSROOT and ROOTFS.

First, compile zlib

AR=$HOST-ar CC=$HOST-gcc RANLIB=$HOST-ranlib ./configure --prefix=$ROOTFS/usr
make
make install

Second, compile OpenSSL

./Configure linux-armv4 shared zlib-dynamic --prefix=/usr
make CC=$HOST-gcc AR="$HOST-ar r" RANLIB=$HOST-ranlib
make CC=$HOST-gcc AR="$HOST-ar r" RANLIB=$HOST-ranlib INSTALL_PREFIX=$ROOTFS install

Note that --prefix is set to /usr instead of $ROOTFS/usr. The reason is that if you set --prefix to $ROOTFS/usr, it will try to access configuration files in $ROOTFS/usr in runtime on Mini6410, which does not exist. The installation path specified in Makefile is $INSTALL_PREFIX/$PREFIX, so we use $ROOTFS for $INSTALL_PREFIX.

Finally, compile OpenSSH

  1. ./confgure --host=$HOST --prefix=/usr
  2. Remove the variable STRIP_OPT and check-config in the rule install in Makefile.
  3. make && make DESTDIR=$ROOTFS install
  4. Boot your Mini6410 and use command ssh-keygen to generate host keys.

The reason using /usr for --prefix is the same as OpenSSL. If you specify --prefix=$ROOTFS/usr, you will not be able to execute command scp.

STRIP_OPT have to be removed because it is impossible to use /usr/bin/install on x86-64 to strip binaries on ARM. The rule check-config will run the generated sshd on the host, so we have to avoid that.

In the last step, check Makefile and find the rule host-key. And The next line is @if [ -z "$(DESTDIR)" ] ; then, which means it does nothing if the length of $(DESTDIR) is nonzero. Thus, we must generate these keys manually on Mini6410:

ssh-keygen -t rsa1 -f /usr/etc/ssh_host_key -N ""
ssh-keygen -t dsa -f /usr/etc/ssh_host_dsa_key -N ""
ssh-keygen -t rsa -f /usr/etc/ssh_host_rsa_key -N ""
ssh-keygen -t ecdsa -f /usr/etc/ssh_host_ecdsa_key -N ""

I do like this

CC=arm-none-linux-gnueabi-gcc RANLIB=arm-none-linux-gnueabi-ranlib ./Configure linux-armv4 --prefix=$OPENSSLARM --openssldir=$OPENSSLARM

make CC=arm-none-linux-gnueabi-gcc AR="arm-none-linux-gnueabi-ar r" RANLIB="arm-none-linux-gnueabi-ranlib"

make install