M. Feser KBS GmbH
Date: 06.02.2025

This patch fixes the issue of RTC time (hwclock) not reliably being 
updated with system time. If timex maxerror is not explicitly set,
the Linux kernel sets STA_UNSYNC every second, which prevents the
RTC time update. Simply set timex maxerror to zero with each call of
adjtimex. The same approach is used in OpenNTPD since version 6.0p1.
-------------------------------------------------------------------------
diff -ruPN a/networking/ntpd.c b/networking/ntpd.c
--- a/networking/ntpd.c	2024-04-16 09:23:50.000000000 +0200
+++ b/networking/ntpd.c	2025-02-06 14:44:15.552875064 +0100
@@ -1645,7 +1645,7 @@
 	/* 65536 is one ppm */
 	tmx.freq = G.discipline_freq_drift * 65536e6;
 #endif
-	tmx.modes = ADJ_OFFSET | ADJ_STATUS | ADJ_TIMECONST;// | ADJ_MAXERROR | ADJ_ESTERROR;
+	tmx.modes = ADJ_OFFSET | ADJ_STATUS | ADJ_TIMECONST | ADJ_MAXERROR;// | ADJ_ESTERROR;
 
 	tmx.offset = (long)(offset * 1000000); /* usec */
 	if (SLEW_THRESHOLD < STEP_THRESHOLD) {
@@ -1740,6 +1740,7 @@
 
 	//tmx.esterror = (uint32_t)(clock_jitter * 1e6);
 	//tmx.maxerror = (uint32_t)((sys_rootdelay / 2 + sys_rootdisp) * 1e6);
+	tmx.maxerror = 0;
 	rc = adjtimex(&tmx);
 	if (rc < 0)
 		bb_simple_perror_msg_and_die("adjtimex");
