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/04 04:38:03 UTC
[05/13] incubator-mynewt-core git commit: MYNEWT-418;
common functions for download/debug with JLink.
MYNEWT-418; common functions for download/debug with JLink.
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/6ba3b4bd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/6ba3b4bd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/6ba3b4bd
Branch: refs/heads/develop
Commit: 6ba3b4bd9df352798820ab60d596f4174a408ab9
Parents: 9112760
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Thu Nov 3 15:30:54 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu Nov 3 21:32:01 2016 -0700
----------------------------------------------------------------------
hw/scripts/jlink.sh | 127 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 127 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6ba3b4bd/hw/scripts/jlink.sh
----------------------------------------------------------------------
diff --git a/hw/scripts/jlink.sh b/hw/scripts/jlink.sh
new file mode 100644
index 0000000..542b63d
--- /dev/null
+++ b/hw/scripts/jlink.sh
@@ -0,0 +1,127 @@
+# 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.
+
+. $CORE_PATH/hw/scripts/common.sh
+
+#
+# FILE_NAME is the file to load
+# FLASH_OFFSET is location in the flash
+# JLINK_DEV is what we tell JLinkGDBServer this device to be
+#
+jlink_load () {
+ GDB_CMD_FILE=.gdb_cmds
+ GDB_OUT_FILE=.gdb_out
+
+ 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" $FLASH_OFFSET
+
+ # XXX for some reason JLinkExe overwrites flash at offset 0 when
+ # downloading somewhere in the flash. So need to figure out how to tell it
+ # not to do that, or report failure if gdb fails to write this file
+ #
+ echo "shell /bin/sh -c 'trap \"\" 2;JLinkGDBServer -device $JLINK_DEV -speed 4000 -if SWD -port 3333 -singlerun' & " > $GDB_CMD_FILE
+ echo "target remote localhost:3333" >> $GDB_CMD_FILE
+ echo "mon reset" >> $GDB_CMD_FILE
+ echo "restore $FILE_NAME binary $FLASH_OFFSET" >> $GDB_CMD_FILE
+ echo "quit" >> $GDB_CMD_FILE
+
+ msgs=`arm-none-eabi-gdb -x $GDB_CMD_FILE 2>&1`
+ echo $msgs > $GDB_OUT_FILE
+
+# rm $GDB_CMD_FILE
+
+ # Echo output from script run, so newt can show it if things go wrong.
+ echo $msgs
+
+ error=`echo $msgs | grep error`
+ if [ -n "$error" ]; then
+ return 1
+ fi
+
+ error=`echo $msgs | grep -i failed`
+ if [ -n "$error" ]; then
+ return 1
+ fi
+
+ error=`echo $msgs | grep -i "unknown / supported"`
+ if [ -n "$error" ]; then
+ return 1
+ fi
+
+ error=`echo $msgs | grep -i "not found"`
+ if [ -n "$error" ]; then
+ return 1
+ fi
+
+ return 0
+}
+
+#
+# FILE_NAME is the file to debug
+# NO_GDB is set if we should not start gdb
+# JLINK_DEV is what we tell JLinkGDBServer this device to be
+# EXTRA_GDB_CMDS is for extra commands to pass to gdb
+# RESET is set if we should reset the target at attach time
+#
+jlink_debug() {
+ if [ -z "$NO_GDB" ]; then
+ GDB_CMD_FILE=.gdb_cmds
+
+ if [ -z $FILE_NAME ]; then
+ echo "Missing filename"
+ return 1
+ fi
+ if [ ! -f "$FILE_NAME" ]; then
+ echo "Cannot find file" $FILE
+ return 1
+ fi
+
+ echo "Debugging" $FILE_NAME
+
+ # Monitor mode. Background process gets it's own process group.
+ set -m
+ JLinkGDBServer -device $JLINK_DEV -speed 4000 -if SWD -port 3333 -singlerun > /dev/null &
+ set +m
+
+ echo "target remote localhost:3333" > $GDB_CMD_FILE
+ # Whether target should be reset or not
+ if [ ! -z "$RESET" ]; then
+ echo "mon reset" >> $GDB_CMD_FILE
+ echo "si" >> $GDB_CMD_FILE
+ fi
+ echo "$EXTRA_GDB_CMDS" >> $GDB_CMD_FILE
+
+ arm-none-eabi-gdb -x $GDB_CMD_FILE $FILE_NAME
+
+ rm $GDB_CMD_FILE
+ else
+ JLinkGDBServer -device $JLINK_DEV -speed 4000 -if SWD -port 3333 -singlerun
+ fi
+ return 0
+}