diff --git a/net/linuxptp/files/linuxptp.config b/net/linuxptp/files/linuxptp.config index 15b8ae3610..7fef7637d6 100644 --- a/net/linuxptp/files/linuxptp.config +++ b/net/linuxptp/files/linuxptp.config @@ -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') diff --git a/net/linuxptp/files/phc2sys.init b/net/linuxptp/files/phc2sys.init index c9619cae67..ca5f239a33 100644 --- a/net/linuxptp/files/phc2sys.init +++ b/net/linuxptp/files/phc2sys.init @@ -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' diff --git a/net/linuxptp/files/ptp4l.init b/net/linuxptp/files/ptp4l.init index 70cd3b2821..cb9a860e9f 100644 --- a/net/linuxptp/files/ptp4l.init +++ b/net/linuxptp/files/ptp4l.init @@ -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