arm移植NTP(同步嵌入式linux系統(tǒng)時(shí)間)
二、準(zhǔn)備工作
1、ntp源碼包:ntp-dev-4.3.91.tar.gz(可下載地址:http://www.ntp.org/downloads.html)
2、交叉編譯工具:arm-none-linux-gnueabi-gcc 4.7.3
3、編譯環(huán)境Ubuntu 13.02
三、移植步驟
1、解壓ntp源碼包到指定目錄
satellite@ubuntu:~/share$ tar -zxvf ntp-dev-4.3.91.tar.gz
2、進(jìn)入剛解壓目錄,并配置
(1)satellite@ubuntu:~/share$ cd ntp-dev-4.3.91
出現(xiàn)錯(cuò)誤:
checking for pthread_kill_other_threads_np... no
checking for LinuxThreads implementation... no
checking for LinuxThreads consistency... no
checking if pthread_create() works... yes
checking if select yields when using pthreads... cross
configure: error: crossing compiling: use --with-yielding-select=yes|no|manual
執(zhí)行命令:satellite@ubuntu:~/share/ntp-dev-4.3.91$ ./configure --prefix=$PWD/install --exec-prefix=$PWD/install --host=arm-none-linux-gnueabi CC=arm-none-linux-gnueabi-gcc --with-yielding-select=yes
此次,在安裝目錄下成功生成了Makefile文件。
3、編譯并安裝
satellite@ubuntu:~/share/ntp-dev-4.3.91$ make
出現(xiàn)錯(cuò)誤:
ntp_loopfilter.c: In function 'local_clock':
ntp_loopfilter.c:760: error: 'MOD_NANO' undeclared (first use in this function)
ntp_loopfilter.c:760: error: (Each undeclared identifier is reported only once
ntp_loopfilter.c:760: error: for each function it appears in.)
在ntpd/ntp_loopfilter.c中增加下面的宏定義
satellite@ubuntu:~/share/ntp-dev-4.3.91$ make install
4、安裝完之后在安裝目錄下install文件夾會(huì)有三個(gè)文件夾產(chǎn)生
bin libexec sbin share
bin目錄中的命令文件有如下:
5、把bin目錄下的需要的命令文件拷貝到開發(fā)板的/bin目錄下,或者全部拷貝過(guò)去
ntp客戶端需要用到的命令有ntpdate,ntp服務(wù)器需要用到的命令有ntpd
1、保證網(wǎng)絡(luò)能正常使用(否則ntpdate程序可能會(huì)被阻塞在獲取網(wǎng)絡(luò)時(shí)間的地方,同事啟動(dòng)ntpdate時(shí)也要注意ntpdate的阻塞不能影響其他程序的啟動(dòng))
root@EasyARM-iMX283 /# ntpdate time.buptnet.edu.cn(或者ntpdate 202.112.10.60)
說(shuō)明:time.buptnet.edu.cn是北京時(shí)間的NTP服務(wù)器(IP:202.112.10.60)
提示:
1 Jan 01:19:17 ntpdate[2179]: no server suitable for synchronization found
1.pool.ntp.org
2.pool.ntp.org
3.pool.ntp.org
則解決辦法:在安裝交叉編譯工具的目錄arm-arago-linux-gnueabi/usr/lib中有文件libcap.so.2和libattr.so.1直接拷貝到開發(fā)板/lib目錄下即可
(本人arm開發(fā)板內(nèi)已經(jīng)有了這兩個(gè)庫(kù),故沒(méi)有出現(xiàn)上面的錯(cuò)誤,直接時(shí)間同步成功)
3、拷貝完以上兩個(gè)文件即可完成時(shí)間同步
root@EasyARM-iMX283 /# ntpdate 0.pool.ntp.org
14 Apr 12:38:30 ntpdate[2188]: step time server 110.75.186.248 offset 1460632666.423442 sec
root@EasyARM-iMX283 /# date
Thu Apr 14 20:49:19 CST 2016
注意:用date命令查看之后顯示的是UTC時(shí)間(世界標(biāo)準(zhǔn)時(shí)間),比北京時(shí)間(CST=UTC+8)相差8個(gè)小時(shí),所以需要設(shè)置時(shí)區(qū)
4、設(shè)置時(shí)區(qū)為CST時(shí)間
(1)把redhat或者ubuntu系統(tǒng)目錄/usr/share/zoneinfo/Asia中的文件Shanghai拷貝到開發(fā)板目錄/etc中并且改名為localtime之后,用命令reboot重啟即可,如下:
root@EasyARM-iMX283 /# date
Thu Jan 24 15:55:29 CST 2013
5、如果想顯示UTC時(shí)間可以使用命令
root@EasyARM-iMX283 /# date –u
6、如果想將從網(wǎng)絡(luò)上獲取到的系統(tǒng)時(shí)間寫入硬件時(shí)鐘中,則使用命令
root@EasyARM-iMX283 /# hwclock -w
7、如果想每次開機(jī)設(shè)備自動(dòng)同步時(shí)間,可在啟動(dòng)腳本中加入命令行:
ntpdate 0.pool.ntp.org
五、ntp服務(wù)器 (因?yàn)橛貌恢詴簳r(shí)沒(méi)有測(cè)試)
1、保證做ntp服務(wù)器的開發(fā)板和ntp客戶端的系統(tǒng)的網(wǎng)絡(luò)連接正常
2、在要做服務(wù)器的開發(fā)板上編輯文件/etc/ntp.conf
執(zhí)行命令:
root@EasyARM-iMX283 /# vi /etc/ntp.conf
#restrict default nomodify notrap noquery
restrict 127.0.0.1
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 5
driftfile /var/lib/ntp/drift
broadcastdelay 0.008
keys /etc/ntp/keys
*博客內(nèi)容為網(wǎng)友個(gè)人發(fā)布,僅代表博主個(gè)人觀點(diǎn),如有侵權(quán)請(qǐng)聯(lián)系工作人員刪除。











