You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2016/11/03 21:17:30 UTC

[1/5] incubator-mynewt-core git commit: nucleo download; use /bin/sh, not /bin/bash.

Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/develop fc267d699 -> 68410ce4f


nucleo download; use /bin/sh, not /bin/bash.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/77a5ab40
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/77a5ab40
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/77a5ab40

Branch: refs/heads/develop
Commit: 77a5ab406a8e5743accc62008407938b66c42895
Parents: fc267d6
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Thu Nov 3 12:44:49 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu Nov 3 12:44:49 2016 -0700

----------------------------------------------------------------------
 hw/bsp/nucleo-f401re/nucleo-f401re_download.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/77a5ab40/hw/bsp/nucleo-f401re/nucleo-f401re_download.sh
----------------------------------------------------------------------
diff --git a/hw/bsp/nucleo-f401re/nucleo-f401re_download.sh b/hw/bsp/nucleo-f401re/nucleo-f401re_download.sh
index d752ba9..e4e2ab9 100755
--- a/hw/bsp/nucleo-f401re/nucleo-f401re_download.sh
+++ b/hw/bsp/nucleo-f401re/nucleo-f401re_download.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 # Licensed to the Apache Software Foundation (ASF) under one
 # or more contributor license agreements.  See the NOTICE file
 # distributed with this work for additional information


[5/5] incubator-mynewt-core git commit: MYNEWT-418; use the updated openocd functions.

Posted by ma...@apache.org.
MYNEWT-418; use the updated openocd functions.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/68410ce4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/68410ce4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/68410ce4

Branch: refs/heads/develop
Commit: 68410ce4fdfe91f2920c68a6d0f7ab1b4f2dd995
Parents: 5e734a3
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Thu Nov 3 14:16:30 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu Nov 3 14:16:30 2016 -0700

----------------------------------------------------------------------
 hw/bsp/nucleo-f401re/nucleo-f401re_debug.sh             | 12 +-----------
 hw/bsp/nucleo-f401re/nucleo-f401re_download.sh          |  9 +--------
 .../olimex_stm32-e407_devboard_debug.sh                 | 12 +-----------
 .../olimex_stm32-e407_devboard_download.sh              |  9 +--------
 hw/bsp/stm32f4discovery/stm32f4discovery_debug.sh       | 11 +----------
 hw/bsp/stm32f4discovery/stm32f4discovery_download.sh    | 11 +----------
 6 files changed, 6 insertions(+), 58 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/68410ce4/hw/bsp/nucleo-f401re/nucleo-f401re_debug.sh
----------------------------------------------------------------------
diff --git a/hw/bsp/nucleo-f401re/nucleo-f401re_debug.sh b/hw/bsp/nucleo-f401re/nucleo-f401re_debug.sh
index 6935830..1ecd260 100755
--- a/hw/bsp/nucleo-f401re/nucleo-f401re_debug.sh
+++ b/hw/bsp/nucleo-f401re/nucleo-f401re_debug.sh
@@ -30,18 +30,8 @@
 . $CORE_PATH/hw/scripts/openocd.sh
 
 FILE_NAME=$BIN_BASENAME.elf
-OCD_CMD_FILE=.openocd_cmds
-
 CFG="-f board/st_nucleo_f4.cfg"
-
-echo "gdb_port 3333" > $OCD_CMD_FILE
-echo "telnet_port 4444" >> $OCD_CMD_FILE
 # Exit openocd when gdb detaches.
-echo "stm32f4x.cpu configure -event gdb-detach {resume;shutdown}" >> $OCD_CMD_FILE
-if [ ! -z "$EXTRA_JTAG_CMD" ]; then
-    echo "$EXTRA_JTAG_CMD" >> $OCD_CMD_FILE
-fi
+EXTRA_JTAG_CMD="$EXTRA_JTAG_CMD; stm32f4x.cpu configure -event gdb-detach {resume;shutdown}"
 
 openocd_debug
