Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cross Compile OpenSSH for ARM

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
like image 770
arian Avatar asked Aug 07 '12 08:08

arian


People also ask

Can GCC compile for ARM?

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.

Can you compile x86 on ARM?

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.

How does cross compiling work?

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.


3 Answers

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"

like image 111
jaguzu Avatar answered Oct 09 '22 01:10

jaguzu


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 ""
like image 43
chehsunliu Avatar answered Oct 09 '22 02:10

chehsunliu


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
like image 1
asukharev Avatar answered Oct 09 '22 00:10

asukharev