前言:

板子上需要在开机时同步网络时间。

之前板子上有ntpdate工具,可以直接使用。最近突然不能用了。需要手动移植一个。


开发板:Hi3559A

编译工具链:aarch64-himix100-linux-gcc

ntp版本:ntp-4.2.8p13.tar.gz

openssl 版本:openssl-1.0.1f.tar.gz (注意,使用其他版本会报版本错误)


一、openssl:

下载地址:
https://www.openssl.org/source/old/1.0.1/

配置:

tar -vxf openssl-1.0.1f.tar.gz

cd openssl-1.0.1f/

./config no-asm shared --prefix=$PWD/__install

修改Makefile62行:

#CC= gcc
CC=aarch64-himix100-linux-gcc

去掉Makefile64行和180行中的"-m64"如下:

#CFLAG= -fPIC -DOPENSSL_PIC -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -m64 -DL_ENDIAN -DTERMIO -O3 -Wall
CFLAG= -fPIC -DOPENSSL_PIC -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -DL_ENDIAN -DTERMIO -O3 -Wall

#SHARED_LDFLAGS=-m64
SHARED_LDFLAGS=

保存退出。

编译:

make && make install 

把编译出的库文件,拷贝到板子上的/usr/lib目录下即可。

root@ubuntu:~/adams/ntp/openssl-1.0.1f# ls
ACKNOWLEDGMENTS  CHANGES.SSLeay  doc  includeINSTALL.MacOS  INSTALL.W64   libcrypto.so.1.0.0  LICENSE   Makefile.shared  openssl.doxy  PROBLEMS   shlib  util
apps config  engines  __install  INSTALL.NW INSTALL.WCE   libssl.aMacOS makevms.com  openssl.pcREADME sslVMS
bugs Configure   e_os2.h  INSTALLINSTALL.OS2libcrypto.a   libssl.pc   Makefile  ms   openssl.spec  README.ASN1test
certscrypto  e_os.h   install.comINSTALL.VMSlibcrypto.pc  libssl.so   Makefile.bak  Netware  os2   README.ENGINE  times
CHANGES  demos   FAQ  INSTALL.DJGPP  INSTALL.W32libcrypto.so  libssl.so.1.0.0 Makefile.org  NEWS perl  rehash.timetools
root@ubuntu:~/adams/ntp/openssl-1.0.1f# cd __install/
root@ubuntu:~/adams/ntp/openssl-1.0.1f/__install# ls
bin  include  lib  ssl
root@ubuntu:~/adams/ntp/openssl-1.0.1f/__install# cd lib/
root@ubuntu:~/adams/ntp/openssl-1.0.1f/__install/lib# ls
engines  libcrypto.a  libcrypto.so  libcrypto.so.1.0.0  libssl.a  libssl.so  libssl.so.1.0.0  pkgconfig
root@ubuntu:~/adams/ntp/openssl-1.0.1f/__install/lib# file *
engines:directory 
libcrypto.a:current ar archive
libcrypto.so:   symbolic link to `libcrypto.so.1.0.0' 
libcrypto.so.1.0.0: ELF 64-bit LSB  shared object, ARM aarch64, version 1 (SYSV), dynamically linked, not stripped
libssl.a:   current ar archive
libssl.so:  symbolic link to `libssl.so.1.0.0' 
libssl.so.1.0.0:ELF 64-bit LSB  shared object, ARM aarch64, version 1 (SYSV), dynamically linked, not stripped
pkgconfig:  directory 
root@ubuntu:~/adams/ntp/openssl-1.0.1f/__install/lib# 

把库文件和头文件拷贝到交叉编译链的对应目录下。

root@ubuntu:/neo/arm/openssl/openssl/__install# cp -af ./lib/* /opt/hisi-linux/x86-arm/aarch64-himix100-linux/target/usr/lib
root@ubuntu:/neo/arm/openssl/openssl/__install# cp -af ./include/* /opt/hisi-linux/x86-arm/aarch64-himix100-linux/target/usr/lib

注:之前交叉编译过openssl-1.1.1a.tar.gz 版本,发现有版本错误。

/usr/lib/libcrypto.so.1.0.0: no version information available

二、ntpdate交叉编译

下载地址:
http://distfiles.macports.org/ntp/

配置:

tar -vxf ntp-4.2.8p13.tar.gz

cd ntp-4.2.8p13/

./configure --prefix=`pwd`/__install CC=aarch64-himix100-linux-gcc --host=arm-linux -with-yielding-select=no

编译:

make && make install 

如下图在,__install 目录下的bin目录下,生成了可执行的二进制文件。
在这里插入图片描述


按照上面描述来配置编译,应该是不会报错的。


下面两个报错都是在编译时遇到的。大家不需要琢磨,只要按照上述步骤,使用相同版本的源码,把工具编译好即可。

注意:
1、本人测试过很多版本的ntp源码:

ntp-dev-4.3.99.tar_2.gz	
ntp-4.2.8p12.tar.gz
ntp-4.2.8p8.tar.gz
ntp-4.2.8.tar.gz

一开始总是在make时报错,比如:

①:ntp-4.2.8.tar.gz以及ntp-4.2.8p8.tar.gz源码的:

a_md5encrypt.c:70:13: error: storage size of ‘ctx’ isn’t known,报错。如下图:
在这里插入图片描述

该报错 原因不清楚。怀疑是源码版本太低的问题。

②:ntp-dev-4.3.99.tar_2.gz源码的:

bufferevent_openssl.c:112:3: error: dereferencing pointer to incomplete type ‘BIO {aka struct bio_st}’
  	b->init = 0;

bufferevent_openssl.c:234:1: error: variable ‘methods_bufferevent’ has initializer but incomplete type
`static BIO_METHOD methods_bufferevent = {`

bufferevent_openssl.c:234:19: error: storage size of ‘methods_bufferevent’ isn’t known
 static BIO_METHOD methods_bufferevent = {

该报错 是因为在配置时,开启了openssl: --enable-openssl.


__install/bin 目录下的文件。拷贝到板子上。


测试:

使用命令./ntpdate -u ntp.api.bz 同步网络时间:
在这里插入图片描述
时间同步成功。

Logo

更多推荐