-
-rm $OCD_CMD_FILE

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/68410ce4/hw/bsp/nucleo-f401re/nucleo-f401re_download.sh
----------------------------------------------------------------------
diff --git a/hw/bsp/nucleo-f401re/nucleo-f401re_download.sh b/hw/bsp/nucleo-f401re/nucleo-f401re_download.sh
index e4e2ab9..def6af4 100755
--- a/hw/bsp/nucleo-f401re/nucleo-f401re_download.sh
+++ b/hw/bsp/nucleo-f401re/nucleo-f401re_download.sh
@@ -32,18 +32,11 @@
 . $CORE_PATH/hw/scripts/openocd.sh
 
 CFG="-f board/st_nucleo_f4.cfg"
-if [ ! -z "$EXTRA_JTAG_CMD" ]; then
-    CFG="$CFG -c $EXTRA_JTAG_CMD"
-fi
 
 if [ "$MFG_IMAGE" ]; then
     FLASH_OFFSET=0x08000000
-    FILE_NAME=$BIN_BASENAME.bin
-elif [ "$BOOT_LOADER" ]; then
-    FILE_NAME=$BIN_BASENAME.elf.bin
-else
-    FILE_NAME=$BIN_BASENAME.img
 fi
 
+common_file_to_load
 openocd_load
 openocd_reset_run

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/68410ce4/hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard_debug.sh
----------------------------------------------------------------------
diff --git a/hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard_debug.sh b/hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard_debug.sh
index 7717a11..2d8c83e 100755
--- a/hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard_debug.sh
+++ b/hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard_debug.sh
@@ -30,18 +30,8 @@
 . $CORE_PATH/hw/scripts/openocd.sh
 
 FILE_NAME=$BIN_BASENAME.elf
-OCD_CMD_FILE=.openocd_cmds
-
 CFG="-f interface/ftdi/olimex-arm-usb-tiny-h.cfg -s $BSP_PATH -f f407.cfg"
-
-echo "gdb_port 3333" > $OCD_CMD_FILE
-echo "telnet_port 4444" >> $OCD_CMD_FILE
 # Exit openocd when gdb detaches.
-echo "stm32f4x.cpu configure -event gdb-detach {resume;shutdown}" >> $OCD_CMD_FILE
-if [ ! -z "$EXTRA_JTAG_CMD" ]; then
-    echo "$EXTRA_JTAG_CMD" >> $OCD_CMD_FILE
-fi
+EXTRA_JTAG_CMD="$EXTRA_JTAG_CMD; stm32f4x.cpu configure -event gdb-detach {resume;shutdown}"
 
 openocd_debug
-
-rm $OCD_CMD_FILE

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/68410ce4/hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard_download.sh
----------------------------------------------------------------------
diff --git a/hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard_download.sh b/hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard_download.sh
index 660171f..e46b4c3 100755
--- a/hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard_download.sh
+++ b/hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard_download.sh
@@ -31,18 +31,11 @@
 . $CORE_PATH/hw/scripts/openocd.sh
 
 CFG="-f interface/ftdi/olimex-arm-usb-tiny-h.cfg -s $BSP_PATH -f f407.cfg"
-if [ ! -z "$EXTRA_JTAG_CMD" ]; then
-    CFG="$CFG -c $EXTRA_JTAG_CMD"
-fi
 
 if [ "$MFG_IMAGE" ]; then
     FLASH_OFFSET=0x08000000
-    FILE_NAME=$BIN_BASENAME.bin
-elif [ "$BOOT_LOADER" ]; then
-    FILE_NAME=$BIN_BASENAME.elf.bin
-else
-    FILE_NAME=$BIN_BASENAME.img
 fi
 
+common_file_to_load
 openocd_load
 openocd_reset_run

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/68410ce4/hw/bsp/stm32f4discovery/stm32f4discovery_debug.sh
----------------------------------------------------------------------
diff --git a/hw/bsp/stm32f4discovery/stm32f4discovery_debug.sh b/hw/bsp/stm32f4discovery/stm32f4discovery_debug.sh
index 602b764..400157b 100755
--- a/hw/bsp/stm32f4discovery/stm32f4discovery_debug.sh
+++ b/hw/bsp/stm32f4discovery/stm32f4discovery_debug.sh
@@ -30,17 +30,8 @@
 . $CORE_PATH/hw/scripts/openocd.sh
 
 FILE_NAME=$BIN_BASENAME.elf
-OCD_CMD_FILE=.openocd_cmds
-
 CFG="-s $BSP_PATH -f $BSP_PATH/f4discovery.cfg -f $OCD_CMD_FILE"
