15

Does anybody know how I can cross compile OpenSSH for ARM? This is what I have done:

First I've downloaded Zlib source code, untarred it, built it and installed it using the following command lines:

   # ./configure --prefix=/usr/local/cross/arm

   # make 

   # make install

But then when I try to compile OpenSSH for the ARM target board, it gives the error "zlib missing" during the ./configure process:

  # sudo LDFLAGS=-L/usr/local/cross/arm/lib CC=arm-none-linux-gnueabi-gcc PATH=$PATH:/home/arishop/arm-tool-chain/arm-fsl-linux-gnueabi/bin/ ./configure --host=arm-linux --with-zlib=/usr/local/cross/arm/ --prefix=/usr/local/cross/arm/openssh
lvella
  • 10,929
  • 10
  • 42
  • 91
arian
  • 161
  • 1
  • 1
  • 4

3 Answers3

41

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"

Community
  • 1
  • 1
jaguzu
  • 488
  • 5
  • 13
  • 1
    +1 Excellent instructions and worked like a charm. (I was targeting `arm-linux-androideabi` but the process was nearly identical.) – Nathan Osman Mar 06 '13 at 03:58
  • 3
    The OpenSSL build failed on my Ubuntu system, had to change the one line to `export cross=arm-linux-gnueabi-` (remove the "gcc-" prefix) – Robert Apr 23 '13 at 14:17
  • Using openssh 5.3p1, I had to include ranlib `./configure --host=arm-davinc-linux-gnueabi --with-libs --with-zlib=/opt/linux-2-6-31-xtools/x-tools/arm-davinci-linux-gnueabi/ --with-ssl-dir=/opt/linux-2-6-31-xtools/x-tools/arm-davinci-linux-gnueabi/ --disable-etc-default-login CC=arm-davinci-linux-gnueabi-gcc AR=arm-davinc-linux-gnueabi-ar RANLIB=arm-davinc-linux-gnueabi-ranlib` – Kevin May 29 '13 at 21:11
  • The first make of zlib doesn't even use the ARM compiler. Is that intended? If I try making zlib with the ARM compiler, it fails with crc32 not working. – Naftuli Kay Jun 19 '14 at 00:12
  • For the OpenSSL build, one can also do `export CROSS_COMPILE=arm-linux-gnueabi-` prior to the `Configure` call, or equivalently use the `--cross_compile_prefix=arm-linux-gnueabi-` option. This ties the configuration and building steps together so as to avoid the explicit configuration of `CC` and other variables. – alkalinity Jul 28 '15 at 13:39
  • 1
    Before building zlib I had to `export TARGETMACH=arm-linux-gnueabi; export BUILDMACH=i686-pc-linux-gnu; export CROSS=arm-linux-gnueabi; export CC=${CROSS}-gcc; export LD=${CROSS}-ld; export AS=${CROSS}-as;` and later I modified for openssh cross compilation the following `CC=arm-linux-gnueabi-gcc AR=arm-linux-gnueabi-ar` – enthusiasticgeek Nov 23 '15 at 23:02
  • zlib should include `export CHOST=arm-linux-gnueabihf` not `CC=arm-linux-gnueabi-gcc` – david Mar 03 '16 at 16:56
  • Thanks, that gave me a hint as to how to get my `i586-pc-msdosdjgpp` OpenSSL cross-compile working. I had ` missing` errors before but including the right version of gcc did the job. – Pabru Jun 15 '16 at 02:53
  • I ended up here while searching a solution to cross compil OpenSSL for arm. Very nice instructions! I only had to change "arm-linux-gnueabi-" to "arm-linux-gnueabihf-" since my target platform supports hardware float – Anonymous Apr 05 '17 at 10:34
11

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 ""
chehsunliu
  • 551
  • 5
  • 13
  • 1
    Small add-on, add zlib location when configuring openSSL using options: `--with-zlib-include=$ROOTFS/usr/include --with-zlib-lib=$ROOTFS/usr/lib` – Bechir Jan 21 '14 at 13:16
  • This has helped me tremendously. The part about removing `STRIP_OPT` and `check-config` could have been more clear. Also I needed to add `--with-zlib=$ROOTFS/usr` to the configure of OpenSSH. – Dominik Oct 24 '15 at 01:57
1

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
asukharev
  • 477
  • 6
  • 12