yfr24493AzzrggAcom
yfr24493AzzrggAcom

Reputation: 199

How to build openssl for arm linux

I working with Ubuntu x86 and have gcc cross compiler for Arm linux.

I want to build open ssl github project for arm linux.

I read the documents but couldn't understand how to build that.

Upvotes: 7

Views: 23642

Answers (1)

Frant
Frant

Reputation: 5895

Assuming here you are building for 64 bit arm Linux system, The self-contained procedure hereafter should work - working for me on Ubuntu 19.10 x86_64:

# openssl
wget https://www.openssl.org/source/openssl-1.1.1e.tar.gz
tar zxf openssl-1.1.1e.tar.gz

# a toolchain I know is working
wget "https://developer.arm.com/-/media/Files/downloads/gnu-a/9.2-2019.12/binrel/gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu.tar.xz?revision=61c3be5d-5175-4db6-9030-b565aae9f766&la=en&hash=0A37024B42028A9616F56A51C2D20755C5EBBCD7" -O gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu.tar.xz
mkdir -p /opt/arm/9
tar Jxf gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu.tar.xz -C /opt/arm/9

# building
cd openssl-1.1.1e
./Configure linux-aarch64 --cross-compile-prefix=/opt/arm/9/gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu- --prefix=/opt/openssl-1.1.1e --openssldir=/opt/openssl-1.1.1e -static
make install

ls -gG /opt/openssl-1.1.1e/bin/
total 10828
-rwxr-xr-x 1     6214 Mar 23 23:27 c_rehash
-rwxr-xr-x 1 11077448 Mar 23 23:27 openssl

file /opt/openssl-1.1.1e/bin/openssl
/opt/openssl-1.1.1e/bin/openssl: ELF 64-bit LSB executable, ARM aarch64, version 1 (GNU/Linux), statically linked, for GNU/Linux 3.7.0, with debug_info, not stripped

In the case you would want to build for a 32 bits arm system with hardware floating point support, we just need to slightly modify adapt the procedure for three commands:

wget  "https://developer.arm.com/-/media/Files/downloads/gnu-a/9.2-2019.12/binrel/gcc-arm-9.2-2019.12-x86_64-arm-none-linux-gnueabihf.tar.xz?revision=fed31ee5-2ed7-40c8-9e0e-474299a3c4ac&la=en&hash=76DAF56606E7CB66CC5B5B33D8FB90D9F24C9D20" -O gcc-arm-9.2-2019.12-x86_64-arm-none-linux-gnueabihf.tar.xz    
tar Jxf gcc-arm-9.2-2019.12-x86_64-arm-none-linux-gnueabihf.tar.xz -C /opt/arm/9

./Configure linux-generic32 --cross-compile-prefix=/opt/arm/9/gcc-arm-9.2-2019.12-x86_64-arm-none-linux-gnueabihf/bin/arm-none-linux-gnueabihf- --prefix=/opt/openssl-1.1.1e --openssldir=/opt/openssl-1.1.1e -static

Update: providing more information upon reading comment.

1) linux-generic32 is, as implied by its name, a generic 32 bit linux target that should work on any 32 bit system. You can find this information at a lot of places on the Internet, like here. The drawback is that the executable may not be optimized for your target. If you read the Configure script, you will see a list of environment variable you can specify for directing the compilation. For example, if your SoC is a cortex-a9, you may pass the option -mtune=cortex-a9 by setting CFLAGS - you will find a lot of information on the Internet, but I would suggest to look at Configure, it does contain a lot of useful comments.

By the way, if you execute Configure with a non-existing target, you get the list of all possible one:

./Configure does-not-exist

2) hf stands for Hardware floating point. Some 32 bit arm SoC do have hardware support for floating-point operations, some do not. Since you did not specify the exact brand/model of SoC you were targeting, I took a guess, and used a toolchain capable of generating code for the arm floating-point hardware, when present.

Upvotes: 16

Related Questions