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
For example, if you need to compile C code for ARM, you must first install gcc-arm-linux-gnu (32-bit) or gcc-aarch64-linux-gnu (64-bit) on Fedora or RHEL, or arm-linux-gnueabi-gcc and binutils-arm-linux-gnueabi on Ubuntu. This provides the commands and libraries you need to build (at least) a simple C program.
As x86 is currently the industry standard for server hardware and ARM is just starting to gain popularity, nearly all binaries are only compiled for x86 and can't be used on ARM natively.
A cross compiler is a compiler capable of creating executable code for a platform other than the one on which the compiler is running. For example, a compiler that runs on a PC but generates code that runs on an Android smartphone is a cross compiler.
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:
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
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
.
AR=$HOST-ar CC=$HOST-gcc RANLIB=$HOST-ranlib ./configure --prefix=$ROOTFS/usr
make
make install
./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
.
./confgure --host=$HOST --prefix=/usr
STRIP_OPT
and check-config
in the rule install
in Makefile.make && make DESTDIR=$ROOTFS install
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With