NXP LSDK(Layerscape SDK)提供了linuxptp庫羊壹,用于支持PTP/gPTP協(xié)議。本文基于LSDKv20.12,介紹了linuxptp協(xié)議棧的升級(jí)和使用方法。
1. linuxptp升級(jí)
-
根據(jù)
packages/rfs/yocto-poky/meta/recipes-support/linuxptp/linuxptp_2.0.bb
,找到linuxptp的下載網(wǎng)址為http://sourceforge.net/projects/linuxptp/files/v${PV}/linuxptp-${PV}.tgz
懂昂,因此到相關(guān)網(wǎng)站上發(fā)現(xiàn)最新版本為http://sourceforge.net/projects/linuxptp/files/v3.1/linuxptp-3.1.1.tgz
,因此進(jìn)行如下修改以將linuxptp更新到最新版本:將
linuxptp_2.0.bb
重命名為linuxptp_3.1.1.bb
;-
下載最新的linuxptp并解壓没宾,創(chuàng)建git倉庫凌彬,根據(jù)
packages/rfs/yocto-poky/meta/recipes-support/linuxptp/linuxptp
目錄下的2個(gè)patch
修改文件并生成新的patch
:$ tar xvf linuxptp-3.1.1.tgz $ cd linuxptp-3.1.1/ $ git init . $ git add . $ git commit -m "original version" $ vim makefile # 修改Makefile $ git commit # 第一次提交 $ vim makefile # 修改Makefile $ git commit # 第二次提交 $ git log commit 261bd281d79c4024a2413dac1d34bde1dc53ca2f (HEAD -> master) Author: XXX <xxx@xxx.com> Date: Wed Mar 23 15:00:14 2022 +0800 linuxptp: no incdefs using host headers Avoid using host headers via incdefs.sh shell script. Signed-off-by: XXX <xxx@xxx.com> commit b18d6db45bafa6e82cd56208c07404908e71b428 Author: XXX <xxx@xxx.com> Date: Wed Mar 23 10:09:26 2022 +0800 build: Allow CC and prefix to be overriden Signed-off-by: XXX <xxx@xxx.com> commit 1e4cbdfb164b4bc1bfa9fbbd95e62faafb11f8f4 Author: XXX <xxx@xxx.com> Date: Wed Mar 23 09:54:52 2022 +0800 original version $ git format-patch HEAD^^ 0001-build-Allow-CC-and-prefix-to-be-overriden.patch 0002-linuxptp-no-incdefs-using-host-headers.patch
用生成的
patch
替換packages/rfs/yocto-poky/meta/recipes-supportlinuxptp/linuxptp
目錄下原有的patch
;-
修改
linuxptp_3.1.1.bb
循衰,更新下載連接铲敛、文件校驗(yàn)碼和patch名稱:SRC_URI = "http://sourceforge.net/projects/linuxptp/files/v3.1linuxptp-${PV}.tgz \ file://0001-build-Allow-CC-and-prefix-to-be-overridenpatch \ file://0002-linuxptp-no-incdefs-using-host-headers.patch\ " SRC_URI[md5sum] = "3b79ab5e77c5b5cf06bc1c8350d405bb" SRC_URI[sha256sum] ="94d6855f9b7f2d8e9b0ca6d384e3fae6226ce6fc012dbad02608bdef3be1c09"
-
gPTP配置文件在linuxptp目錄:
flexbuild_lsdk2012$ find . -name gPTP.cf ./packages/rfs/yocto-poky/build/tmp/work/core2-64-poky-linux/linuxptp/2.0-r0/linuxptp-3.1.1/configs/gPTP.cfg
-
存在多個(gè)版本時(shí),可以在
configs/yocto/local_arm64_devel.conf
文件中指定版本號(hào):@@ -37,6 +37,8 @@ DISTRO ?= "poky" PACKAGE_CLASSES ?= "package_deb" +PREFERRED_VERSION_linuxptp = "3.1.1" + IMAGE_FSTYPES = "cpio.gz ubi squashfs"
-
修改linxuptp包会钝,打包文件系統(tǒng)時(shí)自動(dòng)將
gPTP.cfg
拷貝到/usr/bin
目錄:diff --git a/meta/recipes-extra/linuxptp/linuxptp/gPTP.cfg b/meta/recipes-extra/linuxptp/linuxptp/gPTP.cfg new file mode 100644 ... diff --git a/meta/recipes-extra/linuxptp/linuxptp_3.1.1.bb b/meta/recipes-extra/linuxptp/linuxptp_3.1.1.bb index c971926a53..2bb91a8a5f 100755 --- a/meta/recipes-extra/linuxptp/linuxptp_3.1.1.bb +++ b/meta/recipes-extra/linuxptp/linuxptp_3.1.1.bb @@ -5,7 +5,7 @@ LIC_FILES_CHKSUM = "file://COPYING;md5=b234ee4d69f5fce4486a80fdaf4a4263" SRC_URI = "http://sourceforge.net/projects/linuxptp/files/v3.1/linuxptp-${PV}.tgz \ file://0001-build-Allow-CC-and-prefix-to-be-overriden.patch \ file://0002-linuxptp-no-incdefs-using-host-headers.patch \ - " + file://gPTP.cfg" SRC_URI[md5sum] = "3b79ab5e77c5b5cf06bc1c8350d405bb" SRC_URI[sha256sum] = "94d6855f9b7f2d8e9b0ca6d384e3fae6226ce6fc012dbad02608bdef3be1c0d9" @@ -16,6 +16,7 @@ EXTRA_OEMAKE = "ARCH=${TARGET_ARCH} \ do_install () { install -d ${D}/${bindir} install -p ${S}/ptp4l ${D}/${bindir} + install -m0600 ${WORKDIR}/gPTP.cfg ${D}${bindir}/gPTP.cfg install -p ${S}/pmc ${D}/${bindir} install -p ${S}/phc2sys ${D}/${bindir} install -p ${S}/hwstamp_ctl ${D}/${bindir}
-
編譯文件系統(tǒng)伐蒋,具體細(xì)節(jié)參加NXP LSDK簡明實(shí)用手冊的正式文件系統(tǒng)編譯和文件系統(tǒng)鏡像創(chuàng)建兩章:
flexbuild_lsdk2012$ source setup.env flexbuild_lsdk2012$ flex-builder -m lx2160ardb_rev2 -a arm64 -i mkrfs -r yocto:devel
-
更新文件系統(tǒng),并下載到板卡上:
root@DevelLinux:~# ptp4l -v 3.1.1
2. linuxptp使用
將2臺(tái)設(shè)備的待測試網(wǎng)口對接;
-
在2臺(tái)設(shè)備上分別使用如下命令進(jìn)行PTP測試:
root@DevelLinux:~# ifconfig eth0 192.168.200.101/24 up && ptp4l -i eth0 -m # 設(shè)備1 ptp4l[18.866]: selected /dev/ptp0 as PTP clock ptp4l[18.916]: port 1: INITIALIZING to LISTENING on INIT_COMPLETE ptp4l[18.917]: port 0: INITIALIZING to LISTENING on INIT_COMPLETE ptp4l[18.917]: port 1: link down ptp4l[18.917]: port 1: LISTENING to FAULTY on FAULT_DETECTED (FT_UNSPECIFIED) ptp4l[18.926]: selected local clock 0629fa.fffe.fd2d1b as best master ptp4l[18.926]: port 1: assuming the grand master role [ 21.067516] dpaa2_mac dpmac.7 mac7: Link is Up - 1Gbps/Full - flow control off [ 21.080889] fsl_dpaa2_eth dpni.4 eth0: Link Event: state up [ 21.086775] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready ptp4l[20.918]: port 1: link up ptp4l[20.978]: port 1: FAULTY to LISTENING on INIT_COMPLETE ptp4l[27.897]: port 1: LISTENING to MASTER on ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES ptp4l[27.897]: selected local clock 0629fa.fffe.fd2d1b as best master ptp4l[27.897]: port 1: assuming the grand master role ptp4l[28.113]: port 1: new foreign master 2e19fe.fffe.2e8922-1 [ 60.198448] ffs_data_put(): freeing ... root@DevelLinux:~# ifconfig eth0 192.168.200.102/24 up && ptp4l -i eth0 -m # 設(shè)備2 ptp4l[15.750]: selected /dev/ptp0 as PTP clock ptp4l[15.799]: port 1: INITIALIZING to LISTENING on INIT_COMPLETE ptp4l[15.800]: port 0: INITIALIZING to LISTENING on INIT_COMPLETE ptp4l[15.800]: port 1: link down ptp4l[15.800]: port 1: LISTENING to FAULTY on FAULT_DETECTED (FT_UNSPECIFIED) ptp4l[15.810]: selected local clock 2e19fe.fffe.2e8922 as best master ptp4l[15.810]: port 1: assuming the grand master role [ 17.936870] dpaa2_mac dpmac.7 mac7: Link is Up - 1Gbps/Full - flow control off [ 17.950549] fsl_dpaa2_eth dpni.4 eth0: Link Event: state up [ 17.956292] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready ptp4l[17.786]: port 1: link up ptp4l[17.848]: port 1: FAULTY to LISTENING on INIT_COMPLETE ptp4l[25.415]: port 1: LISTENING to MASTER on ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES ptp4l[25.415]: selected local clock 2e19fe.fffe.2e8922 as best master ptp4l[25.415]: port 1: assuming the grand master role [ 33.296169] dpaa2_mac dpmac.7 mac7: Link is Down [ 33.302513] fsl_dpaa2_eth dpni.4 eth0: Link Event: state down ptp4l[33.416]: timed out while polling for tx timestamp ptp4l[33.417]: increasing tx_timestamp_timeout may correct this issue, but it is likely caused by a driver bug ptp4l[33.417]: port 1: send sync failed ptp4l[33.417]: port 1: MASTER to FAULTY on FAULT_DETECTED (FT_UNSPECIFIED) [ 34.320171] dpaa2_mac dpmac.7 mac7: Link is Up - 1Gbps/Full - flow control off ptp4l[34.144]: port 1: link down ptp4l[34.151]: selected local clock 2e19fe.fffe.2e8922 as best master ptp4l[34.151]: port 1: assuming the grand master role [ 34.338790] fsl_dpaa2_eth dpni.4 eth0: Link Event: state up ptp4l[34.171]: port 1: link up ptp4l[34.237]: port 1: FAULTY to LISTENING on INIT_COMPLETE ptp4l[41.312]: port 1: new foreign master 0629fa.fffe.fd2d1b-1 ptp4l[41.525]: port 1: LISTENING to MASTER on ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES ptp4l[41.525]: selected local clock 2e19fe.fffe.2e8922 as best master ptp4l[41.526]: port 1: assuming the grand master role ptp4l[45.312]: selected best master clock 0629fa.fffe.fd2d1b ptp4l[45.312]: port 1: MASTER to UNCALIBRATED on RS_SLAVE ptp4l[48.311]: master offset 13413912505 s0 freq +0 path delay 7315 ptp4l[49.311]: master offset 13413909795 s1 freq -2710 path delay 7315 ptp4l[50.311]: master offset -1344 s2 freq -4054 path delay 7315 ptp4l[50.312]: port 1: UNCALIBRATED to SLAVE on MASTER_CLOCK_SELECTED ptp4l[51.312]: master offset 562 s2 freq -2551 path delay 6751 ptp4l[52.312]: master offset 256 s2 freq -2688 path delay 6791 ptp4l[53.312]: master offset 80 s2 freq -2788 path delay 6781 ptp4l[54.312]: master offset 84 s2 freq -2760 path delay 6761 ...
注意先鱼,此時(shí)使用默認(rèn)配置徒蟆,即
packages/rfs/yocto-poky/build/tmp/work/core2-64-poky-linux/linuxptp/2.0-r0/linuxptp-3.1.1/configs/default.cfg
。 -
根據(jù)LSDK手冊型型,刪除
gPTP.cfg
中的neighborPropDelayThresh 800
配置,并將其下載到板子的/home/root
目錄全蝶,然后在2臺(tái)設(shè)備上分別使用如下命令進(jìn)行g(shù)PTP測試:root@DevelLinux:~# ifconfig eth0 192.168.200.101/24 up && ptp4l -i eth0 -f gPTP.cfg-m & # 設(shè)備1 ptp4l[22.408]: selected /dev/ptp0 as PTP clock ptp4l[22.481]: port 1: INITIALIZING to LISTENING on INIT_COMPLETE ptp4l[22.481]: port 0: INITIALIZING to LISTENING on INIT_COMPLETE ptp4l[22.481]: port 1: link down ptp4l[22.481]: port 1: LISTENING to FAULTY on FAULT_DETECTED (FT_UNSPECIFIED) ptp4l[22.536]: selected local clock 42ac62.fffe.6db1ab as best master ptp4l[22.536]: port 1: assuming the grand master role [ 24.587754] dpaa2_mac dpmac.7 mac7: Link is Up - 1Gbps/Full - flow control off [ 24.601130] fsl_dpaa2_eth dpni.4 eth0: Link Event: state up [ 24.606900] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready ptp4l[24.437]: port 1: link up ptp4l[24.518]: port 1: FAULTY to LISTENING on INIT_COMPLETE ptp4l[27.805]: port 1: LISTENING to MASTER on ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES ptp4l[27.806]: selected local clock 42ac62.fffe.6db1ab as best master ptp4l[27.806]: port 1: assuming the grand master role [ 35.851758] dpaa2_mac dpmac.7 mac7: Link is Down [ 35.858121] fsl_dpaa2_eth dpni.4 eth0: Link Event: state down ptp4l[36.519]: timed out while polling for tx timestamp ptp4l[36.520]: increasing tx_timestamp_timeout may correct this issue, but it is likely caused by a driver bug ptp4l[36.520]: port 1: send peer delay request failed ptp4l[36.520]: port 1: MASTER to FAULTY on FAULT_DETECTED (FT_UNSPECIFIED) [ 36.875755] dpaa2_mac dpmac.7 mac7: Link is Up - 1Gbps/Full - flow control off ptp4l[36.700]: port 1: link down ptp4l[36.707]: selected local clock 42ac62.fffe.6db1ab as best master ptp4l[36.707]: port 1: assuming the grand[ 36.893879] fsl_dpaa2_eth dpni.4 eth0: Link Event: state up master role ptp4l[36.726]: port 1: link up ptp4l[36.803]: port 1: FAULTY to LISTENING on INIT_COMPLETE ptp4l[40.092]: port 1: LISTENING to MASTER on ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES ptp4l[40.092]: selected local clock 42ac62.fffe.6db1ab as best master ptp4l[40.092]: port 1: assuming the grand master role ptp4l[41.426]: port 1: new foreign master a6ef06.fffe.60084e-1 ... root@DevelLinux:~# ifconfig eth0 192.168.200.102/24 up && ptp4l -i eth0 -f gPTP.cfg -m &# 設(shè)備2 ptp4l[17.390]: selected /dev/ptp0 as PTP clock ptp4l[17.453]: port 1: INITIALIZING to LISTENING on INIT_COMPLETE ptp4l[17.453]: port 0: INITIALIZING to LISTENING on INIT_COMPLETE ptp4l[17.453]: port 1: link down ptp4l[17.453]: port 1: LISTENING to FAULTY on FAULT_DETECTED (FT_UNSPECIFIED) ptp4l[17.504]: selected local clock a6ef06.fffe.60084e as best master ptp4l[17.504]: port 1: assuming the grand master role [ 19.563863] dpaa2_mac dpmac.7 mac7: Link is Up - 1Gbps/Full - flow control off [ 19.577303] fsl_dpaa2_eth dpni.4 eth0: Link Event: state up [ 19.582908] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready ptp4l[19.413]: port 1: link up ptp4l[19.494]: port 1: FAULTY to LISTENING on INIT_COMPLETE ptp4l[22.830]: port 1: new foreign master 42ac62.fffe.6db1ab-1 ptp4l[23.161]: port 1: LISTENING to MASTER on ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES ptp4l[23.161]: selected local clock a6ef06.fffe.60084e as best master ptp4l[23.161]: port 1: assuming the grand master role ptp4l[24.830]: selected best master clock 42ac62.fffe.6db1ab ptp4l[24.830]: port 1: MASTER to UNCALIBRATED on RS_SLAVE ptp4l[25.830]: port 1: UNCALIBRATED to SLAVE on MASTER_CLOCK_SELECTED ptp4l[26.455]: rms 9131880424 max 18263760993 freq +791 +/- 648 delay 6733 +/- 0 ptp4l[27.456]: rms 166 max 329 freq +1475 +/- 203 delay 6730 +/- 0 ptp4l[28.456]: rms 198 max 220 freq +1936 +/- 67 delay 6729 +/- 0 ptp4l[29.457]: rms 170 max 210 freq +2093 +/- 43 delay 6729 +/- 0 ptp4l[30.457]: rms 84 max 110 freq +2103 +/- 21 delay 6729 +/- 0 ...
注意闹蒜,此時(shí)使用
gPTP.cfg
覆蓋默認(rèn)配置中的部分選項(xiàng)。 -
每臺(tái)設(shè)備上可以同時(shí)啟動(dòng)多個(gè)gPTP程序抑淫,但是不能存在多個(gè)gPTP master绷落,否則會(huì)自動(dòng)切換;
root@DevelLinux:~# ifconfig eth0 192.168.200.101/24 up && ptp4l -i eth0 -f gPTP.cfg-m & # 設(shè)備1 root@DevelLinux:~# ifconfig eth0 192.168.200.102/24 up && ptp4l -i eth0 -f gPTP.cfg-m & # 設(shè)備2 root@DevelLinux:~# ifconfig eth2 192.168.201.101/24 up && ptp4l -i eth2 -f gPTP.cfg-m & # 設(shè)備1 root@DevelLinux:~# ifconfig eth1 192.168.201.102/24 up && ptp4l -i eth1 -f gPTP.cfg-m & # 設(shè)備2
-
根據(jù)NXP建議始苇,在
gPTP.cfg
中增加如下配置項(xiàng)砌烁,并為從節(jié)點(diǎn)啟動(dòng)命令增加-s
選項(xiàng)以限制模式為slave,未發(fā)現(xiàn)明顯改進(jìn):neighborPropDelayThresh 20000 summary_interval -3
-
根據(jù)NXP建議催式,CPU頻率是影響測試結(jié)果的重要因素函喉,因此查看CPU支持頻率和當(dāng)前頻率:
root@DevelLinux:~# cat /sys/devices/system/cpu/cpu0/cpufreqscaling_available_frequencies 1800000 900000 root@DevelLinux:~# cat /sys/devices/system/cpu/cpu0/cpufreqscaling_cur_freq 1800000
當(dāng)前頻率已經(jīng)是當(dāng)前RCW可以支持的最高頻率,否則可以使用如下命令調(diào)整:
root@DevelLinux:~# echo 1800000 > /sys/devices/system/cpu/cpu0cpufreq/scaling_setspeed 1800000