VOL-455: Instructions for deployment of asfvolt16-driver on OLT

    Added asfvolt-bal-prepare.sh and asfvolt-bal-buildall.sh scripts
    Moved asfvolt- scripts to top level scripts directory
    Moved grpc patches used by scripts to patches directory
    Reverted device_simulator/README.md back to original bal_server instructions
    Improved src/README.md for detailed build instructions for ASFvOLT16 ONL, SDK and voltha_bal_driver

Change-Id: Ic747853debf54fb06a9455aaeadc2c6f24aff09d
diff --git a/scripts/asfvolt-bal-buildall.sh b/scripts/asfvolt-bal-buildall.sh
new file mode 100755
index 0000000..29bcbcf
--- /dev/null
+++ b/scripts/asfvolt-bal-buildall.sh
@@ -0,0 +1,48 @@
+#
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+#
+# Run from OpenNetworkLinux top directory INSIDE of onlbuilder docker workspace
+#
+#cd /aux/OpenNetworkLinux
+set -e
+
+# override shell variables to match custom local build environment
+: ${ONL_TOPDIR:=`pwd`}
+: ${MAKE_JOBS:=1}
+: ${BALSRC_RELEASE:=bal_src_release}
+: ${SWISDK_TARNAME:=sdk-all-6.5.7}
+
+echo ONL_TOPDIR=${ONL_TOPDIR}
+echo MAKE_JOBS=${MAKE_JOBS}
+echo BALSRC_RELEASE=${BALSRC_RELEASE}
+
+cd ${BALSRC_RELEASE}/bal_release
+make BOARD=asfvolt16 maple_sdk_dir
+make BOARD=asfvolt16 maple_sdk
+make BOARD=asfvolt16 switch_sdk_dir
+make BOARD=asfvolt16 switch_sdk
+
+pushd 3rdparty/bcm-sdk/build-asfvolt16/${SWISDK_TARNAME}/systems/linux/user/x86-generic_64-2_6
+KERNDIR=$ONL_TOPDIR/packages/base/amd64/kernels/kernel-3.7-x86-64-all/builds/linux-3.7.10 BOARD=asfvolt16 ARCH=x86_64 SDKBUILD=build_bcm_user make
+popd
+
+make BOARD=asfvolt16 bal
+make BOARD=asfvolt16 release_board
+
+ls -l 3rdparty/maple/cur/asfvolt16/release
+
+date
+echo "ASFvOLT16 build finished!"
diff --git a/scripts/asfvolt-bal-prepare.sh b/scripts/asfvolt-bal-prepare.sh
new file mode 100755
index 0000000..d3ed825
--- /dev/null
+++ b/scripts/asfvolt-bal-prepare.sh
@@ -0,0 +1,57 @@
+#
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+#
+# Run from OpenNetworkLinux top directory
+#
+#cd /aux/OpenNetworkLinux
+set -e
+
+# override shell variables to match custom local build environment
+: ${ONL_TOPDIR:=`pwd`}
+: ${BALSRC_RELEASE:=bal_src_release}
+: ${BALSRC_ZIPNAME:=SW-BCM68620_2_4_3_6.zip}
+: ${SWISDK_TARNAME:=sdk-all-6.5.7}
+
+: ${BROADCOM_DOWNLOAD_DIR:=${HOME}/broadcom/download}  # directory containing SW-BCM68620_2_4_x.zip
+: ${EDGECORE_DOWNLOAD_DIR:=${HOME}/edgecore/download}  # directory containing ASFvOLT16 patch file for BAL
+
+: ${PATCH_FILENAME:=BAL_2.4.3.6-V201709291146.patch}   # use latest know ASFvOLT16 patch file as default
+
+echo ONL_TOPDIR=${ONL_TOPDIR}
+echo BALSRC_RELEASE=${BALSRC_RELEASE}
+echo BALSRC_ZIPNAME=${BALSRC_ZIPNAME}
+echo SWISDK_TARNAME=${SWISDK_TARNAME}
+echo PATCH_FILENAME=${PATCH_FILENAME}
+echo BROADCOM_DOWNLOAD_DIR=${BROADCOM_DOWNLOAD_DIR}
+echo EDGECORE_DOWNLOAD_DIR=${EDGECORE_DOWNLOAD_DIR}
+
+mkdir -p $ONL_TOPDIR/${BALSRC_RELEASE}
+cd $ONL_TOPDIR/${BALSRC_RELEASE}
+
+unzip ${BROADCOM_DOWNLOAD_DIR}/${BALSRC_ZIPNAME}
+cp $BROADCOM_DOWNLOAD_DIR/${SWISDK_TARNAME}.tar.gz bal_release/3rdparty/bcm-sdk/
+
+cp $EDGECORE_DOWNLOAD_DIR/${PATCH_FILENAME}  .
+chmod -R 744 .
+patch -p1 < ${PATCH_FILENAME}
+
+mkdir -p bcm68620_release/asfvolt16/kernels
+cd bcm68620_release/asfvolt16/kernels
+ln -s ../../../../packages/base/amd64/kernels/kernel-3.7-x86-64-all/builds/linux-3.7.10 linux-3.7.10
+ln -s ../../../../packages/base/any/kernels/archives/linux-3.7.10.tar.xz linux-3.7.10.tar.xz
+ln -s ../../../../packages/base/any/kernels/3.7/configs/x86_64-all/x86_64-all.config x86_64-all.config
+
+echo "BAL build area prepared"
diff --git a/scripts/asfvolt-driver-build.sh b/scripts/asfvolt-driver-build.sh
new file mode 100755
index 0000000..7995fd6
--- /dev/null
+++ b/scripts/asfvolt-driver-build.sh
@@ -0,0 +1,200 @@
+#
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+#
+# Run from OpenNetworkLinux top directory
+#
+#cd /aux/OpenNetworkLinux
+set -e
+ASFVOLT_REPO_NAME=asfvolt16-driver
+: ${MAKE_JOBS:=4}
+
+# override shell variables to match custom local build environment
+: ${ONL_TOPDIR:=`pwd`}
+: ${BALSRC_RELEASE=bal_src_release}
+: ${VOLTHA_TOPDIR:=${HOME}/voltha/incubator/voltha}
+: ${BALSRC_TOPDIR:=${ONL_TOPDIR}/${BALSRC_RELEASE}/bal_release}
+: ${ASFSRC_TOPDIR:=${ONL_TOPDIR}/${ASFVOLT_REPO_NAME}/src}
+: ${DEVSIM_TOPDIR:=${ONL_TOPDIR}/${ASFVOLT_REPO_NAME}/device_simulator}
+: ${PATCHF_TOPDIR:=${ONL_TOPDIR}/${ASFVOLT_REPO_NAME}/patches}
+
+echo ONL_TOPDIR=${ONL_TOPDIR}
+echo MAKE_JOBS=${MAKE_JOBS}
+echo BALSRC_RELEASE=${BALSRC_RELEASE}
+echo VOLTHA_TOPDIR=${VOLTHA_TOPDIR}
+echo BALSRC_TOPDIR=${BALSRC_TOPDIR}
+echo ASFSRC_TOPDIR=${ASFSRC_TOPDIR}
+echo DEVSIM_TOPDIR=${DEVSIM_TOPDIR}
+echo PATCHF_TOPDIR=${PATCHF_TOPDIR}
+
+# archived ZIP files from "https://github.com/opennetworkinglab/asfvolt16-driver/tree/master/third_party"
+GRPC_ARCH=ed7d06af3eef1c27f10328c73b3ae3ab10d72b10
+GRPC_C_ARCH=be82ab1605717f33e2e0d3038996ea46d9efe25e
+PROTOBUF_ARCH=703cd8e11c8d34283d4c8bf869c61866e8211c9d
+PROTOBUF_C_ARCH=6a4f9a9a67c06769aaa9f65e8f89a56483271f5a
+
+# Note: removes existing directories: grpc, protobuf
+rm -rf grpc protobuf grpc-* protobuf-*
+
+#Clone asfvolt16-driver
+#    - The guide assumes that the asfvolt16-driver gerrit repo is cloned under the ONL toplevel directory:
+#    - git clone ssh://user@gerrit.opencord.org:29418/asfvolt16-driver ${HOME}/OpenNetworkLinux/asfvolt16-driver
+
+#git clone https://gerrit.opencord.org/${ASFVOLT_REPO_NAME} ${ONL_TOPDIR}/${ASFVOLT_REPO_NAME}
+
+#steps to install grpc
+#   - Download as zip "grpc", "grpc-c", "protobuf" and "protobuf-c" from "https://github.com/opennetworkinglab/asfvolt16-driver/tree/master/third_party"
+wget https://github.com/grpc/grpc/archive/${GRPC_ARCH}.zip
+wget https://github.com/Juniper/grpc-c/archive/${GRPC_C_ARCH}.zip
+wget https://github.com/google/protobuf/archive/${PROTOBUF_ARCH}.zip
+wget https://github.com/shadansari/protobuf-c/archive/${PROTOBUF_C_ARCH}.zip
+
+#   - extract grpc at ${HOME}/OpenNetworkLinux/grpc
+unzip -q ${GRPC_ARCH}.zip; rm ${GRPC_ARCH}.zip
+mv grpc-${GRPC_ARCH} grpc
+
+#   - extract grpc-c at ${HOME}/OpenNetworkLinux/grpc-c
+unzip -q ${GRPC_C_ARCH}.zip; rm ${GRPC_C_ARCH}.zip
+mv grpc-c-${GRPC_C_ARCH} grpc-c
+
+#   - extract protobuf at ${HOME}/OpenNetworkLinux/grpc/thirdparty/protobuf
+unzip -q ${PROTOBUF_ARCH}.zip; rm ${PROTOBUF_ARCH}.zip
+mkdir -p grpc/thirdparty
+mv protobuf-${PROTOBUF_ARCH} grpc/thirdparty/protobuf
+
+
+#   - extract protobuf-c folder at ${HOME}/OpenNetworkLinux/grpc-c/third_party/protobuf-c
+unzip -q ${PROTOBUF_C_ARCH}.zip; rm ${PROTOBUF_C_ARCH}.zip
+(cd protobuf-c-${PROTOBUF_C_ARCH};tar cf - .)|(cd grpc-c/third_party/protobuf-c;tar xf -)
+rm -rf protobuf-c-${PROTOBUF_C_ARCH}
+
+#steps to install grpc-c
+# cd ${HOME}/OpenNetworkLinux/grpc/thirdparty/protobuf
+#  - ./autogen.sh
+#  - ./configure
+#  - make
+#  - sudo make install
+cd ${ONL_TOPDIR}/grpc/thirdparty/protobuf
+./autogen.sh
+./configure
+make --jobs=${MAKE_JOBS}
+sudo make install
+
+# cd ${HOME}/OpenNetworkLinux/grpc
+# - export LD_LIBRARY_PATH=/usr/local/lib
+# - make
+# - sudo make install
+
+cd ${ONL_TOPDIR}/grpc
+export LD_LIBRARY_PATH=/usr/local/lib
+make --jobs=${MAKE_JOBS}
+sudo make install
+
+#cd ${HOME}/OpenNetworkLinux/grpc-c/third_party/protobuf-c
+#- ./autogen.sh
+#- ./configure
+#- export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/protobuf
+#- make
+#- sudo make install
+
+cd ${ONL_TOPDIR}/grpc-c/third_party/protobuf-c
+./autogen.sh
+./configure
+export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/protobuf
+make --jobs=${MAKE_JOBS}
+sudo make install
+
+#Apply grpc-c patch
+#   - cd ${HOME}/OpenNetworkLinux/grpc-c/
+cd ${ONL_TOPDIR}/grpc-c
+#     Patch 1:
+#     Apply patch in following link for grpc-c/lib - "https://github.com/Juniper/grpc-c/commit/353b40cd920cd749ed6cf71f8df17f1d5cf2c89d"
+#     Note:
+#        (This patch is having very few changes in two files(grpc-c/lib/client.c, grpc-c/lib/service.c. 
+#         Download these two files from above link and replace at grpc-c/lib or merge these changes manually.)       
+patch -p1 -i ${PATCHF_TOPDIR}/grpc-c_compile-error.patch
+
+#     Patch 2:
+#     Apply patch in service.c.patch and client.c.patch
+patch -p1 -i ${PATCHF_TOPDIR}/grpc-c_asfvolt16.patch
+
+#
+#     - cd ${HOME}/OpenNetworkLinux
+#     - cp asfvolt16-driver/device_simulator/Makefile.am grpc-c/examples/
+#     - cp asfvolt16-driver/device_simulator/voltha_bal_driver.c grpc-c/examples/
+#     - cp asfvolt16-driver/device_simulator/bal_stub.c grpc-c/examples/
+#     - cp asfvolt16-driver/device_simulator/bal_stub.h grpc-c/examples/
+#         - Note: Update voltha adaptor IP in bal_stub.c (Is this required? Not clear which variable needs to be updated).
+cd ${ONL_TOPDIR}
+cp ${DEVSIM_TOPDIR}/Makefile.am grpc-c/examples/
+cp ${DEVSIM_TOPDIR}/voltha_bal_driver.c grpc-c/examples/
+cp ${DEVSIM_TOPDIR}/bal_stub.c grpc-c/examples/
+cp ${DEVSIM_TOPDIR}/bal_stub.h grpc-c/examples/
+
+#
+#     - cd ${HOME}/OpenNetworkLinux/grpc-c
+#     - autoreconf --install
+#     - mkdir build && cd build
+#     - ../configure
+#     - make
+#     - sudo make install
+cd ${ONL_TOPDIR}/grpc-c
+autoreconf --install
+mkdir build && cd build
+../configure
+make --jobs=${MAKE_JOBS}
+sudo make install
+
+#To obtain proto files - Have a repo sync of opencord voltha code base:
+#     - git clone https://github.com/opencord/voltha.git ${HOME}/voltha
+#     - cd ${HOME}/OpenNetworkLinux/grpc-c/
+#     - cp ${HOME}/voltha/voltha/adapters/asfvolt16_olt/protos/* examples/
+#
+cd ${ONL_TOPDIR}/grpc-c
+cp ${VOLTHA_TOPDIR}/voltha/adapters/asfvolt16_olt/protos/* examples
+
+#To autogenerate code from proto files:
+#     - cd ${HOME}/OpenNetworkLinux/grpc-c/build/examples
+#     - make autogen
+cd ${ONL_TOPDIR}/grpc-c/build/examples
+make autogen
+
+#
+#Build voltha_bal_driver:
+#     - cd ${HOME}/OpenNetworkLinux/grpc-c/build/examples
+#     - Note: Remove "-O2" from Makefile
+#     - Note: Set EDGECORE and BRCM_PATH in Makefile
+cd ${ONL_TOPDIR}/grpc-c/build/examples
+sed -i -e 's/-O2/-O0/g' \
+       -e "s:^EDGECORE = /home/asfvolt/shared.*:#&\nEDGECORE = ${ASFSRC_TOPDIR}:" \
+       -e "s:^BRCM_PATH = /home/asfvolt/shared.*:#&\nBRCM_PATH = ${BALSRC_TOPDIR}:" \
+        Makefile
+
+pushd ${ASFSRC_TOPDIR}
+sed -i -e "s:^BRDCM_SRC=/home/asfvolt/shared.*:#&\nBRDCM_SRC = ${BALSRC_TOPDIR}:" \
+       -e "s:^GRPC_C_PATH= /home/asfvolt/shared.*:#&\nGRPC_C_PATH = ${ONL_TOPDIR}/grpc-c:" \
+        Makefile
+popd
+#```
+#       EDGECORE = ${HOME}/OpenNetworkLinux/asfvolt16-driver/src/
+#       BRCM_PATH = ${HOME}/OpenNetworkLinux/bal_src_release/bal_release
+#```
+#     - make clean_all;make
+make clean_all
+make
+#
+#The ultimate executable voltha_bal_driver can be found under ~/grpc-c/build/examples/.libs/
+
+echo "${ASFVOLT_REPO_NAME} build complete"
diff --git a/scripts/asfvolt-driver-package.sh b/scripts/asfvolt-driver-package.sh
new file mode 100755
index 0000000..b71ed01
--- /dev/null
+++ b/scripts/asfvolt-driver-package.sh
@@ -0,0 +1,82 @@
+#
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+#
+
+# Run from OpenNetworkLinux top directory
+#
+#cd /aux/OpenNetworkLinux
+set -e
+ASFVOLT_REPO_NAME=asfvolt16-driver
+
+# override shell variables to match custom local build environment
+: ${ONL_TOPDIR:=`pwd`}
+: ${BALSRC_RELEASE:=bal_src_release}
+: ${BALREL_TOPDIR:=${ONL_TOPDIR}/${BALSRC_RELEASE}}
+: ${BALSRC_TOPDIR:=${ONL_TOPDIR}/${BALSRC_RELEASE}/bal_release}
+: ${ASFDRVR_PKGDIR:=${ONL_TOPDIR}/asfdrvr-package-dir}
+: ${ASFDVR_TARBALL_NAME:=asfvolt16-voltha-bal}
+: ${BUILD_FILENAME_TAG:=`date +%Y%m%d%H%M`}
+: ${ASFDVR_TARBALL_FNAME:=${ASFDVR_TARBALL_NAME}-${BUILD_FILENAME_TAG}.tgz}
+
+echo ONL_TOPDIR=${ONL_TOPDIR}
+echo BALSRC_RELEASE=${BALSRC_RELEASE}
+echo BALREL_TOPDIR=${BALREL_TOPDIR}
+echo BALSRC_TOPDIR=${BALSRC_TOPDIR}
+echo ASFDRVR_PKGDIR=${ASFDRVR_PKGDIR}
+echo ASFDVR_TARBALL_NAME=${ASFDVR_TARBALL_NAME}
+echo BUILD_FILENAME_TAG=${BUILD_FILENAME_TAG}
+echo ASFDVR_TARBALL_FNAME=${ASFDVR_TARBALL_FNAME}
+
+# Note: removes existing directories: asfvolt16-driver, grpc, protobuf
+rm -rf ${ASFDRVR_PKGDIR}
+
+
+mkdir -p ${ASFDRVR_PKGDIR}
+cd ${ASFDRVR_PKGDIR}
+
+#extract ASFvOLT16 BAL/Maple built release tarball
+tar zxf ${BALREL_TOPDIR}/bcm68620_release/asfvolt16/release/release_asfvolt16_V*.tar.gz
+
+# voltha_bal_driver and grpc/protobufs live in /broadcom dir on ASFvOLT16 target
+cd broadcom
+
+# add grpc-c libs
+cp -pR ${ONL_TOPDIR}/grpc-c/build/lib/.libs/libgrpc-c.so.0.0.0 .
+ln -s /broadcom/libgrpc-c.so.0.0.0 libgrpc-c.so.0
+ln -s /broadcom/libgrpc-c.so.0.0.0 libgrpc-c.so
+
+# add grpc libs
+cp -pR ${ONL_TOPDIR}/grpc/libs/opt/libgrp*.so* .
+cp -pR ${ONL_TOPDIR}/grpc/libs/opt/libgpr*.so* .
+
+# add protobuf-c libs
+cp -pR ${ONL_TOPDIR}/grpc-c/third_party/protobuf-c/protobuf-c/.libs/libprotobuf-c.so* .
+
+# add protobuf libs
+cp -pR ${ONL_TOPDIR}/grpc/thirdparty/protobuf/src/.libs/libprotobuf.so* .
+cp -pR ${ONL_TOPDIR}/grpc/thirdparty/protobuf/src/.libs/libprotobuf-lite.so* .
+cp -pR ${ONL_TOPDIR}/grpc/thirdparty/protobuf/src/.libs/libprotoc.so* .
+rm *.0T
+
+# add voltha_bal_driver
+cp -pR ${ONL_TOPDIR}/grpc-c/build/examples/.libs/voltha_bal_driver .
+
+#extract ASFvOLT16 BAL/Maple built release tarball
+cd ..
+tar cvzf ${ASFDVR_TARBALL_FNAME} broadcom opt
+
+ls -l `pwd`/${ASFDVR_TARBALL_FNAME}
+echo "${ASFVOLT_REPO_NAME} package build complete"