NXP LSDK(Layerscape SDK)提供了linuxptp库,用于支持PTP/gPTP协议。本文基于LSDKv20.12,介绍了linuxptp协议栈的升级和使用方法。
- 1. linuxptp升级
- 2. linuxptp使用
1. linuxptp升级
-
根据
packages/rfs/yocto-poky/meta/recipes-support/linuxptp/linuxptp_2.0.bb
,找到linuxptp的下载网址为http://sourceforge.net/projects/linuxptp/files/v${PV}/linuxptp-${PV}.tgz
,因此到相关网站上发现最新版本为http://sourceforge.net/projects/linuxptp/files/v3.1/linuxptp-3.1.1.tgz
,因此进行如下修改以将linuxptp更新到最新版本:将
linuxptp_2.0.bb
重命名为linuxptp_3.1.1.bb
;-
下载最新的linuxptp并解压,创建git仓库,根据
packages/rfs/yocto-poky/meta/recipes-support/linuxptp/linuxptp
目录下的2个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
,更新下载连接、文件校验码和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
-
存在多个版本时,可以在
configs/yocto/local_arm64_devel.conf
文件中指定版本号:@@ -37,6 +37,8 @@ DISTRO ?= "poky" PACKAGE_CLASSES ?= "package_deb" +PREFERRED_VERSION_linuxptp = "3.1.1" + IMAGE_FSTYPES = "cpio.gz ubi squashfs"
-
修改linxuptp包,打包文件系统时自动将
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}
-
编译文件系统,具体细节参加NXP LSDK简明实用手册的正式文件系统编译和文件系统镜像创建两章:
flexbuild_lsdk2012$ source setup.env flexbuild_lsdk2012$ flex-builder -m lx2160ardb_rev2 -a arm64 -i mkrfs -r yocto:devel
-
更新文件系统,并下载到板卡上:
root@DevelLinux:~# ptp4l -v 3.1.1
2. linuxptp使用
将2台设备的待测试网口对接;
-
在2台设备上分别使用如下命令进行PTP测试:
root@DevelLinux:~# ifconfig eth0 192.168.200.101/24 up && ptp4l -i eth0 -m # 设备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 # 设备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 ...
注意,此时使用默认配置,即
packages/rfs/yocto-poky/build/tmp/work/core2-64-poky-linux/linuxptp/2.0-r0/linuxptp-3.1.1/configs/default.cfg
。 -
根据LSDK手册,删除
gPTP.cfg
中的neighborPropDelayThresh 800
配置,并将其下载到板子的/home/root
目录,然后在2台设备上分别使用如下命令进行gPTP测试:root@DevelLinux:~# ifconfig eth0 192.168.200.101/24 up && ptp4l -i eth0 -f gPTP.cfg-m & # 设备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 &# 设备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 ...
注意,此时使用
gPTP.cfg
覆盖默认配置中的部分选项。 -
每台设备上可以同时启动多个gPTP程序,但是不能存在多个gPTP master,否则会自动切换;
root@DevelLinux:~# ifconfig eth0 192.168.200.101/24 up && ptp4l -i eth0 -f gPTP.cfg-m & # 设备1 root@DevelLinux:~# ifconfig eth0 192.168.200.102/24 up && ptp4l -i eth0 -f gPTP.cfg-m & # 设备2 root@DevelLinux:~# ifconfig eth2 192.168.201.101/24 up && ptp4l -i eth2 -f gPTP.cfg-m & # 设备1 root@DevelLinux:~# ifconfig eth1 192.168.201.102/24 up && ptp4l -i eth1 -f gPTP.cfg-m & # 设备2
-
根据NXP建议,在
gPTP.cfg
中增加如下配置项,并为从节点启动命令增加-s
选项以限制模式为slave,未发现明显改进:neighborPropDelayThresh 20000 summary_interval -3
-
根据NXP建议,CPU频率是影响测试结果的重要因素,因此查看CPU支持频率和当前频率:
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
当前频率已经是当前RCW可以支持的最高频率,否则可以使用如下命令调整:
root@DevelLinux:~# echo 1800000 > /sys/devices/system/cpu/cpu0cpufreq/scaling_setspeed 1800000