0

I followed this steps:

Cross Compile OpenSSH for ARM

Cross compilation of openssh for ARM

Install ssh server on embedded device

1) Build zlib with:

CC=aarch64-linux-gnu-gcc
./configure --prefix=$HOME/zlibArm --static
sudo make
sudo make install

2) Build OpenSSL with:

export cross=aarch64-linux-gnu-
./Configure linux-aarch64 --prefix=$HOME/opensslArm no-shared -fPIC
make CC="${cross}gcc" AR="${cross}ar r" RANLIB="${cross}ranlib"
make install

3) Build OpenSSH with:

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

4) I'm getting this errors:

/usr/lib/gcc-cross/aarch64-linux-gnu/5/../../../../aarch64-linux-gnu/bin/ld: warning: -z retpolineplt ignored.
/usr/lib/gcc-cross/aarch64-linux-gnu/5/../../../../aarch64-linux-gnu/bin/ld: skipping incompatible /home/lfpm1993/zlibArm/lib/libz.so when searching for -lz
/usr/lib/gcc-cross/aarch64-linux-gnu/5/../../../../aarch64-linux-gnu/bin/ld: /home/lfpm1993/zlibArm/lib/libz.a(inflate.o): relocation R_AARCH64_ADR_PREL_PG_HI21 against external symbol `__stack_chk_guard@@GLIBC_2.17' can not be used when making a shared object; recompile with -fPIC
/usr/lib/gcc-cross/aarch64-linux-gnu/5/../../../../aarch64-linux-gnu/bin/ld: /home/lfpm1993/zlibArm/lib/libz.a(inflate.o)(.text+0x6dc): unresolvable R_AARCH64_ADR_PREL_PG_HI21 relocation against symbol `__stack_chk_guard@@GLIBC_2.17'
/usr/lib/gcc-cross/aarch64-linux-gnu/5/../../../../aarch64-linux-gnu/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
Makefile:172: recipe for target 'ssh' failed
make: *** [ssh] Error 1

I'm trying to make ssh work on arm versatile juno r2 development board statically.

Thanks!

LuisM
  • 61
  • 2
  • 9
  • In the `./Configure` of the OpenSSL step, you can use `--cross-compile-prefix=aarch64-linux-gnu-` instead. – Ealhad Dec 06 '18 at 13:33

1 Answers1

0

Not a pretty solution, but doing what the logs suggest of recompiling with -fPIC I went to the zlib Makefile and added it in all the *.o rules the -fPIC. Something like this:

example.o: $(SRCDIR)test/example.c $(SRCDIR)zlib.h zconf.h
$(CC) $(CFLAGS) $(ZINCOUT) -c -fPIC -o $@ $(SRCDIR)test/example.c

minigzip.o: $(SRCDIR)test/minigzip.c $(SRCDIR)zlib.h zconf.h
$(CC) $(CFLAGS) $(ZINCOUT) -c -fPIC -o $@ $(SRCDIR)test/minigzip.c

example64.o: $(SRCDIR)test/example.c $(SRCDIR)zlib.h zconf.h
$(CC) $(CFLAGS) $(ZINCOUT) -D_FILE_OFFSET_BITS=64 -c -fPIC -o $@ $(SRCDIR)test/example.c

minigzip64.o: $(SRCDIR)test/minigzip.c $(SRCDIR)zlib.h zconf.h
$(CC) $(CFLAGS) $(ZINCOUT) -D_FILE_OFFSET_BITS=64 -c -fPIC -o $@ $(SRCDIR)test/minigzip.c


adler32.o: $(SRCDIR)adler32.c
$(CC) $(CFLAGS) $(ZINC) -c -fPIC -o $@ $(SRCDIR)adler32.c

crc32.o: $(SRCDIR)crc32.c
$(CC) $(CFLAGS) $(ZINC) -c -fPIC -o $@ $(SRCDIR)crc32.c

deflate.o: $(SRCDIR)deflate.c
$(CC) $(CFLAGS) $(ZINC) -c -fPIC -o $@ $(SRCDIR)deflate.c

infback.o: $(SRCDIR)infback.c
$(CC) $(CFLAGS) $(ZINC) -c -fPIC -o $@ $(SRCDIR)infback.c

inffast.o: $(SRCDIR)inffast.c
$(CC) $(CFLAGS) $(ZINC) -c -fPIC -o $@ $(SRCDIR)inffast.c

inflate.o: $(SRCDIR)inflate.c
$(CC) $(CFLAGS) $(ZINC) -c -fPIC -o $@ $(SRCDIR)inflate.c

inftrees.o: $(SRCDIR)inftrees.c
$(CC) $(CFLAGS) $(ZINC) -c -fPIC -o $@ $(SRCDIR)inftrees.c

trees.o: $(SRCDIR)trees.c
$(CC) $(CFLAGS) $(ZINC) -c -fPIC -o $@ $(SRCDIR)trees.c

zutil.o: $(SRCDIR)zutil.c
$(CC) $(CFLAGS) $(ZINC) -c -fPIC -o $@ $(SRCDIR)zutil.c

compress.o: $(SRCDIR)compress.c
$(CC) $(CFLAGS) $(ZINC) -c -fPIC -o $@ $(SRCDIR)compress.c

uncompr.o: $(SRCDIR)uncompr.c
$(CC) $(CFLAGS) $(ZINC) -c -fPIC -o $@ $(SRCDIR)uncompr.c

gzclose.o: $(SRCDIR)gzclose.c
$(CC) $(CFLAGS) $(ZINC) -c -fPIC -o $@ $(SRCDIR)gzclose.c

gzlib.o: $(SRCDIR)gzlib.c
$(CC) $(CFLAGS) $(ZINC) -c -fPIC -o $@ $(SRCDIR)gzlib.c

gzread.o: $(SRCDIR)gzread.c
$(CC) $(CFLAGS) $(ZINC) -c -fPIC -o $@ $(SRCDIR)gzread.c

gzwrite.o: $(SRCDIR)gzwrite.c
$(CC) $(CFLAGS) $(ZINC) -c -fPIC -o $@ $(SRCDIR)gzwrite.c

So after, solving that it compiles and make perfectly. It is when I do sudo make install that I get this logs:

/bin/mkdir -p /home/lfpm1993/opensshArm/etc
/home/lfpm1993/opensshArm/etc/ssh_config already exists, install will not overwrite
/home/lfpm1993/opensshArm/etc/sshd_config already exists, install will not overwrite
/home/lfpm1993/opensshArm/etc/moduli already exists, install will not overwrite
/lib/ld-linux-aarch64.so.1: No such file or directory
Makefile:379: recipe for target 'host-key' failed
make: *** [host-key] Error 255

Am I doing this correctly? It seems it takes a lot of effort just to build ssh statically. Are there other solutions? Or is this the right approach?

I just want to connect remotely to the board, but I get connection refused and I'm pretty sure I don't have ssh installed there or if it is installed it isn't configured properly. I can ping it and I can connect if I am in the same network.

Thanks!

LuisM
  • 61
  • 2
  • 9