[scripts] Add common script for flashing AVB compatible boards

TEST: flash and boot mt8167_ref
Change-Id: I56a8762c8fab65e298bdd6532791e1e31a19e24e
diff --git a/scripts/flash-avb b/scripts/flash-avb
new file mode 100755
index 0000000..be861d3
--- /dev/null
+++ b/scripts/flash-avb
@@ -0,0 +1,43 @@
+#!/usr/bin/env bash
+
+# Copyright 2018 The Fuchsia Authors
+#
+# Use of this source code is governed by a MIT-style
+# license that can be found in the LICENSE file or at
+# https://opensource.org/licenses/MIT
+
+DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+
+BUILD_DIR="${DIR}/../build-arm64"
+
+function HELP {
+    echo "help:"
+    echo "-b <board>            : Board to flash"
+    echo "-h for help"
+    exit 1
+}
+
+BOARD=
+
+while getopts "b:h:" FLAG; do
+    case $FLAG in
+        b) BOARD="${OPTARG}";;
+        h) HELP;;
+        \?)
+            echo unrecognized option
+            HELP
+            ;;
+    esac
+done
+shift $((OPTIND-1))
+
+
+if [[ -z "${BOARD}" ]]; then
+    echo must specify a board to flash
+    HELP
+fi
+
+BOOT_IMG=${BUILD_DIR}/${BOARD}-boot.img
+VBMETA_IMG=${BUILD_DIR}/${BOARD}-vbmeta.img
+
+fastboot flash boot_a ${BOOT_IMG} && fastboot flash vbmeta_a ${VBMETA_IMG} && fastboot reboot
diff --git a/scripts/flash-imx8mevk b/scripts/flash-imx8mevk
index 923450c..b1e2ae8 100755
--- a/scripts/flash-imx8mevk
+++ b/scripts/flash-imx8mevk
@@ -7,9 +7,5 @@
 # https://opensource.org/licenses/MIT
 
 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
-BUILD_DIR="${DIR}/../build-arm64"
 
-BOOT_IMG=${BUILD_DIR}/imx8mevk-boot.img
-VBMETA_IMG=${BUILD_DIR}/imx8mevk-vbmeta.img
-
-fastboot flash boot_a ${BOOT_IMG} && fastboot flash vbmeta_a ${VBMETA_IMG} && fastboot reboot
+exec $DIR/flash-avb -b imx8mevk
diff --git a/scripts/flash-mt8167s_ref b/scripts/flash-mt8167s_ref
index 61beccf..d85d5c0 100755
--- a/scripts/flash-mt8167s_ref
+++ b/scripts/flash-mt8167s_ref
@@ -7,9 +7,5 @@
 # https://opensource.org/licenses/MIT
 
 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
-BUILD_DIR="${DIR}/../build-arm64"
 
-BOOT_IMG=${BUILD_DIR}/mt8167s_ref-boot.img
-VBMETA_IMG=${BUILD_DIR}/mt8167s_ref-vbmeta.img
-
-fastboot flash boot_a ${BOOT_IMG} && fastboot flash vbmeta_a ${VBMETA_IMG} && fastboot reboot
+exec $DIR/flash-avb -b mt8167s_ref