Merge "buildroot: Add Ghn init scripts"
diff --git a/fs/skeleton/etc/init.d/S45ghn.platform_gfiberlt b/fs/skeleton/etc/init.d/S45ghn.platform_gfiberlt
new file mode 100755
index 0000000..16ac013
--- /dev/null
+++ b/fs/skeleton/etc/init.d/S45ghn.platform_gfiberlt
@@ -0,0 +1,51 @@
+#! /bin/sh
+
+. /etc/utils.sh
+
+GHN_DIR="/tmp/ghn"
+GHN_MAC_ADDR_FILE="${GHN_DIR}/mac_addr"
+
+case "$1" in
+ start|"")
+ platform=$(cat /etc/platform)
+ if ! startswith "$platform" "GFLT4"; then
+ exit 0
+ fi
+
+ # Create Ghn directory and mac_addr file
+ mkdir -p "$GHN_DIR"
+
+ HNVRAM_MAC=$(hnvram -q -r MAC_ADDR_PON)
+ if [ -z "$HNVRAM_MAC" ]; then
+ echo "S45ghn: hnvram G.hn mac_addr is empty!"
+ exit 1
+ fi
+ echo "$HNVRAM_MAC" >"$GHN_MAC_ADDR_FILE"
+
+ # Bring up eth1 interface to ghn
+ ip link set up dev eth1
+ # ghn defaults to 10.10.1.69, we want to be on the same subnet
+ ip addr add 10.10.1.2/24 dev eth1
+
+ if ! read-ghn-local "NODE.GENERAL.ENABLE" 1>/dev/null; then
+ echo "S45ghn: Failed to read stats from G.hn: $HNVRAM_MAC"
+ exit 1
+ fi
+
+ # Periodically grab GHN stats and write to file
+ babysit 60 ghn-periodic-stats 2>&1 | logos ghn-periodic-stats &
+ ;;
+ stop)
+ pkillwait -f ghn-periodic-stats
+ ip addr del 10.10.1.2/24 dev eth1
+ ip link set down dev eth1
+ rm -rf "$GHN_DIR"
+ ;;
+ restart)
+ $0 stop; $0 start
+ ;;
+ *)
+ echo "Usage: S45ghn {start|stop|restart}" >&2
+ exit 1
+ ;;
+esac
diff --git a/fs/skeleton/usr/bin/ghn-periodic-stats.platform_gfiberlt b/fs/skeleton/usr/bin/ghn-periodic-stats.platform_gfiberlt
new file mode 100755
index 0000000..879d1b6
--- /dev/null
+++ b/fs/skeleton/usr/bin/ghn-periodic-stats.platform_gfiberlt
@@ -0,0 +1,63 @@
+#!/bin/sh
+
+. /etc/utils.sh
+
+GHN_DIR="/tmp/ghn"
+GHN_STATS_FILE="${GHN_DIR}/config"
+
+usage() {
+ echo "Usage:"
+ echo
+ echo " $0"
+ echo
+ echo " Repeatedly grabs up to date stats from G.hn chip using 'configlayer' "
+ echo " These stats are eventually used in catawampus' periodic statistics. "
+ echo
+ exit 99
+}
+
+platform=$(cat /etc/platform)
+if ! startswith "$platform" "GFLT4"; then
+ # Only GFLT400 has G.hn chip (Marvell's 88x5153)
+ exit 0
+fi
+
+if [ "$#" -ne "0" ]; then
+ usage
+fi
+
+GHN_MAC_ADDR=$(cat "$GHN_DIR"/mac_addr)
+while true; do
+ if configlayer -o GET -i eth1 -m "$GHN_MAC_ADDR" -w paterna \
+ -p NODE.GENERAL.ENABLE \
+ -p NTP.GENERAL.STATUS \
+ -p NODE.GENERAL.DEVICE_ALIAS \
+ -p NODE.GENERAL.DEVICE_NAME \
+ -p SYSTEM.PRODUCTION.DEVICE_NAME \
+ -p NODE.GENERAL.LAST_CHANGE \
+ -p SYSTEM.PRODUCTION.MAC_ADDR \
+ -p SYSTEM.GENERAL.API_VERSION \
+ -p SYSTEM.GENERAL.FW_VERSION \
+ -p SYSTEM.GENERAL.FW_VERSION_CORE \
+ -p NODE.GENERAL.DOMAIN_NAME \
+ -p NODE.GENERAL.DNI \
+ -p NODE.GENERAL.DOMAIN_ID \
+ -p NODE.GENERAL.DEVICE_ID \
+ -p NODE.GENERAL.NODE_TYPE \
+ -p SYSTEM.GENERAL.DOMAIN_MASTER_CAPABLE \
+ -p SYSTEM.GENERAL.SEC_CONTROLLER_CAPABLE \
+ -p SYSTEM.GENERAL.SEC_CONTROLLER_STATUS \
+ -p DIDMNG.GENERAL.NUM_DIDS \
+ -p DIDMNG.GENERAL.DIDS \
+ -p DIDMNG.GENERAL.MACS \
+ -p DIDMNG.GENERAL.TX_BPS \
+ -p DIDMNG.GENERAL.RX_BPS \
+ -p DIDMNG.GENERAL.ACTIVE \
+ > "${GHN_STATS_FILE}.tmp"; then
+ # Do write in two stages to preserve atomicity
+ mv "${GHN_STATS_FILE}.tmp" "$GHN_STATS_FILE"
+ else
+ echo "$0 failed to grab config from G.hn: $GHN_MAC_ADDR"
+ fi
+ sleep 60
+done
diff --git a/fs/skeleton/usr/bin/read-ghn-local.platform_gfiberlt b/fs/skeleton/usr/bin/read-ghn-local.platform_gfiberlt
new file mode 100755
index 0000000..a3988d1
--- /dev/null
+++ b/fs/skeleton/usr/bin/read-ghn-local.platform_gfiberlt
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+. /etc/utils.sh
+
+GHN_DIR="/tmp/ghn"
+
+usage() {
+ echo "Usage:"
+ echo
+ echo " $0 $1"
+ echo
+ echo " A wrapper for 'read-ghn-node' when querying the local G.hn node "
+ echo " Grabs a single paramater and prints the value. "
+ echo
+ exit 99
+}
+
+platform=$(cat /etc/platform)
+if ! startswith "$platform" "GFLT4"; then
+ # Only GFLT400 has G.hn chip (Marvell's 88x5153)
+ exit 0
+fi
+
+if [ "$#" -ne "1" ]; then
+ usage "$1"
+fi
+
+GHN_MAC_ADDR=$(cat "$GHN_DIR"/mac_addr)
+read-ghn-node "$GHN_MAC_ADDR" "$1"