linuxptp: fix boot-block, phc2sys auto-start and interface validation

- ptp4l.init: bound wait_disciplined with clock_sync_max_tries (default
  8 attempts, ~2 min) so a server-role device with no time source does
  not stall rcS indefinitely; set to 0 to wait without limit
- ptp4l.init: validate that at least one [interface] section was written
  to ptp4l.conf (by counting section headers); a config with only
  [global] is now rejected with a clear error rather than launching
  ptp4l into a respawn loop
- phc2sys.init: require phc_device to be explicitly configured; removes
  the /dev/ptp0 default so phc2sys does not auto-start on upgrade and
  slew CLOCK_REALTIME from an undisciplined PHC
- linuxptp.config: comment out the config ptp_interface section header
  so the shipped default contains no load-bearing anonymous section;
  validation is now in the init script rather than the config structure
- linuxptp.config: comment out phc_device so both daemons require
  explicit admin opt-in before starting
- linuxptp.config: document clock_sync_max_tries option

Signed-off-by: Aleks Mariusz <a+git-commit@alek.cx>
This commit is contained in:
Aleks Mariusz authored and Hannu Nyman committed 2026-10-24 16:59:03 +03:00
1 parent b63bea16a0
commit 71666498b7
3 files changed
+35 -16

No files matched your search

+13 -9
View File
@@ -11,23 +11,27 @@ config ptp4l 'ptp4l' # configures the ptp4l daemon
#option clock_sync_check_interval '15' # Seconds between clock discipline checks (default: 15).
# Only used when require_clock_sync is 1.
#option clock_sync_max_tries '8' # Max attempts before giving up clock sync wait (default: 8, ~2 min).
# Set to 0 to wait indefinitely (blocks boot until clock disciplines).
# For global lines in ptp4l.conf - Each item is one line like "key value" for the [global] section
#list global_opts 'clockClass 6'
# For extra ptp4l command line options
#list extra_args ''
config ptp_interface # repeat multiple times for each interface ptp4l should work on
#option interface 'lan' # required - UCI's interface name, init-script looks up kernel ifname as needed
#option transport 'UDPv4' # Network transport: UDPv4 (default), UDPv6, L2.
#option delay_mechanism 'E2E' # PTP delay mechanism: E2E (End-to-End, default), P2P (Peer-to-Peer).
# For interface-specific sections in ptp4l.conf
#list interface_opts 'logSyncInterval -3'
# At least one ptp_interface section is required for ptp4l to start.
# Repeat this block for each interface ptp4l should listen on.
#config ptp_interface
# option interface 'lan' # required - UCI's interface name, init-script looks up kernel ifname as needed
# #option transport 'UDPv4' # Network transport: UDPv4 (default), UDPv6, L2.
# #option delay_mechanism 'E2E' # PTP delay mechanism: E2E (End-to-End, default), P2P (Peer-to-Peer).
# #list interface_opts 'logSyncInterval -3'
config phc2sys 'phc2sys' # configures the phc2sys daemon, which syncs either system clock from PHC in NIC (as a client, or vice versa as a server)
#option phc_device '/dev/ptp0' # PTP Hardware Clock device
# User should verify this is the correct PHC for their PTP interface
#option phc_device '/dev/ptp0' # PTP Hardware Clock device - required, no default.
# Verify this matches the PHC for your PTP interface (e.g. /dev/ptp0).
# phc2sys will not start until this is set.
# specifies clock sync'ing direction # 'phc_to_sys': PHC (sync'd by ptp4l) disciplines system clock (default unless ptp4l role is 'server')
#option sync_direction 'phc_to_sys' # 'sys_to_phc': System clock disciplines PHC (default if ptp4l's role is 'server')
+2 -1
View File
@@ -19,7 +19,8 @@ make_cmdline() {
echo $PROG
config_get dev $cfg "phc_device" "/dev/ptp0"
config_get dev $cfg "phc_device" ""
[ -z "$dev" ] && { log err "phc_device not configured. Set 'option phc_device' in /etc/config/linuxptp."; return 1; }
! [ -c "$dev" ] && { log crit "PHC device '$dev' not found!"; return 1; }
dir='phc_to_sys'
+20 -6
View File
@@ -33,13 +33,15 @@ is_clock_disciplined() {
}
wait_disciplined() {
local check_msg interval is_synced=0 rc role
local check_msg interval is_synced=0 max_tries rc role tries=0
config_get role $ID "role" ""
config_get interval $ID "clock_sync_check_interval" "15"
config_get max_tries $ID "clock_sync_max_tries" "8"
log info "Preparing to start with role:$role -> first checking if system clock is disciplined (has been synchronized)..."
log info "Preparing to start with role:$role -> checking if system clock is disciplined..."
while [ $is_synced -eq 0 ]; do
tries=$((tries + 1))
check_msg=$(is_clock_disciplined); rc=$?
if [ $rc -eq 0 ]; then
@@ -47,7 +49,12 @@ wait_disciplined() {
log info "sysclock-discipline-check: $check_msg. Continuing."
return 0
elif [ $rc -eq 1 ]; then
log info "sysclock-discipline-check: $check_msg. Waiting..."
if [ "$max_tries" -gt 0 ] && [ "$tries" -ge "$max_tries" ]; then
log err "Clock sync wait timed out after $tries attempts. ptp4l will NOT start."
log err "Increase 'clock_sync_max_tries' or set 'require_clock_sync 0' to skip."
return 1
fi
log info "sysclock-discipline-check: $check_msg. Waiting... ($tries/$max_tries)"
else
log crit "Clock sync check FAILED: $check_msg."
log err "ptp4l will NOT start. Resolve issue, or set 'require_clock_sync' to 0"
@@ -94,7 +101,7 @@ handle_global() {
}
make_configfile() {
local cfg=$1 rc
local cfg=$1 iface_count rc
. /lib/functions/network.sh
@@ -106,7 +113,14 @@ make_configfile() {
) > "$CONFIGFILE"
rc=$?
return $rc
[ $rc -ne 0 ] && return 1
# Require at least one [interface] section beyond [global]
iface_count=$(grep -c '^\[' "$CONFIGFILE" 2>/dev/null)
if [ "${iface_count:-0}" -lt 2 ]; then
log err "No PTP interfaces configured. Add a 'config ptp_interface' section to /etc/config/linuxptp."
return 1
fi
}
make_cmdline() {
@@ -141,7 +155,7 @@ start_service() {
fi
make_configfile $ID; rc=$?
if [ $rc -ne 0 ] || [ ! -s "$CONFIGFILE" ]; then
if [ $rc -ne 0 ]; then
log err "Failed to generate $CONFIGFILE. Aborting."
rm -f "$CONFIGFILE"
return 1