-
-echo "gdb_port 3333" > $OCD_CMD_FILE
-echo "telnet_port 4444" >> $OCD_CMD_FILE
-# Exit openocd when gdb detaches.
-echo "stm32f4x.cpu configure -event gdb-detach {resume;shutdown}" >> $OCD_CMD_FILE
-if [ ! -z "$EXTRA_JTAG_CMD" ]; then
-    echo "$EXTRA_JTAG_CMD" >> $OCD_CMD_FILE
-fi
+EXTRA_JTAG_CMD="$EXTRA_JTAG_CMD; stm32f4x.cpu configure -event gdb-detach {resume;shutdown}"
 
 openocd_debug
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/68410ce4/hw/bsp/stm32f4discovery/stm32f4discovery_download.sh
----------------------------------------------------------------------
diff --git a/hw/bsp/stm32f4discovery/stm32f4discovery_download.sh b/hw/bsp/stm32f4discovery/stm32f4discovery_download.sh
index 893efed..4eacf2a 100755
--- a/hw/bsp/stm32f4discovery/stm32f4discovery_download.sh
+++ b/hw/bsp/stm32f4discovery/stm32f4discovery_download.sh
@@ -28,23 +28,14 @@
 #  - MFG_IMAGE is "1" if this is a manufacturing image
 #  - FLASH_OFFSET contains the flash offset to download to
 #  - BOOTLOADER is set if downloading a bootloader
-set -x 
 . $CORE_PATH/hw/scripts/openocd.sh
 
 CFG="-s $BSP_PATH -f f4discovery.cfg"
 
-if [ ! -z "$EXTRA_JTAG_CMD" ]; then
-    CFG="$CFG -c $EXTRA_JTAG_CMD"
-fi
-
 if [ "$MFG_IMAGE" ]; then
-    FILE_NAME=$BIN_BASENAME.bin
     FLASH_OFFSET=0x08000000
-elif [ "$BOOT_LOADER" ]; then
-    FILE_NAME=$BIN_BASENAME.elf.bin
-else
-    FILE_NAME=$BIN_BASENAME.img
 fi
 
+common_file_to_load
 openocd_load
 openocd_reset_run


[4/5] incubator-mynewt-core git commit: MYNEWT-418; construct start script in openocd_debug().

Posted by ma...@apache.org.
MYNEWT-418; construct start script in openocd_debug().


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/5e734a36
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/5e734a36
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/5e734a36

Branch: refs/heads/develop
Commit: 5e734a361ecd25a224072c4959e52898beedf867
Parents: 513bab2
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Thu Nov 3 14:03:41 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu Nov 3 14:03:41 2016 -0700

----------------------------------------------------------------------
 hw/scripts/openocd.sh | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5e734a36/hw/scripts/openocd.sh
----------------------------------------------------------------------
diff --git a/hw/scripts/openocd.sh b/hw/scripts/openocd.sh
index 792ac07..4d6fc2e 100644
--- a/hw/scripts/openocd.sh
+++ b/hw/scripts/openocd.sh
@@ -15,6 +15,7 @@
 # specific language governing permissions and limitations
 # under the License.
 #
+. $CORE_PATH/hw/scripts/common.sh
 
 #
 # FILE_NAME must contain the name of the file to load
