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 19:12:15 UTC
incubator-mynewt-core git commit: MYNEWT-418;
have common code for targets using openocd.
Repository: incubator-mynewt-core
Updated Branches:
refs/heads/develop 13c9cc8df -> af3e2035e
MYNEWT-418; have common code for targets using openocd.
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/af3e2035
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/af3e2035
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/af3e2035
Branch: refs/heads/develop
Commit: af3e2035e6907571819771b005687ceed8aca1f1
Parents: 13c9cc8
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Thu Nov 3 12:10:56 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu Nov 3 12:10:56 2016 -0700
----------------------------------------------------------------------
.../stm32f4discovery/stm32f4discovery_debug.sh | 36 +++------
.../stm32f4discovery_download.sh | 33 +++-----
hw/scripts/openocd.sh | 85 ++++++++++++++++++++
3 files changed, 111 insertions(+), 43 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/af3e2035/hw/bsp/stm32f4discovery/stm32f4discovery_debug.sh
----------------------------------------------------------------------
diff --git a/hw/bsp/stm32f4discovery/stm32f4discovery_debug.sh b/hw/bsp/stm32f4discovery/stm32f4discovery_debug.sh
index 20a5a3b..602b764 100755
--- a/hw/bsp/stm32f4discovery/stm32f4discovery_debug.sh
+++ b/hw/bsp/stm32f4discovery/stm32f4discovery_debug.sh
@@ -18,40 +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="-s $BSP_PATH -f $BSP_PATH/f4discovery.cfg -f $OCD_CMD_FILE"
-#
-# 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 -s $BSP_PATH -f f4discovery.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
-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/af3e2035/hw/bsp/stm32f4discovery/stm32f4discovery_download.sh
----------------------------------------------------------------------
diff --git a/hw/bsp/stm32f4discovery/stm32f4discovery_download.sh b/hw/bsp/stm32f4discovery/stm32f4discovery_download.sh
index ee6d352..893efed 100755
--- a/hw/bsp/stm32f4discovery/stm32f4discovery_download.sh
+++ b/hw/bsp/stm32f4discovery/stm32f4discovery_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
@@ -18,6 +18,7 @@
#
# 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 +26,25 @@
# - 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
+set -x
+. $CORE_PATH/hw/scripts/openocd.sh
-if [ -z "$BIN_BASENAME" ]; then
- echo "Need binary to download"
- exit 1
-fi
-
-IS_BOOTLOADER=0
+CFG="-s $BSP_PATH -f f4discovery.cfg"
-# Look for 'BOOT_LOADER' in FEATURES
-for feature in $FEATURES; do
- if [ $feature == "BOOT_LOADER" ]; then
- IS_BOOTLOADER=1
- fi
-done
+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
+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 openocd -s $BSP_PATH -f f4discovery.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
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/af3e2035/hw/scripts/openocd.sh
----------------------------------------------------------------------
diff --git a/hw/scripts/openocd.sh b/hw/scripts/openocd.sh
new file mode 100644
index 0000000..118e1bc
--- /dev/null
+++ b/hw/scripts/openocd.sh
@@ -0,0 +1,85 @@
+# 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.
+#
+
+#
+# FILE_NAME must contain the name of the file to load
+# FLASH_OFFSET must contain the offset in flash where to place it
+#
+openocd_load () {
+ if [ -z $FILE_NAME ]; then
+ echo "Missing filename"
+ return 1
+ fi
+ if [ ! -f "$FILE_NAME" ]; then
+ echo "Cannot find file" $FILE
+ return 1
+ fi
+ if [ -z $FLASH_OFFSET ]; then
+ echo "Missing flash offset"
+ return 1
+ fi
+
+ echo "Downloading" $FILE_NAME "to" $OFF
+
+ openocd $CFG -c init -c "reset halt" -c "flash write_image erase $FILE_NAME $FLASH_OFFSET" -c shutdown
+ return $?
+}
+
+openocd_debug () {
+ if [ -z "$NO_GDB" ]; then
+ if [ -z $FILE_NAME ]; then
+ echo "Missing filename"
+ return 1
+ fi
+ if [ ! -f "$FILE_NAME" ]; then
+ echo "Cannot find file" $FILE_NAME
+ return 1
+ fi
+
+ #
+ # Block Ctrl-C from getting passed to openocd.
+ #
+ set -m
+ openocd $CFG -c init -c halt &
+ set +m
+
+ GDB_CMD_FILE=.gdb_cmds
+
+ echo "target remote localhost:3333" > $GDB_CMD_FILE
+ if [ ! -z "$RESET" ]; then
+ echo "mon reset halt" >> $GDB_CMD_FILE
+ fi
+ arm-none-eabi-gdb -x $GDB_CMD_FILE $FILE_NAME
+ rm $GDB_CMD_FILE
+ else
+ # No GDB, wait for openocd to exit
+ openocd $CFG -c init -c halt
+ fi
+
+ return 0
+}
+
+openocd_halt () {
+ openocd $CFG -c init -c "halt" -c shutdown
+ return $?
+}
+
+openocd_reset_run () {
+ openocd $CFG -c init -c "reset run" -c shutdown
+ return $?
+}