VOL-515: Allow ASFVOLT16 OLT Software to boot up and start autonomously

added startup script to release package
start BAL and voltha_bal_driver components

Change-Id: I1e127cf6b4d17679dc1b89b493f30ad6ec181afe
diff --git a/scripts/asfvolt-driver-package.sh b/scripts/asfvolt-driver-package.sh
index b71ed01..71ee2aa 100755
--- a/scripts/asfvolt-driver-package.sh
+++ b/scripts/asfvolt-driver-package.sh
@@ -26,6 +26,7 @@
 : ${BALSRC_RELEASE:=bal_src_release}
 : ${BALREL_TOPDIR:=${ONL_TOPDIR}/${BALSRC_RELEASE}}
 : ${BALSRC_TOPDIR:=${ONL_TOPDIR}/${BALSRC_RELEASE}/bal_release}
+: ${ASFSCR_TOPDIR:=${ONL_TOPDIR}/${ASFVOLT_REPO_NAME}/scripts}
 : ${ASFDRVR_PKGDIR:=${ONL_TOPDIR}/asfdrvr-package-dir}
 : ${ASFDVR_TARBALL_NAME:=asfvolt16-voltha-bal}
 : ${BUILD_FILENAME_TAG:=`date +%Y%m%d%H%M`}
@@ -35,6 +36,7 @@
 echo BALSRC_RELEASE=${BALSRC_RELEASE}
 echo BALREL_TOPDIR=${BALREL_TOPDIR}
 echo BALSRC_TOPDIR=${BALSRC_TOPDIR}
+echo ASFSCR_TOPDIR=${ASFSCR_TOPDIR}
 echo ASFDRVR_PKGDIR=${ASFDRVR_PKGDIR}
 echo ASFDVR_TARBALL_NAME=${ASFDVR_TARBALL_NAME}
 echo BUILD_FILENAME_TAG=${BUILD_FILENAME_TAG}
@@ -74,6 +76,9 @@
 # add voltha_bal_driver
 cp -pR ${ONL_TOPDIR}/grpc-c/build/examples/.libs/voltha_bal_driver .
 
+# add voltha driver startup scripts
+cp -p ${ASFSCR_TOPDIR}/voltha_init_sh voltha_init.sh
+
 #extract ASFvOLT16 BAL/Maple built release tarball
 cd ..
 tar cvzf ${ASFDVR_TARBALL_FNAME} broadcom opt
diff --git a/scripts/voltha_init_sh b/scripts/voltha_init_sh
new file mode 100644
index 0000000..daa465f
--- /dev/null
+++ b/scripts/voltha_init_sh
@@ -0,0 +1,49 @@
+#!/bin/sh -e
+#
+# add these lines to ASFvOLT16 /etc/rc.local
+#    /opt/bcm68620/svk_init.sh
+#    /broadcom/voltha_init.sh
+#
+cd /broadcom
+
+if [ -f ./voltha_config ]; then
+	. ./voltha_config
+fi
+
+LD_LIBRARY_PATH=/broadcom
+export LD_LIBRARY_PATH
+
+if [ "${MGMT_IFACE}" = "" ]
+then
+	MGMT_IFACE=ma1
+fi
+if [ "${VOLTHA_LOCIP}" = "" ]
+then
+	VOLTHA_LOCIP=$(ifconfig "$MGMT_IFACE" | grep "inet addr" | cut -d : -f 2 | cut -d ' ' -f 1)
+fi
+echo VOLTHA_LOCIP="${VOLTHA_LOCIP}"
+
+if [ "${CONSOLE_DEVOUT}" = "" ]
+then
+	CONSOLE_DEVOUT=/dev/console
+fi
+echo CONSOLE_DEVOUT="${CONSOLE_DEVOUT}"
+
+if [ "${CONSOLE_DEVINP}" = "" ]
+then
+	CONSOLE_DEVINP=/dev/tty1
+fi
+echo CONSOLE_DEVINP="${CONSOLE_DEVINP}"
+
+if [ "${FAN_RATE}" = "" ]
+then
+	FAN_RATE=70
+fi
+echo FAN_RATE="${FAN_RATE}"
+echo "${FAN_RATE}" > /sys/devices/pci0000:00/0000:00:1f.3/i2c-0/i2c-1/i2c-9/9-0066/fan_duty_cycle_percentage
+
+echo Starting distributed BAL server
+./bal_core_dist -ne -C ${VOLTHA_LOCIP}:40000 -A ${VOLTHA_LOCIP}:50000 2>${CONSOLE_DEVOUT} <${CONSOLE_DEVINP} &
+sleep 1
+echo Starting VOLTHA BAL driver
+./voltha_bal_driver ${VOLTHA_LOCIP}:50060 -C ${VOLTHA_LOCIP}:40000 -A ${VOLTHA_LOCIP}:50000 2>${CONSOLE_DEVOUT} <${CONSOLE_DEVINP} &
diff --git a/src/README.md b/src/README.md
index a63e11a..2aa887f 100644
--- a/src/README.md
+++ b/src/README.md
@@ -116,6 +116,38 @@
 asfvolt16-voltha-bal-201710051908.tgz  broadcom  opt
 ```
 
+### Install `voltha_bal_driver` BAL release tarball
+
+Transfer BAL release tarball to ASFvOLT16:
+
+```
+    > cp asfdrvr-package-dir/asfvolt16-voltha-bal-201710231906.tgz  root@<ASFvOLT16_IP>:.
+```
+
+Install release tarball on ASFvOLT16:
+
+```
+    > ssh root@<ASFvOLT16_IP>
+    Enter passphrase for key '/home/kimk/.ssh/id_rsa':
+    root@192.168.140.72's password: onl
+    Last login: Tue Oct 24 11:00:48 2017 from 192.168.140.32
+
+    root@localhost:~# ls
+    asfvolt16-voltha-bal-201710231906.tgz
+    root@localhost:~# cd /
+    root@localhost:/# mv /broadcom /broadcom.prev
+    root@localhost:/# mv /opt/bcm68620/ /opt/bcm68620.prev
+    root@localhost:/# tar zxf ~/asfvolt16-voltha-bal-201710231906.tgz
+    root@localhost:/# tail -5 /etc/rc.local # ensure rc.local has the following lines
+    # By default this script does nothing.
+
+    /opt/bcm68620/svk_init.sh
+    /broadcom/voltha_init.sh
+    exit 0
+
+    root@localhost:/# shutdown -r now
+```
+
 USAGE:
     ./voltha_bal_driver "serverIP:port1" -C "serverIP:port2" -A "serverIP:port3"
     ./bal_core_dist -C "serverIP:port2" -A "serverIP:port3"