ASR_BASE
Change-Id: Icf3719cc0afe3eeb3edc7fa80a2eb5199ca9dda1
diff --git a/external/subpack/net/linuxptp/patches/001-fix_kbuild_output.patch b/external/subpack/net/linuxptp/patches/001-fix_kbuild_output.patch
new file mode 100644
index 0000000..a43e511
--- /dev/null
+++ b/external/subpack/net/linuxptp/patches/001-fix_kbuild_output.patch
@@ -0,0 +1,11 @@
+--- a/incdefs.sh
++++ b/incdefs.sh
+@@ -152,7 +152,7 @@ user_flags()
+ kernel_flags()
+ {
+ prefix=""
+- tstamp=/usr/include/linux/net_tstamp.h
++ tstamp=/include/uapi/linux/net_tstamp.h
+ ptp_clock=/usr/include/linux/ptp_clock.h
+ if_team=/usr/include/linux/if_team.h
+
diff --git a/external/subpack/net/linuxptp/patches/010-64bit.patch b/external/subpack/net/linuxptp/patches/010-64bit.patch
new file mode 100644
index 0000000..3529978
--- /dev/null
+++ b/external/subpack/net/linuxptp/patches/010-64bit.patch
@@ -0,0 +1,12 @@
+--- a/ts2phc_pps_sink.c
++++ b/ts2phc_pps_sink.c
+@@ -4,6 +4,9 @@
+ * @note Copyright (C) 2019 Balint Ferencz <fernya@sch.bme.hu>
+ * @note SPDX-License-Identifier: GPL-2.0+
+ */
++#ifndef __SANE_USERSPACE_TYPES__
++#define __SANE_USERSPACE_TYPES__ /* For PPC64, to get LL64 types */
++#endif
+ #include <errno.h>
+ #include <linux/ptp_clock.h>
+ #include <poll.h>
diff --git a/external/subpack/net/linuxptp/patches/010-support_pps_as_ptp_master.patch b/external/subpack/net/linuxptp/patches/010-support_pps_as_ptp_master.patch
new file mode 100644
index 0000000..3340bed
--- /dev/null
+++ b/external/subpack/net/linuxptp/patches/010-support_pps_as_ptp_master.patch
@@ -0,0 +1,137 @@
+--- a/config.c
++++ b/config.c
+@@ -244,6 +244,7 @@ struct config_item config_tab[] = {
+ PORT_ITEM_INT("fault_badpeernet_interval", 16, INT32_MIN, INT32_MAX),
+ PORT_ITEM_INT("fault_reset_interval", 4, INT8_MIN, INT8_MAX),
+ GLOB_ITEM_DBL("first_step_threshold", 0.00002, 0.0, DBL_MAX),
++ GLOB_ITEM_DBL("integral_threshold", 0.0, 0.0, DBL_MAX),
+ PORT_ITEM_INT("follow_up_info", 0, 0, 1),
+ GLOB_ITEM_INT("free_running", 0, 0, 1),
+ PORT_ITEM_INT("freq_est_interval", 1, 0, INT_MAX),
+--- a/phc2sys.c
++++ b/phc2sys.c
+@@ -692,6 +692,7 @@ static int do_pps_loop(struct phc2sys_pr
+
+ if (update_pmc(priv, 0) < 0)
+ continue;
++
+ update_clock(priv, clock, pps_offset, pps_ts, -1);
+ }
+ close(fd);
+@@ -1340,6 +1341,7 @@ static void usage(char *progname)
+ " -I [ki] integration constant (0.3)\n"
+ " -S [step] step threshold (disabled)\n"
+ " -F [step] step threshold only on start (0.00002)\n"
++ " -B [step] Integral separation threshold(0.0)\n"
+ " -R [rate] slave clock update rate in HZ (1.0)\n"
+ " -N [num] number of master clock readings per update (5)\n"
+ " -L [limit] sanity frequency limit in ppb (200000000)\n"
+@@ -1388,7 +1390,7 @@ int main(int argc, char *argv[])
+ progname = strrchr(argv[0], '/');
+ progname = progname ? 1+progname : argv[0];
+ while (EOF != (c = getopt_long(argc, argv,
+- "arc:d:f:s:E:P:I:S:F:R:N:O:L:M:i:u:wn:xz:l:t:mqvh",
++ "arc:d:f:s:E:P:I:S:F:B:R:N:O:L:M:i:u:wn:xz:l:t:mqvh",
+ opts, &index))) {
+ switch (c) {
+ case 0:
+@@ -1459,6 +1461,11 @@ int main(int argc, char *argv[])
+ config_set_double(cfg, "first_step_threshold", tmp))
+ goto end;
+ break;
++ case 'B':
++ if (get_arg_val_d(c, optarg, &tmp, 0.0, DBL_MAX) ||
++ config_set_double(cfg, "integral_threshold", tmp))
++ goto end;
++ break;
+ case 'R':
+ if (get_arg_val_d(c, optarg, &phc_rate, 1e-9, DBL_MAX))
+ goto end;
+@@ -1618,12 +1625,14 @@ int main(int argc, char *argv[])
+ dst->state = PS_MASTER;
+ LIST_INSERT_HEAD(&priv.dst_clocks, dst, dst_list);
+
++ /* Comment out to allow adjust frequency of /dev/ptpX with PPS sginal */
++#if 0
+ if (pps_fd >= 0 && dst->clkid != CLOCK_REALTIME) {
+ fprintf(stderr,
+ "cannot use a pps device unless destination is CLOCK_REALTIME\n");
+ goto bad_usage;
+ }
+-
++#endif
+ r = -1;
+
+ if (wait_sync) {
+--- a/pi.c
++++ b/pi.c
+@@ -83,7 +83,7 @@ static double pi_sample(struct servo *se
+ s->local[1] = local_ts;
+
+ /* Make sure the first sample is older than the second. */
+- if (s->local[0] >= s->local[1]) {
++ if (s->local[0] > s->local[1]) {
+ *state = SERVO_UNLOCKED;
+ s->count = 0;
+ break;
+@@ -137,8 +137,16 @@ static double pi_sample(struct servo *se
+ break;
+ }
+
+- ki_term = s->ki * offset * weight;
+- ppb = s->kp * offset * weight + s->drift + ki_term;
++ /* Integral separation PID algorithm if enable integral_threshold */
++ if (servo->integral_threshold &&
++ servo->integral_threshold < llabs(offset)) {
++ ki_term = 0;
++ ppb = s->kp * offset * weight;
++ } else {
++ ki_term = s->ki * offset * weight;
++ ppb = s->kp * offset * weight + s->drift + ki_term;
++ }
++
+ if (ppb < -servo->max_frequency) {
+ ppb = -servo->max_frequency;
+ } else if (ppb > servo->max_frequency) {
+@@ -146,6 +154,7 @@ static double pi_sample(struct servo *se
+ } else {
+ s->drift += ki_term;
+ }
++
+ *state = SERVO_LOCKED;
+ break;
+ }
+--- a/servo_private.h
++++ b/servo_private.h
+@@ -27,6 +27,7 @@
+ struct servo {
+ double max_frequency;
+ double step_threshold;
++ double integral_threshold;
+ double first_step_threshold;
+ int first_update;
+ int64_t offset_threshold;
+--- a/servo.c
++++ b/servo.c
+@@ -35,6 +35,7 @@ struct servo *servo_create(struct config
+ {
+ double servo_first_step_threshold;
+ double servo_step_threshold;
++ double integral_threshold;
+ int servo_max_frequency;
+ struct servo *servo;
+
+@@ -65,6 +66,13 @@ struct servo *servo_create(struct config
+ servo->step_threshold = 0.0;
+ }
+
++ integral_threshold = config_get_double(cfg, NULL, "integral_threshold");
++ if (integral_threshold > 0.0) {
++ servo->integral_threshold = integral_threshold * NSEC_PER_SEC;
++ } else {
++ servo->integral_threshold = 0.0;
++ }
++
+ servo_first_step_threshold =
+ config_get_double(cfg, NULL, "first_step_threshold");
+
diff --git a/external/subpack/net/linuxptp/patches/020-allow-disabling-MAC-autodetection.patch b/external/subpack/net/linuxptp/patches/020-allow-disabling-MAC-autodetection.patch
new file mode 100644
index 0000000..ce71480
--- /dev/null
+++ b/external/subpack/net/linuxptp/patches/020-allow-disabling-MAC-autodetection.patch
@@ -0,0 +1,195 @@
+Date: Sun, 15 Sep 2024 18:41:20 +0800
+To: linuxptp-devel@lists.nwtime.org
+From: Shenghao Yang <me@shenghaoyang.info>
+Subject: [PATCH] sad: allow disabling MAC library autodetection
+
+Avoids ptp4l linking against MAC libraries in a build
+environment with insufficient isolation (OpenWRT).
+
+NO_AUTODETECT_SAD_MAC_LIB can be set to any value to disable
+autodetection, and then one of the SAD_MAC_* variables can be
+used to choose a preferred MAC implementation.
+
+Signed-off-by: Shenghao Yang <me@shenghaoyang.info>
+---
+ incdefs.sh | 154 ++++++++++++++++++++++++++++-------------------------
+ 1 file changed, 81 insertions(+), 73 deletions(-)
+
+--- a/incdefs.sh
++++ b/incdefs.sh
+@@ -52,94 +52,102 @@ user_flags()
+ done
+
+ # Look for nettle support.
+- for d in $dirs; do
+- sdirs=$(find $d -type d -name "nettle")
+- for s in $sdirs; do
+- have_hmac="0"
+- files=$(find $s -type f -name hmac.h)
+- for f in $files; do
+- if grep -q hmac_sha256_set_key $f; then
+- have_hmac="1"
+- break 1;
+- fi
+- done
+- have_memops="0"
+- files=$(find $s -type f -name memops.h)
+- for f in $files; do
+- if grep -q memeql_sec $f; then
+- have_memops="1"
+- break 1;
+- fi
+- done
+- have_nettle_meta="0"
+- files=$(find $s -type f -name nettle-meta.h)
+- for f in $files; do
+- if grep -q nettle_get_macs $f; then
+- have_nettle_meta="1"
+- break 1;
++ if [ "x$NO_AUTODETECT_SAD_MAC_LIB" = "x" ] || [ "x$SAD_MAC_NETTLE" != "x" ]; then
++ for d in $dirs; do
++ sdirs=$(find $d -type d -name "nettle")
++ for s in $sdirs; do
++ have_hmac="0"
++ files=$(find $s -type f -name hmac.h)
++ for f in $files; do
++ if grep -q hmac_sha256_set_key $f; then
++ have_hmac="1"
++ break 1;
++ fi
++ done
++ have_memops="0"
++ files=$(find $s -type f -name memops.h)
++ for f in $files; do
++ if grep -q memeql_sec $f; then
++ have_memops="1"
++ break 1;
++ fi
++ done
++ have_nettle_meta="0"
++ files=$(find $s -type f -name nettle-meta.h)
++ for f in $files; do
++ if grep -q nettle_get_macs $f; then
++ have_nettle_meta="1"
++ break 1;
++ fi
++ done
++ if [ $have_hmac = "1" ] &&
++ [ $have_memops = "1" ] &&
++ [ $have_nettle_meta = "1" ]; then
++ printf " -DHAVE_NETTLE"
++ break 2
+ fi
+ done
+- if [ $have_hmac = "1" ] &&
+- [ $have_memops = "1" ] &&
+- [ $have_nettle_meta = "1" ]; then
+- printf " -DHAVE_NETTLE"
+- break 2
+- fi
+ done
+- done
++ fi
+
+ # Look for gnutls support.
+- for d in $dirs; do
+- sdirs=$(find $d -type d -name "gnutls")
+- for s in $sdirs; do
+- files=$(find $s -type f -name crypto.h)
+- for f in $files; do
+- if grep -q gnutls_hmac_init $f; then
+- printf " -DHAVE_GNUTLS"
+- break 3
+- fi
++ if [ "x$NO_AUTODETECT_SAD_MAC_LIB" = "x" ] || [ "x$SAD_MAC_GNUTLS" != "x" ]; then
++ for d in $dirs; do
++ sdirs=$(find $d -type d -name "gnutls")
++ for s in $sdirs; do
++ files=$(find $s -type f -name crypto.h)
++ for f in $files; do
++ if grep -q gnutls_hmac_init $f; then
++ printf " -DHAVE_GNUTLS"
++ break 3
++ fi
++ done
+ done
+ done
+- done
++ fi
+
+ # Look for gnupg support.
+- for d in $dirs; do
+- files=$(find $d -type f -name gcrypt.h)
+- for f in $files; do
+- if grep -q gcry_mac_open $f; then
+- printf " -DHAVE_GNUPG"
+- break 2
+- fi
++ if [ "x$NO_AUTODETECT_SAD_MAC_LIB" = "x" ] || [ "x$SAD_MAC_GNUPG" != "x" ]; then
++ for d in $dirs; do
++ files=$(find $d -type f -name gcrypt.h)
++ for f in $files; do
++ if grep -q gcry_mac_open $f; then
++ printf " -DHAVE_GNUPG"
++ break 2
++ fi
++ done
+ done
+- done
++ fi
+
+ # Look for openssl support.
+- for d in $dirs; do
+- sdirs=$(find $d -type d -name "openssl")
+- for s in $sdirs; do
+- have_crypto="0"
+- files=$(find $s -type f -name crypto.h)
+- for f in $files; do
+- if grep -q CRYPTO_memcmp $f; then
+- have_crypto="1"
+- break 1;
++ if [ "x$NO_AUTODETECT_SAD_MAC_LIB" = "x" ] || [ "x$SAD_MAC_OPENSSL" != "x" ]; then
++ for d in $dirs; do
++ sdirs=$(find $d -type d -name "openssl")
++ for s in $sdirs; do
++ have_crypto="0"
++ files=$(find $s -type f -name crypto.h)
++ for f in $files; do
++ if grep -q CRYPTO_memcmp $f; then
++ have_crypto="1"
++ break 1;
++ fi
++ done
++ have_evp="0"
++ files=$(find $s -type f -name evp.h)
++ for f in $files; do
++ if grep -q EVP_MAC_init $f; then
++ have_evp="1"
++ break 1;
++ fi
++ done
++ if [ $have_crypto = "1" ] &&
++ [ $have_evp = "1" ]; then
++ printf " -DHAVE_OPENSSL"
++ break 2
+ fi
+ done
+- have_evp="0"
+- files=$(find $s -type f -name evp.h)
+- for f in $files; do
+- if grep -q EVP_MAC_init $f; then
+- have_evp="1"
+- break 1;
+- fi
+- done
+- if [ $have_crypto = "1" ] &&
+- [ $have_evp = "1" ]; then
+- printf " -DHAVE_OPENSSL"
+- break 2
+- fi
+ done
+- done
++ fi
+ }
+
+ #