1、ntp源包: ntp-dev-4.3.91.tar.gz (可下载地址: http://www.NTP.org/downloads.html ) )。
2、交叉编译工具: arm-linux-gnueabihf-gcc将ntp源包解压到指定目录tar -zxvf ntp-dev-4.3.91.tar.gz
访问刚刚解压缩的目录,配置cd ntp-dev-4.3.91,并在ntpd/ntp_loopfilter.c中添加以下宏定义
#ifndef MOD_NANO
#define MOD_NANO0x2000
#endif
./configure-- prefix=$ pwd/install-- exec-prefix=$ pwd/install-- host=arm-none-Linux-gnueabicc=arm
发生错误:
checking for pthread _ kill _ other _ threads _ NP . no
checkingforlinuxthreadsimplementation . no
checkingforlinuxthreadsconsistency .否
checking if pthread_create () works .是
checkingifselectyieldswhenusingpthreads . cross
配置:错误:交叉计算3360使用- -具有意义的选择=是|否|手动
执行指令: satellite @ Ubuntu : (/share/NTP-dev-4.3.91 $./configure-- prefix=$ pwd/install-exec-prefix
这次,在安装目录中成功生成了makefile。
编译并安装make
发生错误:
NTP _ loop filter.c : in function ' local _ clock ' :
NTP _ loop filter.c :760: error : ' mod _ nano ' undeclared (firstuseinthisfunction ) )。
NTP _ loop filter.c :7603360错误: (eachundeclaredidentifierisreportedonlyonce
NTP _ loop filter.c :760: error : foreachfunctionitappearsin.)
将以下宏定义#ifndef MOD_NANO添加到ntpd/ntp_loopfilter.c中
#define MOD_NANO0x2000
#endif
制造安装
4 .安装完成后,安装目录下的install文件夹中有三个文件夹生成ls
zxdbd libexec szxdbd share
zxdbd目录中的命令文件如下: ls zxdbd
calc _ tickadjntpdatentpdcntp-keygenntpqntptimentptracentp-waitsntptickadjupdate-leap
5、将zxdbd目录中所需的命令文件复制或全部复制到开发板的/zxdbd目录中
ntp客户机使用的命令有ntpdate,而ntp服务器使用的命令有ntpd
6、ntp客户端
将ntpdate命令复制到开发板后,运行以下命令ntpdate time.buptnet.edu.cn或ntpdate 202.112.10.60
说明: time.buptnet.edu.cn是北京时间的NTP服务器(IP: 202.112.10.60 ) )。
提示: Jan 01:19336017 ntpdate [ 2179 ] : noserversuitableforsynchronizationfound
出现了ntpdate time.buptnet.edu.cn问题
ntpdate : errorwhileloadingsharedlibraries 3360 libcap.so.2: cannotopensharedobjectfile 3360
no such file or directory
解决方案:将libcap.so.2和libattr.so.1文件直接复制到安装交叉编译工具的目录arm-linux-gnueabihf/usr/lib中,并将其复制到开发板/lib目录中
复制上述两个文件将完成时间同步ntpdate 0.pool.ntp.org
step time server 110.75.186.248 offset 1460632666.423442 sec
日期
thu apr 1420:49:19 CST 2016
如果从网络获取的系统时间写入硬件时钟,请使用命令hwclock -w
每次启动设备自动同步时间时,都可以将命令行" ntpdate 0.pool.ntp.org "添加到启动脚本中
或上位机发送到ARM,ARM获取稍后到达系统的时间。 date-s ' 2018-10-3111336020336035 '
7、ntp服务器(因为不能使用,所以暂时没有测试) )。
ntp服务器的开发板和ntp客户机系统的网络必须正常连接
在将成为服务器的开发板中编辑文件/etc/ntp.conf
执行命令: vi /etc/ntp.conf
# restrictdefaultnomodifynotrapnoquery
restrict 127.0.0.1
restrict 192.168.1.0 mask 255.255.255.0否修改注释
server 127.127.1.0 #本地时钟
fudge 127.127.1.0 stratum 5
driftfile /var/lib/ntp/drift
broadcastdelay 0.008
keys /etc/ntp/keys
打开ntp服务器ntpd -c /etc/ntp.conf
在ntp服务器打开后5~10分钟内,可以在客户端系统上运行以下命令: 否则,时间同步将失败
ntpdate 192.168.1.x (将192.168.1.x更改为服务器的IP地址) ) )。