diff options
author | Tom Hughes <tomhughes@chromium.org> | 2020-04-24 10:51:11 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-05-05 01:59:40 +0000 |
commit | 4574908d30b789e049ade2dee80678b8da4f2c6b (patch) | |
tree | 009d65d1ef9f26a67e213956d09271e83025a390 | |
parent | a4820cc7079cffc315c04b792429f6392b193b20 (diff) | |
download | chrome-ec-4574908d30b789e049ade2dee80678b8da4f2c6b.tar.gz |
util: Add support to auto-flash with Segger J-Link gdbserver
Automatically flash the EC binary when running gdb combined with Segger
J-Link gdbserver and JTrace.
For most code changes, the flashing only takes a 10-20 seconds.
Also updated FPMCU debugging docs to mention the gdbinit.
BRANCH=none
BUG=none
TEST=On machine with dragonclaw attached to J-Trace:
JLink_Linux_V670e_x86_64/JLinkGDBServerCLExe
-select USB -device STM32F412CG -endian little -if SWD
-speed auto -noir -noLocalhostOnly
BOARD=bloonchipper GDBSERVER=segger
gdb --ex "target remote 127.0.0.1:2331"
TEST=Same as above, but using CLion for gdb as described in
https://chromium.googlesource.com/chromiumos/platform/ec/+/refs/heads/master/docs/fingerprint/fingerprint-debugging.md
and setting USING_CLION=FALSE
Signed-off-by: Tom Hughes <tomhughes@chromium.org>
Change-Id: I88440c0bc8c9b170b239335a33b3c0a0387447f2
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2166143
Reviewed-by: Craig Hesling <hesling@chromium.org>
-rw-r--r-- | docs/fingerprint/fingerprint-debugging.md | 17 | ||||
-rw-r--r-- | util/gdbinit | 52 |
2 files changed, 59 insertions, 10 deletions
diff --git a/docs/fingerprint/fingerprint-debugging.md b/docs/fingerprint/fingerprint-debugging.md index f5d9760049..84832e38b6 100644 --- a/docs/fingerprint/fingerprint-debugging.md +++ b/docs/fingerprint/fingerprint-debugging.md @@ -27,9 +27,9 @@ used for JTAG and SWD for ARM devices. ## Software Required -* [JLink Software] (when using [J-Trace] or other Segger debug probes). +* [JLink Software] \(when using [J-Trace] or other Segger debug probes). * Any tool that supports connecting `gdbserver`. This document will assume - [CLion]. + [CLion] and was tested with `JLink_Linux_V670e_x86_64`. * Alternatively, you can use [Ozone] a standalone debugger from Segger. ## Connecting SWD @@ -76,7 +76,7 @@ Start the JLink gdbserver for the appropriate MCU type: * Dragontalon / [Nucleo STM32H743ZI]: `STM32H743ZI` ```bash -(outside) $ ./JLink_Linux_V660c_x86_64/JLinkGDBServerCLExe -select USB -device STM32F412CG -endian little -if SWD -speed auto -noir -noLocalhostOnly +(outside) $ ./JLink_Linux_V670e_x86_64/JLinkGDBServerCLExe -select USB -device STM32F412CG -endian little -if SWD -speed auto -noir -noLocalhostOnly ``` You should see the port that gdbserver is running on in the output: @@ -96,13 +96,18 @@ Connected to target Waiting for GDB connection... ``` -In your editor, specify the IP address and port for gdbserver: +Configure your editor to use this [`.gdbinit`], taking care to set the correct +environment variables for the `BOARD` and `GDBSERVER` being used. For CLion, if +you want to use a `.gdbinit` outside of your `HOME` directory, you'll need to +[configure `~/.gdbinit`]. + +In your editor, specify the IP address and port for `gdbserver`: ``` 127.0.0.1:2331 ``` -You will also want to provide the symbol file: +You will also want to provide the symbol files: * RW image: `build/<board>/RW/ec.RW.elf` * RO image: `build/<board>/RO.ec.RO.elf` @@ -155,6 +160,8 @@ STM32F412 package that does not have the synchronous trace pins, but the [CLion Start Remote Debug]: https://www.jetbrains.com/help/clion/remote-debug.html#start-remote-debug [Nucleo STM32F412ZG]: https://www.st.com/en/evaluation-tools/nucleo-f412zg.html [Nucleo STM32H743ZI]: https://www.st.com/en/evaluation-tools/nucleo-h743zi.html +[`.gdbinit`]: /util/gdbinit +[configure `~/.gdbinit`]: https://www.jetbrains.com/help/clion/configuring-debugger-options.html#gdbinit-lldbinit <!-- Images --> diff --git a/util/gdbinit b/util/gdbinit index b40137c5a1..f82afa699d 100644 --- a/util/gdbinit +++ b/util/gdbinit @@ -26,27 +26,66 @@ # Environment Setup and Initialization # ##################################################################### +set verbose on + +# Start of python code + # Setup environment and pull in object files for the particular BOARD. # This requires setting the environment variables mentioned above. python +import distutils.util import os BOARD = os.getenv('BOARD', '') GDBSERVER = os.getenv('GDBSERVER', 'openocd') -GDBPORT = os.getenv('GDBPORT', '3333') +USING_CLION = distutils.util.strtobool(os.getenv('USING_CLION', 'FALSE')) + +if GDBSERVER == "openocd": + DEFAULT_GDB_PORT = '3333' +else: + DEFAULT_GDB_PORT = '2331' + +GDBPORT = os.getenv('GDBPORT', DEFAULT_GDB_PORT) + +EC_DIR = os.getenv('EC_DIR', os.path.join(os.getenv('HOME'), + 'chromiumos/src/platform/ec')) + +if not os.path.isdir(EC_DIR): + print('Error - EC_DIR "' + EC_DIR + '" doesn\'t exist. Aborting.') + gdb.execute('quit') + +# Monitor commands must be run after connecting to the remote target +# See https://stackoverflow.com/a/39828850 +# https://youtrack.jetbrains.com/issue/CPP-7322 +# https://sourceware.org/gdb/onlinedocs/gdb/Hooks.html +post_remote_hook=''' +define target hookpost-remote + echo \ Flashing EC binary + load {EC_DIR}/build/{BOARD}/ec.obj + echo \ Resetting target + monitor reset + echo \ Halting target + monitor halt + echo \ Setting breakpoint on main + b main +end\n +'''.format(BOARD=BOARD, EC_DIR=EC_DIR) + gdb.execute('set $BOARD = "%s"'%BOARD) gdb.execute('set $GDBSERVER = "%s"'%GDBSERVER) gdb.execute('set $GDBPORT = "%s"'%GDBPORT) -build = 'build/' + BOARD +build = os.path.join(EC_DIR, 'build', BOARD) if BOARD != "": if not os.path.isdir(build): print('Error - Build path "' + build + '" doesn\'t exist. Aborting.') gdb.execute('quit') - gdb.execute('file ' + build + '/ec.obj') - gdb.execute('add-symbol-file ' + build + '/RO/ec.RO.elf') - gdb.execute('add-symbol-file ' + build + '/RW/ec.RW.elf') + # When using gdb from CLion, this kills gdb. + if not USING_CLION: + gdb.execute('file ' + os.path.join(build, 'ec.obj')) + gdb.execute('add-symbol-file ' + os.path.join(build, 'RO/ec.RO.elf')) + gdb.execute('add-symbol-file ' + os.path.join(build, 'RW/ec.RW.elf')) if GDBSERVER == "openocd": gdb.execute('set $GDBSERVER_OPENOCD = 1') @@ -54,9 +93,12 @@ if GDBSERVER == "openocd": elif GDBSERVER == "segger": gdb.execute('set $GDBSERVER_OPENOCD = 0') gdb.execute('set $GDBSERVER_SEGGER = 1') + gdb.execute(post_remote_hook) else: print('Error - GDBSERVER="' + GDBSERVER + '" is invalid.') gdb.execute('quit') + +# End of python code end # OpenOCD specific config |