Add flash support for boards using latest SDK

Using the latest SDK (0.7.2) you can flash directly using make
by specifying the board, for example

make BOARD=arduino_101 flash

This will build and flash the generated binary to the board.

Change-Id: I90254abd69874efbb449ef318079958980c23074
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
diff --git a/scripts/support/openocd.sh b/scripts/support/openocd.sh
new file mode 100644
index 0000000..b70fa1e
--- /dev/null
+++ b/scripts/support/openocd.sh
@@ -0,0 +1,53 @@
+#!/bin/sh
+
+OPENOCD_CMD="${OPENOCD:-openocd} -s ${OPENOCD_DEFAULT_PATH}"
+OPENOCD_CONFIG=${ZEPHYR_BASE}/boards/${BOARD_NAME}/support/openocd.cfg
+BIN_NAME=${O}/${KERNEL_BIN_NAME}
+
+test_config() {
+    if [ ! -f "${OPENOCD_CONFIG}" ]; then
+        echo "Error: Unable to locate OpenOCD configuration file: ${OPENOCD_CONFIG}"
+        exit 1
+    fi
+    if [ ! -f "${OPENOCD}" ]; then
+        echo "Error: Unable to locate OpenOCD executable: ${OPENOCD}"
+        exit 1
+    fi
+}
+
+test_bin() {
+    if [ ! -f "${BIN_NAME}" ]; then
+        echo "Error: Unable to locate image binary: ${BIN_NAME}"
+        exit 1
+    fi
+}
+
+do_flash() {
+    test_config
+    test_bin
+
+    # flash device with specified image
+    sh -c  "${OPENOCD_CMD} -f '${OPENOCD_CONFIG}' \
+            -c 'init' \
+            -c 'targets' \
+            ${OPENOCD_PRE_CMD} \
+            -c 'reset halt' \
+            -c ${OPENOCD_LOAD_CMD} \
+            -c 'reset halt' \
+            -c ${OPENOCD_VERIFY_CMD} \
+            ${OPENOCD_POST_CMD} \
+            -c 'reset run' \
+            -c 'shutdown'"
+    echo 'Done flashing'
+}
+
+
+CMD="$1"
+shift
+
+case "${CMD}" in
+  flash)
+    echo "Flashing Target Device"
+    do_flash "$@"
+    ;;
+esac