Debian Codegraph @

scripts/ptp.sh

raw symbols SCIP
1 #!/bin/bash
2 #
3 # Copyright (C) 2021,2025 Linutronix GmbH
4 # Author Kurt Kanzenbach <[email protected]>
5 #
6 # SPDX-License-Identifier: BSD-2-Clause
7 #
8 # Start ptp and synchronize system to network time.
9 #
10
11 set -e
12
13 cd "$(dirname "$0")"
14
15 # Interface
16 INTERFACE=$1
17 [ -z $INTERFACE ] && INTERFACE="eth0"
18
19 # Kill already running daemons
20 pkill ptp4l || true
21 pkill phc2sys || true
22
23 # Set NTP time into PHC
24 phc_ctl ${INTERFACE} set
25
26 # Stop ntpd
27 systemctl stop systemd-timesyncd || true
28 systemctl stop ntpd || true
29 systemctl stop chrony || true
30
31 # Start ptp with 802.1AS-2011 endstation profile
32 ptp4l -2 -H -i ${INTERFACE} --socket_priority=4 --tx_timestamp_timeout=40 -f /etc/gPTP.cfg &
33
34 # Wait for ptp4l
35 sleep 10
36
37 # Configure UTC-TAI offset
38 pmc -u -b 0 -t 1 "SET GRANDMASTER_SETTINGS_NP clockClass 248 \
39 clockAccuracy 0xfe offsetScaledLogVariance 0xffff \
40 currentUtcOffset 37 leap61 0 leap59 0 currentUtcOffsetValid 1 \
41 ptpTimescale 1 timeTraceable 1 frequencyTraceable 0 \
42 timeSource 0xa0"
43
44 # Synchronize system to network time
45 phc2sys -s ${INTERFACE} --step_threshold=1 --transportSpecific=1 -w &
46
47 exit 0