@@ -33,6 +34,9 @@ openocd_load () {
 	echo "Missing flash offset"
 	return 1
     fi
+    if [ ! -z "$EXTRA_JTAG_CMD" ]; then
+	CFG="$CFG -c $EXTRA_JTAG_CMD"
+    fi
 
     echo "Downloading" $FILE_NAME "to" $FLASH_OFFSET
 
@@ -40,7 +44,17 @@ openocd_load () {
     return $?
 }
 
+#
+# NO_GDB should be set if gdb should not be started
+# FILE_NAME should point to elf-file being debugged
+#
 openocd_debug () {
+    OCD_CMD_FILE=.openocd_cmds
+
+    echo "gdb_port 3333" > $OCD_CMD_FILE
+    echo "telnet_port 4444" >> $OCD_CMD_FILE
+    echo "$EXTRA_JTAG_CMD" >> $OCD_CMD_FILE
+
     if [ -z "$NO_GDB" ]; then
 	if [ -z $FILE_NAME ]; then
 	    echo "Missing filename"
@@ -55,7 +69,7 @@ openocd_debug () {
 	# Block Ctrl-C from getting passed to openocd.
 	#
 	set -m
-	openocd $CFG -c init -c halt &
+	openocd $CFG -f $OCD_CMD_FILE -c init -c halt &
 	set +m
 
     	GDB_CMD_FILE=.gdb_cmds
@@ -68,9 +82,11 @@ openocd_debug () {
 	rm $GDB_CMD_FILE
     else
 	# No GDB, wait for openocd to exit
-	openocd $CFG -c init -c halt
+	openocd $CFG -f $OCD_CMD_FILE -c init -c halt
     fi
 
+
+    rm $OCD_CMD_FILE
     return 0
 }
 


[3/5] incubator-mynewt-core git commit: MYNEWT-418; common functions to use from debug/download scripts

Posted by ma...@apache.org.
MYNEWT-418; common functions to use from debug/download scripts


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/513bab2f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/513bab2f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/513bab2f

Branch: refs/heads/develop
Commit: 513bab2f807cbdc9d05a0382c665a684e14b3967
Parents: ffe55aa
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Thu Nov 3 14:01:34 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu Nov 3 14:01:34 2016 -0700

----------------------------------------------------------------------
 hw/scripts/common.sh | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/513bab2f/hw/scripts/common.sh
----------------------------------------------------------------------
diff --git a/hw/scripts/common.sh b/hw/scripts/common.sh
new file mode 100644
index 0000000..bca3fe3
--- /dev/null
+++ b/hw/scripts/common.sh
@@ -0,0 +1,31 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you 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.
+#
+
+#
+# Which build artifact should be loaded to target
+#
+common_file_to_load () {
+    if [ "$MFG_IMAGE" ]; then
+	FILE_NAME=$BIN_BASENAME.bin
+    elif [ "$BOOT_LOADER" ]; then
+	FILE_NAME=$BIN_BASENAME.elf.bin
+    else
+	FILE_NAME=$BIN_BASENAME.img
+    fi
+}
+    


[2/5] incubator-mynewt-core git commit: MYNEWT-418; olimex - use common functions for debug/download.

Posted by ma...@apache.org.
MYNEWT-418; olimex - use common functions for debug/download.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/ffe55aae
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/ffe55aae
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/ffe55aae

Branch: refs/heads/develop
Commit: ffe55aaed24b7b5c4aaad2a11b8e1496707318da
Parents: 77a5ab4
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Thu Nov 3 12:45:10 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu Nov 3 12:45:37 2016 -0700

----------------------------------------------------------------------
 .../olimex_stm32-e407_devboard_debug.sh         | 37 +++++++-------------
 .../olimex_stm32-e407_devboard_download.sh      | 35 +++++++-----------
 2 files changed, 26 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ffe55aae/hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard_debug.sh
----------------------------------------------------------------------
diff --git a/hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard_debug.sh b/hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard_debug.sh
index 2190a9c..7717a11 100755
--- a/hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard_debug.sh
+++ b/hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard_debug.sh
@@ -18,41 +18,30 @@
 #
 
 # Called with following variables set:
+#  - CORE_PATH is absolute path to @apache-mynewt-core
 #  - BSP_PATH is absolute path to hw/bsp/bsp_name
 #  - BIN_BASENAME is the path to prefix to target binary,
 #    .elf appended to name is the ELF file
 #  - FEATURES holds the target features string
 #  - EXTRA_JTAG_CMD holds extra parameters to pass to jtag software
 #  - RESET set if target should be reset when attaching
+#  - NO_GDB set if we should not start gdb to debug
 #
-if [ -z "$BIN_BASENAME" ]; then
-    echo "Need binary to debug"
-    exit 1
-fi
-
-if [ -z "$BSP_PATH" ]; then
-    echo "Need BSP path for openocd script location"
-    exit 1
-fi
+. $CORE_PATH/hw/scripts/openocd.sh
 
 FILE_NAME=$BIN_BASENAME.elf
-GDB_CMD_FILE=.gdb_cmds
+OCD_CMD_FILE=.openocd_cmds
 
-echo "Debugging" $FILE_NAME
+CFG="-f interface/ftdi/olimex-arm-usb-tiny-h.cfg -s $BSP_PATH -f f407.cfg"
 
-#
-# Block Ctrl-C from getting passed to openocd.
+echo "gdb_port 3333" > $OCD_CMD_FILE
+echo "telnet_port 4444" >> $OCD_CMD_FILE
 # Exit openocd when gdb detaches.
-#
-set -m
-openocd -f interface/ftdi/olimex-arm-usb-tiny-h.cfg -s $BSP_PATH -f f407.cfg -c "gdb_port 3333; telnet_port 4444; stm32f4x.cpu configure -event gdb-detach {resume;shutdown}" -c "$EXTRA_JTAG_CMD" -c init -c halt &
-set +m
-
-echo "target remote localhost:3333" > $GDB_CMD_FILE
-# Whether target should be reset or not
-if [ ! -z "$RESET" ]; then
-    echo "mon reset halt" >> $GDB_CMD_FILE
+echo "stm32f4x.cpu configure -event gdb-detach {resume;shutdown}" >> $OCD_CMD_FILE
+if [ ! -z "$EXTRA_JTAG_CMD" ]; then
+    echo "$EXTRA_JTAG_CMD" >> $OCD_CMD_FILE
 fi
 
-arm-none-eabi-gdb -x $GDB_CMD_FILE $FILE_NAME
-rm $GDB_CMD_FILE
+openocd_debug
+
+rm $OCD_CMD_FILE

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ffe55aae/hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard_download.sh
----------------------------------------------------------------------
diff --git a/hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard_download.sh b/hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard_download.sh
index 7c52f6b..660171f 100755
--- a/hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard_download.sh
+++ b/hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard_download.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 # Licensed to the Apache Software Foundation (ASF) under one
 # or more contributor license agreements.  See the NOTICE file
 # distributed with this work for additional information
@@ -17,7 +17,7 @@
 # under the License.
 #
 
-# Called with following variables set:
+#  - CORE_PATH is absolute path to @apache-mynewt-core
 #  - BSP_PATH is absolute path to hw/bsp/bsp_name
 #  - BIN_BASENAME is the path to prefix to target binary,
 #    .elf appended to name is the ELF file
@@ -25,33 +25,24 @@
 #  - FEATURES holds the target features string
 #  - EXTRA_JTAG_CMD holds extra parameters to pass to jtag software
 #  - MFG_IMAGE is "1" if this is a manufacturing image
+#  - FLASH_OFFSET contains the flash offset to download to
+#  - BOOTLOADER is set if downloading a bootloader
 
-if [ -z "$BIN_BASENAME" ]; then
-    echo "Need binary to download"
-    exit 1
-fi
-
-IS_BOOTLOADER=0
+. $CORE_PATH/hw/scripts/openocd.sh
 
-# Look for 'bootloader' in FEATURES
-for feature in $FEATURES; do
-    if [ $feature == "BOOT_LOADER" ]; then
-        IS_BOOTLOADER=1
-    fi
-done
+CFG="-f interface/ftdi/olimex-arm-usb-tiny-h.cfg -s $BSP_PATH -f f407.cfg"
+if [ ! -z "$EXTRA_JTAG_CMD" ]; then
+    CFG="$CFG -c $EXTRA_JTAG_CMD"
+fi
 
 if [ "$MFG_IMAGE" ]; then
-    FLASH_OFFSET=0x0
-    FILE_NAME=$BIN_BASENAME.bin
-elif [ $IS_BOOTLOADER -eq 1 ]; then
     FLASH_OFFSET=0x08000000
+    FILE_NAME=$BIN_BASENAME.bin
+elif [ "$BOOT_LOADER" ]; then
     FILE_NAME=$BIN_BASENAME.elf.bin
 else
-    FLASH_OFFSET=0x08020000
     FILE_NAME=$BIN_BASENAME.img
 fi
 
-echo "Downloading" $FILE_NAME "to" $FLASH_OFFSET
-
-openocd -f interface/ftdi/olimex-arm-usb-tiny-h.cfg -s $BSP_PATH -f f407.cfg -c "$EXTRA_JTAG_CMD" -c init -c "reset halt" -c "flash write_image erase $FILE_NAME $FLASH_OFFSET" -c "reset run" -c shutdown
-
+openocd_load
+openocd_reset_run